<?php  
	require "commonincludefiles.php";
	
	if($_SESSION["VedantnrSchoolId"]!="" && isset($_SESSION["VedantnrSchoolId"]))
	{
		$objSchool = new SchoolMgmt();
		$objSchool->school_id				=$_POST['school_id'];
		$objSchool->school_name				=$_POST['school_name'];	
		$objSchool->school_type				=$_POST['school_type'];		
		$objSchool->school_address			=$_POST['school_address'];
		$objSchool->school_district			=$_POST['dist_code1'];
		$objSchool->school_taluka			=$_POST['hidtaluka_id'];
		$objSchool->school_city			    =$_POST['school_city'];
		$objSchool->school_phone1			=$_POST['school_phone1'];
		$objSchool->school_phone2			=$_POST['school_phone2'];
		$objSchool->school_fax				=$_POST['school_fax'];
		$objSchool->school_emailid			=$_POST['school_emailid'];
		$objSchool->school_url				=$_POST['school_url'];
		$objSchool->school_location			=$_POST['school_location'];
		$objSchool->school_population		=$_POST['school_population'];
		$objSchool->school_ward				=$_POST['school_ward'];
		$objSchool->school_t_distance		=$_POST['school_t_distance'];
		$objSchool->schoo_d_distance		=$_POST['schoo_d_distance'];
		$objSchool->school_legislative		=$_POST['hidleg_id'];
		$objSchool->school_parlament		=$_POST['hidpar_id'];
		$objSchool->school_salarycompuno	=$_POST['school_salarycompuno'];
		$objSchool->school_sscindex			=$_POST['school_sscindex'];
		$objSchool->school_hscindex			=$_POST['school_hscindex'];
		$objSchool->school_svsno			=$_POST['hidsvs_id'];
		$objSchool->school_qdcno			=$_POST['school_qdcno'];
		$objSchool->school_admtype			=$_POST['school_admtype'];
		$objSchool->school_shiftbase		=$_POST['school_shiftbase'];
		$objSchool->school_softwareversion	=$_POST['soft_ver_hidden'];
		$objSchool->school_matrixgrade		=$_POST['school_matrixgrade'];
		$objSchool->school_activitygrade	=$_POST['school_activitygrade'];
		$objSchool->school_sscgrade			=$_POST['school_sscgrade'];
		$objSchool->school_hscgrade			=$_POST['school_hscgrade'];
		$objSchool->school_edutype			=$_POST['school_edutype']; 
		$objSchool->school_building			=$_POST['school_building'];
		$objSchool->school_grant			=$_POST['school_grant'];
		$objSchool->jila_seat	        	=$_POST['jila_seat'];
		$objSchool->taluka_seat	        	=$_POST['taluka_seat'];
		$objSchool->area_type				=$_POST['area_type'];
		$objSchool->building_location		=$_POST['building_location'];
		$objSchool->school_rent				=$_POST['school_rent']; 
		$objSchool->school_owneradd			=$_POST['school_owneradd'];
		$objSchool->school_rent				=$_POST['school_rent'];
		
	
		if($objSchool->school_id=="0"){
		
			$objSchool->add();
			
		}
		else{			
			$objSchool->edit();
		}
		if ($objSchool->school_id!="0") 
		{	
			$school_id = $objSchool->school_id;
			$FileName = $_REQUEST["school_photo"];
			$temp = "school_".$_SESSION["VedantnrSchoolId"].".jpg";
			if($FileName!="" && $FileName!="default.gif" && $FileName!=$temp) 
			{
							
					$Ext = substr($FileName, strrpos($FileName, ".")+1);
					$Ext = strtolower($Ext);
				
					$thumbimg = "school_" . $school_id . "." . $Ext;
					$thumbimg_path = $SchoolImagePath . $thumbimg;																							
					
					if (file_exists($thumbimg_path)) {
						unlink($thumbimg_path);
					}
					
					copy($SchoolImagePath.$FileName, $thumbimg_path);
					
					$file_path=realpath($thumbimg_path);
					chmod($file_path, 0777);			
					
					if (file_exists($SchoolImagePath.$FileName)) {
						unlink($SchoolImagePath.$FileName);
					}
					
					$objSchool->school_photo = $thumbimg;
					$objSchool->updatePhoto();			
					$_SESSION['aSchoolPhoto'] = $thumbimg;
			}						
			$_SESSION['aSchoolName'] = $objSchool->school_name;
		}
		
		echo '{"success":"true"}';
	}
	else{
		echo '{"success":"false","msg":"session expiry"}';
	}
?>