<?php  
	require "commonincludefiles.php";
	
	if($_SESSION["cCompany_id"]!="" && isset($_SESSION["cCompany_id"]))
	{
		$objcompanyMgmt = new companyMgmt();
	
		$objcompanyMgmt->company_id				=$_POST['company_id'];
		$objcompanyMgmt->company_name			=$_POST['company_name'];		
		$objcompanyMgmt->company_address		=$_POST['company_address'];
		$objcompanyMgmt->company_phone			=$_POST['comapny_phoneno'];
		$objcompanyMgmt->company_fax			=$_POST['company_fax'];
		$objcompanyMgmt->company_email			=$_POST['company_emailid'];
		$objcompanyMgmt->company_website		=$_POST['company_url'];
		
		$objcompanyMgmt->company_tinno    		=$_POST['company_tinno'];
		$objcompanyMgmt->company_cstno 			=$_POST['company_cstno'];
		$objcompanyMgmt->company_servicetaxno 	=$_POST['company_servicetaxno'];
		$objcompanyMgmt->company_panno 			=$_POST['company_panno'];

		$objcompanyMgmt->company_regno	=$_POST['register_no'];
		$objcompanyMgmt->company_description =$_POST['company_disciption'];
		$objcompanyMgmt->company_slogan=$_POST['company_slogan'];
		
		$_SESSION["cCompany_name"]=$_POST['company_name'];
		$_SESSION["cCompany_address"]=$_POST['company_address'];
	
		if($objcompanyMgmt->company_id=="0"){
		
			$objcompanyMgmt->add();
			
		}
		else{		
			$objcompanyMgmt->edit();
		}
		if ($objcompanyMgmt->company_id!="0") 
		{							
	
			$company_id = $objcompanyMgmt->company_id;
			
			$FileName = $_REQUEST["company_photo"];
			
			if($FileName!="" && $FileName!="default.gif") 
			{
							
					$Ext = substr($FileName, strrpos($FileName, ".")+1);
					$Ext = strtolower($Ext);
				
					$thumbimg = "company_" . $company_id . "." . $Ext;
					$newCompanyImagePath=$SiteImagePath.$company_id."/";
					$thumbimg_path =$newCompanyImagePath.$thumbimg;																							
					
					if (file_exists($thumbimg_path)) {
						unlink($thumbimg_path);
					}
					
					copy($CompanyImagePath.$FileName, $thumbimg_path);
					
					$file_path=realpath($thumbimg_path);
					chmod($file_path, 0777);			
					
					if (file_exists($CompanyImagePath.$FileName)) {
						unlink($CompanyImagePath.$FileName);
					}
					
					$objcompanyMgmt->company_logo = $thumbimg;
					$objcompanyMgmt->updatePhoto();			
					//$_SESSION['aSchoolPhoto'] = $thumbimg;
			}						
			//$_SESSION['aCompanyName'] = $objcompanyMgmt->company_name;
		}
		
		echo '{"success":"true"}';
	}
	else{
		echo '{"success":"false","msg":"session expiry"}';
	}
?>