diff --git a/admin_dashboard.php b/admin_dashboard.php new file mode 100644 index 0000000..2bf8426 --- /dev/null +++ b/admin_dashboard.php @@ -0,0 +1,204 @@ +prepare("UPDATE hospitals SET status = ? WHERE id = ?"); + $stmt->execute([$new_status, $hospital_id]); + } + header("Location: admin_dashboard.php"); + exit; +} + +// Handle donor status updates +if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['donor_id'])) { + $donor_id = $_POST['donor_id']; + $new_status = $_POST['status']; // 'approved' or 'rejected' + + if (in_array($new_status, ['approved', 'rejected'])) { + $stmt = $pdo->prepare("UPDATE donors SET status = ? WHERE id = ?"); + $stmt->execute([$new_status, $donor_id]); + } + header("Location: admin_dashboard.php?tab=donors"); + exit; +} + +// Fetch pending hospitals +$stmt_hospitals = $pdo->prepare("SELECT * FROM hospitals WHERE status = 'pending_verification'"); +$stmt_hospitals->execute(); +$pending_hospitals = $stmt_hospitals->fetchAll(PDO::FETCH_ASSOC); + +// Fetch all donors +$stmt_donors = $pdo->prepare("SELECT * FROM donors ORDER BY registration_date DESC"); +$stmt_donors->execute(); +$all_donors = $stmt_donors->fetchAll(PDO::FETCH_ASSOC); + +// Fetch all recipients +$stmt_recipients = $pdo->prepare("SELECT r.*, h.hospital_name FROM recipients r JOIN hospitals h ON r.hospital_id = h.id ORDER BY r.registration_date DESC"); +$stmt_recipients->execute(); +$all_recipients = $stmt_recipients->fetchAll(PDO::FETCH_ASSOC); + +?> + + + + + + Admin Dashboard - Organ Donation + + + + + + + +
+

Admin Dashboard

+ + + +
+ +
+
+

Pending Hospital Approvals

+
+ +

No pending hospital registrations.

+ +
+ + + + + + + + + + + + + + +
IDHospital NameEmailPhoneRegistered OnAction
+
+
+
+
+ +
+
+
+ + +
+
+

Donor Management

+
+
+ + + + + + + + + + + + + + + +
IDNameEmailBlood TypeOrgansStatusAction
+ +
+
+ +
+
+
+
+
+ + +
+
+

Registered Recipients

+
+
+ + + + + + + + + + + + + + +
IDNameBlood TypeOrgan NeededRegistered ByDate
+
+
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/admin_login.php b/admin_login.php new file mode 100644 index 0000000..63e83a7 --- /dev/null +++ b/admin_login.php @@ -0,0 +1,91 @@ + + + + + + + Admin Login - Organ Donation + + + + + + + +
+
+
+
+
+

Admin Login

+
+
+ +
+ +
+
+ + +
+
+ + +
+ +
+
+ Default credentials: admin / password +
+
+
+
+
+
+ + + + diff --git a/admin_logout.php b/admin_logout.php new file mode 100644 index 0000000..c9ac44d --- /dev/null +++ b/admin_logout.php @@ -0,0 +1,12 @@ +exec("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, + registration_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + status VARCHAR(50) DEFAULT 'pending_verification' + )"); +} catch (PDOException $e) { + $error_message = "Database error: " . $e->getMessage(); +} + + +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $full_name = trim($_POST['full_name']); + $email = trim($_POST['email']); + $phone = trim($_POST['phone']); + $blood_type = $_POST['blood_type']; + $organs = isset($_POST['organs']) ? implode(', ', $_POST['organs']) : ''; + + if (empty($full_name) || empty($email) || empty($blood_type) || empty($organs)) { + $error_message = "Please fill all required fields."; + } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + $error_message = "Invalid email format."; + } else { + try { + $stmt = $pdo->prepare("INSERT INTO donors (full_name, email, phone, blood_type, organs_to_donate) VALUES (?, ?, ?, ?, ?)"); + $stmt->execute([$full_name, $email, $phone, $blood_type, $organs]); + $success_message = "Thank you for registering as a donor! Your registration is pending verification."; + } catch (PDOException $e) { + if ($e->getCode() == 23000) { // Integrity constraint violation (e.g., duplicate email) + $error_message = "This email address is already registered."; + } else { + $error_message = "There was an error with your registration. Please try again."; + } + } + } +} +?> + + + + + + Donor Registration - Organ Donation Management + + + + + + + +
+
+
+

Become a Life Saver: Register as a Donor

+ + +
+ + +
+ + + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+
+
+
+ +
+
+
+ + + + + + + \ No newline at end of file diff --git a/hospital_dashboard.php b/hospital_dashboard.php new file mode 100644 index 0000000..e74f9a0 --- /dev/null +++ b/hospital_dashboard.php @@ -0,0 +1,221 @@ +prepare("SELECT status FROM hospitals WHERE id = ?"); +$stmt->execute([$hospital_id]); +$hospital = $stmt->fetch(PDO::FETCH_ASSOC); +$hospital_status = $hospital['status'] ?? 'pending_verification'; + +$success_message = ''; +$error_message = ''; + +// Table creation and form processing only if hospital is approved +if ($hospital_status === 'approved') { + try { + // Idempotent table creation for recipients + $pdo->exec("CREATE TABLE IF NOT EXISTS recipients ( + id INT AUTO_INCREMENT PRIMARY KEY, + hospital_id INT NOT NULL, + full_name VARCHAR(255) NOT NULL, + email VARCHAR(255) NOT NULL, + phone VARCHAR(50), + blood_type VARCHAR(10) NOT NULL, + organ_needed VARCHAR(100) NOT NULL, + urgency_level VARCHAR(50) NOT NULL, + registration_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + status VARCHAR(50) DEFAULT 'waiting', /* e.g., waiting, matched, transplanted */ + FOREIGN KEY (hospital_id) REFERENCES hospitals(id) + )"); + } catch (PDOException $e) { + $error_message = "Database error: " . $e->getMessage(); + } + + // Handle new recipient registration + if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['register_recipient'])) { + $full_name = trim($_POST['full_name']); + $email = trim($_POST['email']); + $phone = trim($_POST['phone']); + $blood_type = $_POST['blood_type']; + $organ_needed = $_POST['organ_needed']; + $urgency_level = $_POST['urgency_level']; + + if (empty($full_name) || empty($email) || empty($blood_type) || empty($organ_needed) || empty($urgency_level)) { + $error_message = "Please fill all required fields."; + } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + $error_message = "Invalid email format."; + } else { + try { + $stmt = $pdo->prepare("INSERT INTO recipients (hospital_id, full_name, email, phone, blood_type, organ_needed, urgency_level) VALUES (?, ?, ?, ?, ?, ?, ?)"); + $stmt->execute([$hospital_id, $full_name, $email, $phone, $blood_type, $organ_needed, $urgency_level]); + $success_message = "Recipient registered successfully!"; + } catch (PDOException $e) { + $error_message = "Error registering recipient. Please try again."; + } + } + } +} + +// Fetch this hospital's registered recipients +$recipients = []; +if ($hospital_status === 'approved') { + $stmt = $pdo->prepare("SELECT * FROM recipients WHERE hospital_id = ? ORDER BY registration_date DESC"); + $stmt->execute([$hospital_id]); + $recipients = $stmt->fetchAll(PDO::FETCH_ASSOC); +} + +// Logout logic +if (isset($_GET['logout'])) { + session_destroy(); + header("Location: index.php"); + exit(); +} +?> + + + + + + Hospital Dashboard + + + + + + + +
+ + +
+

Account Pending Approval

+

Your hospital registration is currently under review by our administrators. You will be able to register recipients once your account is approved.

+
+ +
+

Account Registration Rejected

+

Your hospital registration was not approved. Please contact an administrator for more information.

+
+ + +
+
+ + +
+
+

Register a New Recipient

+
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ + +
+
+

Your Registered Recipients

+
+
+ +

You have not registered any recipients yet.

+ +
+ + + + + + + + + + + + + + + + + + + +
NameEmailBlood TypeOrgan NeededUrgencyStatusDate
+
+ +
+
+ + + +
+ + + + + + \ No newline at end of file diff --git a/hospital_login.php b/hospital_login.php new file mode 100644 index 0000000..70eed6d --- /dev/null +++ b/hospital_login.php @@ -0,0 +1,119 @@ +Please enter both email and password.'; + } else { + try { + $pdo = db(); + $stmt = $pdo->prepare("SELECT * FROM hospitals WHERE email = ?"); + $stmt->execute([$email]); + $hospital = $stmt->fetch(); + + if ($hospital && password_verify($password, $hospital['password'])) { + if ($hospital['status'] == 'verified') { + $_SESSION['hospital_id'] = $hospital['id']; + $_SESSION['hospital_name'] = $hospital['hospital_name']; + header("Location: hospital_dashboard.php"); + exit(); + } else { + $message = '
Your account is pending verification by the administrator.
'; + } + } else { + $message = '
Invalid email or password.
'; + } + } catch (PDOException $e) { + $message = '
Error: ' . $e->getMessage() . '
'; + } + } +} +?> + + + + + + Hospital Login - Organ Donation Management System + + + + + + + +
+
+
+
+
+

Hospital Login

+
+
+ +
+
+ + +
+
+ + +
+ +
+
+ +
+
+
+
+ + + + + + + diff --git a/hospital_register.php b/hospital_register.php new file mode 100644 index 0000000..7a6d493 --- /dev/null +++ b/hospital_register.php @@ -0,0 +1,140 @@ +exec($sql); +} catch (PDOException $e) { + die("Could not create table: " . $e->getMessage()); +} + +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $hospital_name = trim($_POST['hospital_name']); + $email = trim($_POST['email']); + $password = $_POST['password']; + $phone = trim($_POST['phone']); + $address = trim($_POST['address']); + + if (empty($hospital_name) || empty($email) || empty($password)) { + $message = '
Please fill in all required fields.
'; + } else { + try { + $pdo = db(); + // Check if email already exists + $stmt = $pdo->prepare("SELECT id FROM hospitals WHERE email = ?"); + $stmt->execute([$email]); + if ($stmt->fetch()) { + $message = '
This email address is already registered.
'; + } else { + // Hash the password + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + + $sql = "INSERT INTO hospitals (hospital_name, email, password, phone, address) VALUES (?, ?, ?, ?, ?)"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$hospital_name, $email, $hashed_password, $phone, $address]); + $message = '
Hospital registered successfully! You will be able to log in once the admin verifies your account.
'; + } + } catch (PDOException $e) { + $message = '
Error: ' . $e->getMessage() . '
'; + } + } +} +?> + + + + + + Hospital Registration - Organ Donation Management System + + + + + + + +
+
+
+
+
+

Hospital Registration

+

Register your hospital to manage recipient information.

+
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + iv> +
+
+
+
+
+
+ + + + + + + diff --git a/index.php b/index.php index 7205f3d..3e59f96 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,91 @@ - - - - - - New Style - - - - - - - - - - - - - - - - - - - + + + + + + Organ Donation Management System + + + + + + + + -
-
-

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

+ +
- + + +
+
+

Give the Gift of Life

+

Join our community of organ donors and help save lives. Your decision can make a world of difference.

+ Register as a Donor Today +
+
+ +
+
+

How It Works

+
+
+ +

Register

+

Quickly sign up as a donor through our simple registration form.

+
+
+ +

Verification

+

Our team verifies your information to ensure validity and eligibility.

+
+
+ +

Save a Life

+

Once matched, you will be contacted to begin the life-saving process.

+
+
+
+
+ + + + +