<?php
error_reporting(0);
require '../class/resizeImage.php';

session_start();
include_once("../class/class.MySQL.php");
$db	=new MySQL();


$data1="";	
$data2="";	
$data4="";	
if(isset($_GET['employ_id']))
			{	

				$idn=$_GET['employ_id'];
				
				$employ = $db->fetchQuery("Select *,idprooftype.file as idfiles,DATE_FORMAT(employee.hist_date_releve,'%d-%m-%Y') as date_releve ,DATE_FORMAT(employee.e_dstart,'%d-%m-%Y') as e_dstart from employee AS employee 
							LEFT JOIN employee_expirence AS exp ON exp.e_id=employee.e_id 
							LEFT JOIN  file AS  file ON  file.e_id=employee.e_id 
							LEFT JOIN idproof AS idproof ON idproof.e_id=employee.e_id
							LEFT JOIN idprooftype AS idprooftype ON idprooftype.e_id=employee.e_id
							LEFT JOIN department AS department ON department.depart_id=employee.departid
							LEFT JOIN branches AS branches ON branches.branch_id=employee.branchid
							LEFT JOIN designation AS designation ON designation.desig_id=employee.e_post
							LEFT JOIN country AS country ON country.country_id=employee.e_country
							LEFT JOIN state AS state ON state.state_id=employee.e_state
							where employee.e_id='".$idn."'");
							
			$imd_supervisor_id=$employ[0]['imd_supervisor_id'];
			$immsuperquery=$db->fetchQuery("SELECT * from employee as employee where e_id=$imd_supervisor_id");
			
			$immediatesupervisr=$immsuperquery[0]['e_fname'];
			
			$employ[0]['immediatesupervisr']=$immediatesupervisr;
			
			
			$PFquery=$db->fetchQuery("SELECT * from pf_esi_details as employee where emp_id='".$idn."' and type_status = 1");
			
			$emp_pfamt=$PFquery[0]['emp_pf'];
			
			$employ[0]['emp_pfamt']=$emp_pfamt;
			
			
			
			//echo "<br />DOB is : ".$immsuperquery[0]['e_dob'];
			if($employ[0]['e_dob'] != '' && !is_null($employ[0]['e_dob'])){
				$employ[0]['e_dob']= date("d-m-Y", strtotime($employ[0]['e_dob']));
			}else{
				$employ[0]['e_dob']= '';
			}
			if($employ[0]['date_join'] != '' && !is_null($employ[0]['date_join'])){
				$employ[0]['date_join']= date("d-m-Y", strtotime($employ[0]['date_join']));
			}else{
				$employ[0]['date_join']= '';
			}
			if($employ[0]['hist_dt_join'] != '' && !is_null($employ[0]['hist_dt_join'])){
				$employ[0]['hist_dt_join']= date("d-m-Y", strtotime($employ[0]['hist_dt_join']));
			}else{
				$employ[0]['hist_dt_join']= '';
			}
			if($employ[0]['passport_exp_date'] != '' && !is_null($employ[0]['passport_exp_date'])){
				$employ[0]['passport_exp_date']= date("d-m-Y", strtotime($employ[0]['passport_exp_date']));
			}else{
				$employ[0]['passport_exp_date']= '';
			}
			if($employ[0]['visa_exp_date'] != '' && !is_null($employ[0]['visa_exp_date'])){
				$employ[0]['visa_exp_date']= date("d-m-Y", strtotime($employ[0]['visa_exp_date']));
			}else{
				$employ[0]['visa_exp_date']= '';
			}
			if($employ[0]['hist_date_releve'] != '' && !is_null($employ[0]['hist_date_releve'])){
				$employ[0]['hist_date_releve']= date("d-m-Y", strtotime($employ[0]['hist_date_releve']));
			}else{
				$employ[0]['hist_date_releve']= '';
			}
			if($employ[0]['pass_issue_dat'] != '' && !is_null($employ[0]['pass_issue_dat'])){
				$employ[0]['pass_issue_dat']= date("d-m-Y", strtotime($employ[0]['pass_issue_dat']));
			}else{
				$employ[0]['pass_issue_dat']= '';
			}
			if($employ[0]['pass_exp_dat'] != '' && !is_null($employ[0]['pass_exp_dat'])){
				$employ[0]['pass_exp_dat']= date("d-m-Y", strtotime($employ[0]['pass_exp_dat']));
			}else{
				$employ[0]['pass_exp_dat']= '';
			}
			if($employ[0]['vsa_isue_dat'] != '' && !is_null($employ[0]['vsa_isue_dat'])){
				$employ[0]['vsa_isue_dat']= date("d-m-Y", strtotime($employ[0]['vsa_isue_dat']));
			}else{
				$employ[0]['vsa_isue_dat']= '';
			}
			if($employ[0]['vsa_exp_dat'] != '' && !is_null($employ[0]['vsa_exp_dat'])){
				$employ[0]['vsa_exp_dat']= date("d-m-Y", strtotime($employ[0]['vsa_exp_dat']));
			}else{
				$employ[0]['vsa_exp_dat']= '';
			}
			
			$fileToSend ='../upload/idproof/'.$employ[0]['idfiles'];
			if(file_exists($fileToSend)){
			
			$employ[0]['idfiles']= $employ[0]['idfiles'];
			}
			else
			{
			$employ[0]['idfiles']='';
			}
			
			
			
			/*$employ[0]['date_join']= date("d-m-Y", strtotime($employ[0]['date_join']));
			$employ[0]['e_dstart']= date("d-m-Y", strtotime($employ[0]['e_dstart']));
			$employ[0]['hist_dt_join']= date("d-m-Y", strtotime($employ[0]['hist_dt_join']));
			$employ[0]['passport_exp_date']= date("d-m-Y", strtotime($employ[0]['passport_exp_date']));
			$employ[0]['visa_exp_date']= date("d-m-Y", strtotime($employ[0]['visa_exp_date']));
			$employ[0]['hist_date_releve']= date("d-m-Y", strtotime($employ[0]['hist_date_releve']));
			$employ[0]['pass_issue_dat']= date("d-m-Y", strtotime($employ[0]['pass_issue_dat']));
			$employ[0]['pass_exp_dat']= date("d-m-Y", strtotime($employ[0]['pass_exp_dat']));
			$employ[0]['vsa_isue_dat']= date("d-m-Y", strtotime($employ[0]['vsa_isue_dat']));
			$employ[0]['vsa_exp_dat']= date("d-m-Y", strtotime($employ[0]['vsa_exp_dat']));*/
			
			#device Id
			
			$device	=  $db->fetchQuery("SELECT device_name FROM `device` WHERE dev_id IN(".$employ[0]['device_id'].")");
			foreach($device	 as $dev_id){
				$device_id[]	= $dev_id['device_name'];
			}
			if(!empty($device_id))
				$employ[0]['device_id'] = implode(',',$device_id);
			else
				$employ[0]['device_id'] = "";
					
			echo '{"employ":'.json_encode($employ).'}';
			

}
$data3="";

if(isset($_REQUEST['emp_id']))
{
	$idd=$_REQUEST['emp_id'];
	//echo $idd;	
$data3=array();
$data3['e_id']= $idd;
$j=0;

 


foreach($_FILES['idproof']['name'] as $image){

$data3['filetype']=$_POST['ptype'][$j];

if(isset($_FILES['idproof']['name'][$j]) && $_FILES['idproof']['name'][$j]!=''){
		$randnum		=rand(1200,9999);

	 	$image			=$randnum.$_FILES['idproof']['name'][$j];
		$data3['file']		=$image;
		$paththumb= "upload/thumb/".$randnum.$_FILES['idproof']['name'][$j];
		$pathimg= "upload/image/".$randnum.$_FILES['idproof']['name'][$j];
		try {
	
				$image = new ImageResize($_FILES['idproof']['tmp_name'][$j]);
				
				//// Save thumb
				$image->resize(230,110);
				$image->save($paththumb);
				
				/// Save Image
				$image1 = new ImageResize($_FILES['idproof']['tmp_name'][$j]);
				$image1->resizeToWidth(500);
				$image1->save($pathimg);

		} catch (Exception $e) {

		}
		}
	
	
		$db->Insert($data3,'idproof');
		
		$j++;
}		
}

if(isset($_REQUEST['e_id']))
{
	$idd=$_REQUEST['e_id'];
	
	//echo $idd;	
$data1=array();


$k=0;

	foreach($_POST['work'] as $test)
		
	{
		$data1['e_id']=$idd;
		$data1['refer']=$_POST['work'][$k];
		$data1['emp']=$_POST['addr'][$k];
		$data1['phno']=$_POST['Contact'][$k];
		$data1['email']=$_POST['send'][$k];
		$data1['from']=$_POST['source'][$k];
		$data1['to']=$_POST['dest'][$k];
		$data1['posi']=$_POST['place'][$k];
		$data1['sal']=$_POST['pay'][$k];
		$data1['rfl']=$_POST['leave'][$k];
		
		$db->Insert($data1,'employee_expirence');
		$k++;
		
	}
	
}


if(isset($_REQUEST['del_id']))
{
	$idd1=$_REQUEST['del_id'];
	$where['eid']			= $idd1;
	$db->Delete('employee_expirence',$where);
}
if(isset($_REQUEST['delll_id']))
{
	$idd2=$_REQUEST['delll_id'];
	$where['lan_id']			= $idd2;
	$db->Delete('language',$where);
}

if(isset($_REQUEST['dell_id']))
{
	$iddo=$_REQUEST['dell_id'];
	$where['idid']			= $iddo;
	$db->Delete('idproof',$where);
}


if(isset($_REQUEST['up_id']))
{
	$idd2=$_REQUEST['up_id'];
	
	
	
$data2=array();

		
		$data2['refer']=$_POST['refer'];
		$data2['emp']=$_POST['emp'];
		$data2['phno']=$_POST['phno'];
		$data2['email']=$_POST['email'];
		$data2['from']=$_POST['from'];
		$data2['to']=$_POST['to'];
		$data2['posi']=$_POST['posi'];
		$data2['sal']=$_POST['sal'];
		$data2['rfl']=$_POST['rfl'];
		
		$where['eid']= $idd2;
		$db->Update('employee_expirence',$data2,$where);
		
		
	
		
		
	
}
if(isset($_REQUEST['upd_id']))
{
	$idd3=$_REQUEST['upd_id'];
	
	
	
$data4=array();

		
		$data4['e_lang']=$_POST['other'];
		$data4['e_level']=$_POST['level1'];
		
		$where['lan_id']= $idd3;
		$db->Update('language',$data4,$where);
		
		
	
		
		
	
}
?>
<?
$opt='';
		$names = $db->fetchAll('designation');
		
		foreach($names as $names)
		{
		$opt.="<option value='".$names['desig_name']."'>".$names['desig_name']."</option>";
		}
		?>
	
		<?                                      
//echo $opt;  <option value="">--select--</option>
?>