<?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 * FROM pwi_submit WHERE proctor_sheet_id ='$get_id'";

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

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

$status_collection =json_decode($row_get_submit['status']);

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

          if($status_collection[$i] == 1)

           {
             $present[] = $status_collection[$i];

           }

           elseif($status_collection[$i] == 0)
           {
            $absent[] = $status_collection[$i];
           }

           else
           {
              $malpractice[] = $status_collection[$i];
           }

    }



      $user_get_submit=$row_get_submit;

       $list_present_count[]=count($present);
       $list_present_count[]=count($absent);
       $list_present_count[]=count($malpractice);
       $list_present_count[]=count($status_collection);
       



$keys = array('present', 'absent', 'malpractice','total');
       $list_present[] = array_combine($keys, $list_present_count);

     // print_r($list_present);

      array_push($user_get_submit, $list_present);

    }

  echo json_encode($list_present);

        

?>