116 lines
4.8 KiB
PHP
116 lines
4.8 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// Check if user is logged in and is an admin
|
|
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true || !isset($_SESSION['user_role']) || $_SESSION['user_role'] !== 'admin') {
|
|
header("location: login.php");
|
|
exit;
|
|
}
|
|
|
|
$db = db();
|
|
|
|
// Fetch all submissions with user information
|
|
$stmt = $db->prepare("
|
|
SELECT
|
|
s.id,
|
|
s.item_type,
|
|
s.quantity,
|
|
s.points_awarded,
|
|
s.submission_date,
|
|
u.name as user_name,
|
|
u.email as user_email
|
|
FROM
|
|
waste_submissions s
|
|
JOIN
|
|
users u ON s.user_id = u.id
|
|
ORDER BY
|
|
s.submission_date DESC
|
|
");
|
|
$stmt->execute();
|
|
$all_submissions = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Admin Dashboard - E-Waste Reclaimer</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
|
<div class="container-fluid">
|
|
<a class="navbar-brand" href="index.php"><i class="fas fa-recycle me-2"></i>E-Waste Reclaimer (Admin)</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav ms-auto">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="dashboard.php">My Dashboard</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link active" href="admin_dashboard.php">Admin Dashboard</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="logout.php">Logout</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container my-5">
|
|
<h1 class="mb-4">Admin Dashboard: All Submissions</h1>
|
|
|
|
<div class="card shadow-sm">
|
|
<div class="card-header">
|
|
<h5 class="mb-0">All User Submissions</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<?php if (empty($all_submissions)): ?>
|
|
<p class="text-center">No submissions have been made by any user yet.</p>
|
|
<?php else: ?>
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>Date</th>
|
|
<th>User</th>
|
|
<th>Email</th>
|
|
<th>Item Type</th>
|
|
<th>Quantity</th>
|
|
<th>Points</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($all_submissions as $submission): ?>
|
|
<tr>
|
|
<td><?php echo date("F j, Y, g:i a", strtotime($submission['submission_date'])); ?></td>
|
|
<td><?php echo htmlspecialchars($submission['user_name']); ?></td>
|
|
<td><?php echo htmlspecialchars($submission['user_email']); ?></td>
|
|
<td><?php echo htmlspecialchars($submission['item_type']); ?></td>
|
|
<td><?php echo $submission['quantity']; ?></td>
|
|
<td><span class="badge bg-success"><?php echo $submission['points_awarded']; ?></span></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<footer class="bg-dark text-white text-center p-3 mt-auto">
|
|
<p class="mb-0">© <?php echo date("Y"); ?> E-Waste Reclaimer. All Rights Reserved.</p>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|