You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
4.9 KiB
124 lines
4.9 KiB
6 months ago
|
<?php
|
||
|
require 'db_connection.php';
|
||
|
session_start();
|
||
|
|
||
|
// Ensure the admin is logged in
|
||
|
if (!isset($_SESSION['user_email']) || $_SESSION['role'] !== 'admin') {
|
||
|
header("Location: login.php");
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
// Fetch dashboard metrics
|
||
|
$total_users = $conn->query("SELECT COUNT(*) AS count FROM users")->fetch_assoc()['count'];
|
||
|
$total_donations = $conn->query("SELECT COUNT(*) AS count FROM material_donations")->fetch_assoc()['count'];
|
||
|
$pending_donations = $conn->query("SELECT COUNT(*) AS count FROM material_donations WHERE status = 'pending'")->fetch_assoc()['count'];
|
||
|
|
||
|
// Fetch users and donations
|
||
|
$users = $conn->query("SELECT * FROM users ORDER BY created_at DESC");
|
||
|
$donations = $conn->query("SELECT * FROM material_donations ORDER BY created_at DESC");
|
||
|
?>
|
||
|
|
||
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
<title>Admin Dashboard</title>
|
||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
|
||
|
</head>
|
||
|
<body>
|
||
|
<?php include 'includes/header.php'; ?>
|
||
|
|
||
|
<div class="container mt-5">
|
||
|
<h2>Admin Dashboard</h2>
|
||
|
|
||
|
<!-- Dashboard Metrics -->
|
||
|
<div class="row text-center my-4">
|
||
|
<div class="col-md-4">
|
||
|
<div class="card bg-primary text-white">
|
||
|
<div class="card-body">
|
||
|
<h3><?php echo $total_users; ?></h3>
|
||
|
<p>Total Users</p>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="col-md-4">
|
||
|
<div class="card bg-success text-white">
|
||
|
<div class="card-body">
|
||
|
<h3><?php echo $total_donations; ?></h3>
|
||
|
<p>Total Donations</p>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="col-md-4">
|
||
|
<div class="card bg-warning text-white">
|
||
|
<div class="card-body">
|
||
|
<h3><?php echo $pending_donations; ?></h3>
|
||
|
<p>Pending Approvals</p>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<!-- Users Management -->
|
||
|
<h3>Manage Users</h3>
|
||
|
<table class="table table-bordered">
|
||
|
<thead>
|
||
|
<tr>
|
||
|
<th>ID</th>
|
||
|
<th>Email</th>
|
||
|
<th>Role</th>
|
||
|
<th>Actions</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody>
|
||
|
<?php while ($user = $users->fetch_assoc()): ?>
|
||
|
<tr>
|
||
|
<td><?php echo $user['id']; ?></td>
|
||
|
<td><?php echo $user['email']; ?></td>
|
||
|
<td><?php echo ucfirst($user['role']); ?></td>
|
||
|
<td>
|
||
|
<a href="edit_user.php?id=<?php echo $user['id']; ?>" class="btn btn-sm btn-primary">Edit</a>
|
||
|
<a href="delete_user.php?id=<?php echo $user['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this user?');">Delete</a>
|
||
|
</td>
|
||
|
</tr>
|
||
|
<?php endwhile; ?>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
|
||
|
<!-- Donations Management -->
|
||
|
<h3 class="mt-5">Manage Donations</h3>
|
||
|
<table class="table table-bordered">
|
||
|
<thead>
|
||
|
<tr>
|
||
|
<th>ID</th>
|
||
|
<th>Item Name</th>
|
||
|
<th>Condition</th>
|
||
|
<th>Quantity</th>
|
||
|
<th>Status</th>
|
||
|
<th>Actions</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody>
|
||
|
<?php while ($donation = $donations->fetch_assoc()): ?>
|
||
|
<tr>
|
||
|
<td><?php echo $donation['id']; ?></td>
|
||
|
<td><?php echo $donation['item_name']; ?></td>
|
||
|
<td><?php echo $donation['conditions']; ?></td>
|
||
|
<td><?php echo $donation['quantity']; ?></td>
|
||
|
<td><?php echo ucfirst($donation['status']); ?></td>
|
||
|
<td>
|
||
|
<?php if ($donation['status'] === 'pending'): ?>
|
||
|
<a href="approve_donation.php?id=<?php echo $donation['id']; ?>" class="btn btn-sm btn-success">Approve</a>
|
||
|
<a href="reject_donation.php?id=<?php echo $donation['id']; ?>" class="btn btn-sm btn-warning">Reject</a>
|
||
|
<?php endif; ?>
|
||
|
<a href="delete_donation.php?id=<?php echo $donation['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this donation?');">Delete</a>
|
||
|
</td>
|
||
|
</tr>
|
||
|
<?php endwhile; ?>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|