<?php

$con = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

$course_id = $request->getAttribute('course_id');
$exams_id=$request->getAttribute('exams_id');
$papers_id=$request->getAttribute('papers_id');




$response=array();
if ($passed=="") {
    $passed="0";
   }
   if ($failed=="") {
    $failed="0";
   }
   if ($absent=="") {
    $absent="0";
   }




//passed
if(isset($course_id)&&isset($exams_id)&&isset($papers_id)){
    $sql=("SELECT state  from pwe_answersheet_submit WHERE state='pass'  AND  course_id=$course_id AND exams_id=$exams_id 
    AND papers_id=$papers_id");
    }

// elseif(isset($course_id)&&isset($exams_id)){
// $sql=("SELECT state  from pwe_answersheet_submit WHERE state='pass'  AND  course_id=$course_id AND exams_id=$exams_id");
// }

// elseif(isset($course_id)){
// $sql=("SELECT state  from pwe_answersheet_submit WHERE state='pass'  AND  course_id=$course_id");
// }

// else{ 
// $sql=("SELECT state  from pwe_answersheet_submit WHERE state='pass' ");
// }
$result=mysqli_query($con,$sql);

    while ($row[]=mysqli_fetch_assoc($result)) {  

      $passed[passed]=count($row);

    }
    
    

//failed
if(isset($course_id)&&isset($exams_id)&&isset($papers_id)){
    $sql1=("SELECT state  from pwe_answersheet_submit WHERE state='fail'  AND  course_id=$course_id AND exams_id=$exams_id 
    AND papers_id=$papers_id");
    }

// elseif(isset($course_id)&&isset($exams_id)){
// $sql1=("SELECT state  from pwe_answersheet_submit WHERE state='fail'  AND  course_id=$course_id AND exams_id=$exams_id");
// }

// elseif(isset($course_id)){
// $sql1=("SELECT state  from pwe_answersheet_submit WHERE state='fail'  AND  course_id=$course_id");
// }

// else{ 
// $sql1=("SELECT state  from pwe_answersheet_submit WHERE state='fail' ");
// }
$result1=mysqli_query($con,$sql1);

    while ($row1[]=mysqli_fetch_assoc($result1)) {  

      $failed[failed]=count($row1);

    }
    
//absent
    if(isset($course_id)&&isset($exams_id)&&isset($papers_id)){
        $sql2=("SELECT state  from pwe_answersheet_submit WHERE state='fail'  AND  course_id=$course_id AND exams_id=$exams_id 
        AND papers_id=$papers_id");
        }
    
    // elseif(isset($course_id)&&isset($exams_id)){
    // $sql2=("SELECT state  from pwe_answersheet_submit WHERE state='fail'  AND  course_id=$course_id AND exams_id=$exams_id");
    // }
    
    // elseif(isset($course_id)){
    // $sql2=("SELECT state  from pwe_answersheet_submit WHERE state='fail'  AND  course_id=$course_id");
    // }
    
    // else{ 
    // $sql2=("SELECT state  from pwe_answersheet_submit WHERE state='fail' ");
    // }
    $result1=mysqli_query($con,$sql2);
    
        while ($row2[]=mysqli_fetch_assoc($result2)) {  
    
          $failed[failed]=count($row2);
    
        }


      



	
echo '[{"passed":"'.$passed.'","failed":"'.$failed.'","absent":"'.$absent.'"}]';




?>