<?php
include "../include/config.php";
session_start();
$userlogin = $_SESSION['email'];
$role=$_SESSION['role'];
$intake = $_SESSION['department'];
if (isset($_POST['program'], $_POST['semester'])) {
    $program  = mysqli_real_escape_string($conn, $_POST['program']);
    $semester = mysqli_real_escape_string($conn, $_POST['semester']);
    if($role=="Admin" || $role=="Superadmin"){
    $sql = "SELECT * FROM timetable 
            WHERE program = '$program' 
            ORDER BY course";
             $result = $conn->query($sql);
    }else{
        $sql = "SELECT * FROM timetable 
            WHERE program = '$program' AND semester = '$semester' and staff_id='$email' 
            ORDER BY course"; 
             $result = $conn->query($sql);
    }
   
    
    if ($result->num_rows > 0) {
        echo "<option value=''>Select Course</option>";
        while ($row = $result->fetch_assoc()) {
            echo "<option value='" . $row['course'] . "'>" . $row['course'] . "</option>";
        }
    } else {
        echo "<option value=''>No courses found</option>";
    }
}
?>
