<?php

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

$course_id = $request->getAttribute('course_id');
$exams_id=$request->getAttribute('exams_id');
$date=$request->getAttribute('date');
$time=$request->getAttribute('time');
$slots=$request->getAttribute('slots');
$papers_shortcode=$request->getAttribute('papers_shortcode');
$file=$request->getAttribute('file');

$response=array();

if($pass==""){
    $pass="0";
}
if($fail==""){
    $fail="0";
}
if($file==""){
    $file="0";
}

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

           $result=mysqli_query($con,$sql);
              while ($row1[]=mysqli_fetch_assoc($result)) {  
                $pass=count($row1);
                     }

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


//--------------------------------------------------file-------------------------------------------------------------//

 if(isset($course_id)&&isset($exams_id)&&isset($papers_shortcode)&&isset($slots)){
     $sql3="SELECT file from pwe_answersheet_submit WHERE  course_id='$course_id' AND exams_id='$exams_id' 
        AND papers_shortcode='$papers_shortcode' AND slots='$slots'";
         }
        
   
        $result2=mysqli_query($con,$sql3);        
            while ($row3[]=mysqli_fetch_assoc($result2)) {         
              $file=count($row3);       
            }


//--------------------------------------------------students-------------------------------------------------------------//
 if(isset($course_id)&&isset($exams_id)&&isset($papers_shortcode)&&isset($slots)){
     $sql4="SELECT roll_number from pwe_answersheet_submit WHERE  course_id='$course_id' AND exams_id='$exams_id' 
       AND papers_shortcode='$papers_shortcode' AND slots='$slots'";
          }
            
   
            $result4=mysqli_query($con,$sql4);
            
                while ($row4[]=mysqli_fetch_assoc($result4)) {  
            
                  $students=count($row4);
            
                }

        echo '[{"passed":"'.$pass.'","failed":"'.$fail.'","Evaluated":"'.$file.'","students":"'.$students.'"}]';


?>