<?php

/*Student API*/


/*Fetching API*/


/* Attempt to connect to MySQL database */
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'Restax_final');

define('DB_PASSWORD', 'Restax_final123');

define('DB_NAME', 'Restax_api_data'); 

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

$course_id = $request->getAttribute('course_id');
$semester_id = $request->getAttribute('semester_id');
$exams_id = $request->getAttribute('exams_id');
$date = $request->getAttribute('date');
$time = $request->getAttribute('time');
// Check connection

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$response=array();

$sql_seat="SELECT paper,papers_shortcode,roll_number,slot FROM pwi_submit WHERE course_id = '$course_id' AND season_id = '$semester_id' AND exams_id = '$exams_id' AND date = '$date' AND time = '$time'";

$result_seat=mysqli_query($con,$sql_seat);

    while ($row_seat=mysqli_fetch_assoc($result_seat)) {  


$finaldata = $row_seat;

$get_paper = json_decode($row_seat['paper']);
$get_papers_shortcode = json_decode($row_seat['papers_shortcode']);
$get_slot = json_decode($row_seat['slot']);
$get_roll_number = json_decode($row_seat['roll_number']);


$last_paper = array_unique($get_paper);
$last_papers_shortcode = array_unique($get_papers_shortcode);
$last_slot = array_unique($get_slot);
$last_count_roll_no = count($get_roll_number);


}

$j=0;
foreach($get_roll_number as $data)
{
 $sql_select = "SELECT * FROM pwe_answersheet_submit WHERE course_id = '$course_id' AND season_id ='$semester_id' AND exam_id = '$exams_id' AND roll_number = '$get_roll_number[$j]'";
$result_select=mysqli_query($con,$sql_select);

while ($row_select=mysqli_fetch_assoc($result_select)) {  
    
    $final_data[] = $row_select;
}
$j++;
}

$get_eval_stu = count($final_data);

$key[] = array('paper'=>$last_paper,'slot'=>$last_slot,'paper_shortcode'=>$last_papers_shortcode,'total_students'=>$last_count_roll_no,'eval_student'=>$get_eval_stu);

// $loop=0;
// foreach($get_paper as $value)
// {
// $user_seat[$loop]['paper'] = $get_paper[$loop];
    
//     $loop ++;
// }

echo json_encode($key);


 

?>