<?php  
require "commonincludefiles.php";
if($_SESSION["cCompany_id"]!="" && isset($_SESSION["cCompany_id"]))
{

	$objEmployee = new EmployeeMgmt();
	
	$objEmployee->employee_id              		= $_REQUEST["employee_id"] ;
	$objEmployee->employee_name					= $_REQUEST['employee_name'] ;
	$objEmployee->employee_address			= $_REQUEST['employee_address'];
	$objEmployee->employee_phone				= $_REQUEST['employee_phone'];
	$objEmployee->employee_mobile				= $_REQUEST['employee_mobile'];
	$objEmployee->employee_email				= $_REQUEST['employee_email'];
	$objEmployee->employee_salary		    = $_REQUEST['employee_salary'] ;
	$objEmployee->employee_birthdate			= $_REQUEST['employee_birthdate'] ;
	$objEmployee->employee_joindate			= $_REQUEST['employee_joindate'] ;
	$objEmployee->designation_id			= $_REQUEST['employeedesignation'] ;
	$objEmployee->company_id              		= $_SESSION["cCompany_id"] ;
	
	if($objEmployee->employee_id=="0"){
		$objEmployee->add();						
	}
	else{
		$objEmployee->edit();												
	}
	
	if ($objEmployee->employee_id!="0"){							
	
			$employee_id = $objEmployee->employee_id;
			
			$FileName = $_REQUEST["employee_photo"];
			
			if($FileName!="" && $FileName!="default.gif") {
							
			$Ext = substr($FileName, strrpos($FileName, ".")+1);
			$Ext = strtolower($Ext);
		
			$thumbimg = "employee_" . $employee_id . "." . $Ext;
			$thumbimg_path = $EmployeeImagePath . $thumbimg;																							
			
			if (file_exists($thumbimg_path)) {
				unlink($thumbimg_path);
			}
			
			copy($EmployeeImagePath.$FileName, $thumbimg_path);
			
			$file_path=realpath($thumbimg_path);
			chmod($file_path, 0777);			
			
			if (file_exists($EmployeeImagePath.$FileName)) {
				unlink($EmployeeImagePath.$FileName);
			}
			
			$objEmployee->employee_photo = $thumbimg;
			$objEmployee->updatePhoto();			
		}
	}
	
	echo '{"success":"true","msg":""}';
}
else {
	echo '{"success":"false","msg":"session expiry"}';
}	         
?>