<?php  
	require "commonincludefiles.php";
	
	if($_SESSION["VedantnrCollegeId"]!="" && isset($_SESSION["VedantnrCollegeId"]))
	{
		$objCollege = new CollegeMgmt();
		$objCollege->college_id			= $_POST['college_id'];
		$objCollege->college_name		= $_POST['college_name'];
		$objCollege->college_address	= $_POST['college_address'];
		$objCollege->college_phone		= $_POST['college_phone'];
		$objCollege->college_email		= $_POST['college_email'];
		$objCollege->college_url		= $_POST['college_url'];
		$objCollege->college_logo		= $_POST['college_logo'];
		
		if($objCollege->college_id == "0"){
			$objCollege->add();
		}
		else{			
			$objCollege->edit();
		}
		
		if($objCollege->college_id!="0"){
			$college_id = $objCollege->college_id;
			$FileName = $_REQUEST["college_logo"];
			if($FileName!="" && $FileName!="default.gif"){
				$Ext = substr($FileName, strrpos($FileName, ".")+1);
				$Ext = strtolower($Ext);
				
				$thumbimg = "college_" . $college_id . "." . $Ext;
				$thumbimg_path = $CollegeImagePath . $thumbimg;

				if(file_exists($thumbimg_path)){
					unlink($thumbimg_path);
				}
					
				copy($CollegeImagePath.$FileName, $thumbimg_path);
				$file_path = realpath($thumbimg_path);
				chmod($file_path, 0777);			
					
				if(file_exists($CollegeImagePath.$FileName)){
					unlink($CollegeImagePath.$FileName);
				}
					
				$objCollege->college_logo = $thumbimg;
				$objCollege->updatePhoto();			
				$_SESSION['aCollegeLogo'] = $thumbimg;
			}						
			
			$_SESSION['aCollegeName'] = $objCollege->college_name;
			$_SESSION['aCollegeAddress'] = $objCollege->college_address;
			$_SESSION['aCollegePhone'] = $objCollege->college_phone;
			$_SESSION['aCollegeEmail'] = $objCollege->college_email;
			$_SESSION['aCollegeUrl'] = $objCollege->college_url;
		}
		
		echo '{"success":"true"}';
	}
	else{
		echo '{"success":"false","msg":"session expiry"}';
	}
?>