35296-vm/student_dashboard.php
Flatlogic Bot 8d0660a262 yu
2025-11-02 07:44:15 +00:00

103 lines
4.1 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_role']) || $_SESSION['user_role'] !== 'student') {
header('Location: index.php');
exit;
}
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/includes/header.php';
$success_message = '';
if (isset($_GET['success']) && $_GET['success'] == 1) {
$success_message = 'Leave request submitted successfully!';
}
$leave_requests = [];
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT * FROM leave_requests WHERE student_id = ? ORDER BY created_at DESC");
$stmt->execute([$_SESSION['user_id']]);
$leave_requests = $stmt->fetchAll();
} catch (PDOException $e) {
// handle error
}
?>
<div class="container">
<div class="d-flex justify-content-between align-items-center mb-3">
<h1>Student Dashboard</h1>
<div>
<span class="me-3">Welcome, <?php echo htmlspecialchars($_SESSION['user_full_name']); ?>!</span>
<a href="logout.php" class="btn btn-primary">Logout</a>
</div>
</div>
<?php if ($success_message): ?>
<div class="alert alert-success" role="alert">
<?php echo $success_message; ?>
</div>
<?php endif; ?>
<div class="row mt-4">
<div class="col-md-6">
<h2>Submit Leave Request</h2>
<form action="submit_leave_request.php" method="POST" enctype="multipart/form-data">
<div class="mb-3">
<label for="leave_type" class="form-label">Leave Type</label>
<select class="form-select" id="leave_type" name="leave_type" required>
<option value="" selected disabled>Select leave type</option>
<option value="sick_leave">Sick Leave</option>
<option value="vacation">Vacation</option>
<option value="personal">Personal</option>
<option value="other">Other</option>
</select>
</div>
<div class="mb-3">
<label for="start_date" class="form-label">Start Date</label>
<input type="date" class="form-control" id="start_date" name="start_date" required>
</div>
<div class="mb-3">
<label for="end_date" class="form-label">End Date</label>
<input type="date" class="form-control" id="end_date" name="end_date" required>
</div>
<div class="mb-3">
<label for="reason" class="form-label">Reason</label>
<textarea class="form-control" id="reason" name="reason" rows="3" required></textarea>
</div>
<div class="mb-3">
<label for="attachment" class="form-label">Attachment (optional)</label>
<input type="file" class="form-control" id="attachment" name="attachment">
</div>
<button type="submit" class="btn btn-primary">Submit Request</button>
</form>
</div>
<div class="col-md-6">
<h2>My Leave Requests</h2>
<table class="table">
<thead>
<tr>
<th>Leave Type</th>
<th>Start Date</th>
<th>End Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($leave_requests as $request): ?>
<tr>
<td><?php echo htmlspecialchars($request['leave_type']); ?></td>
<td><?php echo htmlspecialchars($request['start_date']); ?></td>
<td><?php echo htmlspecialchars($request['end_date']); ?></td>
<td><?php echo htmlspecialchars($request['status']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php require_once __DIR__ . '/includes/footer.php'; ?>