<?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)
		{
			$sql_2 		= mysql_query(" SELECT * FROM `tbl_emp_records` WHERE `state`='".$filesop[5]."' and `emp_name`='".$filesop[2]."' and `fname`='".$filesop[4]."' and `status`='0'  ")or die(mysql_error()); 
			if(mysql_num_rows($sql_2)>0)
			{
				$j++;
				$data_2 = mysql_fetch_array($sql_2);
				mysql_query(" UPDATE `tbl_emp_records` SET `emp_zone` ='".$filesop[6]."' WHERE `id` ='".$data_2['id']."' ") or die(mysql_error());
			}
			else
			{
				echo "Name : ".ucwords(strtolower($filesop[2]));
				echo "<br />";
			}
	   }
	$i++;
	}
	if($i>0)
	{
		$_SESSION['msg'] = "Total Records Uploaded : ".($i-1)."<br />Total Update Range : $j";
	}
	else
	{
		$_SESSION['msg'] = "Sorry! There is some problem.";
	}
	echo "<br />";
echo 	$_SESSION['msg'];die;
	header("location:update_zone_data.php");
}
 ?>