78 lines
2.9 KiB
PHP
78 lines
2.9 KiB
PHP
<?php
|
|
require_once 'auth_check.php';
|
|
require_once 'db/config.php';
|
|
require_once 'includes/helpers.php';
|
|
|
|
// Admin-only view
|
|
if ($_SESSION['role'] !== 'admin') {
|
|
header("Location: index.php"); // Redirect non-admins
|
|
exit;
|
|
}
|
|
|
|
$pageTitle = 'All Change Requests';
|
|
|
|
// Fetch all requests from the database
|
|
try {
|
|
$pdoconn = db();
|
|
$stmt = $pdoconn->prepare('SELECT cr.*, u.username as requester_name FROM change_requests cr JOIN users u ON cr.requester_id = u.id ORDER BY cr.created_at DESC');
|
|
$stmt->execute();
|
|
$requests = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
$requests = [];
|
|
error_log("Database error: " . $e->getMessage());
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?= htmlspecialchars($pageTitle) ?></title>
|
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
<?php include 'header.php'; ?>
|
|
|
|
<div class="container mt-5">
|
|
<h2>All Submitted Requests</h2>
|
|
<hr>
|
|
<?php if (empty($requests)): ?>
|
|
<div class="alert alert-info">No requests have been submitted yet.</div>
|
|
<?php else: ?>
|
|
<table class="table table-bordered table-striped">
|
|
<thead class="thead-dark">
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Change Title</th>
|
|
<th>Requester</th>
|
|
<th>Status</th>
|
|
<th>Submitted On</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($requests as $request): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($request['id']) ?></td>
|
|
<td><?= htmlspecialchars($request['change_title']) ?></td>
|
|
<td><?= htmlspecialchars($request['requester_name']) ?></td>
|
|
<td><?= displayStatusBadge($request['status']) ?></td>
|
|
<td><?= htmlspecialchars(date('Y-m-d H:i', strtotime($request['created_at']))) ?></td>
|
|
<td>
|
|
<a href="view_request.php?id=<?= $request['id'] ?>" class="btn btn-sm btn-primary">View</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.2/dist/umd/popper.min.js"></script>
|
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
|
</body>
|
|
</html>
|