<?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['prdaddate']))
{
// add data to  employee
$data=array();
/*print_r($_POST['docnum']);
*/



$productivity_date=date('Y-m-d',strtotime($_POST['prdaddate']));
$data['prd_date'] = $productivity_date;
$data['prd_empid'] = $_POST['employeeid'];
$data['prd_branch_id'] = $_POST['brachid'];
$data['prd_unique'] = $_POST['prduniqueid'];
$data['prd_wt_totcarried'] = $_POST['totwt'];

$productivityadd	=	$db->Insert($data,'productivity');
$employee1   =   $db->LastInsertID();


for($i=0;$i<count($_POST['docnum']);$i++)
{
	//echo $_POST['docnum'][$i];
	$dat['prd_ids'] = $employee1;
	$dat['prd_docno'] = $_POST['docnum'][$i];
	$dat['prd_wt_carry'] = $_POST['wtcarried'][$i];
	
	$productivitysubadd	=	$db->Insert($dat,'productivity_sub');
}


	
//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" ,"zip");
$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/resume/". $_FILES['resume']['name']))
      {
      echo "<script>alert('filename already exists.')</script> ";
      }
    else
      {
      move_uploaded_file($_FILES["resume"]["tmp_name"],
      "../upload/resume/". $_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');
		

	}
	
	
	?>