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

	
	$objEmployee = new EmployeeMgmt();
	$objEmployee->employee_id              		= $_REQUEST["employee_id"] ;
	$objEmployee->college_id              		= $_SESSION["VedantnrCollegeId"] ;
	$objEmployee->employee_salaryno				= $_REQUEST['employee_salaryno'];
	$objEmployee->employee_no				= $_REQUEST['employee_no'];
	$objEmployee->employee_name					= ucwords(strtolower($_REQUEST['employee_name'])) ;
	$objEmployee->branch_id					= $_REQUEST['branch_id_hid'] ;
	$objEmployee->employee_designation			= $_REQUEST['employeedesignation'] ;
	$objEmployee->employee_category				= $_REQUEST['employee_category'] ;
	$objEmployee->employee_gender				= $_REQUEST['employee_gender'] ;
	$objEmployee->employee_ishandicap			= $_REQUEST['employee_ishandicap'] ;
	$objEmployee->employee_birthdate			= $_REQUEST['employee_birthdate'] ;
	$objEmployee->employee_regularorfixpay		= $_REQUEST['employee_regularorfixpay'] ;
	$objEmployee->employee_panno				= $_REQUEST['employee_panno'] ;
	$objEmployee->employee_gpfacno				= $_REQUEST['employee_gpfacno'] ;
	$objEmployee->employee_bankacno				= $_REQUEST['employee_bankacno'] ;
	$objEmployee->employee_isteaching			= $_REQUEST['employee_isteaching'] ;
	$objEmployee->employee_deptjoindate			= $_REQUEST['employee_deptjoindate'] ;
	$objEmployee->employee_schooljoindate		= $_REQUEST['employee_schooljoindate'] ;
	$objEmployee->employee_payscale				= $_REQUEST['payscale_id'];
	$objEmployee->employee_basicsalary		    = $_REQUEST['employee_basicsalary'] ;
	$objEmployee->employee_incrdate				= $_REQUEST['employee_incrdate'] ;
	$objEmployee->employee_eduqualification     = $_REQUEST['employee_eduqualification'] ;   	   
	$objEmployee->employee_edusub				= $_REQUEST['employee_edusub'] ;
	$objEmployee->employee_eduuni				= $_REQUEST['employee_eduuni'] ;
	$objEmployee->employee_eduyear				= $_REQUEST['employee_eduyear'] ;
	$objEmployee->employee_eduobtclass			= $_REQUEST['employee_eduobtclass'];
	$objEmployee->employee_profqualification	= $_REQUEST['employee_profqualification'] ;
	$objEmployee->employee_profsub				= $_REQUEST['employee_profsub'] ;
	$objEmployee->employee_profuni				= $_REQUEST['employee_profuni'] ;
	$objEmployee->employee_profyear				= $_REQUEST['employee_profyear'];
	$objEmployee->employee_profobtclass	    	= $_REQUEST['employee_profobtclass'];
	$objEmployee->employee_otherqualification	= $_REQUEST['employee_otherqualification'] ;
	$objEmployee->employee_othersub				= $_REQUEST['employee_othersub'] ;
	$objEmployee->employee_otheruni				= $_REQUEST['employee_otheruni']  ;
	$objEmployee->employee_otheryear			= $_REQUEST['employee_otheryear'];
	$objEmployee->employee_otherobtclass		= $_REQUEST['employee_otherobtclass'];
	$objEmployee->employee_retddate				= $_REQUEST['employee_retddate'];
	$objEmployee->employee_nominee				= $_REQUEST['employee_nominee'];
	$objEmployee->employee_pension				= $_REQUEST['employee_pension'];
	$objEmployee->employee_active				= $_REQUEST['employee_active'];
	$objEmployee->employee_curaddress			= $_REQUEST['employee_curaddress'];
	$objEmployee->employee_contactnores			= $_REQUEST['employee_contactnores'];
	$objEmployee->employee_mobile				= $_REQUEST['employee_mobile'];
	$objEmployee->employee_permaddress			= $_REQUEST['employee_permaddress'];
	$objEmployee->employee_phone				= $_REQUEST['employee_phone'];
	$objEmployee->employee_emailid				= $_REQUEST['employee_emailid'];
	$objEmployee->employee_bloodgroup			= $_REQUEST['employee_bloodgroup'];
	$objEmployee->user_id						= $_REQUEST['user_id_hid'];
	$objEmployee->employee_adharno						= $_REQUEST['employee_adharno'];
	
	
	
	$objEmployee->employee_credit_amount				= $_REQUEST['employee_credit_amount'];
	$objEmployee->employee_loan			= $_REQUEST['employee_loan'];
	$objEmployee->loan_amount						= $_REQUEST['loan_amount'];
	$objEmployee->loan_month				= $_REQUEST['loan_month'];
	$objEmployee->loan_date				= $_REQUEST['loan_date'];
	
	
	if($_REQUEST['act'] != "del"){
		if($_REQUEST['employee_id'] > 0){
			$objEmployee->edit();
		} else if($_REQUEST['employee_id'] == 0){
			$objEmployee->add();
		} 
	} else if($_REQUEST['act'] == "del"){
		$objEmployee->delete();
		$thumbimg = "employee_".$objEmployee->employee_id. ".jpg";
		$thumbimg_path = $EmployeeImagePath . $thumbimg;
		if (file_exists($thumbimg_path)) {
			unlink($thumbimg_path);
		}
	}	

		 if (isset($_FILES['employee_sign']['name']) && !empty($_FILES['employee_sign']['name'])) {

            if (strlen($_FILES['employee_sign']['name']) > 0) {
            		$employee_id1 = $objEmployee->employee_id;
             	 $FileName1 = $_FILES['employee_sign']['name'];  
								      
             	 
              	$Ext = substr($FileName1, strrpos($FileName1, ".")+1);
								$Ext = strtolower($Ext);
								$thumbimg = "employee_sign_" . $employee_id1 . "." . $Ext; 
								$thumbimg_path = $EmployeeImagePath . $thumbimg;	
								if (file_exists($thumbimg_path)) {
                    unlink($thumbimg_path);
                }
                  if (!is_dir($EmployeeImagePath)) {
                    mkdir($EmployeeImagePath, 0755);
                    chmod($EmployeeImagePath, 0755);
                }
                copy($_FILES['employee_sign']['tmp_name'], $thumbimg_path);
                 $file_path=realpath($thumbimg_path);
                  chmod($file_path, 0644);
                  $objEmployee->employee_sign = $thumbimg;
                  $objEmployee->updatefile1();
            } 
          }

	if($objEmployee->employee_id!="0"){							
		$employee_id = $objEmployee->employee_id;
			
			
		if($_REQUEST["path"] != NULL)
		{
			$FileName = $_REQUEST["path"];
		}else{
		$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 = $SiteImagePath . $thumbimg;
			
			if($FileName != $thumbimg){
				if (file_exists($thumbimg_path)) {
					unlink($thumbimg_path);
				}
			}
			
			copy($SiteImagePath.$FileName, $thumbimg_path);
			$file_path=realpath($thumbimg_path);
			chmod($file_path, 0777);			
			
			if($FileName != $thumbimg){
				if(file_exists($SiteImagePath.$FileName)) {
					unlink($SiteImagePath.$FileName);
				}
			}
				unlink($SiteImagePath.$FileName);
			$objEmployee->employee_photo = $thumbimg;
			$objEmployee->updatePhoto();			
		}
	}

	header("Cache-Control: no-cache");
	echo '{"success":"true","msg":""}';
}
else {
	echo '{"success":"false","msg":"session expiry"}';
}	         
?>
