<?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($_POST['upload']))
{
	$file   = $_FILES['file']['tmp_name'];
	$handle = fopen($file, "r");
	$i		= 0; 
	$match	= 0;
	$non_matched = 0;
	while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
	{
		if($i>0)
		{
			$emp_name	= ucwords(strtolower($filesop[1]));
			$state		= "Rajasthan";
			$sql_check	= mysql_query(" SELECT * FROM `tbl_emp_records` WHERE `emp_name`='$emp_name' and `state`='$state' and `status`='0' ")or die(mysql_error());
			if(mysql_num_rows($sql_check)>0)
			{
				$data_check = mysql_fetch_array($sql_check);
				$jul_1		= $filesop[3];
				$jul_2		= $filesop[4];
				$jul_3		= $filesop[5];
				$jul_4		= $filesop[6];
				$jul_5		= $filesop[7];
				$jul_6		= $filesop[8];
				$jul_7		= $filesop[9];
				$jul_8		= $filesop[10];
				$jul_9		= $filesop[11];
				$jul_10		= $filesop[12];
				$jul_11		= $filesop[13];
				$jul_12		= $filesop[14];
				$jul_13		= $filesop[15];
				$jul_14		= $filesop[16];
				$jul_15		= $filesop[17];
				$jul_16		= $filesop[18];
				$jul_17		= $filesop[19];
				$jul_18		= $filesop[20];
				$jul_19		= $filesop[21];
				$jul_20		= $filesop[22];
				$jul_21		= $filesop[23];
				$jul_22		= $filesop[24];
				$jul_23		= $filesop[25];
				$jul_24		= $filesop[26];
				$jul_25		= $filesop[27];
				$jul_26		= $filesop[28];
				$jul_27		= $filesop[29];
				$jul_28		= $filesop[30];
				$jul_29		= $filesop[31];
				$jul_30		= $filesop[32];
				$jul_31		= $filesop[33];
				for($i=1;$i<=31;$i++)
				{
					$val		= "jul_".$i;
					$mark_qry	= mysql_query(" SELECT * FROM `tbl_attend_type` where `symbol`='".$$val."' ");
					$mark_data	= mysql_fetch_array($mark_qry);
					mysql_query(" insert into `tbl_attendence` SET `emp_id`='".$data_check['id']."',`state`='$state',`date`='2018-07-".$i."',`mark`='".$mark_data['id']."' ");
//					echo "<br />";
				}
			}
			else
			{
				echo $emp_name;
				echo "<br />";
				$non_matched++;
			}
		}
	$i++;
	}
	if($i>0)
	{
		$_SESSION['msg'] = "Total Records Uploaded : ".($i-1)."<br />mathch : ".$match."<br />Not mathch : ".$non_matched;
	}
	else
	{
		$_SESSION['msg'] = "Sorry! There is some problem.";
	}
	//header("location:upload_attendence.php");
}
if(isset($_SESSION['msg']))
{
	echo $_SESSION['msg'];
	unset($_SESSION['msg']);	
}
 ?>