<?php
session_start();

if(!isset($_SESSION['login_id'])){
    header("Location: ../login/login.php");
    exit();
}

header("Cache-Control: no-cache, no-store, must-revalidate");
header("Pragma: no-cache");
header("Expires: 0");
?>

<?php
$con = mysqli_connect("localhost","root","","WSAS");
if (!$con) die("Database connection failed");

if (!isset($_GET['course_id'])) header("location: ../adminpanel/admincourse.php");

$course_id = $_GET['course_id'];
$course = mysqli_query($con, "SELECT * FROM admincourse WHERE course_id='$course_id'");
$course_data = mysqli_fetch_assoc($course);
?>

<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE-edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>View Course's Student - Admin</title>
    <link rel="shortcut icon" type="x-icon" href="../images/logo.png">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@24,400,0,0" />
    <link rel="stylesheet" href="../Style/navstyle.css">

<style>

.dashboard-container {
  display: flex;
  height: 100vh;
}

.mainbar {
    margin-left: 280px;
    width: calc(100% - 280px);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.mainbar-context {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

.container {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.subject {
  background-color: #4a9c3f;
  color: white;
  padding: 20px;
  flex: 1;
  min-width: 200px;
  border-radius: 10px;
  text-align: center;
}

.container1 {
  display: flex;
  padding: 10px;
  gap: 20px;
  flex-wrap: wrap;
  align-items: center;
}

table {
  width: 100%;
  border-collapse: collapse; 
  background: rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  overflow: hidden;
  font-family: "Segoe UI", sans-serif;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 
  text-align: center;
}


table th {
  background-color: #2b5820; 
  color: white;
  font-weight: 600;
  padding: 12px;
  border: 1px solid #2b5820; 
}


table td {
  border: 1px solid #ccc; 
  padding: 10px;
  color: #222;
}


table tr:nth-child(even) {
  background-color: #f8f8f8;
}


table tr:hover {
  background-color: rgba(74, 156, 63, 0.1);
  transition: background-color 0.3s ease;
}

@media (max-width: 1024px) {
  .mainbar {
    margin-left: 0; 
    margin-top: 70px;
  }

  .dashboard-container {
    flex-direction: column;
  }
}

.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
}

.modal-content {
  background: white;
  width: 400px;
  margin: 10% auto;
  padding: 20px;
  border-radius: 10px;
  animation: pop 0.3s ease;
}

.close-btn {
  float: right;
  cursor: pointer;
  font-size: 25px;
  padding: 5px;
}

.open-btn {
  background: #4a9c3f;
  color: white;
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

@keyframes pop {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
</style>

<body> 
<?php include('../adminpanel/adminnav.php'); ?>

<aside class="mainbar">
    <h1><?php echo $course_data['course_code']; ?> - <?php echo $course_data['course_name']; ?> - Curriculum</h1>

<?php
$sy_query = mysqli_query($con, "SELECT * FROM school_year WHERE is_active = 1 LIMIT 1");
$sy = mysqli_fetch_assoc($sy_query);

$students_query = mysqli_query($con, "
    SELECT s.student_id, s.student_id_num, s.f_name, s.m_name, s.l_name, s.sex,
           e.year_level, e.student_status
    FROM enroll_student e
    JOIN adminstudent s ON e.student_id = s.student_id
    WHERE e.course_id = '$course_id'
    AND e.sy_id = '{$sy['sy_id']}'
    AND e.semester = '{$sy['semester']}'
    ORDER BY e.year_level ASC, s.l_name ASC
");

?>

<table>
<thead>
<tr>
<th>Student ID</th>
<th>Full Name</th>
<th>Sex</th>
<th>Year Level</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>

<tbody>

<?php while($row = mysqli_fetch_assoc($students_query)): ?>

<tr>
<td><?= $row['student_id_num']; ?></td>

<td>
<?= $row['f_name']." ".$row['m_name']." ".$row['l_name']; ?>
</td>

<td><?= $row['sex']; ?></td>

<td><?= $row['year_level']; ?></td>

<td><?= $row['student_status']; ?></td>

<td>
<a class="upd_btn" href="../view/student_sub.php?student_id=<?= $row['student_id']; ?>">View</a>
</td>

</tr>

<?php endwhile; ?>

</tbody>
</table>
</aside>

    <!-- Script -->
     <script src="../Jscript/script.js"></script>
     <script src="../Jscript/form.js"></script>

    
</body>
</html>