<?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)
		{
		    $type       = $filesop[4];
			$sql_2 		= mysql_query(" select * from `tbl_emp_records` where `account_no`='".$filesop[3]."' ")or die(mysql_error()); 
			if(mysql_num_rows($sql_2)>0)
			{
			    $sql_1              = "";
			    if($type=='SALARY')
			    {
			       $sql_1           = " ,`uan_status`='Done',`uan_status_2`='Done' " ;
			    }
				$sql_2 		        = mysql_query(" UPDATE `tbl_emp_records` SET  `payment_status`='Complete', `payment_status_2`='Complete' ".$sql_1." where `account_no`='".$filesop[3]."' ")or die(mysql_error());
				
				$j++;
			}
			else
			{
				echo "Account No : ".ucwords(strtolower($filesop[3]));
				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_uan_status.php");
}
 ?>