<?php
include 'dbConfig.php';
if(isset($_POST["sav_btn"])){
    
    $company_id = $_POST["company_id"];
    
$add_user_id = $_POST["add_user_id"];

$user_id_top_manager = $_POST["user_id_top_manager"];


  $link_lang = $_POST["link_lang"];
 $messag_add = $_POST["messag_add"];
$i = 0;
function GetSeriaother() {	
		$strings = '123456789';	
		$stringLength = strlen($strings);
		$newStrings = '';
		for ($i = 0; $i < 6; $i++) {
			$newStrings .= $strings[rand(0, $stringLength - 1)];
		}
		return $newStrings;
	}
	$no=GetSeriaother();

echo $filename=$_FILES["file"]["tmp_name"];	
if($_FILES["file"]["size"] > 0)
		 {

$file = fopen($filename, "r");
 while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
  {
      
   date_default_timezone_set("Asia/Riyadh");	 
  $d1=$emapData[2];
  $date_convert=date("Y-m-d", strtotime($d1));
$createdDate_time = date("Y-m-d h:i:sa");
  $hodoor_ensraf_type='hodoor';
  $createdDate= date("Y-m-d");



$sql24="SELECT * FROM hr_add_hodor_ensraf_tbl where employee_number_fingerprint='$emapData[7]'  AND hodor_ensraf_date='$emapData[4]'  ";
  $result24 = $conn->query($sql24);
 if ($result24->num_rows > 0) {
   
 }else{
   if($emapData['2']==$emapData['1']){
    $hodor_ensraf_stat='0'; 
   }else{
     $hodor_ensraf_stat='1';    
   }
  $sql = "INSERT INTO hr_add_hodor_ensraf_tbl(`system_id`,`user_id_top_manager`,`employee_number_fingerprint`,`hodor_ensraf_date`,`hodor_time`,`ensraf_time`,`hodor_ensraf_stat`,`createdDate`,`createdDate_time`,`add_user_id`) 
  values('2222',$user_id_top_manager,'$emapData[7]','$emapData[4]','$emapData[2]','$emapData[1]','$hodor_ensraf_stat','$createdDate','$createdDate_time','$add_user_id')";
  $result = mysqli_query( $conn, $sql );
	       
				if(! $result)
				{
				
				}else{
				    $i++;
				}
			
 }

  
	       
				if($i>0)
				{
					echo "<script type=\"text/javascript\">
							alert(\"Invalid File:Please Upload CSV File.\");
							window.location = \"hr_add_att_excel.php?$link_lang&company_id=$company_id\"
						</script>";
				
				}

	         }
	         fclose($file);
	         //throws a message if data successfully imported to mysql database from excel file
	         echo "<script type=\"text/javascript\">
						alert(\"CSV File has been successfully Imported.\");
						window.location = \"hr_add_att_excel.php?$link_lang&company_id=$company_id\"
					</script>";
	        
			 

			 //close of connection
			mysqli_close($conn); 
				
		 	
			
		 }
		 

		 
	}	 
?>		


