Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
466e6355cc | ||
|
|
9bc03d5115 | ||
|
|
cf1ff1d401 | ||
|
|
b2bd22e909 | ||
|
|
11336c0d33 | ||
|
|
391fd84e69 |
115
admin_dashboard.php
Normal file
115
admin_dashboard.php
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
<?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>
|
||||||
49
assets/css/custom.css
Normal file
49
assets/css/custom.css
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/* E-Waste Reclaimer Custom Styles */
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--primary-color: #28a745;
|
||||||
|
--secondary-color: #6c757d;
|
||||||
|
--light-gray: #f8f9fa;
|
||||||
|
--dark-color: #343a40;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-brand {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary {
|
||||||
|
background-color: var(--primary-color);
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:hover {
|
||||||
|
background-color: #218838;
|
||||||
|
border-color: #1e7e34;
|
||||||
|
}
|
||||||
|
.text-success {
|
||||||
|
color: var(--primary-color) !important;
|
||||||
|
}
|
||||||
|
.hero-section {
|
||||||
|
background: linear-gradient(to right, rgba(40, 167, 69, 0.1), rgba(248, 249, 250, 0.1)), var(--light-gray);
|
||||||
|
border-bottom: 5px solid var(--primary-color);
|
||||||
|
}
|
||||||
|
.card-icon i {
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
.bg-dark {
|
||||||
|
background-color: var(--dark-color) !important;
|
||||||
|
}
|
||||||
|
footer {
|
||||||
|
background-color: var(--dark-color);
|
||||||
|
}
|
||||||
194
dashboard.php
Normal file
194
dashboard.php
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
<?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>
|
||||||
@ -8,10 +8,56 @@ define('DB_PASS', '2c66b530-2a65-423a-a106-6760b49ad1a2');
|
|||||||
function db() {
|
function db() {
|
||||||
static $pdo;
|
static $pdo;
|
||||||
if (!$pdo) {
|
if (!$pdo) {
|
||||||
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
|
try {
|
||||||
|
// Connect without specifying a database
|
||||||
|
$pdo = new PDO('mysql:host='.DB_HOST.';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Create the database if it doesn't exist
|
||||||
|
$pdo->exec('CREATE DATABASE IF NOT EXISTS '.DB_NAME);
|
||||||
|
// Select the database
|
||||||
|
$pdo->exec('USE '.DB_NAME);
|
||||||
|
|
||||||
|
$pdo->exec('CREATE TABLE IF NOT EXISTS centers (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
address VARCHAR(255) NOT NULL,
|
||||||
|
contact VARCHAR(255) NOT NULL
|
||||||
|
);');
|
||||||
|
|
||||||
|
$pdo->exec("CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
email VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
password VARCHAR(255) NOT NULL,
|
||||||
|
role ENUM('guest', 'user', 'center_staff', 'admin') NOT NULL DEFAULT 'user',
|
||||||
|
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
|
||||||
|
);");
|
||||||
|
|
||||||
|
$pdo->exec("CREATE TABLE IF NOT EXISTS password_resets (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
email VARCHAR(255) NOT NULL,
|
||||||
|
token VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
expires_at TIMESTAMP NOT NULL
|
||||||
|
);");
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
error_log('Database setup failed: ' . $e->getMessage());
|
||||||
|
// You could display a generic error page here instead of dying
|
||||||
|
die('Database setup failed. Please check the logs.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $pdo;
|
return $pdo;
|
||||||
}
|
}
|
||||||
|
|||||||
67
forgot_password.php
Normal file
67
forgot_password.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
include_once 'db/config.php';
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Forgot Password - E-Waste Reclaimer</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-dark bg-success">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<a class="navbar-brand" href="index.php">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">Home</a></li>
|
||||||
|
<?php if (isset($_SESSION['user_id'])): ?>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="dashboard.php">Dashboard</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="logout.php">Logout</a></li>
|
||||||
|
<?php else: ?>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="login.php">Login</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link" href="register.php">Register</a></li>
|
||||||
|
<?php endif; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="container mt-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header bg-success text-white">
|
||||||
|
<h4>Forgot Password</h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<?php if (isset($_SESSION['message'])): ?>
|
||||||
|
<div class="alert alert-<?php echo $_SESSION['message_type']; ?> alert-dismissible fade show" role="alert">
|
||||||
|
<?php echo $_SESSION['message']; ?>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<?php unset($_SESSION['message'], $_SESSION['message_type']); ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
<p>Enter your email address and we will send you a link to reset your password.</p>
|
||||||
|
<form action="send_reset_link.php" method="post">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="email" class="form-label">Email address</label>
|
||||||
|
<input type="email" class="form-control" id="email" name="email" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-success w-100">Send Password Reset Link</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
237
index.php
237
index.php
@ -1,150 +1,111 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
session_start();
|
||||||
@ini_set('display_errors', '1');
|
require_once 'db/config.php';
|
||||||
@error_reporting(E_ALL);
|
|
||||||
@date_default_timezone_set('UTC');
|
|
||||||
|
|
||||||
$phpVersion = PHP_VERSION;
|
|
||||||
$now = date('Y-m-d H:i:s');
|
|
||||||
?>
|
?>
|
||||||
<!doctype html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>New Style</title>
|
<title>E-Waste Reclaimer</title>
|
||||||
<?php
|
<meta name="description" content="A platform to help you recycle your e-waste responsibly.">
|
||||||
// Read project preview data from environment
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
||||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
?>
|
|
||||||
<?php if ($projectDescription): ?>
|
|
||||||
<!-- Meta description -->
|
|
||||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
|
||||||
<!-- Open Graph meta tags -->
|
|
||||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
|
||||||
<!-- Twitter meta tags -->
|
|
||||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php if ($projectImageUrl): ?>
|
|
||||||
<!-- Open Graph image -->
|
|
||||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
|
||||||
<!-- Twitter image -->
|
|
||||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
|
||||||
<?php endif; ?>
|
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
|
||||||
<style>
|
|
||||||
:root {
|
|
||||||
--bg-color-start: #6a11cb;
|
|
||||||
--bg-color-end: #2575fc;
|
|
||||||
--text-color: #ffffff;
|
|
||||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
|
||||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
font-family: 'Inter', sans-serif;
|
|
||||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
|
||||||
color: var(--text-color);
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
min-height: 100vh;
|
|
||||||
text-align: center;
|
|
||||||
overflow: hidden;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
body::before {
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
|
||||||
animation: bg-pan 20s linear infinite;
|
|
||||||
z-index: -1;
|
|
||||||
}
|
|
||||||
@keyframes bg-pan {
|
|
||||||
0% { background-position: 0% 0%; }
|
|
||||||
100% { background-position: 100% 100%; }
|
|
||||||
}
|
|
||||||
main {
|
|
||||||
padding: 2rem;
|
|
||||||
}
|
|
||||||
.card {
|
|
||||||
background: var(--card-bg-color);
|
|
||||||
border: 1px solid var(--card-border-color);
|
|
||||||
border-radius: 16px;
|
|
||||||
padding: 2rem;
|
|
||||||
backdrop-filter: blur(20px);
|
|
||||||
-webkit-backdrop-filter: blur(20px);
|
|
||||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
.loader {
|
|
||||||
margin: 1.25rem auto 1.25rem;
|
|
||||||
width: 48px;
|
|
||||||
height: 48px;
|
|
||||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
|
||||||
border-top-color: #fff;
|
|
||||||
border-radius: 50%;
|
|
||||||
animation: spin 1s linear infinite;
|
|
||||||
}
|
|
||||||
@keyframes spin {
|
|
||||||
from { transform: rotate(0deg); }
|
|
||||||
to { transform: rotate(360deg); }
|
|
||||||
}
|
|
||||||
.hint {
|
|
||||||
opacity: 0.9;
|
|
||||||
}
|
|
||||||
.sr-only {
|
|
||||||
position: absolute;
|
|
||||||
width: 1px; height: 1px;
|
|
||||||
padding: 0; margin: -1px;
|
|
||||||
overflow: hidden;
|
|
||||||
clip: rect(0, 0, 0, 0);
|
|
||||||
white-space: nowrap; border: 0;
|
|
||||||
}
|
|
||||||
h1 {
|
|
||||||
font-size: 3rem;
|
|
||||||
font-weight: 700;
|
|
||||||
margin: 0 0 1rem;
|
|
||||||
letter-spacing: -1px;
|
|
||||||
}
|
|
||||||
p {
|
|
||||||
margin: 0.5rem 0;
|
|
||||||
font-size: 1.1rem;
|
|
||||||
}
|
|
||||||
code {
|
|
||||||
background: rgba(0,0,0,0.2);
|
|
||||||
padding: 2px 6px;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
||||||
}
|
|
||||||
footer {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 1rem;
|
|
||||||
font-size: 0.8rem;
|
|
||||||
opacity: 0.7;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||||
<div class="card">
|
<div class="container-fluid">
|
||||||
<h1>Analyzing your requirements and generating your website…</h1>
|
<a class="navbar-brand" href="index.php"><i class="fas fa-recycle me-2"></i>E-Waste Reclaimer</a>
|
||||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
<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="sr-only">Loading…</span>
|
<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 active" href="index.php">Find a Center</a>
|
||||||
|
</li>
|
||||||
|
<?php if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true): ?>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="dashboard.php">Dashboard</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="logout.php">Logout</a>
|
||||||
|
</li>
|
||||||
|
<?php else: ?>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="login.php">Login</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="register.php">Register</a>
|
||||||
|
</li>
|
||||||
|
<?php endif; ?>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
|
||||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
|
||||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
|
||||||
</div>
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main class="container my-5">
|
||||||
|
<div class="bg-light p-5 rounded-3 text-center shadow-sm hero-section">
|
||||||
|
<h1 class="display-4">Welcome to E-Waste Reclaimer</h1>
|
||||||
|
<p class="lead">Your partner in responsible electronics recycling. Find a center near you and help us build a sustainable future.</p>
|
||||||
|
<a href="#centers-list" class="btn btn-primary btn-lg">Find a Recycling Center</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<section id="centers-list" class="py-5">
|
||||||
|
<h2 class="text-center mb-4">Recycling Centers</h2>
|
||||||
|
<div class="row">
|
||||||
|
<?php
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
|
||||||
|
$stmt = $pdo->query("SELECT COUNT(*) FROM centers");
|
||||||
|
if ($stmt->fetchColumn() == 0) {
|
||||||
|
$sample_centers = [
|
||||||
|
['name' => 'GreenTech Recyclers', 'address' => '123 Eco Lane, Green City', 'contact' => 'contact@greentech.com'],
|
||||||
|
['name' => 'Circuit Savers', 'address' => '456 Recycle Ave, Tech Town', 'contact' => 'info@circuitsavers.com'],
|
||||||
|
['name' => 'Eco-Warriors', 'address' => '789 Planet Blvd, Nature Village', 'contact' => 'support@ecowarriors.org']
|
||||||
|
];
|
||||||
|
|
||||||
|
$insert_stmt = $pdo->prepare("INSERT INTO centers (name, address, contact) VALUES (:name, :address, :contact)");
|
||||||
|
foreach ($sample_centers as $center) {
|
||||||
|
$insert_stmt->execute($center);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$centers = $pdo->query("SELECT * FROM centers ORDER BY name")->fetchAll();
|
||||||
|
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$centers = [];
|
||||||
|
error_log("Database error: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($centers)):
|
||||||
|
foreach ($centers as $center): ?>
|
||||||
|
<div class="col-md-4 mb-4">
|
||||||
|
<div class="card h-100 shadow-sm">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<div class="card-icon mb-3"><i class="fas fa-recycle fa-3x text-success"></i></div>
|
||||||
|
<h5 class="card-title"><?php echo htmlspecialchars($center['name']); ?></h5>
|
||||||
|
<p class="card-text"><i class="fas fa-map-marker-alt me-2"></i><?php echo htmlspecialchars($center['address']); ?></p>
|
||||||
|
<p class="card-text"><i class="fas fa-envelope me-2"></i><?php echo htmlspecialchars($center['contact']); ?></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endforeach;
|
||||||
|
else: ?>
|
||||||
|
<div class="col">
|
||||||
|
<div class="alert alert-info">No recycling centers found. Please check back later.</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</main>
|
</main>
|
||||||
<footer>
|
|
||||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
<footer class="bg-dark text-white text-center p-3">
|
||||||
|
<p class="mb-0">© <?php echo date("Y"); ?> E-Waste Reclaimer. All Rights Reserved.</p>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
128
login.php
Normal file
128
login.php
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
$errors = [];
|
||||||
|
$success_msg = '';
|
||||||
|
|
||||||
|
if (isset($_GET['registered']) && $_GET['registered'] == 'true') {
|
||||||
|
$success_msg = 'Registration successful! Please log in.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$email = trim($_POST['email']);
|
||||||
|
$password = $_POST['password'];
|
||||||
|
|
||||||
|
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$errors[] = 'A valid email is required.';
|
||||||
|
}
|
||||||
|
if (empty($password)) {
|
||||||
|
$errors[] = 'Password is required.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($errors)) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?");
|
||||||
|
$stmt->execute([$email]);
|
||||||
|
$user = $stmt->fetch();
|
||||||
|
|
||||||
|
if ($user && password_verify($password, $user['password'])) {
|
||||||
|
$_SESSION['loggedin'] = true;
|
||||||
|
$_SESSION['user_id'] = $user['id'];
|
||||||
|
$_SESSION['user_name'] = $user['name'];
|
||||||
|
$_SESSION['user_role'] = $user['role'];
|
||||||
|
header("Location: dashboard.php");
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
|
$errors[] = 'Invalid email or password.';
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$errors[] = "Database error: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Login - 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="login.php">Login</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="register.php">Register</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main class="container my-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card shadow-sm">
|
||||||
|
<div class="card-body p-5">
|
||||||
|
<h2 class="card-title text-center mb-4">Login to Your Account</h2>
|
||||||
|
|
||||||
|
<?php if (!empty($errors)): ?>
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<?php foreach ($errors as $error): ?>
|
||||||
|
<p class="mb-0"><?php echo htmlspecialchars($error); ?></p>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($success_msg): ?>
|
||||||
|
<div class="alert alert-success">
|
||||||
|
<p class="mb-0"><?php echo htmlspecialchars($success_msg); ?></p>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<form action="login.php" method="post">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="email" class="form-label">Email Address</label>
|
||||||
|
<input type="email" class="form-control" id="email" name="email" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="password" class="form-label">Password</label>
|
||||||
|
<input type="password" class="form-control" id="password" name="password" required>
|
||||||
|
</div>
|
||||||
|
<div class="d-grid">
|
||||||
|
<button type="submit" class="btn btn-primary">Login</button>
|
||||||
|
</div>
|
||||||
|
<div class="text-center mt-3">
|
||||||
|
<a href="forgot_password.php">Forgot Password?</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</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>
|
||||||
21
logout.php
Normal file
21
logout.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
// Unset all of the session variables
|
||||||
|
$_SESSION = [];
|
||||||
|
|
||||||
|
// Destroy the session
|
||||||
|
if (ini_get("session.use_cookies")) {
|
||||||
|
$params = session_get_cookie_params();
|
||||||
|
setcookie(session_name(), '', time() - 42000,
|
||||||
|
$params["path"], $params["domain"],
|
||||||
|
$params["secure"], $params["httponly"]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
session_destroy();
|
||||||
|
|
||||||
|
// Redirect to home page
|
||||||
|
header("Location: index.php");
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
119
register.php
Normal file
119
register.php
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
$errors = [];
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$name = trim($_POST['name']);
|
||||||
|
$email = trim($_POST['email']);
|
||||||
|
$password = $_POST['password'];
|
||||||
|
|
||||||
|
if (empty($name)) {
|
||||||
|
$errors[] = 'Name is required.';
|
||||||
|
}
|
||||||
|
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$errors[] = 'A valid email is required.';
|
||||||
|
}
|
||||||
|
if (empty($password) || strlen($password) < 6) {
|
||||||
|
$errors[] = 'Password must be at least 6 characters long.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($errors)) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
|
||||||
|
$stmt->execute([$email]);
|
||||||
|
if ($stmt->fetch()) {
|
||||||
|
$errors[] = 'Email address is already registered.';
|
||||||
|
} else {
|
||||||
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO users (name, email, password) VALUES (?, ?, ?)");
|
||||||
|
$stmt->execute([$name, $email, $hashed_password]);
|
||||||
|
header("Location: login.php?registered=true");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$errors[] = "Database error: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Register - 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" href="login.php">Login</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link active" href="register.php">Register</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main class="container my-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card shadow-sm">
|
||||||
|
<div class="card-body p-5">
|
||||||
|
<h2 class="card-title text-center mb-4">Create an Account</h2>
|
||||||
|
|
||||||
|
<?php if (!empty($errors)): ?>
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<?php foreach ($errors as $error): ?>
|
||||||
|
<p class="mb-0"><?php echo htmlspecialchars($error); ?></p>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<form action="register.php" method="post">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="name" class="form-label">Full Name</label>
|
||||||
|
<input type="text" class="form-control" id="name" name="name" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="email" class="form-label">Email Address</label>
|
||||||
|
<input type="email" class="form-control" id="email" name="email" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="password" class="form-label">Password</label>
|
||||||
|
<input type="password" class="form-control" id="password" name="password" required minlength="6">
|
||||||
|
</div>
|
||||||
|
<div class="d-grid">
|
||||||
|
<button type="submit" class="btn btn-primary">Register</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</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>
|
||||||
85
reset_password_form.php
Normal file
85
reset_password_form.php
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
$token = $_GET['token'] ?? '';
|
||||||
|
$error = '';
|
||||||
|
$token_valid = false;
|
||||||
|
|
||||||
|
if (empty($token)) {
|
||||||
|
$error = "Invalid password reset token.";
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("SELECT * FROM password_resets WHERE token = ?");
|
||||||
|
$stmt->execute([$token]);
|
||||||
|
$reset_request = $stmt->fetch();
|
||||||
|
|
||||||
|
if ($reset_request) {
|
||||||
|
if ($reset_request['expires'] >= date("U")) {
|
||||||
|
$token_valid = true;
|
||||||
|
} else {
|
||||||
|
$error = "Password reset token has expired.";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$error = "Invalid password reset token.";
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error = "Database error: " . $e->getMessage();
|
||||||
|
error_log($error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Reset Password - E-Waste Reclaimer</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-dark bg-success">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<a class="navbar-brand" href="index.php">E-Waste Reclaimer</a>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="container mt-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header bg-success text-white">
|
||||||
|
<h4>Reset Password</h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<?php if (!empty($error)): ?>
|
||||||
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($token_valid): ?>
|
||||||
|
<form action="update_password.php" method="post">
|
||||||
|
<input type="hidden" name="token" value="<?php echo htmlspecialchars($token); ?>">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="password" class="form-label">New Password</label>
|
||||||
|
<input type="password" class="form-control" id="password" name="password" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="password_confirm" class="form-label">Confirm New Password</label>
|
||||||
|
<input type="password" class="form-control" id="password_confirm" name="password_confirm" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-success w-100">Reset Password</button>
|
||||||
|
</form>
|
||||||
|
<?php else: ?>
|
||||||
|
<p>Please return to the <a href="forgot_password.php">forgot password</a> page to request a new link.</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
62
send_reset_link.php
Normal file
62
send_reset_link.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once 'db/config.php';
|
||||||
|
require_once 'mail/MailService.php';
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$email = trim($_POST['email']);
|
||||||
|
$message = '';
|
||||||
|
$message_type = 'danger';
|
||||||
|
|
||||||
|
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$message = 'A valid email is required.';
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
|
||||||
|
$stmt->execute([$email]);
|
||||||
|
$user = $stmt->fetch();
|
||||||
|
|
||||||
|
if ($user) {
|
||||||
|
$token = bin2hex(random_bytes(50));
|
||||||
|
$expires_timestamp = time() + 1800; // 30 minutes
|
||||||
|
$expires_datetime = date('Y-m-d H:i:s', $expires_timestamp);
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO password_resets (email, token, expires_at) VALUES (?, ?, ?)");
|
||||||
|
$stmt->execute([$email, $token, $expires_datetime]);
|
||||||
|
|
||||||
|
$reset_link = "http://" . $_SERVER['HTTP_HOST'] . "/reset_password_form.php?token=" . $token;
|
||||||
|
|
||||||
|
$subject = "Password Reset Request";
|
||||||
|
$body = "<p>Hello,</p>";
|
||||||
|
$body .= "<p>You requested a password reset. Click the link below to reset your password:</p>";
|
||||||
|
$body .= "<p><a href='" . $reset_link . "'>" . $reset_link . "</a></p>";
|
||||||
|
$body .= "<p>This link will expire in 30 minutes.</p>";
|
||||||
|
$body .= "<p>If you did not request a password reset, please ignore this email.</p>";
|
||||||
|
|
||||||
|
// Use MailService to send the email
|
||||||
|
$mail_result = MailService::sendMail($email, $subject, $body, strip_tags($body));
|
||||||
|
|
||||||
|
if (!empty($mail_result['success'])) {
|
||||||
|
$message = 'A password reset link has been sent to your email address.';
|
||||||
|
$message_type = 'success';
|
||||||
|
} else {
|
||||||
|
$message = 'Could not send the password reset email. Please try again later.';
|
||||||
|
error_log("MailService Error: " . ($mail_result['error'] ?? 'Unknown error'));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$message = 'No user found with that email address.';
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$message = "Database error: " . $e->getMessage();
|
||||||
|
error_log($message);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$message = "An error occurred: " . $e->getMessage();
|
||||||
|
error_log($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$_SESSION['message'] = $message;
|
||||||
|
$_SESSION['message_type'] = $message_type;
|
||||||
|
header("Location: forgot_password.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
53
submit_waste.php
Normal file
53
submit_waste.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||||
|
header("location: login.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$item_type = trim($_POST["item_type"]);
|
||||||
|
$quantity = trim($_POST["quantity"]);
|
||||||
|
$user_id = $_SESSION['user_id'];
|
||||||
|
|
||||||
|
if (empty($item_type) || empty($quantity) || !is_numeric($quantity) || $quantity <= 0) {
|
||||||
|
$_SESSION['error_message'] = "Please enter a valid item and quantity.";
|
||||||
|
header("location: dashboard.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Basic points system: 10 points per item
|
||||||
|
$points_awarded = $quantity * 10;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$db = db();
|
||||||
|
|
||||||
|
// Insert submission
|
||||||
|
$sql = "INSERT INTO waste_submissions (user_id, item_type, quantity, points_awarded) VALUES (:user_id, :item_type, :quantity, :points_awarded)";
|
||||||
|
$stmt = $db->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;
|
||||||
|
}
|
||||||
|
?>
|
||||||
52
update_password.php
Normal file
52
update_password.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$token = $_POST['token'] ?? '';
|
||||||
|
$password = $_POST['password'] ?? '';
|
||||||
|
$password_confirm = $_POST['password_confirm'] ?? '';
|
||||||
|
$error = '';
|
||||||
|
|
||||||
|
if (empty($token) || empty($password) || empty($password_confirm)) {
|
||||||
|
$error = "All fields are required.";
|
||||||
|
} elseif ($password !== $password_confirm) {
|
||||||
|
$error = "Passwords do not match.";
|
||||||
|
} elseif (strlen($password) < 8) {
|
||||||
|
$error = "Password must be at least 8 characters long.";
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("SELECT * FROM password_resets WHERE token = ?");
|
||||||
|
$stmt->execute([$token]);
|
||||||
|
$reset_request = $stmt->fetch();
|
||||||
|
|
||||||
|
if ($reset_request && $reset_request['expires'] >= date("U")) {
|
||||||
|
$email = $reset_request['email'];
|
||||||
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("UPDATE users SET password = ? WHERE email = ?");
|
||||||
|
$stmt->execute([$hashed_password, $email]);
|
||||||
|
|
||||||
|
// Delete the used token
|
||||||
|
$stmt = $pdo->prepare("DELETE FROM password_resets WHERE email = ?");
|
||||||
|
$stmt->execute([$email]);
|
||||||
|
|
||||||
|
$_SESSION['message'] = 'Your password has been successfully reset. Please log in with your new password.';
|
||||||
|
$_SESSION['message_type'] = 'success';
|
||||||
|
header("Location: login.php");
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
|
$error = "Invalid or expired password reset token.";
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error = "Database error: " . $e->getMessage();
|
||||||
|
error_log($error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there was an error, redirect back to the reset form with the token
|
||||||
|
$_SESSION['error'] = $error;
|
||||||
|
header("Location: reset_password_form.php?token=" . urlencode($token));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user