diff --git a/admin_dashboard.php b/admin_dashboard.php new file mode 100644 index 0000000..c87cbe4 --- /dev/null +++ b/admin_dashboard.php @@ -0,0 +1,115 @@ +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); + +?> + + + + + + Admin Dashboard - E-Waste Reclaimer + + + + + + + +
+

Admin Dashboard: All Submissions

+ +
+
+
All User Submissions
+
+
+ +

No submissions have been made by any user yet.

+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
DateUserEmailItem TypeQuantityPoints
+
+ +
+
+
+ + + + + + diff --git a/dashboard.php b/dashboard.php index dd240f2..cd89604 100644 --- a/dashboard.php +++ b/dashboard.php @@ -7,6 +7,28 @@ if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) { } 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); + ?> @@ -33,6 +55,11 @@ require_once 'db/config.php'; + + + @@ -43,17 +70,31 @@ require_once 'db/config.php';
-

Welcome, !

+

Welcome, !

+
-

This is your dashboard. From here you can submit e-waste, track your points, and view your submission history.

+ + + + + +
Your Points
-

0

+

Keep recycling to earn more!

@@ -61,19 +102,93 @@ require_once 'db/config.php';
-
Your Submissions
-

0

- Submit New E-Waste +
Total Submissions
+

+

Thank you for your contribution!

+ +
+
+
Your Submission History
+
+
+ +

You haven't made any submissions yet. Click the "Submit E-Waste" button to get started!

+ +
+ + + + + + + + + + + + + + + + + + + +
DateItem TypeQuantityPoints Awarded
+
+ +
+
+ + + - \ No newline at end of file + diff --git a/db/config.php b/db/config.php index 8ab4362..bf88243 100644 --- a/db/config.php +++ b/db/config.php @@ -36,6 +36,16 @@ function db() { points INT DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );"); + + $pdo->exec("CREATE TABLE IF NOT EXISTS waste_submissions ( + id INT AUTO_INCREMENT PRIMARY KEY, + user_id INT NOT NULL, + item_type VARCHAR(100) NOT NULL, + quantity INT NOT NULL, + points_awarded INT NOT NULL, + submission_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE + );"); } catch (PDOException $e) { error_log('Database setup failed: ' . $e->getMessage()); // You could display a generic error page here instead of dying diff --git a/submit_waste.php b/submit_waste.php new file mode 100644 index 0000000..f6808f4 --- /dev/null +++ b/submit_waste.php @@ -0,0 +1,53 @@ +prepare($sql); + $stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT); + $stmt->bindParam(':item_type', $item_type, PDO::PARAM_STR); + $stmt->bindParam(':quantity', $quantity, PDO::PARAM_INT); + $stmt->bindParam(':points_awarded', $points_awarded, PDO::PARAM_INT); + $stmt->execute(); + + // Update user points + $sql_update_points = "UPDATE users SET points = points + :points_awarded WHERE id = :user_id"; + $stmt_update_points = $db->prepare($sql_update_points); + $stmt_update_points->bindParam(':points_awarded', $points_awarded, PDO::PARAM_INT); + $stmt_update_points->bindParam(':user_id', $user_id, PDO::PARAM_INT); + $stmt_update_points->execute(); + + $_SESSION['success_message'] = "E-waste submitted successfully! You earned " . $points_awarded . " points."; + + } catch (PDOException $e) { + $_SESSION['error_message'] = "Oops! Something went wrong. Please try again later."; + error_log("E-waste submission failed: " . $e->getMessage()); + } + + header("location: dashboard.php"); + exit; +} +?> \ No newline at end of file