<?php
require_once 'dao/Admission.php';
if(isset($_FILES['file']))
{
	print_r($_FILES);


echo $filename=$_FILES["file"]["tmp_name"];
$ext=substr($filename,strrpos($filename,"."),(strlen($filename)-strrpos($filename,".")));

//we check,file must be have csv extention
// if($ext=="csv")
// {
  $file = fopen($filename, "r");
         while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
         {
         	 // values('$emapData[0]','$emapData[1]','$emapData[2]')
        // $data = array("class"=>$emapData[0],"track"=>$emapData[1],
        // 			  "student_name"=>$emapData[2],"student_picture"=>$emapData[3],"dob"=>$emapData[4],"home_phone"=>$emapData[5],"admission_year"=>$emapData[6],"alumini"=>$emapData[7],"guardian"=>$emapData[8],"jhs"=>$emapData[9],"district"=>$emapData[10],"religion"=>$emapData[11],"postal_address"=>$emapData[12],"home_address"=>$emapData[13],"bece_index"=>$emapData[14],"form_id"=>$emapData[15],"house_id"=>$emapData[16]);
        $data = array("first_name"=>$emapData[0],"staff_id"=>$emapData[1]);
        // $data2 = array("staff_id"=>$emapData[1],"role"=>$emapData[2],"password"=>md5($emapData[3]));
        print_r($data);
           $success =  $admission->import_staffs($data);
           // $success2 = $admission->import_staffs_login($data2);
           if ($success) {
           	echo 0;
           }else{
           	echo 1;
           }
           //break;
         }
         fclose($file);
         echo 3;

         $file = fopen($filename, "r");
         while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
         {
           // values('$emapData[0]','$emapData[1]','$emapData[2]')
        // $data = array("class"=>$emapData[0],"track"=>$emapData[1],
        //        "student_name"=>$emapData[2],"student_picture"=>$emapData[3],"dob"=>$emapData[4],"home_phone"=>$emapData[5],"admission_year"=>$emapData[6],"alumini"=>$emapData[7],"guardian"=>$emapData[8],"jhs"=>$emapData[9],"district"=>$emapData[10],"religion"=>$emapData[11],"postal_address"=>$emapData[12],"home_address"=>$emapData[13],"bece_index"=>$emapData[14],"form_id"=>$emapData[15],"house_id"=>$emapData[16]);
        // $data = array("first_name"=>$emapData[0],"staff_id"=>$emapData[1]);
        $data2 = array("staff_id"=>$emapData[1],"role"=>$emapData[2],"password"=>md5($emapData[3]));
        print_r($data);
           // $success =  $admission->import_staffs($data);
           $success2 = $admission->import_staffs_login($data2);
           if ($success2) {
            echo 0;
           }else{
            echo 1;
           }
           //break;
         }
         fclose($file);
         echo 3;
// }
// else {
//     echo "Error: Please Upload only CSV File";
// }


}

?>