Compare commits

...

1 Commits

Author SHA1 Message Date
Flatlogic Bot
c12628e2d9 v2 2025-12-05 21:07:12 +00:00
16 changed files with 1352 additions and 111 deletions

25
assets/css/custom.css Normal file
View File

@ -0,0 +1,25 @@
body {
background-color: #f8f9fa;
}
.header-gradient {
background: linear-gradient(90deg, #007BFF, #0056b3);
}
.card {
border: none;
border-radius: 0.5rem;
}
.btn-primary {
background-color: #007BFF;
border: none;
}
.btn-primary:hover {
background-color: #0056b3;
}
.footer {
background-color: #e9ecef;
}

64
dashboard.php Normal file
View File

@ -0,0 +1,64 @@
<?php
session_start();
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
$user_type = $_SESSION['user_type'];
$page_title = ucfirst($user_type) . " Dashboard";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= htmlspecialchars($page_title) ?> - Organ Donation</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>
<header class="header bg-primary text-white text-center py-4">
<div class="container">
<h1 class="display-4">Organ Donation Management</h1>
<nav class="nav justify-content-center">
<a class="nav-link text-white" href="dashboard.php">Dashboard</a>
<?php if ($user_type === 'donor'): ?>
<a class="nav-link text-white" href="edit_donor_profile.php">Edit Profile</a>
<?php endif; ?>
<a class="nav-link text-white" href="logout.php">Logout</a>
</nav>
</div>
</header>
<main class="container my-5">
<?php
switch ($user_type) {
case 'donor':
include 'donor_dashboard_content.php';
break;
case 'hospital':
include 'hospital_dashboard_content.php';
break;
case 'admin':
echo '<h2 class="text-center">Welcome, Admin!</h2>';
break;
default:
echo '<p class="text-center">Invalid user type.</p>';
break;
}
?>
</main>
<footer class="footer bg-light text-center py-3 mt-5">
<div class="container">
<p class="mb-0">&copy; <?= date("Y") ?> Organ Donation Management System. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View File

@ -15,3 +15,41 @@ function db() {
} }
return $pdo; return $pdo;
} }
function run_migrations() {
$pdo = db();
$migrations_dir = __DIR__ . '/migrations';
// 1. Create migrations table if it doesn't exist (handle the very first run)
try {
$pdo->query('SELECT 1 FROM migrations LIMIT 1');
} catch (PDOException $e) {
$pdo->exec("CREATE TABLE migrations (id INT AUTO_INCREMENT PRIMARY KEY, migration_name VARCHAR(255) NOT NULL UNIQUE, executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);");
}
// 2. Get all executed migration names
$executed_migrations_stmt = $pdo->query('SELECT migration_name FROM migrations');
$executed_migrations = $executed_migrations_stmt->fetchAll(PDO::FETCH_COLUMN);
// 3. Find and run new migration files
if (is_dir($migrations_dir)) {
$files = glob($migrations_dir . '/*.sql');
sort($files); // Ensure they run in order
foreach ($files as $file) {
$migration_name = basename($file);
if (!in_array($migration_name, $executed_migrations)) {
$sql = file_get_contents($file);
if ($sql) {
$pdo->exec($sql);
$insert_stmt = $pdo->prepare('INSERT INTO migrations (migration_name) VALUES (?)');
$insert_stmt->execute([$migration_name]);
}
}
}
}
}
run_migrations();

View File

@ -0,0 +1,69 @@
CREATE TABLE IF NOT EXISTS migrations (
id INT AUTO_INCREMENT PRIMARY KEY,
migration_name VARCHAR(255) NOT NULL UNIQUE,
executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS donors (
id INT AUTO_INCREMENT PRIMARY KEY,
full_name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
phone VARCHAR(50),
blood_type VARCHAR(10),
organs_to_donate TEXT,
medical_history TEXT,
registration_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
status VARCHAR(50) DEFAULT 'pending_verification',
password_hash VARCHAR(255) NOT NULL
);
CREATE TABLE IF NOT EXISTS hospitals (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
phone VARCHAR(255),
address TEXT,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
status VARCHAR(50) DEFAULT 'pending' -- pending, approved, rejected
);
CREATE TABLE IF NOT EXISTS sessions (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
user_type VARCHAR(50) NOT NULL, -- 'hospital', 'donor', 'admin'
token VARCHAR(255) NOT NULL UNIQUE,
expires_at DATETIME NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS recipients (
id INT AUTO_INCREMENT PRIMARY KEY,
hospital_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
blood_type VARCHAR(10) NOT NULL,
organ VARCHAR(50) NOT NULL,
urgency INT NOT NULL, -- 1-10 scale
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (hospital_id) REFERENCES hospitals(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS admins (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Add a default admin user
INSERT INTO admins (email, password) VALUES ('admin@email.com', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi'); -- password
CREATE TABLE IF NOT EXISTS matches (
id INT AUTO_INCREMENT PRIMARY KEY,
donor_id INT NOT NULL,
recipient_id INT NOT NULL,
status VARCHAR(50) DEFAULT 'pending', -- pending, approved, rejected
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (donor_id) REFERENCES donors(id) ON DELETE CASCADE,
FOREIGN KEY (recipient_id) REFERENCES recipients(id) ON DELETE CASCADE
);

View File

@ -0,0 +1,2 @@
<h2 class="text-center">Welcome, Donor!</h2>
<p class="text-center">This is your dashboard. More features will be added soon.</p>

186
donor_registration.php Normal file
View File

@ -0,0 +1,186 @@
<?php
session_start();
require_once 'db/config.php';
$success_message = '';
$error_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
$full_name = $_POST['full_name'] ?? '';
$email = trim($_POST['email'] ?? '');
$phone = $_POST['phone'] ?? '';
$password = $_POST['password'] ?? '';
$confirm_password = $_POST['confirm_password'] ?? '';
$blood_type = $_POST['blood_type'] ?? '';
$organs_to_donate = isset($_POST['organs']) ? implode(', ', $_POST['organs']) : '';
$medical_history = $_POST['medical_history'] ?? '';
if (empty($full_name) || empty($email) || empty($password) || empty($blood_type) || empty($organs_to_donate)) {
throw new Exception('Please fill all required fields.');
}
if ($password !== $confirm_password) {
throw new Exception('Passwords do not match.');
}
$password_hash = password_hash($password, PASSWORD_DEFAULT);
$stmt = db()->prepare(
'INSERT INTO donors (full_name, email, phone, blood_type, organs_to_donate, medical_history, password_hash) VALUES (?, ?, ?, ?, ?, ?, ?)'
);
$stmt->execute([$full_name, $email, $phone, $blood_type, $organs_to_donate, $medical_history, $password_hash]);
$donor_id = db()->lastInsertId();
$_SESSION['user_id'] = $donor_id;
$_SESSION['user_type'] = 'donor';
$_SESSION['user_email'] = $email;
header("Location: dashboard.php");
exit;
} catch (PDOException $e) {
if ($e->getCode() == 23000) { // Integrity constraint violation (duplicate entry)
$error_message = "The email address you entered is already registered.";
} else {
$error_message = "An error occurred while processing your request. Please try again later.";
}
} catch (Exception $e) {
$error_message = $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Organ Donation Donor Registration</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>
<header class="header-gradient text-white p-4">
<div class="container">
<h1>Organ Donation Management</h1>
</div>
</header>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card shadow-sm">
<div class="card-body">
<h2 class="card-title text-center mb-4">Donor Registration</h2>
<?php if ($success_message): ?>
<div class="alert alert-success"><?php echo $success_message; ?></div>
<?php endif; ?>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?php echo $error_message; ?></div>
<?php endif; ?>
<form action="donor_registration.php" method="POST" class="needs-validation" novalidate>
<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" required>
<div class="invalid-feedback">Please enter your full name.</div>
</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 class="invalid-feedback">Please enter a valid email address.</div>
</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 class="invalid-feedback">Please enter a password.</div>
</div>
<div class="mb-3">
<label for="confirm_password" class="form-label">Confirm Password</label>
<input type="password" class="form-control" id="confirm_password" name="confirm_password" required>
<div class="invalid-feedback">Please confirm your password.</div>
</div>
<div class="mb-3">
<label for="phone" class="form-label">Phone Number</label>
<input type="tel" class="form-control" id="phone" name="phone">
</div>
<div class="mb-3">
<label for="blood_type" class="form-label">Blood Type</label>
<select class="form-select" id="blood_type" name="blood_type" required>
<option value="" disabled selected>Select your blood type</option>
<option value="A+">A+</option>
<option value="A-">A-</option>
<option value="B+">B+</option>
<option value="B-">B-</option>
<option value="AB+">AB+</option>
<option value="AB-">AB-</option>
<option value="O+">O+</option>
<option value="O-">O-</option>
</select>
<div class="invalid-feedback">Please select your blood type.</div>
</div>
<div class="mb-3">
<label class="form-label">Organs to Donate</label>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="organs[]" value="Kidney" id="org_kidney">
<label class="form-check-label" for="org_kidney">Kidney</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="organs[]" value="Liver" id="org_liver">
<label class="form-check-label" for="org_liver">Liver</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="organs[]" value="Heart" id="org_heart">
<label class="form-check-label" for="org_heart">Heart</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="organs[]" value="Lungs" id="org_lungs">
<label class="form-check-label" for="org_lungs">Lungs</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="organs[]" value="Pancreas" id="org_pancreas">
<label class="form-check-label" for="org_pancreas">Pancreas</label>
</div>
</div>
<div class="mb-3">
<label for="medical_history" class="form-label">Brief Medical History (optional)</label>
<textarea class="form-control" id="medical_history" name="medical_history" rows="3"></textarea>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary">Register as Donor</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<footer class="text-center p-4 mt-5">
<p>&copy; <?php echo date('Y'); ?> Organ Donation Management System</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Bootstrap form validation
(() => {
'use strict'
const forms = document.querySelectorAll('.needs-validation')
Array.from(forms).forEach(form => {
form.addEventListener('submit', event => {
if (!form.checkValidity()) {
event.preventDefault()
event.stopPropagation()
}
form.classList.add('was-validated')
}, false)
})
})()
</script>
</body>
</html>

145
edit_donor_profile.php Normal file
View File

@ -0,0 +1,145 @@
<?php
session_start();
require_once 'db/config.php';
// Check if user is logged in and is a donor
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'donor') {
header("Location: login.php");
exit;
}
$page_title = "Edit Profile";
$donor_id = $_SESSION['user_id'];
$error_message = '';
$success_message = '';
$pdo = db();
// Fetch donor data
$stmt = $pdo->prepare("SELECT * FROM donors WHERE id = ?");
$stmt->execute([$donor_id]);
$donor = $stmt->fetch(PDO::FETCH_ASSOC);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$blood_type = trim($_POST['blood_type']);
$organs = isset($_POST['organs']) ? implode(',', $_POST['organs']) : '';
$medical_history = trim($_POST['medical_history']);
if (empty($name) || empty($email) || empty($blood_type)) {
$error_message = "Please fill in all required fields.";
} else {
try {
$sql = "UPDATE donors SET name = ?, email = ?, phone = ?, blood_type = ?, organs = ?, medical_history = ? WHERE id = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$name, $email, $phone, $blood_type, $organs, $medical_history, $donor_id]);
$success_message = "Profile updated successfully!";
// Refresh donor data
$stmt = $pdo->prepare("SELECT * FROM donors WHERE id = ?");
$stmt->execute([$donor_id]);
$donor = $stmt->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$error_message = "Database error: " . $e->getMessage();
}
}
}
$organs_available = ['Heart', 'Lungs', 'Liver', 'Kidneys', 'Pancreas', 'Intestines', 'Corneas'];
$donor_organs = explode(',', $donor['organs']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= htmlspecialchars($page_title) ?> - Organ Donation</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>
<header class="header bg-primary text-white text-center py-4">
<div class="container">
<h1 class="display-4">Organ Donation Management</h1>
<nav class="nav justify-content-center">
<a class="nav-link text-white" href="donor_dashboard.php">Dashboard</a>
<a class="nav-link text-white active" href="edit_donor_profile.php">Edit Profile</a>
<a class="nav-link text-white" href="logout.php">Logout</a>
</nav>
</div>
</header>
<main class="container my-5">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header bg-primary text-white">
<h2 class="h4 mb-0">Edit Your Profile</h2>
</div>
<div class="card-body">
<?php if ($success_message): ?>
<div class="alert alert-success"><?= htmlspecialchars($success_message) ?></div>
<?php endif; ?>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?= htmlspecialchars($error_message) ?></div>
<?php endif; ?>
<form action="edit_donor_profile.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" value="<?= htmlspecialchars($donor['name']) ?>" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email" value="<?= htmlspecialchars($donor['email']) ?>" required>
</div>
<div class="mb-3">
<label for="phone" class="form-label">Phone</label>
<input type="tel" class="form-control" id="phone" name="phone" value="<?= htmlspecialchars($donor['phone']) ?>">
</div>
<div class="mb-3">
<label for="blood_type" class="form-label">Blood Type</label>
<select class="form-select" id="blood_type" name="blood_type" required>
<option value="A+" <?= $donor['blood_type'] == 'A+' ? 'selected' : '' ?>>A+</option>
<option value="A-" <?= $donor['blood_type'] == 'A-' ? 'selected' : '' ?>>A-</option>
<option value="B+" <?= $donor['blood_type'] == 'B+' ? 'selected' : '' ?>>B+</option>
<option value="B-" <?= $donor['blood_type'] == 'B-' ? 'selected' : '' ?>>B-</option>
<option value="AB+" <?= $donor['blood_type'] == 'AB+' ? 'selected' : '' ?>>AB+</option>
<option value="AB-" <?= $donor['blood_type'] == 'AB-' ? 'selected' : '' ?>>AB-</option>
<option value="O+" <?= $donor['blood_type'] == 'O+' ? 'selected' : '' ?>>O+</option>
<option value="O-" <?= $donor['blood_type'] == 'O-' ? 'selected' : '' ?>>O-</option>
</select>
</div>
<div class="mb-3">
<label class="form-label">Organs to Donate</label>
<div>
<?php foreach ($organs_available as $organ): ?>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" name="organs[]" value="<?= $organ ?>" id="organ_<?= strtolower($organ) ?>" <?= in_array($organ, $donor_organs) ? 'checked' : '' ?>>
<label class="form-check-label" for="organ_<?= strtolower($organ) ?>"><?= $organ ?></label>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="mb-3">
<label for="medical_history" class="form-label">Medical History / Conditions</label>
<textarea class="form-control" id="medical_history" name="medical_history" rows="4"><?= htmlspecialchars($donor['medical_history']) ?></textarea>
</div>
<button type="submit" class="btn btn-primary">Save Changes</button>
</form>
</div>
</div>
</div>
</div>
</main>
<footer class="footer bg-light text-center py-3 mt-5">
<div class="container">
<p class="mb-0">&copy; <?= date("Y") ?> Organ Donation Management System. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View File

@ -0,0 +1,2 @@
<h2 class="text-center">Welcome, Hospital!</h2>
<p class="text-center">This is your dashboard. More features will be added soon.</p>

131
hospital_registration.php Normal file
View File

@ -0,0 +1,131 @@
<?php
require_once 'db/config.php';
$page_title = "Hospital Registration";
$error_message = '';
$success_message = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$address = trim($_POST['address']);
$password = $_POST['password'];
$password_confirm = $_POST['password_confirm'];
if (empty($name) || empty($email) || empty($password)) {
$error_message = "Please fill in all required fields (Name, Email, Password).";
} elseif ($password !== $password_confirm) {
$error_message = "Passwords do not match.";
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error_message = "Invalid email format.";
} else {
try {
$pdo = db();
// Check if email already exists
$stmt = $pdo->prepare("SELECT id FROM hospitals WHERE email = ?");
$stmt->execute([$email]);
if ($stmt->fetch()) {
$error_message = "A hospital with this email is already registered.";
} else {
$hashed_password = password_hash($password, PASSWORD_BCRYPT);
$sql = "INSERT INTO hospitals (name, email, phone, address, password) VALUES (?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$name, $email, $phone, $address, $hashed_password]);
$hospital_id = $pdo->lastInsertId();
$_SESSION['user_id'] = $hospital_id;
$_SESSION['user_type'] = 'hospital';
$_SESSION['user_email'] = $email;
header("Location: dashboard.php");
exit;
}
} catch (PDOException $e) {
$error_message = "Database error: " . $e->getMessage();
// In a real application, you would log this error, not show it to the user
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= htmlspecialchars($page_title) ?> - Organ Donation</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>
<header class="header bg-primary text-white text-center py-4">
<div class="container">
<h1 class="display-4">Organ Donation Management</h1>
<nav class="nav justify-content-center">
<a class="nav-link text-white" href="index.php">Home</a>
<a class="nav-link text-white" href="donor_registration.php">Donor Registration</a>
<a class="nav-link text-white active" href="hospital_registration.php">Hospital Registration</a>
<a class="nav-link text-white" href="login.php">Login</a>
</nav>
</div>
</header>
<main class="container my-5">
<div class="row justify-content-center">
<div class="col-md-8 col-lg-6">
<div class="card shadow-sm">
<div class="card-header bg-primary text-white">
<h2 class="h4 mb-0"><?= htmlspecialchars($page_title) ?></h2>
</div>
<div class="card-body">
<?php if ($success_message): ?>
<div class="alert alert-success"><?= htmlspecialchars($success_message) ?></div>
<?php endif; ?>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?= htmlspecialchars($error_message) ?></div>
<?php endif; ?>
<form action="hospital_registration.php" method="POST">
<div class="mb-3">
<label for="name" class="form-label">Hospital 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="phone" class="form-label">Phone Number</label>
<input type="tel" class="form-control" id="phone" name="phone">
</div>
<div class="mb-3">
<label for="address" class="form-label">Address</label>
<textarea class="form-control" id="address" name="address" rows="3"></textarea>
</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="mb-3">
<label for="password_confirm" class="form-label">Confirm Password</label>
<input type="password" class="form-control" id="password_confirm" name="password_confirm" required>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary">Register</button>
</div>
</form>
</div>
</div>
</div>
</div>
</main>
<footer class="footer bg-light text-center py-3 mt-5">
<div class="container">
<p class="mb-0">&copy; <?= date("Y") ?> Organ Donation Management System. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

190
index.php
View File

@ -3,24 +3,21 @@ declare(strict_types=1);
@ini_set('display_errors', '1'); @ini_set('display_errors', '1');
@error_reporting(E_ALL); @error_reporting(E_ALL);
@date_default_timezone_set('UTC'); @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" />
<title>New Style</title> <title>Organ Donation Management System</title>
<?php <?php
// Read project preview data from environment // Read project preview data from environment
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? ''; $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Welcome to our Organ Donation Management System. Your selfless act can save lives.';
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? ''; $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
?> ?>
<?php if ($projectDescription): ?> <?php if ($projectDescription): ?>
<!-- Meta description --> <!-- Meta description -->
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' /> <meta name="description" content="<?= htmlspecialchars($projectDescription) ?>" />
<!-- Open Graph meta tags --> <!-- Open Graph meta tags -->
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" /> <meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<!-- Twitter meta tags --> <!-- Twitter meta tags -->
@ -32,119 +29,100 @@ $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
<!-- Twitter image --> <!-- Twitter image -->
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" /> <meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<?php endif; ?> <?php endif; ?>
<link rel="preconnect" href="https://fonts.googleapis.com"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="stylesheet" href="assets/css/custom.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
<style> <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 { body {
margin: 0; background-color: #F8F9FA;
font-family: 'Inter', sans-serif; }
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end)); .hero {
color: var(--text-color); background: linear-gradient(90deg, #007BFF, #0056b3);
display: flex; color: white;
justify-content: center; padding: 100px 0;
align-items: center;
min-height: 100vh;
text-align: center; text-align: center;
overflow: hidden;
position: relative;
} }
body::before { .hero h1 {
content: ''; font-size: 3.5rem;
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; 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> </style>
</head> </head>
<body> <body>
<header class="header-gradient text-white p-3">
<div class="container d-flex justify-content-between align-items-center">
<h4 class="mb-0">Organ Donation Management</h4>
<nav>
<a href="donor_registration.php" class="btn btn-light">Donor Registration</a>
<a href="hospital_registration.php" class="btn btn-light ms-2">Hospital Registration</a>
<a href="login.php" class="btn btn-outline-light ms-2">Login</a>
</nav>
</div>
</header>
<main> <main>
<div class="card"> <section class="hero">
<h1>Analyzing your requirements and generating your website…</h1> <div class="container">
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes"> <h1 class="display-4">Give the Gift of Life</h1>
<span class="sr-only">Loading…</span> <p class="lead">Your decision to become an organ donor can save up to eight lives. <br> Join our community of heroes today.</p>
<a href="donor_registration.php" class="btn btn-success btn-lg mt-3">Become a Donor Now</a>
</div> </div>
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p> </section>
<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> <section class="container mt-5 text-center">
<div class="row">
<div class="col-md-6">
<div class="card h-100 card-body">
<h2>For Donors</h2>
<p>Register yourself as an organ donor and become a potential lifesaver.</p>
<a href="donor_registration.php" class="btn btn-primary mt-auto">Register as a Donor</a>
</div> </div>
</div>
<div class="col-md-6">
<div class="card h-100 card-body">
<h2>For Hospitals</h2>
<p>Register your hospital to manage recipients and coordinate with donors.</p>
<a href="hospital_registration.php" class="btn btn-secondary mt-auto">Register Your Hospital</a>
</div>
</div>
</div>
</section>
<section class="container mt-5 text-center">
<h2 class="mb-4">How It Works</h2>
<div class="row mt-4">
<div class="col-md-4">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">1. Register</h5>
<p class="card-text">Fill out the secure registration form with your details. It only takes a few minutes.</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">2. Verification</h5>
<p class="card-text">Our team verifies your information to ensure safety and eligibility for donation.</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">3. Save Lives</h5>
<p class="card-text">Once matched, you get a chance to make a life-changing impact.</p>
</div>
</div>
</div>
</div>
</section>
</main> </main>
<footer>
Page updated: <?= htmlspecialchars($now) ?> (UTC) <footer class="text-center p-4 mt-5">
<p>&copy; <?php echo date('Y'); ?> Organ Donation Management System</p>
</footer> </footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body> </body>
</html> </html>

147
login.php Normal file
View File

@ -0,0 +1,147 @@
<?php
require_once 'db/config.php';
session_start();
$page_title = "Login";
$error_message = '';
// Redirect if already logged in
if (isset($_SESSION['user_id'])) {
$user_type = $_SESSION['user_type'];
header("Location: dashboard.php");
exit;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = trim($_POST['email']);
$password = $_POST['password'];
$user_type = $_POST['user_type'];
if (empty($email) || empty($password) || empty($user_type)) {
$error_message = "Please fill in all fields.";
} else {
$pdo = db();
$table_name = '';
$password_column = '';
switch ($user_type) {
case 'donor':
$table_name = 'donors';
$password_column = 'password_hash';
break;
case 'hospital':
$table_name = 'hospitals';
$password_column = 'password';
break;
case 'admin':
$table_name = 'admins';
$password_column = 'password';
break;
default:
$error_message = "Invalid user type selected.";
}
if ($table_name) {
try {
$stmt = $pdo->prepare("SELECT id, " . $password_column . " FROM " . $table_name . " WHERE email = ?");
$stmt->execute([$email]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if ($user && password_verify($password, $user[$password_column])) {
// Regenerate session ID to prevent session fixation
session_regenerate_id(true);
// Store user info in session
$_SESSION['user_id'] = $user['id'];
$_SESSION['user_type'] = $user_type;
$_SESSION['user_email'] = $email;
// Set a session token in a cookie for "Remember Me" functionality (optional)
// $token = bin2hex(random_bytes(32));
// setcookie('session_token', $token, time() + (86400 * 30), "/"); // 30 days
// $expires_at = date('Y-m-d H:i:s', time() + (86400 * 30));
// $stmt = $pdo->prepare("INSERT INTO sessions (user_id, user_type, token, expires_at) VALUES (?, ?, ?, ?)");
// $stmt->execute([$user['id'], $user_type, $token, $expires_at]);
header("Location: dashboard.php");
exit;
} else {
$error_message = "Invalid email, password, or role.";
}
} catch (PDOException $e) {
$error_message = "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><?= htmlspecialchars($page_title) ?> - Organ Donation</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>
<header class="header bg-primary text-white text-center py-4">
<div class="container">
<h1 class="display-4">Organ Donation Management</h1>
<nav class="nav justify-content-center">
<a class="nav-link text-white" href="index.php">Home</a>
<a class="nav-link text-white" href="donor_registration.php">Donor Registration</a>
<a class="nav-link text-white" href="hospital_registration.php">Hospital Registration</a>
<a class="nav-link text-white active" href="login.php">Login</a>
</nav>
</div>
</header>
<main class="container my-5">
<div class="row justify-content-center">
<div class="col-md-6 col-lg-4">
<div class="card shadow-sm">
<div class="card-header bg-primary text-white">
<h2 class="h4 mb-0">Login</h2>
</div>
<div class="card-body">
<?php if ($error_message): ?>
<div class="alert alert-danger"><?= htmlspecialchars($error_message) ?></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="mb-3">
<label for="user_type" class="form-label">Login as:</label>
<select class="form-select" id="user_type" name="user_type">
<option value="donor">Donor</option>
<option value="hospital">Hospital</option>
<option value="admin">Admin</option>
</select>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary">Login</button>
</div>
</form>
</div>
</div>
</div>
</div>
</main>
<footer class="footer bg-light text-center py-3 mt-5">
<div class="container">
<p class="mb-0">&copy; <?= date("Y") ?> Organ Donation Management System. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

22
logout.php Normal file
View File

@ -0,0 +1,22 @@
<?php
session_start();
// Unset all of the session variables
$_SESSION = array();
// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
// Finally, destroy the session.
session_destroy();
// Redirect to login page
header("Location: login.php");
exit;

124
register_recipient.php Normal file
View File

@ -0,0 +1,124 @@
<?php
session_start();
require_once 'db/config.php';
// Check if user is logged in and is a hospital
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'hospital') {
header("Location: login.php");
exit;
}
$page_title = "Register a New Recipient";
$hospital_id = $_SESSION['user_id'];
$error_message = '';
$success_message = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST['name']);
$blood_type = trim($_POST['blood_type']);
$organ = trim($_POST['organ']);
$urgency = trim($_POST['urgency']);
if (empty($name) || empty($blood_type) || empty($organ) || empty($urgency)) {
$error_message = "Please fill in all fields.";
} else {
try {
$pdo = db();
$sql = "INSERT INTO recipients (hospital_id, name, blood_type, organ, urgency) VALUES (?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$hospital_id, $name, $blood_type, $organ, $urgency]);
$success_message = "Recipient registered successfully!";
} catch (PDOException $e) {
$error_message = "Database error: " . $e->getMessage();
}
}
}
$organs_available = ['Heart', 'Lungs', 'Liver', 'Kidneys', 'Pancreas', 'Intestines', 'Corneas'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= htmlspecialchars($page_title) ?> - Organ Donation</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>
<header class="header bg-primary text-white text-center py-4">
<div class="container">
<h1 class="display-4">Organ Donation Management</h1>
<nav class="nav justify-content-center">
<a class="nav-link text-white" href="hospital_dashboard.php">Dashboard</a>
<a class="nav-link text-white active" href="register_recipient.php">Register Recipient</a>
<a class="nav-link text-white" href="logout.php">Logout</a>
</nav>
</div>
</header>
<main class="container my-5">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header bg-primary text-white">
<h2 class="h4 mb-0"><?= htmlspecialchars($page_title) ?></h2>
</div>
<div class="card-body">
<?php if ($success_message): ?>
<div class="alert alert-success"><?= htmlspecialchars($success_message) ?></div>
<?php endif; ?>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?= htmlspecialchars($error_message) ?></div>
<?php endif; ?>
<form action="register_recipient.php" method="POST">
<div class="mb-3">
<label for="name" class="form-label">Recipient Full Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="blood_type" class="form-label">Blood Type</label>
<select class="form-select" id="blood_type" name="blood_type" required>
<option value="">Select Blood Type</option>
<option value="A+">A+</option>
<option value="A-">A-</option>
<option value="B+">B+</option>
<option value="B-">B-</option>
<option value="AB+">AB+</option>
<option value="AB-">AB-</option>
<option value="O+">O+</option>
<option value="O-">O-</option>
</select>
</div>
<div class="mb-3">
<label for="organ" class="form-label">Required Organ</label>
<select class="form-select" id="organ" name="organ" required>
<option value="">Select Organ</option>
<?php foreach ($organs_available as $organ): ?>
<option value="<?= $organ ?>"><?= $organ ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label for="urgency" class="form-label">Urgency Level (1-10)</label>
<input type="number" class="form-control" id="urgency" name="urgency" min="1" max="10" required>
</div>
<button type="submit" class="btn btn-primary">Register Recipient</button>
</form>
</div>
</div>
</div>
</div>
</main>
<footer class="footer bg-light text-center py-3 mt-5">
<div class="container">
<p class="mb-0">&copy; <?= date("Y") ?> Organ Donation Management System. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

154
run_matching.php Normal file
View File

@ -0,0 +1,154 @@
<?php
session_start();
require_once 'db/config.php';
// Check if user is logged in and is an admin
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
header("Location: login.php");
exit;
}
$page_title = "Run Organ Matching Algorithm";
$pdo = db();
$match_message = '';
// Matching Logic
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['run_matching'])) {
try {
// Fetch all approved donors and recipients
$donors = $pdo->query("SELECT * FROM donors WHERE status = 'approved'")->fetchAll(PDO::FETCH_ASSOC);
$recipients = $pdo->query("SELECT * FROM recipients")->fetchAll(PDO::FETCH_ASSOC);
$matches_found = 0;
foreach ($recipients as $recipient) {
foreach ($donors as $donor) {
// Simple matching logic: blood type and organ must match
// And donor must have the organ listed
if ($recipient['blood_type'] === $donor['blood_type'] &&
strpos($donor['organs'], $recipient['organ']) !== false) {
// Check if this match already exists
$stmt = $pdo->prepare("SELECT id FROM matches WHERE donor_id = ? AND recipient_id = ?");
$stmt->execute([$donor['id'], $recipient['id']]);
if (!$stmt->fetch()) {
// Insert new match as 'pending'
$insert_stmt = $pdo->prepare("INSERT INTO matches (donor_id, recipient_id, status) VALUES (?, ?, 'pending')");
$insert_stmt->execute([$donor['id'], $recipient['id']]);
$matches_found++;
}
}
}
}
if ($matches_found > 0) {
$match_message = "Found $matches_found new potential matches! They are now pending approval.";
} else {
$match_message = "No new matches found at this time.";
}
} catch (PDOException $e) {
$match_message = "Database error during matching: " . $e->getMessage();
}
}
// Fetch current matches
$matches = $pdo->query("
SELECT m.id, d.name as donor_name, r.name as recipient_name, h.name as hospital_name, m.status
FROM matches m
JOIN donors d ON m.donor_id = d.id
JOIN recipients r ON m.recipient_id = r.id
JOIN hospitals h ON r.hospital_id = h.id
ORDER BY m.created_at DESC
")->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><?= htmlspecialchars($page_title) ?> - Organ Donation</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>
<header class="header bg-primary text-white text-center py-4">
<div class="container">
<h1 class="display-4">Organ Donation Management</h1>
<nav class="nav justify-content-center">
<a class="nav-link text-white" href="dashboard.php">Dashboard</a>
<a class="nav-link text-white" href="verify.php">Verify Donors/Hospitals</a>
<a class="nav-link text-white active" href="run_matching.php">Run Matching</a>
<a class="nav-link text-white" href="logout.php">Logout</a>
</nav>
</div>
</header>
<main class="container my-5">
<div class="text-center mb-5">
<h2>Run Matching Algorithm</h2>
<p>Click the button below to find potential matches between approved donors and recipients.</p>
<form action="run_matching.php" method="POST">
<button type="submit" name="run_matching" class="btn btn-lg btn-success">Find Matches</button>
</form>
<?php if ($match_message): ?>
<div class="alert alert-info mt-4"><?= htmlspecialchars($match_message) ?></div>
<?php endif; ?>
</div>
<hr>
<h3 class="text-center mb-4">Current Matches</h3>
<?php if (empty($matches)): ?>
<p class="text-center">No matches found yet.</p>
<?php else: ?>
<table class="table table-striped">
<thead>
<tr>
<th>Donor</th>
<th>Recipient</th>
<th>Hospital</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($matches as $match): ?>
<tr>
<td><?= htmlspecialchars($match['donor_name']) ?></td>
<td><?= htmlspecialchars($match['recipient_name']) ?></td>
<td><?= htmlspecialchars($match['hospital_name']) ?></td>
<td>
<span class="badge bg-<?= $match['status'] === 'approved' ? 'success' : ($match['status'] === 'rejected' ? 'danger' : 'warning') ?>">
<?= htmlspecialchars(ucfirst($match['status'])) ?>
</span>
</td>
<td>
<?php if($match['status'] === 'pending'): ?>
<form action="run_matching.php" method="POST" class="d-inline">
<input type="hidden" name="match_id" value="<?= $match['id'] ?>">
<button type="submit" name="action" value="approve_match" class="btn btn-sm btn-outline-success">Approve</button>
<button type="submit" name="action" value="reject_match" class="btn btn-sm btn-outline-danger">Reject</button>
</form>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</main>
<footer class="footer bg-light text-center py-3 mt-5">
<div class="container">
<p class="mb-0">&copy; <?= date("Y") ?> Organ Donation Management System. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

3
session_test.php Normal file
View File

@ -0,0 +1,3 @@
<?php
phpinfo();
?>

151
verify.php Normal file
View File

@ -0,0 +1,151 @@
<?php
session_start();
require_once 'db/config.php';
// Check if user is logged in and is an admin
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
header("Location: login.php");
exit;
}
$page_title = "Verify Donors and Hospitals";
$pdo = db();
// Handle status updates
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action'])) {
$action = $_POST['action'];
$id = $_POST['id'];
$type = $_POST['type']; // 'donor' or 'hospital'
if ($action === 'approve') {
$status = 'approved';
} elseif ($action === 'reject') {
$status = 'rejected';
}
if (isset($status) && ($type === 'donor' || $type === 'hospital')) {
$table = $type . 's';
$sql = "UPDATE $table SET status = ? WHERE id = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$status, $id]);
}
}
// Fetch pending donors and hospitals
$pending_donors = $pdo->query("SELECT * FROM donors WHERE status = 'pending'")->fetchAll(PDO::FETCH_ASSOC);
$pending_hospitals = $pdo->query("SELECT * FROM hospitals WHERE status = 'pending'")->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><?= htmlspecialchars($page_title) ?> - Organ Donation</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>
<header class="header bg-primary text-white text-center py-4">
<div class="container">
<h1 class="display-4">Organ Donation Management</h1>
<nav class="nav justify-content-center">
<a class="nav-link text-white" href="dashboard.php">Dashboard</a>
<a class="nav-link text-white active" href="verify.php">Verify Donors/Hospitals</a>
<a class="nav-link text-white" href="run_matching.php">Run Matching</a>
<a class="nav-link text-white" href="logout.php">Logout</a>
</nav>
</div>
</header>
<main class="container my-5">
<h2 class="text-center mb-4">Verification Queue</h2>
<section id="pending_donors">
<h3>Pending Donor Registrations</h3>
<?php if (empty($pending_donors)): ?>
<p>No pending donor registrations.</p>
<?php else: ?>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Blood Type</th>
<th>Organs</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($pending_donors as $donor): ?>
<tr>
<td><?= htmlspecialchars($donor['name']) ?></td>
<td><?= htmlspecialchars($donor['email']) ?></td>
<td><?= htmlspecialchars($donor['blood_type']) ?></td>
<td><?= htmlspecialchars($donor['organs']) ?></td>
<td>
<form action="verify.php" method="POST" class="d-inline">
<input type="hidden" name="id" value="<?= $donor['id'] ?>">
<input type="hidden" name="type" value="donor">
<button type="submit" name="action" value="approve" class="btn btn-success btn-sm">Approve</button>
<button type="submit" name="action" value="reject" class="btn btn-danger btn-sm">Reject</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</section>
<hr class="my-5">
<section id="pending_hospitals">
<h3>Pending Hospital Registrations</h3>
<?php if (empty($pending_hospitals)): ?>
<p>No pending hospital registrations.</p>
<?php else: ?>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Address</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($pending_hospitals as $hospital): ?>
<tr>
<td><?= htmlspecialchars($hospital['name']) ?></td>
<td><?= htmlspecialchars($hospital['email']) ?></td>
<td><?= htmlspecialchars($hospital['phone']) ?></td>
<td><?= htmlspecialchars($hospital['address']) ?></td>
<td>
<form action="verify.php" method="POST" class="d-inline">
<input type="hidden" name="id" value="<?= $hospital['id'] ?>">
<input type="hidden" name="type" value="hospital">
<button type="submit" name="action" value="approve" class="btn btn-success btn-sm">Approve</button>
<button type="submit" name="action" value="reject" class="btn btn-danger btn-sm">Reject</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</section>
</main>
<footer class="footer bg-light text-center py-3 mt-5">
<div class="container">
<p class="mb-0">&copy; <?= date("Y") ?> Organ Donation Management System. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>