From c12628e2d971b912e744da05dbb21539fec9c9c0 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Fri, 5 Dec 2025 21:07:12 +0000 Subject: [PATCH] v2 --- assets/css/custom.css | 25 ++++ dashboard.php | 64 +++++++++ db/config.php | 38 +++++ db/migrations/001_initial_schema.sql | 69 +++++++++ donor_dashboard_content.php | 2 + donor_registration.php | 186 +++++++++++++++++++++++++ edit_donor_profile.php | 145 +++++++++++++++++++ hospital_dashboard_content.php | 2 + hospital_registration.php | 131 ++++++++++++++++++ index.php | 200 ++++++++++++--------------- login.php | 147 ++++++++++++++++++++ logout.php | 22 +++ register_recipient.php | 124 +++++++++++++++++ run_matching.php | 154 +++++++++++++++++++++ session_test.php | 3 + verify.php | 151 ++++++++++++++++++++ 16 files changed, 1352 insertions(+), 111 deletions(-) create mode 100644 assets/css/custom.css create mode 100644 dashboard.php create mode 100644 db/migrations/001_initial_schema.sql create mode 100644 donor_dashboard_content.php create mode 100644 donor_registration.php create mode 100644 edit_donor_profile.php create mode 100644 hospital_dashboard_content.php create mode 100644 hospital_registration.php create mode 100644 login.php create mode 100644 logout.php create mode 100644 register_recipient.php create mode 100644 run_matching.php create mode 100644 session_test.php create mode 100644 verify.php diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..7d4e90b --- /dev/null +++ b/assets/css/custom.css @@ -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; +} diff --git a/dashboard.php b/dashboard.php new file mode 100644 index 0000000..2ab0a73 --- /dev/null +++ b/dashboard.php @@ -0,0 +1,64 @@ + + + + + + + <?= htmlspecialchars($page_title) ?> - Organ Donation + + + + +
+
+

Organ Donation Management

+ +
+
+ +
+ Welcome, Admin!'; + break; + default: + echo '

Invalid user type.

'; + break; + } + ?> +
+ + + + + + diff --git a/db/config.php b/db/config.php index 60c5680..a085b47 100644 --- a/db/config.php +++ b/db/config.php @@ -15,3 +15,41 @@ function db() { } 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(); + diff --git a/db/migrations/001_initial_schema.sql b/db/migrations/001_initial_schema.sql new file mode 100644 index 0000000..ecfb7f8 --- /dev/null +++ b/db/migrations/001_initial_schema.sql @@ -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 +); diff --git a/donor_dashboard_content.php b/donor_dashboard_content.php new file mode 100644 index 0000000..d1e5c1e --- /dev/null +++ b/donor_dashboard_content.php @@ -0,0 +1,2 @@ +

Welcome, Donor!

+

This is your dashboard. More features will be added soon.

diff --git a/donor_registration.php b/donor_registration.php new file mode 100644 index 0000000..f537b63 --- /dev/null +++ b/donor_registration.php @@ -0,0 +1,186 @@ +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(); + } +} +?> + + + + + + Organ Donation Donor Registration + + + + + +
+
+

Organ Donation Management

+
+
+ +
+
+
+
+
+

Donor Registration

+ + +
+ + +
+ + +
+
+ + +
Please enter your full name.
+
+
+ + +
Please enter a valid email address.
+
+
+ + +
Please enter a password.
+
+
+ + +
Please confirm your password.
+
+
+ + +
+
+ + +
Please select your blood type.
+
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+ +
+
+
+
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/edit_donor_profile.php b/edit_donor_profile.php new file mode 100644 index 0000000..8603527 --- /dev/null +++ b/edit_donor_profile.php @@ -0,0 +1,145 @@ +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']); + +?> + + + + + + <?= htmlspecialchars($page_title) ?> - Organ Donation + + + + +
+
+

Organ Donation Management

+ +
+
+ +
+
+
+
+
+

Edit Your Profile

+
+
+ +
+ + +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ +
+ > + +
+ +
+
+
+ + +
+ +
+
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/hospital_dashboard_content.php b/hospital_dashboard_content.php new file mode 100644 index 0000000..d3cbf99 --- /dev/null +++ b/hospital_dashboard_content.php @@ -0,0 +1,2 @@ +

Welcome, Hospital!

+

This is your dashboard. More features will be added soon.

diff --git a/hospital_registration.php b/hospital_registration.php new file mode 100644 index 0000000..1c43f0a --- /dev/null +++ b/hospital_registration.php @@ -0,0 +1,131 @@ +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 + } + } +} +?> + + + + + + <?= htmlspecialchars($page_title) ?> - Organ Donation + + + + +
+
+

Organ Donation Management

+ +
+
+ +
+
+
+
+
+

+
+
+ +
+ + +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/index.php b/index.php index 7205f3d..0c3940b 100644 --- a/index.php +++ b/index.php @@ -3,24 +3,21 @@ declare(strict_types=1); @ini_set('display_errors', '1'); @error_reporting(E_ALL); @date_default_timezone_set('UTC'); - -$phpVersion = PHP_VERSION; -$now = date('Y-m-d H:i:s'); ?> - New Style + Organ Donation Management System - + @@ -32,119 +29,100 @@ $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? ''; - - - + + -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

+ +
+
+

Organ Donation Management

+
-
- + + +
+
+
+

Give the Gift of Life

+

Your decision to become an organ donor can save up to eight lives.
Join our community of heroes today.

+ Become a Donor Now +
+
+ +
+
+
+
+

For Donors

+

Register yourself as an organ donor and become a potential lifesaver.

+ Register as a Donor +
+
+
+
+

For Hospitals

+

Register your hospital to manage recipients and coordinate with donors.

+ Register Your Hospital +
+
+
+
+ +
+

How It Works

+
+
+
+
+
1. Register
+

Fill out the secure registration form with your details. It only takes a few minutes.

+
+
+
+
+
+
+
2. Verification
+

Our team verifies your information to ensure safety and eligibility for donation.

+
+
+
+
+
+
+
3. Save Lives
+

Once matched, you get a chance to make a life-changing impact.

+
+
+
+
+
+
+ + + + diff --git a/login.php b/login.php new file mode 100644 index 0000000..11b1f68 --- /dev/null +++ b/login.php @@ -0,0 +1,147 @@ +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(); + } + } + } +} +?> + + + + + + <?= htmlspecialchars($page_title) ?> - Organ Donation + + + + +
+
+

Organ Donation Management

+ +
+
+ +
+
+
+
+
+

Login

+
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..3651090 --- /dev/null +++ b/logout.php @@ -0,0 +1,22 @@ +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']; + +?> + + + + + + <?= htmlspecialchars($page_title) ?> - Organ Donation + + + + +
+
+

Organ Donation Management

+ +
+
+ +
+
+
+
+
+

+
+
+ +
+ + +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/run_matching.php b/run_matching.php new file mode 100644 index 0000000..76dc961 --- /dev/null +++ b/run_matching.php @@ -0,0 +1,154 @@ +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); + + +?> + + + + + + <?= htmlspecialchars($page_title) ?> - Organ Donation + + + + +
+
+

Organ Donation Management

+ +
+
+ +
+
+

Run Matching Algorithm

+

Click the button below to find potential matches between approved donors and recipients.

+
+ +
+ +
+ +
+ +
+ +

Current Matches

+ +

No matches found yet.

+ + + + + + + + + + + + + + + + + + + + + + +
DonorRecipientHospitalStatusAction
+ + + + + +
+ + + +
+ +
+ + + +
+ + + + + + \ No newline at end of file diff --git a/session_test.php b/session_test.php new file mode 100644 index 0000000..968c8df --- /dev/null +++ b/session_test.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/verify.php b/verify.php new file mode 100644 index 0000000..016cb17 --- /dev/null +++ b/verify.php @@ -0,0 +1,151 @@ +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); + +?> + + + + + + <?= htmlspecialchars($page_title) ?> - Organ Donation + + + + +
+
+

Organ Donation Management

+ +
+
+ +
+

Verification Queue

+ +
+

Pending Donor Registrations

+ +

No pending donor registrations.

+ + + + + + + + + + + + + + + + + + + + + + +
NameEmailBlood TypeOrgansAction
+
+ + + + +
+
+ +
+ +
+ +
+

Pending Hospital Registrations

+ +

No pending hospital registrations.

+ + + + + + + + + + + + + + + + + + + + + + +
NameEmailPhoneAddressAction
+
+ + + + +
+
+ +
+ +
+ + + + + + \ No newline at end of file