Spaces:
Configuration error
Configuration error
Download admin.php from brucelloyd1/lost-found-tracker-pro: direct link, hf CLI and curl.
- Browser
- Download file 13.7 kB
-
https://huggingface.co/spaces/brucelloyd1/lost-found-tracker-pro/resolve/main/admin.php
- Command line
-
hf download hf://spaces/brucelloyd1/lost-found-tracker-pro/admin.php
-
curl -L -o admin.php https://huggingface.co/spaces/brucelloyd1/lost-found-tracker-pro/resolve/main/admin.php
13.7 kB
| ```php | |
| include 'includes/auth.php'; | |
| redirectIfNotAdmin(); | |
| include 'config/database.php'; | |
| $db = new Database(); | |
| $connection = $db->getConnection(); | |
| // Get system statistics | |
| $statsQueries = [ | |
| 'total_users' => "SELECT COUNT(*) as count FROM users", | |
| 'total_finders' => "SELECT COUNT(*) as count FROM users WHERE role = 'finder'", | |
| 'total_owners' => "SELECT COUNT(*) as count FROM users WHERE role = 'owner'", | |
| 'total_reports' => "SELECT COUNT(*) as count FROM reports", | |
| 'verified_reports' => "SELECT COUNT(*) as count FROM reports WHERE status = 'verified'", | |
| 'pending_verifications' => "SELECT COUNT(*) as count FROM verifications WHERE result = 'pending'", | |
| 'total_claims' => "SELECT COUNT(*) as count FROM claims", | |
| 'approved_claims' => "SELECT COUNT(*) as count FROM claims WHERE status = 'approved'", | |
| 'total_items' => "SELECT COUNT(*) as count FROM items", | |
| 'available_items' => "SELECT COUNT(*) as count FROM items WHERE status = 'available'" | |
| ]; | |
| $stats = []; | |
| foreach ($statsQueries as $key => $query) { | |
| $stmt = $connection->prepare($query); | |
| $stmt->execute(); | |
| $stats[$key] = $stmt->fetch(PDO::FETCH_ASSOC)['count']; | |
| } | |
| // Get recent users | |
| $usersQuery = "SELECT * FROM users ORDER BY createdAt DESC LIMIT 5"; | |
| $usersStmt = $connection->prepare($usersQuery); | |
| $usersStmt->execute(); | |
| $recentUsers = $usersStmt->fetchAll(PDO::FETCH_ASSOC); | |
| // Get recent reports | |
| $reportsQuery = " | |
| SELECT r.*, u.name as userName | |
| FROM reports r | |
| JOIN users u ON r.userId = u.userId | |
| ORDER BY r.timestamp DESC LIMIT 5 | |
| "; | |
| $reportsStmt = $connection->prepare($reportsQuery); | |
| $reportsStmt->execute(); | |
| $recentReports = $reportsStmt->fetchAll(PDO::FETCH_ASSOC); | |
| // Handle user management actions | |
| if ($_SERVER['REQUEST_METHOD'] == 'POST') { | |
| if (isset($_POST['delete_user'])) { | |
| $userId = $_POST['user_id']; | |
| // Check if user has reports or claims | |
| $checkQuery = " | |
| SELECT (SELECT COUNT(*) FROM reports WHERE userId = :userId) as reportCount, | |
| (SELECT COUNT(*) FROM claims WHERE ownerUserId = :userId) as claimCount | |
| "; | |
| $checkStmt = $connection->prepare($checkQuery); | |
| $checkStmt->bindParam(':userId', $userId); | |
| $checkStmt->execute(); | |
| $result = $checkStmt->fetch(PDO::FETCH_ASSOC); | |
| if ($result['reportCount'] > 0 || $result['claimCount'] > 0) { | |
| $error = "Cannot delete user with existing reports or claims."; | |
| } else { | |
| $deleteQuery = "DELETE FROM users WHERE userId = :userId"; | |
| $deleteStmt = $connection->prepare($deleteQuery); | |
| $deleteStmt->bindParam(':userId', $userId); | |
| if ($deleteStmt->execute()) { | |
| $success = "User deleted successfully!"; | |
| } else { | |
| $error = "Error deleting user."; | |
| } | |
| } | |
| } | |
| } | |
| // Get all users for management | |
| $allUsersQuery = "SELECT * FROM users ORDER BY createdAt DESC"; | |
| $allUsersStmt = $connection->prepare($allUsersQuery); | |
| $allUsersStmt->execute(); | |
| $allUsers = $allUsersStmt->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 Panel - Lost & Found</title> | |
| <link rel="stylesheet" href="style.css"> | |
| </head> | |
| <body> | |
| <header> | |
| <div class="container"> | |
| <nav> | |
| <div class="logo">Lost & Found Pro</div> | |
| <ul class="nav-links"> | |
| <li><a href="home.php">Home</a></li> | |
| <li><a href="dashboard.php">Dashboard</a></li> | |
| <li><a href="admin.php">Admin</a></li> | |
| <li><a href="verifications.php">Verifications</a></li> | |
| <li><a href="storage.php">Storage</a></li> | |
| <li><a href="notifications.php">Notifications</a></li> | |
| <li><a href="profile.php">Profile</a></li> | |
| <li><a href="logout.php">Logout</a></li> | |
| </ul> | |
| </nav> | |
| </div> | |
| </header> | |
| <main class="container"> | |
| <div class="card"> | |
| <div class="card-header"> | |
| <h1>Admin Dashboard</h1> | |
| <p>System overview and management</p> | |
| </div> | |
| <?php if (isset($success)): ?> | |
| <div style="background: #D1FAE5; color: #065F46; padding: 1rem; border-radius: 5px; margin-bottom: 1rem;"> | |
| <?php echo $success; ?> | |
| </div> | |
| <?php endif; ?> | |
| <?php if (isset($error)): ?> | |
| <div style="background: #FEE2E2; color: #DC2626; padding: 1rem; border-radius: 5px; margin-bottom: 1rem;"> | |
| <?php echo $error; ?> | |
| </div> | |
| <?php endif; ?> | |
| <!-- Statistics Overview --> | |
| <div class="row mt-3"> | |
| <div class="col-3"> | |
| <div class="card text-center"> | |
| <h3><?php echo $stats['total_users']; ?></h3> | |
| <p>Total Users</p> | |
| <small><?php echo $stats['total_finders']; ?> Finders, <?php echo $stats['total_owners']; ?> Owners</small> | |
| </div> | |
| </div> | |
| <div class="col-3"> | |
| <div class="card text-center"> | |
| <h3><?php echo $stats['total_reports']; ?></h3> | |
| <p>Total Reports</p> | |
| <small><?php echo $stats['verified_reports']; ?> Verified</small> | |
| </div> | |
| </div> | |
| <div class="col-3"> | |
| <div class="card text-center"> | |
| <h3><?php echo $stats['total_claims']; ?></h3> | |
| <p>Total Claims</p> | |
| <small><?php echo $stats['approved_claims']; ?> Approved</small> | |
| </div> | |
| </div> | |
| <div class="col-3"> | |
| <div class="card text-center"> | |
| <h3><?php echo $stats['total_items']; ?></h3> | |
| <p>Total Items</p> | |
| <small><?php echo $stats['available_items']; ?> Available</small> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Recent Activity --> | |
| <div class="row mt-4"> | |
| <div class="col-6"> | |
| <div class="card"> | |
| <h3>Recent Users</h3> | |
| <div class="table-responsive"> | |
| <table class="table"> | |
| <thead> | |
| <tr> | |
| <th>Name</th> | |
| <th>Email</th> | |
| <th>Role</th> | |
| <th>Joined</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <?php foreach ($recentUsers as $user): ?> | |
| <tr> | |
| <td><?php echo $user['name']; ?></td> | |
| <td><?php echo $user['email']; ?></td> | |
| <td> | |
| <span class="badge badge-<?php echo $user['role'] == 'finder' ? 'info' : 'success'; ?>"> | |
| <?php echo ucfirst($user['role']); ?> | |
| </span> | |
| </td> | |
| <td><?php echo date('M j, Y', strtotime($user['createdAt'])); ?></td> | |
| </tr> | |
| <?php endforeach; ?> | |
| </tbody> | |
| </table> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="col-6"> | |
| <div class="card"> | |
| <h3>Recent Reports</h3> | |
| <div class="table-responsive"> | |
| <table class="table"> | |
| <thead> | |
| <tr> | |
| <th>Report ID</th> | |
| <th>User</th> | |
| <th>Location</th> | |
| <th>Status</th> | |
| <th>Date</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <?php foreach ($recentReports as $report): ?> | |
| <tr> | |
| <td>#<?php echo $report['reportID']; ?></td> | |
| <td><?php echo $report['userName']; ?></td> | |
| <td><?php echo substr($report['locationFound'], 0, 20); ?>...</td> | |
| <td> | |
| <span class="badge badge-<?php | |
| switch($report['status']) { | |
| case 'verified': echo 'success'; break; | |
| case 'rejected': echo 'danger'; break; | |
| default: echo 'warning'; | |
| } | |
| "> | |
| <?php echo ucfirst(str_replace('_', ' ', $report['status'])); ?> | |
| </span> | |
| </td> | |
| <td><?php echo date('M j', strtotime($report['timestamp'])); ?></td> | |
| </tr> | |
| <?php endforeach; ?> | |
| </tbody> | |
| </table> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- User Management --> | |
| <div class="mt-4"> | |
| <h3>User Management</h3> | |
| <div class="table-responsive"> | |
| <table class="table"> | |
| <thead> | |
| <tr> | |
| <th>ID</th> | |
| <th>Name</th> | |
| <th>Email</th> | |
| <th>Role</th> | |
| <th>Joined</th> | |
| <th>Actions</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <?php foreach ($allUsers as $user): ?> | |
| <tr> | |
| <td><?php echo $user['userId']; ?></td> | |
| <td><?php echo $user['name']; ?></td> | |
| <td><?php echo $user['email']; ?></td> | |
| <td> | |
| <span class="badge badge- echo $user['role'] == 'finder' ? 'info' : 'success'; "> | |
| <?php echo ucfirst($user['role']); ?> | |
| </span> | |
| </td> | |
| <td><?php echo date('M j, Y', strtotime($user['createdAt'])); ?></td> | |
| <td> | |
| <form method="POST" style="display: inline;"> | |
| <input type="hidden" name="user_id" value=" echo $user['userId']; "> | |
| <button type="submit" name="delete_user" class="btn btn-danger btn-sm" | |
| onclick="return confirm('Are you sure you want to delete this user? This action cannot be undone.')"> | |
| Delete | |
| </button> | |
| </form> | |
| </td> | |
| </tr> | |
| <?php endforeach; ?> | |
| </tbody> | |
| </table> | |
| </div> | |
| </div> | |
| <!-- Quick Actions --> | |
| <div class="mt-4"> | |
| <h3>Quick Actions</h3> | |
| <div class="d-flex gap-2"> | |
| <a href="verifications.php" class="btn btn-primary">Manage Verifications</a> | |
| <a href="storage.php" class="btn btn-success">Manage Storage</a> | |
| <a href="notifications.php" class="btn btn-secondary">View Notifications</a> | |
| </div> | |
| </div> | |
| </div> | |
| </main> | |
| <footer> | |
| <div class="container"> | |
| <div class="footer-content"> | |
| <div class="logo">Lost & Found Pro</div> | |
| <p>© 2024 Lost & Found Management System. All rights reserved.</p> | |
| </div> | |
| </div> | |
| </footer> | |
| </body> | |
| </html> | |
| ``` |