195 lines
9.4 KiB
PHP
195 lines
9.4 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
|
header("location: login.php");
|
|
exit;
|
|
}
|
|
|
|
require_once 'db/config.php';
|
|
$db = db();
|
|
|
|
// Fetch user data
|
|
$user_id = $_SESSION['user_id'];
|
|
$stmt = $db->prepare("SELECT name, email, points, created_at, role FROM users WHERE id = :id");
|
|
$stmt->bindParam(':id', $user_id, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$user) {
|
|
// Handle user not found, though unlikely if session is set
|
|
session_destroy();
|
|
header("location: login.php");
|
|
exit;
|
|
}
|
|
|
|
// Fetch user submissions
|
|
$stmt_submissions = $db->prepare("SELECT item_type, quantity, points_awarded, submission_date FROM waste_submissions WHERE user_id = :user_id ORDER BY submission_date DESC");
|
|
$stmt_submissions->bindParam(':user_id', $user_id, PDO::PARAM_INT);
|
|
$stmt_submissions->execute();
|
|
$submissions = $stmt_submissions->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>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</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="index.php">Find a Center</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link active" href="dashboard.php">Dashboard</a>
|
|
</li>
|
|
<?php if ($user['role'] === 'admin'): ?>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="admin_dashboard.php">Admin</a>
|
|
</li>
|
|
<?php endif; ?>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="logout.php">Logout</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container my-5">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="mb-0">Welcome, <?php echo htmlspecialchars($user['name']); ?>!</h1>
|
|
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#submitWasteModal">
|
|
<i class="fas fa-plus-circle me-2"></i>Submit E-Waste
|
|
</button>
|
|
</div>
|
|
|
|
<?php if (isset($_SESSION['success_message'])): ?>
|
|
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
|
<?php echo $_SESSION['success_message']; unset($_SESSION['success_message']); ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if (isset($_SESSION['error_message'])): ?>
|
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
|
<?php echo $_SESSION['error_message']; unset($_SESSION['error_message']); ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6 mb-4">
|
|
<div class="card text-center h-100 shadow-sm">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Your Points</h5>
|
|
<p class="display-4 text-success fw-bold"><?php echo $user['points']; ?></p>
|
|
<p class="card-text">Keep recycling to earn more!</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6 mb-4">
|
|
<div class="card text-center h-100 shadow-sm">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Total Submissions</h5>
|
|
<p class="display-4 fw-bold"><?php echo count($submissions); ?></p>
|
|
<p class="card-text">Thank you for your contribution!</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card mt-4 shadow-sm">
|
|
<div class="card-header">
|
|
<h5 class="mb-0">Your Submission History</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<?php if (empty($submissions)): ?>
|
|
<p class="text-center">You haven't made any submissions yet. Click the "Submit E-Waste" button to get started!</p>
|
|
<?php else: ?>
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>Date</th>
|
|
<th>Item Type</th>
|
|
<th>Quantity</th>
|
|
<th>Points Awarded</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($submissions as $submission): ?>
|
|
<tr>
|
|
<td><?php echo date("F j, Y, g:i a", strtotime($submission['submission_date'])); ?></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>
|
|
|
|
<!-- Submit Waste Modal -->
|
|
<div class="modal fade" id="submitWasteModal" tabindex="-1" aria-labelledby="submitWasteModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="submitWasteModalLabel">Submit E-Waste for Recycling</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<form action="submit_waste.php" method="post">
|
|
<div class="modal-body">
|
|
<div class="mb-3">
|
|
<label for="item_type" class="form-label">What are you recycling?</label>
|
|
<select class="form-select" id="item_type" name="item_type" required>
|
|
<option value="" disabled selected>Select an item type...</option>
|
|
<option value="Smartphone">Smartphone</option>
|
|
<option value="Laptop">Laptop</option>
|
|
<option value="Tablet">Tablet</option>
|
|
<option value="Desktop Computer">Desktop Computer</option>
|
|
<option value="Monitor">Monitor</option>
|
|
<option value="Printer">Printer</option>
|
|
<option value="Battery">Battery</option>
|
|
<option value="Cables & Chargers">Cables & Chargers</option>
|
|
<option value="Other">Other</option>
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="quantity" class="form-label">How many items?</label>
|
|
<input type="number" class="form-control" id="quantity" name="quantity" min="1" required>
|
|
</div>
|
|
<div class="alert alert-info">You'll earn <strong>10 points</strong> for each item you submit.</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
|
<button type="submit" class="btn btn-primary">Submit for Points</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<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>
|