<?php
session_start();
	
include_once("../class/class.MySQL.php");
require '../class/resizeImage.php';
$db=new MySQL();


$data="";
$data1="";
$data2="";
$data3="";
$data4="";
$data5="";
$data6="";
if(isset($_POST['fname']))
{
// add data to  employee
$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_pay']			=$_POST['Salary'];
$data['e_plocation']	=$_POST['jloc'];
$data['e_dstart']		=date('Y-m-d');
$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['overtime_status']	  =$_POST['overtime'];
//mysql_query("insert into employee (e_mname)values($a)");
	$employee	=	$db->Insert($data,'employee');
	$employee1   =   $db->LastInsertID();
	
	

	
	
//for($k=0; $k<count($_POST['refer']);$k++)	

//add data to table employee_expirence

	$k=0;
	foreach($_POST['refer'] as $test)
	
	{
		$data1['e_id']=$employee1;
		$data1['refer']=$_POST['refer'][$k];
		$data1['emp']=$_POST['emp'][$k];
		$data1['phno']=$_POST['phno'][$k];
		$data1['email']=$_POST['email1'][$k];
		$data1['from']=$_POST['from'][$k];
		$data1['to']=$_POST['to'][$k];
		$data1['posi']=$_POST['posi'][$k];
		$data1['sal']=$_POST['sal'][$k];
		$data1['rfl']=$_POST['rfl'][$k];
		$db->Insert($data1,'employee_expirence');
		$k++;
	}

	

//upload image and resume and enter it to file

$data2=array();
$data2['e_id']=$employee1;


$data2['resume']=$_FILES["resume"]["name"];

$allowedExts = array("doc", "docx", "pdf");
$temp = explode(".", $_FILES["resume"]["name"]);
$extension = end($temp);
if (in_array($extension, $allowedExts))
  {
  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/". $_FILES['resume']['name']))
      {
      echo "<script>alert('filename already exists.')</script> ";
      }
    else
      {
      move_uploaded_file($_FILES["resume"]["tmp_name"],
      "../upload/". $_FILES["resume"]["name"]);
       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'];
		if($image='')
		{
		$data2['photo']		="http://192.168.1.25:8081/kotz/cash//HR/upload/image/noimg.jpg" ;
		}else
		{
		$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(170,172);
				$image->save($paththumb);
				
				/// Save Image
				$image1 = new ImageResize($_FILES['photo']['tmp_name']);
				$image1->resizeToWidth(500);
				$image1->save($pathimg);
				

		} catch (Exception $e) {

		}
		}
		
	
		$db->Insert($data2,'file');

		
			////upload sertificatees and save to the  idproof
		
$data3=array();
$data3['e_id']= $employee1;
$j=0;

 



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


if(isset($_FILES['idproof']['name'][$j]) && $_FILES['idproof']['name'][$j]!=''){
		$randnum		=rand(1200,9999);
		$data3['filetype']=$_POST['ptype'][$j];
	 	$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++;
}


//add data to table language

$k=0;

$data4=array();
foreach($_POST['other'] as $test)
	
	{
		$data4['e_id']=$employee1;
		$data4['e_lang']=$_POST['other'][$k];
		$data4['e_level']=$_POST['level1'][$k];
		
		$db->Insert($data4,'language');
		$k++;
	}

//add data to table certificate

$k=0;

$data6=array();
foreach($_POST['other'] as $cert)
	
	{
		$data6['e_id']=$employee1;
		$data6['e_certname']=$_POST['cert'][$k];
		
		$data6['e_exp']=$_POST['exper'][$k];
		$db->Insert($data6,'certificate');
		$k++;
	}



//add data to time 

$k=0;

$data5=array();

	
	
		$data5['e_id']=$employee1;
		
		
		$db->Insert($data5,'time');
		

	}
	
	
	?>