version3
This commit is contained in:
parent
7181333ac7
commit
34806aba52
12
db/migrations/002_create_donor_profiles_table.sql
Normal file
12
db/migrations/002_create_donor_profiles_table.sql
Normal file
@ -0,0 +1,12 @@
|
||||
CREATE TABLE IF NOT EXISTS donor_profiles (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
full_name VARCHAR(255) NOT NULL,
|
||||
phone VARCHAR(50),
|
||||
address TEXT,
|
||||
city VARCHAR(100),
|
||||
state VARCHAR(100),
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
@ -1,16 +1,64 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'includes/auth.php';
|
||||
check_login();
|
||||
check_role('donor');
|
||||
|
||||
require_once 'includes/header.php';
|
||||
// Ensure user is logged in and is a donor
|
||||
if (!is_logged_in() || $_SESSION['user_role'] !== 'donor') {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
$pdo = db();
|
||||
|
||||
$user_id = $_SESSION['user_id'];
|
||||
|
||||
// Fetch donor profile
|
||||
$stmt = $pdo->prepare("SELECT * FROM donor_profiles WHERE user_id = ?");
|
||||
$stmt->execute([$user_id]);
|
||||
$profile = $stmt->fetch();
|
||||
|
||||
$pageTitle = 'Donor Dashboard';
|
||||
include 'includes/header.php';
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h1>Welcome, Donor!</h1>
|
||||
<p>This is your dashboard. Here you can manage your profile and donations.</p>
|
||||
<a href="logout.php" class="btn btn-danger">Logout</a>
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1>Welcome, <?php echo isset($profile['full_name']) ? htmlspecialchars(explode(' ', $profile['full_name'])[0]) : 'Donor'; ?>!</h1>
|
||||
</div>
|
||||
|
||||
<?php require_once 'includes/footer.php'; ?>
|
||||
<?php if ($profile): ?>
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<h4>My Profile</h4>
|
||||
<a href="donor_profile.php" class="btn btn-sm btn-outline-secondary">Edit Profile</a>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title"><?php echo htmlspecialchars($profile['full_name']); ?></h5>
|
||||
<p class="card-text">
|
||||
<strong>Email:</strong> <?php echo htmlspecialchars($_SESSION['user_email']); ?><br>
|
||||
<strong>Phone:</strong> <?php echo htmlspecialchars($profile['phone'] ?: 'N/A'); ?><br>
|
||||
<strong>Address:</strong> <?php echo htmlspecialchars($profile['address'] ?: 'N/A'); ?><br>
|
||||
<strong>City:</strong> <?php echo htmlspecialchars($profile['city'] ?: 'N/A'); ?><br>
|
||||
<strong>State:</strong> <?php echo htmlspecialchars($profile['state'] ?: 'N/A'); ?><br>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<h3>Start a New Donation</h3>
|
||||
<p>Ready to make a difference? Click the button below to start a new donation request.</p>
|
||||
<a href="donation_request.php" class="btn btn-primary">New Donation Request</a>
|
||||
</div>
|
||||
|
||||
<?php else: ?>
|
||||
<div class="alert alert-info" role="alert">
|
||||
<h4 class="alert-heading">Complete Your Profile</h4>
|
||||
<p>Welcome to DonateConnect! To start making donations, please complete your profile with your contact information.</p>
|
||||
<hr>
|
||||
<a href="donor_profile.php" class="btn btn-primary">Create My Profile</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php include 'includes/footer.php'; ?>
|
||||
|
||||
96
donor_profile.php
Normal file
96
donor_profile.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
require_once 'includes/auth.php';
|
||||
|
||||
// Only donors can access this page
|
||||
if (!is_logged_in() || $_SESSION['user_role'] !== 'donor') {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
$pdo = db();
|
||||
|
||||
$user_id = $_SESSION['user_id'];
|
||||
$profile = null;
|
||||
$message = '';
|
||||
|
||||
// Check if profile exists
|
||||
$stmt = $pdo->prepare("SELECT * FROM donor_profiles WHERE user_id = ?");
|
||||
$stmt->execute([$user_id]);
|
||||
$profile = $stmt->fetch();
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$full_name = trim($_POST['full_name'] ?? '');
|
||||
$phone = trim($_POST['phone'] ?? '');
|
||||
$address = trim($_POST['address'] ?? '');
|
||||
$city = trim($_POST['city'] ?? '');
|
||||
$state = trim($_POST['state'] ?? '');
|
||||
|
||||
if (empty($full_name)) {
|
||||
$message = '<div class="alert alert-danger">Full name is required.</div>';
|
||||
} else {
|
||||
if ($profile) {
|
||||
// Update existing profile
|
||||
$stmt = $pdo->prepare("UPDATE donor_profiles SET full_name = ?, phone = ?, address = ?, city = ?, state = ? WHERE user_id = ?");
|
||||
$stmt->execute([$full_name, $phone, $address, $city, $state, $user_id]);
|
||||
$message = '<div class="alert alert-success">Profile updated successfully!</div>';
|
||||
} else {
|
||||
// Create new profile
|
||||
$stmt = $pdo->prepare("INSERT INTO donor_profiles (user_id, full_name, phone, address, city, state) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute([$user_id, $full_name, $phone, $address, $city, $state]);
|
||||
$message = '<div class="alert alert-success">Profile created successfully!</div>';
|
||||
}
|
||||
// Refresh profile data after insert/update
|
||||
$stmt = $pdo->prepare("SELECT * FROM donor_profiles WHERE user_id = ?");
|
||||
$stmt->execute([$user_id]);
|
||||
$profile = $stmt->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
$pageTitle = 'My Profile';
|
||||
include 'includes/header.php';
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>My Profile</h2>
|
||||
<p>Manage your personal information.</p>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php echo $message; ?>
|
||||
<form action="donor_profile.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="full_name" class="form-label">Full Name</label>
|
||||
<input type="text" class="form-control" id="full_name" name="full_name" value="<?php echo htmlspecialchars($profile['full_name'] ?? ''); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="phone" class="form-label">Phone Number</label>
|
||||
<input type="tel" class="form-control" id="phone" name="phone" value="<?php echo htmlspecialchars($profile['phone'] ?? ''); ?>">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="address" class="form-label">Address</label>
|
||||
<textarea class="form-control" id="address" name="address" rows="3"><?php echo htmlspecialchars($profile['address'] ?? ''); ?></textarea>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="city" class="form-label">City</label>
|
||||
<input type="text" class="form-control" id="city" name="city" value="<?php echo htmlspecialchars($profile['city'] ?? ''); ?>">
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="state" class="form-label">State</label>
|
||||
<input type="text" class="form-control" id="state" name="state" value="<?php echo htmlspecialchars($profile['state'] ?? ''); ?>">
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary"><?php echo $profile ? 'Update Profile' : 'Save Profile'; ?></button>
|
||||
<a href="donor_dashboard.php" class="btn btn-secondary">Back to Dashboard</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'includes/footer.php'; ?>
|
||||
@ -38,11 +38,18 @@
|
||||
<a class="nav-link" href="index.php#contact">Contact</a>
|
||||
</li>
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-outline-primary ms-2" href="<?php echo $_SESSION['user_role']; ?>_dashboard.php">Dashboard</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-primary ms-2" href="logout.php">Logout</a>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
My Account
|
||||
</a>
|
||||
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
<li><a class="dropdown-item" href="<?php echo $_SESSION['user_role']; ?>_dashboard.php">Dashboard</a></li>
|
||||
<?php if ($_SESSION['user_role'] === 'donor'): ?>
|
||||
<li><a class="dropdown-item" href="donor_profile.php">My Profile</a></li>
|
||||
<?php endif; ?>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item" href="logout.php">Logout</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<?php else: ?>
|
||||
<li class="nav-item">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user