<?php
include("header_bulk_uploads.php");
if(isset($_POST["Import"])){
    
		echo $filename=$_FILES["file"]["tmp_name"];
		
            $failure_data=array();
            $failed_count=0;
		 if($_FILES["file"]["size"] > 0)
		 {
		  	$file = fopen($filename, "r");
		  	$ri=0; $j=0;
	         while (($emapData = fgetcsv($file, 50000, ",")) !== FALSE)
	         {
	             if($emapData==''){
	             
	                 break;
	             }
	           
	             if($ri>0 && $emapData!=''){
	             /******************** Check Duplicate Email **************************/
	                    $email=$emapData[1];
	                    $statement = "SELECT * FROM `tbl_user` WHERE email='$email'";
	                 	$response=mysqli_query($conn,$statement);
	                 	$rowcount=mysqli_num_rows($response);
	                 
	               if($rowcount==0){  	 
    	        $statement ="INSERT INTO tbl_user (`full_name`, `email`, `phone`, `location`, `gst_no`, `address`, `password`, `fsc`, `oda`, `extra_pickup`, `rov`, `doc_charges`, `other_charges`, `amount_per_kg`, `photo`, `role`, `status`) 
    	            VALUES ('$emapData[0]','$emapData[1]','$emapData[2]','$emapData[3]','$emapData[4]','$emapData[5]','$emapData[6]','$emapData[7]','$emapData[8]','$emapData[9]','$emapData[10]','$emapData[11]','$emapData[12]','$emapData[13]','user-13.jpg','Modicare','Active')";
    	        $result=$conn->query($statement);
	           $j++;
	               }
	               if($ri>0 && ($result==0 ||$rowcount!=0))
				    { 
				      
				        $failure_data[]=$emapData;
				        $failed_count++;
				    }
	 	                   }
				        $ri++;
		    }
			
	         fclose($file);
	          // throws a message if data successfully imported to mysql database from excel file
	        
	            echo "<script type=\"text/javascript\">
	         	alert(\" $j Clients successfully Imported.$failed_count Clients Failed to Update...\");
	         	 window.location = \"user.php\"
					</script>";
			 //close of connection
			mysqli_close($conn); 
				
	}	 
} 
 ?> 