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.
Code4Change/donorhome.php

131 lines
4.0 KiB

6 months ago
<?php
session_start();
if (!isset($_SESSION['user'])) {
header("Location: login.php");
exit;
}
$donor_name = $_SESSION['user']['name'];
$db_server = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "foodshare";
$conn = mysqli_connect($db_server, $db_user, $db_pass, $db_name);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$query = "SELECT * FROM donations WHERE donor_name = ?";
$stmt = mysqli_prepare($conn, $query);
mysqli_stmt_bind_param($stmt, "s", $donor_name);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$query = "SELECT * FROM donations WHERE donor_name = ?";
$stmt = mysqli_prepare($conn, $query);
mysqli_stmt_bind_param($stmt, "s", $donor_name);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$donations = mysqli_fetch_all($result, MYSQLI_ASSOC);
mysqli_stmt_close($stmt);
mysqli_close($conn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Donor Home</title>
<link rel="stylesheet" href="donorhome.css">
</head>
<body>
<div class="container">
<header>
<h1>Welcome, <span id="user-name"><?php echo htmlspecialchars($donor_name); ?></span>!</h1>
</header>
<div class="profile-section">
<div class="profile-box">
<div class="profile">
<img id="profile-picture" src="anshuman.jpg" alt="Profile Picture">
</div>
<div class="profile-info">
<div class="stat">
<label>Rating:</label>
<span id="rating">Null</span>
</div>
<div class="stat">
<label>Contribution Points:Null</label>
</div>
</div>
</div>
</div>
<div class="actions">
<button id="donate-food">Donate Food</button>
6 months ago
<button id="share" class="SHARE">Share</button>
6 months ago
<button id="toggle-history-btn" class="toggle-btn">Show Contribution History</button>
</div>
<div class="history-section" id="history-section">
<h2>Contribution History</h2>
<?php if (empty($donations)): ?>
6 months ago
<p>No donation history.</p>
6 months ago
<?php else: ?>
<ul id="history-list" class="history-list">
<?php foreach ($donations as $donation): ?>
<li>
Donated <?php echo htmlspecialchars($donation['quantity']); ?> of
<?php echo htmlspecialchars($donation['food_type']); ?> from
<?php echo htmlspecialchars($donation['location']); ?> on
<?php echo htmlspecialchars($donation['donation_date']); ?>
(Expires on <?php echo htmlspecialchars($donation['expiration_date']); ?>)
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
</div>
<script>
const toggleHistoryBtn = document.getElementById('toggle-history-btn');
const historySection = document.getElementById('history-section');
toggleHistoryBtn.addEventListener('click', function() {
if (historySection.style.display === 'none' || historySection.style.display === '') {
historySection.style.display = 'block';
toggleHistoryBtn.textContent = 'Hide Contribution History';
} else {
historySection.style.display = 'none';
toggleHistoryBtn.textContent = 'Show Contribution History';
}
});
document.getElementById("donate-food").addEventListener("click", function() {
window.location.href = "donor.php";
});
</script>
</body>
</html>