145 lines
5.6 KiB
PHP
145 lines
5.6 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user_role']) || $_SESSION['user_role'] !== 'admin') {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
require_once __DIR__ . '/db/config.php';
|
|
require_once __DIR__ . '/includes/header.php';
|
|
|
|
$leave_requests = [];
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT leave_requests.*, users.full_name AS student_name FROM leave_requests JOIN users ON leave_requests.student_id = users.id WHERE leave_requests.status = 'approved_by_teacher' ORDER BY leave_requests.created_at DESC");
|
|
$stmt->execute();
|
|
$leave_requests = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
// handle error
|
|
}
|
|
|
|
// Monthly report
|
|
$report = [];
|
|
$month = date('Y-m');
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT status, COUNT(*) as count FROM leave_requests WHERE DATE_FORMAT(created_at, '%Y-%m') = ? GROUP BY status");
|
|
$stmt->execute([$month]);
|
|
$result = $stmt->fetchAll();
|
|
foreach ($result as $row) {
|
|
$report[$row['status']] = $row['count'];
|
|
}
|
|
} catch (PDOException $e) {
|
|
// handle error
|
|
}
|
|
|
|
$import_success_message = '';
|
|
if (isset($_GET['import_success']) && $_GET['import_success'] == 1) {
|
|
$import_success_message = 'Students imported successfully!';
|
|
}
|
|
|
|
$import_error_message = '';
|
|
if (isset($_GET['import_error']) && $_GET['import_error'] == 1) {
|
|
$import_error_message = 'Error importing students. Please check the file and try again.';
|
|
}
|
|
|
|
?>
|
|
|
|
<div class="container">
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<h1>Admin 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 ($import_success_message): ?>
|
|
<div class="alert alert-success" role="alert">
|
|
<?php echo $import_success_message; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($import_error_message): ?>
|
|
<div class="alert alert-danger" role="alert">
|
|
<?php echo $import_error_message; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="row mt-4">
|
|
<div class="col-md-12">
|
|
<h2>Pending Leave Requests for Final Approval</h2>
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Student Name</th>
|
|
<th>Leave Type</th>
|
|
<th>Start Date</th>
|
|
<th>End Date</th>
|
|
<th>Reason</th>
|
|
<th>Attachment</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($leave_requests as $request): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($request['student_name']); ?></td>
|
|
<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['reason']); ?></td>
|
|
<td>
|
|
<?php if ($request['attachment_path']): ?>
|
|
<a href="<?php echo htmlspecialchars($request['attachment_path']); ?>" target="_blank">View Attachment</a>
|
|
<?php else: ?>
|
|
No Attachment
|
|
<?php endif; ?>
|
|
</td>
|
|
<td>
|
|
<a href="update_leave_status.php?id=<?php echo $request['id']; ?>&status=approved_by_admin" class="btn btn-success btn-sm">Approve</a>
|
|
<a href="update_leave_status.php?id=<?php echo $request['id']; ?>&status=rejected_by_admin" class="btn btn-danger btn-sm">Reject</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row mt-4">
|
|
<div class="col-md-6">
|
|
<h2>Monthly Report (<?php echo date('F Y'); ?>)</h2>
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Status</th>
|
|
<th>Count</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($report as $status => $count): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($status); ?></td>
|
|
<td><?php echo $count; ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<a href="export_report.php" class="btn btn-primary">Export to CSV</a>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<h2>Import Students</h2>
|
|
<form action="import_students.php" method="POST" enctype="multipart/form-data">
|
|
<div class="mb-3">
|
|
<label for="student_file" class="form-label">Select CSV file</label>
|
|
<input type="file" class="form-control" id="student_file" name="student_file" accept=".csv" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Import Students</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|