<?php
session_start();
ob_start();
include("config/database.php");
$conct  = new connectionCreat();
$conct->connectToDB();
$conct->selectDB();
include "config/function.php";
$take_action1   = new actionDo();
?>
<form  action="" method="POST" enctype="multipart/form-data">
  <input type="file"  name="file" >
 <input type= "submit" name="upload" value ="Upload" >
</form>
<?php
if(isset($_SESSION['msg']))
{
	echo $_SESSION['msg'];
	unset($_SESSION['msg']);	
}
if(isset($_POST['upload']))
{
	$file   = $_FILES['file']['tmp_name'];
	$handle = fopen($file, "r");
	$i		= 0;$j		= 0;$k		= 0;
		while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
		{
			if($i>0)
			{
			$emp_name	= ucwords(strtolower($filesop[2]));
			$dob		= date("Y-m-d",strtotime(str_replace('/','-',$filesop[12])));
			$fname		= ucwords(strtolower(mysql_real_escape_string($filesop[15])));
			$sql 		= mysql_query(" INSERT INTO `tbl_emp_records` SET `emp_code`='".$filesop[1]."', `emp_name`='".$emp_name."', `emp_name_alias`='".$filesop[3]."', `desiganation`='".$filesop[4]."', `head_qtrer`='".$filesop[5]."', `state`='".$filesop[6]."', `tsi`='".$filesop[7]."', `tso`='".$filesop[8]."', `asm`='".$filesop[9]."', `st_head`='".$filesop[10]."', `fnct_head`='".$filesop[11]."', `dob`='$dob', `mobil_no`='".$filesop[13]."', `marital_st`='".$filesop[14]."', `fname`='".$fname."', `aadhar_no`='".$filesop[16]."', `bank_name`='".$filesop[17]."', `bank_name_alias`='".$filesop[18]."', `branch_name`='".$filesop[19]."', `branch_city`='".$filesop[20]."', `branch_ifsc`='".$filesop[21]."', `account_no`='".$filesop[22]."', `salary_rate`='".$filesop[23]."', `da_rate`='".$filesop[24]."', `phone_rate`='".$filesop[26]."', `ta_rate`='".$filesop[25]."',`aug_sal`='".$filesop[27]."', `jul_sal`='".$filesop[28]."', `remark`='".$filesop[29]."', `payment_status`='".$filesop[30]."', `uan_status`='".$filesop[31]."' ")or die(mysql_error());
			$id			= mysql_insert_id();
			if($i==1)
			{
				$j		= $id;
			}	
			$k			= $id;
		}
		$i++;
		}
	if($i>0)
	{
		$_SESSION['msg'] = "Total Records Uploaded : ".($i-1)."<br />Id Range : $j-$k";
	}
	else
	{
		$_SESSION['msg'] = "Sorry! There is some problem.";
	}
	header("location:upload_excel.php");
}
 ?>