<li><a href='teacher_upload_attendance'><i class='fa fa-pie-chart'></i><span>Class Attendance</span></a></li>
				<li><a href='teacher_view_attendance'><i class='fa fa-eye'></i><span>View Attendance Records</span></a></li>
				<li><a href='teacher_upload_conduct'><i class='fa fa-circle-o'></i> Manually Handled</a></li>
				<li><a href='teacher_view_conduct'><i class='fa fa-circle-o'></i> View Uploaded Behavioral</a></li>
				<li><a href='teacher_register_student_subject'><i class='fa fa-circle-o'></i> Register Student Subject</a></li>	
				
				
				showIfPermitted('teacher_upload_attendance', "<li><a href='teacher_upload_attendance'><i class='fas fa-caret-right'></i> Class Attendance</a></li>") .
				showIfPermitted('teacher_register_student_subject', "<li><a href='teacher_register_student_subject'><i class='fas fa-caret-right'></i> Register Student Subject</a></li>") .
								
								// Class Teacher
								<option selected disabled>Select Class</option>
								<?php																
								// Query only classes assigned to this teacher
								$query = "SELECT DISTINCT class FROM teacher_classes WHERE teacher_id = '$staff_id'";
								$run_query = mysqli_query($connection, $query);

								if (mysqli_num_rows($run_query) > 0) {
									while ($result = mysqli_fetch_assoc($run_query)) {
										$class = htmlspecialchars($result['class']);
										echo "<option value='{$class}'>{$class}</option>";
									}
								} else {
									echo "<option disabled>No class assigned</option>";
								}
								?>
								
								//Subject teacher
								<?php
								$selected_class = $_POST['class'] ?? '';
								$selected_subject = $_POST['subject'] ?? '';
								$subjects = [];

								if (!empty($selected_class)) {
									$stmt = $connection->prepare("SELECT DISTINCT subject FROM subject_teacher WHERE staff_id = ? AND class = ?");
									$stmt->bind_param("is", $staff_id, $selected_class);
									$stmt->execute();
									$result = $stmt->get_result();
									
									while ($row = $result->fetch_assoc()) {
										$subjects[] = $row['subject'];
									}
									$stmt->close();
								}
								?>
								
													<!-- Class Select -->
					<div class='col-md-3'>
						<div class='input-group'>
							<span class='input-group-addon'>Class:</span>
							<select class='form-control' name='class' onchange='this.form.submit()' required>
								<option disabled <?= $selected_class == '' ? 'selected' : '' ?>>Select Class</option>
								<?php
								$stmt = $connection->prepare("SELECT DISTINCT class FROM subject_teacher WHERE staff_id = ?");
								$stmt->bind_param("i", $staff_id);
								$stmt->execute();
								$result = $stmt->get_result();

								while ($row = $result->fetch_assoc()) {
								    $class = htmlspecialchars($row['class']);
								    $selected = ($selected_class == $class) ? 'selected' : '';
								    echo "<option value='{$class}' $selected>{$class}</option>";
								}
								$stmt->close();
								?>
							</select>
						</div>
						<br />
					</div>

					<!-- Subject Select -->
					<div class='col-md-3'>
						<div class='input-group'>
							<span class='input-group-addon'>Subject:</span>
							<select class='form-control' name='subject' required>
								<?php
								if (!empty($subjects)) {
								    echo "<option disabled>Select Subject</option>";
								    foreach ($subjects as $subj) {
								        $subj = htmlspecialchars($subj);
								        $selected = ($selected_subject == $subj) ? 'selected' : '';
								        echo "<option value='{$subj}' {$selected}>{$subj}</option>";
								    }
								} else {
								    echo "<option>Select a class first</option>";
								}
								?>
							</select>
						</div>
						<br />
					</div>
<div class="row mt-4">
  <!-- Inventory Summary Table -->
  <div class="col-md-6">
    <h5 class="mb-3">ðŸ“¦ Inventory Summary</h5>
    <div class="table-responsive">
      <table class="table table-sm table-bordered text-center">
        <thead class="thead-dark">
          <tr>
            <th>#</th>
            <th>Metric</th>
            <th>Value</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>1</td>
            <td>Total Items</td>
            <td><strong><?= $inv_items ?></strong></td>
          </tr>
          <tr>
            <td>2</td>
            <td>Item Categories</td>
            <td><strong><?= $inv_categories ?></strong></td>
          </tr>
          <tr>
            <td>3</td>
            <td>Low Stock</td>
            <td>
              <span class="badge <?= $inv_low > 0 ? 'badge-danger' : 'badge-success' ?>">
                <?= $inv_low ?>
              </span>
            </td>
          </tr>
          <tr>
            <td>4</td>
            <td>Total Movements</td>
            <td><strong><?= $inv_movements ?></strong></td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>

  <!-- Example: Another Table on the Right -->
  <div class="col-md-6">
    <h5 class="mb-3">ðŸ•’ Recent Stock Movements</h5>
    <div class="table-responsive">
      <table class="table table-sm table-bordered text-center">
        <thead class="thead-light">
          <tr>
            <th>#</th>
            <th>Item</th>
            <th>Type</th>
            <th>Qty</th>
          </tr>
        </thead>
        <tbody>
          <?php
          $recent = $connection->query("
            SELECT m.*, i.name 
            FROM inventory_movements m 
            JOIN inventory_items i ON m.item_id = i.id 
            ORDER BY m.id DESC 
            LIMIT 5
          ");
          $sn = 1;
          while ($r = $recent->fetch_assoc()):
          ?>
          <tr>
            <td><?= $sn++ ?></td>
            <td><?= $r['name'] ?></td>
            <td>
              <span class="badge badge-<?= $r['movement_type'] == 'IN' ? 'success' : 'danger' ?>">
                <?= $r['movement_type'] ?>
              </span>
            </td>
            <td><?= $r['quantity'] ?></td>
          </tr>
          <?php endwhile; ?>
        </tbody>
      </table>
    </div>
  </div>
</div>