<?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_shortcode = $request->getAttribute('papers_shortcode');

$response=array();

if(isset($course_id)&&isset($exams_id)&&isset($papers_shortcode)){
$sql="SELECT pwe_answersheet_submit.course_id, pwe_answersheet_submit.exams_id, pwe_answersheet_submit.papers_shortcode, 
pwe_answersheet_submit.papers_id,
pwe_answersheet_submit.roll_number, course.course_name, Exams.examname  from pwe_answersheet_submit INNER JOIN course ON course.course_id=pwe_answersheet_submit.course_id
INNER JOIN Exams ON Exams.id=pwe_answersheet_submit.exams_id
WHERE re_evaluate='1'
 AND  pwe_answersheet_submit.course_id='$course_id' AND pwe_answersheet_submit.exams_id='$exams_id' 
 AND pwe_answersheet_submit.papers_shortcode='$papers_shortcode'";
}

elseif(isset($course_id)&&isset($exams_id)){
    $sql="SELECT pwe_answersheet_submit.course_id, pwe_answersheet_submit.exams_id, pwe_answersheet_submit.papers_shortcode, 
    pwe_answersheet_submit.papers_id,
    pwe_answersheet_submit.roll_number, course.course_name, Exams.examname  from pwe_answersheet_submit INNER JOIN course ON course.course_id=pwe_answersheet_submit.course_id
    INNER JOIN Exams ON Exams.id=pwe_answersheet_submit.exams_id
    WHERE re_evaluate='1'
     AND  pwe_answersheet_submit.course_id='$course_id' AND pwe_answersheet_submit.exams_id='$exams_id' 
     ";
    }

    elseif(isset($course_id)){
        $sql="SELECT pwe_answersheet_submit.course_id, pwe_answersheet_submit.exams_id, pwe_answersheet_submit.papers_shortcode, 
        pwe_answersheet_submit.papers_id,
        pwe_answersheet_submit.roll_number, course.course_name, Exams.examname  from pwe_answersheet_submit INNER JOIN course ON course.course_id=pwe_answersheet_submit.course_id
        INNER JOIN Exams ON Exams.id=pwe_answersheet_submit.exams_id
        WHERE re_evaluate='1'
         AND  pwe_answersheet_submit.course_id='$course_id' 
         ";
        }

$result=mysqli_query($con,$sql);

$i=0;
while ($row=mysqli_fetch_assoc($result)) {



$course_id = $row['course_id'];
$exams_id =  $row['exams_id'];
$course_name = $row['course_name'];
$examname =  $row['examname'];
$roll_number =  $row['roll_number'];
$papers_shortcode =  $row['papers_shortcode'];
$papers_id =  $row['papers_id'];

$i++;
}


$count = count($roll_number);

if(isset($course_id)&&isset($exams_id)&&isset($papers_shortcode)){
    $sql2="SELECT roll_number from  re_evaluate_submit WHERE  course_id='$course_id' AND exams_id='$exams_id' 
     AND papers_shortcode='$papers_shortcode' ";
      }
      elseif(isset($course_id)&&isset($exams_id)){
        $sql2="SELECT roll_number from  re_evaluate_submit WHERE  course_id='$course_id' AND exams_id='$exams_id' 
          ";
          }
          elseif(isset($course_id)){
            $sql2="SELECT roll_number from  re_evaluate_submit WHERE  course_id='$course_id' ";
              }
     
      
     $result2=mysqli_query($con,$sql2);   
         while ($row2[]=mysqli_fetch_assoc($result2)) {    
           $correction_papers=$row2;   
         }
         $correction_papers2=count($correction_papers);

$keys[] = array("course_id"=>"$course_id","exams_id"=>"$exams_id","course_name"=>"$course_name","examname"=>"$examname",
"papers_shortcode"=>"$papers_shortcode","papers_id"=>"$papers_id",
"total_re_evaluate_students"=>"$count", "resolve_status"=>"$correction_papers2");

echo json_encode($keys);


?>






