<?php

require 'dao/Assessment.php';
//require 'dao/Global.php';
if(isset($_FILES['file']))
{
	print_r($_FILES);

//Globals
  $globals = $global->get_all_globals();
  $a_year_id = $globals[0]['a_year_id'];
  $semester_id = $globals[0]['semester_id'];
  $track_id = $globals[0]['track_id'];
  $date_created = date("Y-m-d");

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]);
          $sn = $emapData[0];
          $student_id = $emapData[1];
          $class_id = $_POST['cid'];
          $subject_id = $_POST['sub'];
          $staff_id = $_SESSION['staff_id'];
          $staff_id = $assessment->get_staff($staff_id);
          $staff_id = $staff_id[0]['staff_detail_id'];
          $student_name = $emapData[2];
          $class_score = $emapData[3];
          $class_score2 = (30/100)*$class_score;
          $exams_score = $emapData[4];
          $exams_score2 = (70/100)*$exams_score;
          $total_score = $class_score2 + $exams_score2;


        $data = array("student_id"=>$student_id,"subject_id"=>$subject_id,
                      "staff_id"=>$staff_id,"class_score"=>$class_score,
                      "exam_score"=>$exams_score,"total_score"=>$total_score,
                      "a_year_id"=>$a_year_id,"semester_id"=>$semester_id,
                      "track_id"=>$track_id,"date_created"=>$date_created,
                      "class_id"=>$class_id);
        print_r($data);
        
           $success =  $assessment->assess($data);
           if ($success) {
           	echo 0;
           }else{
           	echo 1;
           }
           
         }
         fclose($file);
         echo 3;
// }
// else {
//     echo "Error: Please Upload only CSV File";
// }


}

?>