<?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'];
 $room_id = $request->getParsedBody()['room_id'];
 $season_id = $request->getParsedBody()['season_id'];
  $exams_id = $request->getParsedBody()['exams_id'];
  $block_id = $request->getParsedBody()['block_id'];
  $floors=$request->getParsedBody()['floors'];
  $date = $request->getParsedBody()['date'];
  $time = $request->getParsedBody()['time'];

    


 $response=array();
 $data=array();

 //$result_roll = json_encode($room_id);

for($i=0;$i<count($room_id);$i++)

{


$new_insert_set_rooms_room_id = $room_id[$i][set_rooms_room_id];
 $new_insert_seats = $room_id[$i][seats];
 $new_insert_proctors = $room_id[$i][proctors];

$select_sql = "SELECT * FROM seatingarrangements WHERE course_id = '$course_id' AND season_id = '$season_id' AND exams_id = '$exams_id' AND date = '$date' AND time	 = '$time' AND blockid = '$block_id' AND floors = '$floors' AND room_id = '$new_insert_set_rooms_room_id'";

$sql_query = mysqli_query($con,$select_sql);

if(mysqli_num_rows($sql_query)>0)
{
    $response=array('status' => "false",'Message' => "schedule_exam Failed");
}
else{

 $sql="INSERT INTO  seatingarrangements(course_id,season_id,exams_id,date,time,blockid,floors,room_id,seats,proctors) VALUES ('$course_id','$season_id','$exams_id','$date','$time','$block_id','$floors','$new_insert_set_rooms_room_id','$new_insert_seats','$new_insert_proctors')";
$res=mysqli_query($con,$sql);
if ($res=true) {
     // $data=
     //    array(
     //      "Exam_id"=>$exams_id,
     //     );
    
    $message=$data;
 
$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);
        }
        

}   
     // echo $roll_number[1][rollnumber];
      //  print_r($roll_number[0][rollnumber]);
}
?>