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

session_start();
include_once("../class/class.MySQL.php");
$db	=new MySQL(); 
 
$data="";
$data1="";
$data2="";
$data3="";
if(isset($_REQUEST['hid']))
{
	$id=$_REQUEST['hid'];
	
$data=array();

	$data['e_fname']  	 = $_POST['fname'];
	$data['e_mname'] = $_POST['mname'];
	$data['e_lname'] = $_POST['lname'];
	$data['e_add']	 = $_POST['address'];
	$data['e_country']= $_POST['country'];
	$data['e_state'] = $_POST['state'];
	$data['e_zip']	= $_POST['zip'];
	$data['e_dob']	= $_POST['dob'];
	$data['e_phone']=$_POST['phone'];
	$data['e_mob']=$_POST['mobile'];
	$data['e_gender']=$_POST['gender'];
	$data['e_mail']=$_POST['email'];
	$data['e_rname']=$_POST['rname'];
	$data['e_relation']=$_POST['relation'];
	$data['e_contact']=$_POST['contact'];
	$data['e_rlocation']=$_POST['loc'];
	//$data['e_post']=$_POST['pa'];
	$data['e_plocation']=$_POST['jloc'];
	$data['e_dstart']=$_POST['dstart'];
	$data['e_dweek']=$_POST['dw'];
	//$data['e_qualification']=$_POST['level'];
	//$data['e_course']=$_POST['course'];
	$data['e_english']=$_POST['se'];
	$data['e_account']=$_POST['accountname'];
	$data['e_bank']=$_POST['bank'];
	$data['e_accountno']=$_POST['accountno'];
	$data['e_bankadd']=$_POST['bankadd'];
	$data['e_code']=$_POST['bankcode'];
	
	$data['employee_id']	=$_POST['emp_id'];
	$data['date_join']		=$_POST['dt_join'];
	$data['blood_group']	=$_POST['blood_grp'];
	/*$data['pf_accnum']		=$_POST['pf_ac_no'];
	$data['pf_nominee']		=$_POST['pf_nominee'];*/
	$data['esi_details']	=$_POST['esi_details'];
		
	$data['hist_dt_join']	  =$_POST['history_dt_join'];
	$data['hist_emptype']	  =$_POST['emptype'];
	$data['hist_dt_prev_pay'] =$_POST['dt_prev_pay_revision'];
	$data['hist_dt_pay']	  =$_POST['dt_pay_revised'];
	$data['hist_comp_prob']	  =$_POST['comp_probation'];
	
	/*$data['e_eng_rd']	  =$_POST['radio_eng1'];
	$data['e_eng_wt']	  =$_POST['radio_eng2'];
	$data['e_eng_sp'] 	  =$_POST['radio_eng3'];
	
	$data['e_mal_rd']	  =$_POST['radio_mal1'];
	$data['e_mal_wt']	  =$_POST['radio_mal2'];
	$data['e_mal_sp']	  =$_POST['radio_mal3'];
	
	$data['e_tam_rd']	  =$_POST['radio_tam1'];
	$data['e_tam_wt']	  =$_POST['radio_tam2'];
	$data['e_tam_sp']	  =$_POST['radio_tam3'];
	
	$data['e_hin_rd']	  =$_POST['radio_hin1'];
	$data['e_hin_wt']	  =$_POST['radio_hin2'];
	$data['e_hin_sp']	  =$_POST['radio_hin3'];*/
	
	$data['emp_contract']	  	= $_POST['emp_contract'];
	$data['emp_prob_period']  	= $_POST['emp_prob_period'];
	$data['passport_exp_date']	= $_POST['passport_exp_date'];
	$data['visa_exp_date'] 	  	= $_POST['visa_exp_date'];
	
	//$data['overtime_status']	  =$_POST['overtime'];
	$data['emp_status']	  =$_POST['empstat'];
	
	$where['e_id']			= $id;
	$employee	=	$db->Update('employee',$data,$where);
	//print_r($employee);
	
	//echo '{"employee":'.json_encode($employee).'}';
	//exit;
	
	$x=0;


$data2=array();


$allowedExts = array("doc", "docx", "pdf");
$temp = explode(".", $_FILES["resume"]["name"]);

$extension = end($temp);

if (in_array($extension, $allowedExts))
  {
  $randnum		=rand(1200,9999);
  $resumename = $randnum.$_FILES["resume"]["name"];
$data2['resume']=$resumename;

  if ($_FILES["resume"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["resume"]["error"] . "<br>";
    }
  else
    {
	
   "Upload: " . $_FILES["resume"]["name"]. "<br>";
    "Type: " . $_FILES["resume"]["type"] . "<br>";
    "Size: " . ($_FILES["resume"]["size"]/ 1024) . " kB<br>";
    "Temp file: " . $_FILES["resume"]["tmp_name"] . "<br>";


    if(file_exists("upload/resume/". $resumename))
      {
	  echo "<script>alert('$filename already exists.')</script> ";
      }
    else
      {
	  echo $_FILES["resume"]["name"];
      copy($_FILES["resume"]["tmp_name"],"../upload/resume/". $resumename);
      
	   echo "<script>alert('Your Resume has Been Submitted!!')</script> ";
      }
	  
    }
  }

		if(isset($_FILES['photo']['name']) && $_FILES['photo']['name']!=''){
		$randnum		=rand(1200,9999);
		$image			=$randnum.$_FILES['photo']['name'];
		$data2['photo']		=$image;
		$paththumb= "../upload/thumb/".$randnum.$_FILES['photo']['name'];
		$pathimg= "../upload/image/".$randnum.$_FILES['photo']['name'];
		
		try {
	
				$image = new ImageResize($_FILES['photo']['tmp_name']);
				
				//// Save thumb
				$image->resize(230,110);
				$image->save($paththumb);
				
				/// Save Image
				$image1 = new ImageResize($_FILES['photo']['tmp_name']);
				$image1->resizeToWidth(500);
				$image1->save($pathimg);

		} catch (Exception $e) {

		}
		}
	$where['e_id']			= $id;


		$db->Update('file',$data2,$where);

//Id Proof

$g=0;
		
  foreach ( $_FILES['idproof']['name']  as $values)
  {

$data3=array();
$data3['filetype']=$values;

if(isset($_FILES['idproof']['name']) && $_FILES['idproof']['name']!=''){
		$randnum		=rand(1200,9999);
		$image			=$randnum.$_FILES['idproof']['name'][$g];
		$data3['file']		=$image;
		$pathimg= "../upload/image/".$randnum.$_FILES['idproof']['name'][$g];
		
		try {
	
				$image = new ImageResize($_FILES['idproof']['tmp_name'][$g]);
				
				//// Save thumb
				
				
				/// Save Image
				$image1 = new ImageResize($_FILES['idproof']['tmp_name'][$g]);
				$image1->resizeToWidth(500);
				$image1->save($pathimg);

		} catch (Exception $e) {

		}
		}
$where['e_id']			= $id;
		$db->Update('idproof',$data3,$where);		
			////upload sertificatees and save to the  idproof
			}
//idproof type
foreach($_FILES['passfile']['tmp_name'] as $key => $tmp_name )
    { 
    if(isset($_FILES['passfile']['name']) && $_FILES['passfile']['name']!='')
	{
	    $randnum		=rand(1200,9999);
	echo	$image			=$randnum.$_FILES['passfile']['name'];
		$target_Path= "../upload/resume/"
		move_uploaded_file( $_FILES['userFile']['tmp_name'], $target_Path.$image );
	}
	 
	 }


/*foreach ( $_FILES['passfile']['name']  as $values)
  {

$data33=array();
$data33['filetype']=$values;

if(isset($_FILES['passfile']['name']) && $_FILES['passfile']['name']!=''){
		$randnum		=rand(1200,9999);
		$image			=$randnum.$_FILES['passfile']['name'][$g];
		$data33['file']		=$image;
		$pathimg= "../upload/resume/".$randnum.$_FILES['passfile']['name'][$g];
		
		try {
	
				$image = new ImageResize($_FILES['passfile']['tmp_name'][$g]);
				
				//// Save thumb
				
				
				/// Save Image
				$image1 = new ImageResize($_FILES['passfile']['tmp_name'][$g]);
				$image1->resizeToWidth(500);
				$image1->save($pathimg);

		} catch (Exception $e) {

		}
		}
$where['e_id']			= $id;
		$db->Update('idprooftype',$data33,$where);		
			////upload sertificatees and save to the  idproof
			}
			
			//drive
			
foreach ( $_FILES['drfile']['name']  as $values)
  {

$data44=array();
$data44['filetype']=$values;

if(isset($_FILES['drfile']['name']) && $_FILES['drfile']['name']!=''){
		$randnum		=rand(1200,9999);
		$image			=$randnum.$_FILES['drfile']['name'][$g];
		$data44['file']		=$image;
		$pathimg= "../upload/resume/".$randnum.$_FILES['drfile']['name'][$g];
		
		try {
	
				$image = new ImageResize($_FILES['drfile']['tmp_name'][$g]);
				
				//// Save thumb
				
				
				/// Save Image
				$image1 = new ImageResize($_FILES['drfile']['tmp_name'][$g]);
				$image1->resizeToWidth(500);
				$image1->save($pathimg);

		} catch (Exception $e) {

		}
		}
$where['e_id']			= $id;
		$db->Update('idprooftype',$data44,$where);		
			////upload sertificatees and save to the  idproof
			}
		
		//govt
		
		
		
foreach ( $_FILES['gvtfile']['name']  as $values)
  {

$data55=array();
$data55['filetype']=$values;

if(isset($_FILES['gvtfile']['name']) && $_FILES['gvtfile']['name']!=''){
		$randnum		=rand(1200,9999);
		$image			=$randnum.$_FILES['gvtfile']['name'][$g];
		$data55['file']		=$image;
		$pathimg= "../upload/resume/".$randnum.$_FILES['gvtfile']['name'][$g];
		
		try {
	
				$image = new ImageResize($_FILES['gvtfile']['tmp_name'][$g]);
				
				//// Save thumb
				
				
				/// Save Image
				$image1 = new ImageResize($_FILES['gvtfile']['tmp_name'][$g]);
				$image1->resizeToWidth(500);
				$image1->save($pathimg);

		} catch (Exception $e) {

		}
		}
$where['e_id']			= $id;
		$db->Update('idprooftype',$data55,$where);		
			////upload sertificatees and save to the  idproof
			}	
			
			//other
			
foreach ( $_FILES['othfile']['name']  as $values)
  {

$data66=array();
$data66['filetype']=$values;

if(isset($_FILES['othfile']['name']) && $_FILES['othfile']['name']!=''){
		$randnum		=rand(1200,9999);
		$image			=$randnum.$_FILES['othfile']['name'][$g];
		$data66['file']		=$image;
		$pathimg= "../upload/resume/".$randnum.$_FILES['othfile']['name'][$g];
		
		try {
	
				$image = new ImageResize($_FILES['othfile']['tmp_name'][$g]);
				
				//// Save thumb
				
				
				/// Save Image
				$image1 = new ImageResize($_FILES['othfile']['tmp_name'][$g]);
				$image1->resizeToWidth(500);
				$image1->save($pathimg);

		} catch (Exception $e) {

		}
		}
$where['e_id']			= $id;
		$db->Update('idprooftype',$data66,$where);		
			////upload sertificatees and save to the  idproof
			}*/
			
//

//Empl Experience			
  $k=0;
  $where['e_id']		 = $id;
  $db->Delete('employee_expirence',$where);
  
  foreach ( $_POST['refer'] as $value)
  {
	if($value!=""){
		$data4=array();
		$data4['refer']  	 = $value;
		$data4['emp'] 		 = $_POST['emp'][$k];
		$data4['phno'] 		 = $_POST['phno'][$k];
		$data4['email']		 = $_POST['email1'][$k];
		$data4['from']	 	 = $_POST['from'][$k];
		$data4['to'] 		 = $_POST['to'][$k];
		$data4['posi']		 = $_POST['posi'][$k];
		$data4['sal']		 = $_POST['sal'][$k];
		$data4['rfl']		 = $_POST['rfl'][$k];
		$data4['e_id']		 = $id;
		 
		$where['e_id']		 = $id;
		$db->Insert($data4,'employee_expirence');
	}	
	$k++;
}	



#updating employee languages
	$where['e_id']	 = $id;
	//$language	     =	$db->delete('emp_language',$where);
	
	$m=0; 
	foreach ( $_POST['lang'] as $value)
    {
		
		if($value!="")
		{
			if($_POST['emp_lang_id'][$m]){
				$data5=array();
				$data5['lang_id']    = $value;
				$data5['lang_rd']	 = $_POST['radio_eng_rd'][$m];
				$data5['lang_wt']    = $_POST['radio_eng_wt'][$m];
				$data5['lang_sk']    = $_POST['radio_eng_sk'][$m];
				$con['id']		 = $_POST['emp_lang_id'][$m];
				$db->Update('emp_language',$data5,$con);
			}
			else {
				$data5=array();
				$data5['e_id'] 		 = $id;
				$data5['lang_id']    = $value;
				$data5['lang_rd']	 = $_POST['radio_eng_rd'][$m];
				$data5['lang_wt']    = $_POST['radio_eng_wt'][$m];
				$data5['lang_sk']    = $_POST['radio_eng_sk'][$m];
				
				$db->Insert($data5,'emp_language');
			}
		}
		//print_r($data5);
		$m++;
    }	
	

	
#updating employee education
	$where['e_id']	 = $id;
	$edu	         =	$db->Delete('employee_education',$where);
	
	$n=0;
	foreach ( $_POST['course'] as $value)
    {
			if($value!=""){
				$data6=array();
				$data6['e_id'] 	   = $id;
				$data6['course']   = $_POST['course'][$n];
				$data6['spl']	   = $_POST['spl'][$n];
				$data6['unv']      = $_POST['unv'][$n];
				$data6['yr']       = $_POST['yr'][$n];
				$data6['pcntg']    = $_POST['pcntg'][$n];
				
				$db->Insert($data6,'employee_education');
			}
			$n++;
    }
	
	#passport uploading
	$data7=array();
	if(isset($_FILES['passport_doc']['name']) && $_FILES['passport_doc']['name']!=''){
		$randnum		        = rand(1200,9999);
		$passport			    = $randnum.$_FILES['passport_doc']['name'];
		$data7['passport_doc']	= $passport;
		$pathpassport   = "../upload/documents/".$passport;
		copy($_FILES["passport_doc"]["tmp_name"],$pathpassport);
		
		$where['e_id']			= $id;
		$db->Update('employee',$data7,$where);
	}	
	
	#visa uploading
	$data8=array();
	if(isset($_FILES['visa_doc']['name']) && $_FILES['visa_doc']['name']!=''){
		$randnum		    = rand(1200,9999);
		$visa			    = $randnum.$_FILES['visa_doc']['name'];
		$data8['visa_doc']	= $visa;
		$pathvisa   = "../upload/documents/".$visa;
		copy($_FILES["visa_doc"]["tmp_name"],$pathvisa);
		
		$where['e_id']			= $id;
		$db->Update('employee',$data8,$where);
	}	
	
	#update documents
	
	if(!empty($_POST['doc_name'])){
		$r=0;
		foreach($_POST['doc_name'] as $doc){ 
			if($_POST['doc_name'][$r] !=""){
				$data9=array();
				$data9['emp_id'] 	   = $id;
				$data9['doc_name']     = $_POST['doc_name'][$r];
				
				if ($_POST['emp_doc_id'][$r]!="") {
					$conds['emp_doc_id'] = $_POST['emp_doc_id'][$r];
					$db->Update('emp_documents',$data9,$conds);
				} else {
					$db->Insert($data9,'emp_documents');
					$emp_doc_id			   = $db->LastInsertID();
				}
			}
			if( $_FILES['doc']['name'][$r] !=""){	
				#uploading document
				$data9=array();
				$randnum		    = rand(1200,9999);
				$document			= $randnum.$_FILES['doc']['name'][$r];
				$data9['doc']	    = $document;
				$pathdoc  			= "../upload/documents/".$document;
				copy($_FILES["doc"]["tmp_name"][$r],$pathdoc);
				
				$cond['emp_doc_id'] = $emp_doc_id;
				$db->Update('emp_documents',$data9,$cond);
			}
			$r++;
		}
	}		

exit;




}			
			

