<?php

/* 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);

$get_id = $request->getAttribute('id');
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$response=array();

$list_present = array();
//////////////get submit answer/////////////////

$sql_get_submit="SELECT pwi_submit.*,Exams.examname,faculty.Faculty_name FROM pwi_submit INNER JOIN Exams ON Exams.id = pwi_submit.exams_id INNER JOIN faculty ON faculty.id = pwi_submit.proctor_id WHERE pwi_submit.id ='$get_id'";

$result_get_submit=mysqli_query($con,$sql_get_submit);

    while ($row_get_submit=mysqli_fetch_assoc($result_get_submit)) {  

      $user_get_submit=$row_get_submit;
      $date=$row_get_submit['date'];
      $time=$row_get_submit['time'];
      $proctor_id=$row_get_submit['proctor_id'];
      $examname=$row_get_submit['examname'];
      $facultyname=$row_get_submit['Faculty_name'];
      $roll_number=json_decode($row_get_submit['roll_number']);
      $papers_shortcode=json_decode($row_get_submit['papers_shortcode']);
      $status=json_decode($row_get_submit['status']);


    }


//echo count($roll_number);

for($i=0;$i<count($roll_number);$i++)
{


//***********present status***********///
if($status[$i] == 0)
{
 
 $status_result = "Absent";
}
else
{
$status_result = "Present";
}
//*************///

//*************misdeed*******//
if($status[$i] == 2)
{
 
 $misdeed_result = "True";
}
else
{
$misdeed_result = "False";
}
//*******************//
   $status_loop[] = $status_result;
   $misdeed_loop[] = $misdeed_result;
  $date_loop[] = $date;
  $time_loop[] = $time;
  $proctor_id_loop[] = $proctor_id;
   $examname_loop[] = $examname;
   $facultyname_loop[] = $facultyname;


$list_submission_data[$i][] = $date_loop[$i];
$list_submission_data[$i][] = $time_loop[$i];
$list_submission_data[$i][] = $examname_loop[$i];
$list_submission_data[$i][] = $proctor_id_loop[$i];
$list_submission_data[$i][] = $facultyname_loop[$i];
$list_submission_data[$i][] = $roll_number[$i];
$list_submission_data[$i][] = $papers_shortcode[$i];
$list_submission_data[$i][] = $status_loop[$i];
$list_submission_data[$i][] = $misdeed_loop[$i];

      $keys = array('date','time', 'examname', 'proctor_id','faculty_name','student','paper','status','misdeed');
       $list_submission[] = array_combine($keys, $list_submission_data[$i]);


}

 echo json_encode($list_submission);



        //print_r($misdeed_loop);

?>