<?php

// Attempt to connect to MySQL database /
// 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 = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);


$course_id=$request->getParsedBody()['course_id'];
 $season_id = $request->getParsedBody()['season_id'];
 $exams_id = $request->getParsedBody()['exams_id'];
  $date = $request->getParsedBody()['date'];
  $time = $request->getParsedBody()['time'];
  $faculty_number = $request->getParsedBody()['faculty_number'];
  


for($i=0;$i<count($faculty_number);$i++)
{
     $response=array();
 $data=array();
 
 $staff = $faculty_number[$i]["Staff_number"];
 
 /**************faculty update*************/
  $sql_update = "UPDATE faculty SET date='$date',time = '$time' WHERE Staff_number ='$staff'";
  $res=mysqli_query($con,$sql_update);
  if ($res == true) {
    
$response=array('status' => "true",'Message' => "schedule_exam Succesfully");
//echo json_encode($response);
        }
        else{
          $response=array('status' => "false",'Message' => "schedule_exam Failed");
        // echo json_encode($response);
        }
        
        /************************************/
    
}

  /****************Seated Students************/    
  
  $sql_select = "SELECT proctors,id FROM seated_students WHERE date = '$date' AND time = '$time'";
  $result_seat=mysqli_query($con,$sql_select);
  $k=0;
  $l=0;
   while ($row_seat[]=mysqli_fetch_assoc($result_seat)) {  

$staffone = $faculty_number[$k]["Staff_number"];
$idone = $row_seat[$k]["id"];
$proctorsone = $row_seat[$k]["proctors"];
$loop_array=array(); 
for($j=0;$j<$proctorsone;$j++)
{
     array_push($loop_array, $faculty_number[$l]["Staff_number"]);
     $l++;
}

$loop_json = json_encode($loop_array);
$user_seat = $row_seat;
    
  
          $sql_setup = "UPDATE seated_students SET proctors_list ='$loop_json',time = '$time' WHERE id ='$idone'";
  $res=mysqli_query($con,$sql_setup);
  
  if ($res == true) {
    
                      $response=array('status' => "true",'Message' => "schedule_exam Succesfully");
                    }
 else {
            $response=array('status' => "false",'Message' => "schedule_exam Failed");
    }

$k++;
}


    

?>