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

	$objOperator = new OperatorMgmt();
	
	$objOperator->operator_id              		= $_REQUEST["operator_id"] ;
	$objOperator->operator_name					= $_REQUEST['operator_name'] ;
	$objOperator->operator_address			= $_REQUEST['operator_address'];
	$objOperator->operator_phone				= $_REQUEST['operator_phone'];
	$objOperator->operator_mobile				= $_REQUEST['operator_mobile'];
	$objOperator->operator_email				= $_REQUEST['operator_email'];
	$objOperator->operator_panno		    = $_REQUEST['operator_panno'] ;
	$objOperator->operator_aadharno			= $_REQUEST['operator_aadharno'] ;
	$objOperator->operator_otherid			= $_REQUEST['operator_otherid'] ;
	$objOperator->operator_joindate			= $_REQUEST['operator_joindate'] ;
	$objOperator->company_id              		= $_SESSION["cCompany_id"] ;
	
	$objOperator->operator_code		    = $_REQUEST['operator_code'] ;
	$objOperator->account_no			= $_REQUEST['account_no'] ;
	$objOperator->bank_name			= $_REQUEST['bank_name'] ;
	$objOperator->branch_name			= $_REQUEST['branch_name'] ;
	$objOperator->ifsc_code			= $_REQUEST['ifsc_code'] ;
	
	if($objOperator->operator_id=="0"){
		$objOperator->add();						
	}
	else{
		$objOperator->edit();												
	}
	
	if ($objOperator->operator_id!="0"){							
	
			$operator_id = $objOperator->operator_id;
			
			$FileName = $_REQUEST["operator_photo"];
			
			if($FileName!="" && $FileName!="default.gif") {
							
			$Ext = substr($FileName, strrpos($FileName, ".")+1);
			$Ext = strtolower($Ext);
		
			$thumbimg = "operator_" . $operator_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);
			}
			
			$objOperator->operator_photo = $thumbimg;
			$objOperator->updatePhoto();			
		}
	}
	
	echo '{"success":"true","msg":""}';
}
else {
	echo '{"success":"false","msg":"session expiry"}';
}	         
?>