<?php

$con = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
$course_id = $request->getAttribute('course_id');
$season_id=$request->getAttribute('season_id');
$exams_id=$request->getAttribute('exams_id');
/*
$paper=$request->getAttribute('paper');
$slots=$request->getAttribute('slots');
$staff_number=$request->getAttribute('staff_number');
*/
$response=array();
/*
if(isset($course_id)&&isset($season_id)&&isset($exams_id)&&isset($paper)&&isset($slots)&&isset($staff_number)){
$sql=" select assign_pwt.id, assign_pwt.course_id, assign_pwt.season_id, assign_pwt.exams_id, assign_pwt.paper, assign_pwt.slots, assign_pwt.staff_number,
course.course_name, season.seasonname, Exams.examname, set_papers.papers_shortcode, create_slots.slots, faculty.Staff_number
 from (assign_pwt INNER JOIN course ON course.course_id=assign_pwt.course_id 
 INNER JOIN season ON season.id=assign_pwt.season_id
 INNER JOIN Exams ON Exams.id=assign_pwt.exams_id
 INNER JOIN set_papers ON set_papers.papers_id=assign_pwt.paper
 INNER JOIN create_slots ON create_slots.id=assign_pwt.slots
 INNER JOIN faculty ON faculty.id=assign_pwt.Staff_number)
  WHERE assign_pwt.course_id='$course_id' AND assign_pwt.season_id='$season_id' AND assign_pwt.exams_id='$exams_id'
  AND assign_pwt.paper='$paper' AND assign_pwt.slots='$slots' AND assign_pwt.staff_number='$staff_number'";
}

elseif(isset($course_id)&&isset($season_id)&&isset($exams_id)&&isset($paper)&&isset($slots)){
$sql=" select assign_pwt.id, assign_pwt.course_id, assign_pwt.season_id, assign_pwt.exams_id, assign_pwt.paper, assign_pwt.slots, assign_pwt.staff_number,
course.course_name, season.seasonname, Exams.examname, set_papers.papers_shortcode, create_slots.slots, faculty.Staff_number
 from (assign_pwt INNER JOIN course ON course.course_id=assign_pwt.course_id 
 INNER JOIN season ON season.id=assign_pwt.season_id
 INNER JOIN Exams ON Exams.id=assign_pwt.exams_id
 INNER JOIN set_papers ON set_papers.papers_id=assign_pwt.paper
 INNER JOIN create_slots ON create_slots.id=assign_pwt.slots
 INNER JOIN faculty ON faculty.id=assign_pwt.Staff_number)
  WHERE assign_pwt.course_id='$course_id' AND assign_pwt.season_id='$season_id' AND assign_pwt.exams_id='$exams_id'
  AND assign_pwt.paper='$paper' AND assign_pwt.slots='$slots'";
}

elseif(isset($course_id)&&isset($season_id)&&isset($exams_id)&&isset($paper)){
$sql=" select assign_pwt.id, assign_pwt.course_id, assign_pwt.season_id, assign_pwt.exams_id, assign_pwt.paper, assign_pwt.slots, assign_pwt.staff_number,
course.course_name, season.seasonname, Exams.examname, set_papers.papers_shortcode, create_slots.slots, faculty.Staff_number
 from (assign_pwt INNER JOIN course ON course.course_id=assign_pwt.course_id 
 INNER JOIN season ON season.id=assign_pwt.season_id
 INNER JOIN Exams ON Exams.id=assign_pwt.exams_id
 INNER JOIN set_papers ON set_papers.papers_id=assign_pwt.paper
 INNER JOIN create_slots ON create_slots.id=assign_pwt.slots
 INNER JOIN faculty ON faculty.id=assign_pwt.Staff_number)
  WHERE assign_pwt.course_id='$course_id' AND assign_pwt.season_id='$season_id' AND assign_pwt.exams_id='$exams_id'
  AND assign_pwt.paper='$paper'";
}
*/


if(isset($course_id)&&isset($season_id)&&isset($exams_id)){
$sql=" select assign_pwt.id,  assign_pwt.paper, assign_pwt.slots, assign_pwt.staff_number,
set_papers.papers_shortcode, faculty.Staff_number
 from (assign_pwt
 INNER JOIN set_papers ON set_papers.papers_id=assign_pwt.paper
 

 INNER JOIN faculty ON faculty.id=assign_pwt.staff_number
 )
  WHERE   assign_pwt.course_id='$course_id' AND assign_pwt.season_id='$season_id' AND assign_pwt.exams_id='$exams_id'";
}

elseif(isset($course_id)&&isset($season_id)){
$sql=" select assign_pwt.id,  assign_pwt.paper, assign_pwt.slots, assign_pwt.staff_number,
set_papers.papers_shortcode, faculty.Staff_number
 from (assign_pwt
 INNER JOIN set_papers ON set_papers.papers_id=assign_pwt.paper
 

 INNER JOIN faculty ON faculty.id=assign_pwt.staff_number
 )
  WHERE   assign_pwt.course_id='$course_id' AND assign_pwt.season_id='$season_id' ";
}

elseif(isset($course_id)){
$sql=" select assign_pwt.id,  assign_pwt.paper, assign_pwt.slots, assign_pwt.staff_number,
set_papers.papers_shortcode, faculty.Staff_number
 from (assign_pwt
 INNER JOIN set_papers ON set_papers.papers_id=assign_pwt.paper
 

 INNER JOIN faculty ON faculty.id=assign_pwt.staff_number
 )
  WHERE    assign_pwt.course_id='$course_id'";
}

else{
$sql=" select assign_pwt.id,  assign_pwt.paper, assign_pwt.slots, assign_pwt.staff_number,
set_papers.papers_shortcode, faculty.Staff_number
 from (assign_pwt
 INNER JOIN set_papers ON set_papers.papers_id=assign_pwt.paper
 

 INNER JOIN faculty ON faculty.id=assign_pwt.staff_number
 ) ";
}
 
 
$result=mysqli_query($con,$sql);

    while ($row[]=mysqli_fetch_assoc($result)) {  

      $user=$row;

	}


echo json_encode($user);

?>