diff --git a/admin/donors.php b/admin/donors.php new file mode 100644 index 0000000..6704a54 --- /dev/null +++ b/admin/donors.php @@ -0,0 +1,76 @@ +query("SELECT id, name, age, blood_type, status, created_at FROM donors ORDER BY created_at DESC"); + $donors = $stmt->fetchAll(PDO::FETCH_ASSOC); +} catch (PDOException $e) { + // In a real app, you'd log this error and show a user-friendly message. + die("Error: Could not fetch donors. " . $e->getMessage()); +} +?> + +
+
+

Donor Registrations

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDNameAgeBlood TypeStatusRegistered AtActions
No donor registrations found.
+ + + + + +
+ + + +
+
+ + + +
+ + N/A + +
+
+
+ + diff --git a/admin/hospitals.php b/admin/hospitals.php new file mode 100644 index 0000000..051406f --- /dev/null +++ b/admin/hospitals.php @@ -0,0 +1,85 @@ +query("SELECT id, name, license_number, email, has_transplant_capability, status, created_at FROM hospitals ORDER BY created_at DESC"); + $hospitals = $stmt->fetchAll(PDO::FETCH_ASSOC); +} catch (PDOException $e) { + die("Error: Could not fetch hospitals. " . $e->getMessage()); +} +?> + +
+
+

Hospital Registrations

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDNameLicense NumberEmailTransplant ReadyStatusRegistered AtActions
No hospital registrations found.
+ 'bg-warning text-dark', + 'Verified' => 'bg-success', + 'Rejected' => 'bg-danger', + ]; + $class = $status_classes[$hospital['status']] ?? 'bg-secondary'; + ?> + + + + + +
+ + + +
+
+ + + +
+ + N/A + +
+
+
+ + diff --git a/admin/index.php b/admin/index.php new file mode 100644 index 0000000..2df35e2 --- /dev/null +++ b/admin/index.php @@ -0,0 +1,66 @@ +prepare("SELECT COUNT(*) FROM donors WHERE status = 'Pending'"); + $stmt_donors->execute(); + $pending_donors_count = $stmt_donors->fetchColumn(); + + // Fetch count of pending hospitals + $stmt_hospitals = $pdo->prepare("SELECT COUNT(*) FROM hospitals WHERE status = 'Pending Verification'"); + $stmt_hospitals->execute(); + $pending_hospitals_count = $stmt_hospitals->fetchColumn(); + +} catch (PDOException $e) { + // Handle database errors + $pending_donors_count = 0; + $pending_hospitals_count = 0; + // Optionally log the error + error_log("Admin dashboard DB error: " . $e->getMessage()); +} +?> + +
+

Admin Dashboard

+

Welcome to the administration area. From here you can manage donors, hospitals, and system settings.

+ +
+
+
+
+
Donors
+

Manage and verify donor registrations.

+ 0): ?> + + Manage Donors Pending + + + Manage Donors + +
+
+
+
+
+
+
Hospitals
+

Manage and verify hospital registrations.

+ 0): ?> + + Manage Hospitals Pending + + + Manage Hospitals + +
+
+
+
+
+ + diff --git a/admin/login.php b/admin/login.php new file mode 100644 index 0000000..56b6cff --- /dev/null +++ b/admin/login.php @@ -0,0 +1,83 @@ +prepare("SELECT * FROM admin WHERE username = ?"); + $stmt->execute([$username]); + $admin = $stmt->fetch(); + + if ($admin && password_verify($password, $admin['password_hash'])) { + $_SESSION['admin_logged_in'] = true; + $_SESSION['admin_username'] = $admin['username']; + header("Location: index.php"); + exit; + } else { + $error = "Invalid username or password."; + } + } catch (PDOException $e) { + $error = "Database error: " . $e->getMessage(); + } + } +} + +$pageTitle = "Admin Login"; +?> + + + + + + + <?php echo htmlspecialchars($pageTitle); ?> - Organ Donation + + + +
+
+
+
+
+

Admin Login

+
+
+ +
+ +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/admin/logout.php b/admin/logout.php new file mode 100644 index 0000000..2d2c92f --- /dev/null +++ b/admin/logout.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/admin/partials/footer.php b/admin/partials/footer.php new file mode 100644 index 0000000..6793355 --- /dev/null +++ b/admin/partials/footer.php @@ -0,0 +1,10 @@ + + + + + + diff --git a/admin/partials/header.php b/admin/partials/header.php new file mode 100644 index 0000000..c4ae229 --- /dev/null +++ b/admin/partials/header.php @@ -0,0 +1,48 @@ + + + + + + + <?php echo isset($pageTitle) ? htmlspecialchars($pageTitle) : "Admin"; ?> - Organ Donation + + + + + + diff --git a/admin/update_donor_status.php b/admin/update_donor_status.php new file mode 100644 index 0000000..a648629 --- /dev/null +++ b/admin/update_donor_status.php @@ -0,0 +1,23 @@ +prepare("UPDATE donors SET status = :status WHERE id = :id"); + $stmt->execute(['status' => $newStatus, 'id' => $donorId]); + } catch (PDOException $e) { + // In a real app, log this and handle it more gracefully. + die("Database error: " . $e->getMessage()); + } + } +} + +// Redirect back to the donors list +header("Location: donors.php"); +exit; +?> diff --git a/admin/update_hospital_status.php b/admin/update_hospital_status.php new file mode 100644 index 0000000..7729adf --- /dev/null +++ b/admin/update_hospital_status.php @@ -0,0 +1,26 @@ +prepare("UPDATE hospitals SET status = :status WHERE id = :id"); + $stmt->execute(['status' => $newStatus, 'id' => $hospitalId]); + } catch (PDOException $e) { + // In a real app, log this and handle it more gracefully. + die("Database error: " . $e->getMessage()); + } + } +} + +// Redirect back to the hospitals list +header("Location: hospitals.php"); +exit; +?> diff --git a/api/pexels.php b/api/pexels.php new file mode 100644 index 0000000..781a7fe --- /dev/null +++ b/api/pexels.php @@ -0,0 +1,20 @@ +'Failed to fetch image']); exit; } + $photo = $data['photos'][0]; + $src = $photo['src']['large2x'] ?? ($photo['src']['large'] ?? $photo['src']['original']); + $target = __DIR__ . '/../assets/images/pexels/' . $photo['id'] . '.jpg'; + download_to($src, $target); + // Return minimal info and local relative path + echo json_encode([ + 'id' => $photo['id'], + 'local' => 'assets/images/pexels/' . $photo['id'] . '.jpg', + 'photographer' => $photo['photographer'] ?? null, + 'photographer_url' => $photo['photographer_url'] ?? null, + ]); + ?> \ No newline at end of file diff --git a/assets/images/pexels/3698024.jpg b/assets/images/pexels/3698024.jpg new file mode 100644 index 0000000..824aa1b Binary files /dev/null and b/assets/images/pexels/3698024.jpg differ diff --git a/assets/images/pexels/4047073.jpg b/assets/images/pexels/4047073.jpg new file mode 100644 index 0000000..45dc5bc Binary files /dev/null and b/assets/images/pexels/4047073.jpg differ diff --git a/donor_registration.php b/donor_registration.php new file mode 100644 index 0000000..01893aa --- /dev/null +++ b/donor_registration.php @@ -0,0 +1,208 @@ +exec(" + CREATE TABLE IF NOT EXISTS donors ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + age INT NOT NULL, + blood_type VARCHAR(3) NOT NULL, + weight_kg FLOAT NOT NULL, + phone VARCHAR(20) NOT NULL, + email VARCHAR(255) NOT NULL UNIQUE, + emergency_contact_name VARCHAR(255) NOT NULL, + emergency_contact_phone VARCHAR(20) NOT NULL, + status VARCHAR(20) DEFAULT 'Pending Verification', + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ) + "); + + // Validation + $required_fields = ['name', 'age', 'blood_type', 'weight_kg', 'phone', 'email', 'emergency_contact_name', 'emergency_contact_phone']; + foreach ($required_fields as $field) { + if (empty($_POST[$field])) { + throw new Exception("All fields are required."); + } + } + + if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { + throw new Exception("Invalid email format."); + } + + if ($_POST['age'] < 18 || $_POST['age'] > 75) { + throw new Exception("Age must be between 18 and 75."); + } + + // Insert data + $stmt = $pdo->prepare( + "INSERT INTO donors (name, age, blood_type, weight_kg, phone, email, emergency_contact_name, emergency_contact_phone) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" + ); + + $stmt->execute([ + $_POST['name'], + $_POST['age'], + $_POST['blood_type'], + $_POST['weight_kg'], + $_POST['phone'], + $_POST['email'], + $_POST['emergency_contact_name'], + $_POST['emergency_contact_phone'] + ]); + + $successMessage = "Thank you for registering! Your application is pending verification."; + + } catch (PDOException $e) { + if ($e->errorInfo[1] == 1062) { // Duplicate entry for email + $errorMessage = "This email address is already registered."; + } else { + $errorMessage = "Database error: " . $e->getMessage(); + } + } catch (Exception $e) { + $errorMessage = $e->getMessage(); + } +} +?> + + + + + + <?= htmlspecialchars($pageTitle) ?> - Organ Donation System + + + + + + + + + + +
+
+

Donor Registration

+

Complete the form below to become a registered organ donor.

+ + +
+ + +
+ + + +
+ + +
+ + + +
+
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+ +
+
Emergency Contact
+ +
+
+ + +
+
+ + +
+
+ +
+ +
+
+ +
+
+ + + + + + + diff --git a/hospital_dashboard.php b/hospital_dashboard.php new file mode 100644 index 0000000..e1a32e8 --- /dev/null +++ b/hospital_dashboard.php @@ -0,0 +1,103 @@ + + + + + + + + Hospital Dashboard - Organ Donation + + + + + + + + +
+

Hospital Dashboard

+ +
+
+

Recipient Management

+

Register new recipients and manage existing patient records.

+ Register a New Recipient → +
+
+

View Registered Recipients

+

View a list of all patients registered by your hospital.

+ View Recipients → +
+
+ + prepare("SELECT * FROM recipients WHERE hospital_id = ? ORDER BY created_at DESC"); + $stmt->execute([$_SESSION['hospital_id']]); + $recipients = $stmt->fetchAll(); + ?> +
+

Registered Recipients

+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Patient NameOrgan NeededBlood TypeRegistered On
No recipients registered yet.
+
+
+ +
+ + + diff --git a/hospital_login.php b/hospital_login.php new file mode 100644 index 0000000..d440404 --- /dev/null +++ b/hospital_login.php @@ -0,0 +1,107 @@ +prepare("SELECT * FROM hospitals WHERE email = ?"); + $stmt->execute([$email]); + $hospital = $stmt->fetch(); + + if ($hospital && password_verify($password, $hospital['password_hash'])) { + if ($hospital['status'] == 'Verified') { + $_SESSION['hospital_id'] = $hospital['id']; + $_SESSION['hospital_name'] = $hospital['name']; + header("Location: hospital_dashboard.php"); + exit; + } else { + $error = "Your hospital account is not yet verified."; + } + } else { + $error = "Invalid email or password."; + } + } +} +?> + + + + + + + Hospital Login - Organ Donation + + + + + + + + +
+
+

Hospital Login

+ + + + + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+ + + + + diff --git a/hospital_registration.php b/hospital_registration.php new file mode 100644 index 0000000..58cbda7 --- /dev/null +++ b/hospital_registration.php @@ -0,0 +1,169 @@ +exec($sql); +} catch (PDOException $e) { + die("Could not create table: " . $e->getMessage()); +} + +$message = ''; +$error = ''; + +if ($_SERVER["REQUEST_METHOD"] == "POST") { + // Collect and sanitize input + $name = trim($_POST['name']); + $license_number = trim($_POST['license_number']); + $address = trim($_POST['address']); + $phone = trim($_POST['phone']); + $email = trim($_POST['email']); + $password = $_POST['password']; + $has_transplant_capability = isset($_POST['has_transplant_capability']) ? 1 : 0; + + // Validation + if (empty($name) || empty($license_number) || empty($address) || empty($phone) || empty($email) || empty($password)) { + $error = "All fields except transplant capability are required."; + } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + $error = "Invalid email format."; + } else { + // Check if email already exists + $stmt = $pdo->prepare("SELECT id FROM hospitals WHERE email = ?"); + $stmt->execute([$email]); + if ($stmt->fetch()) { + $error = "This email address is already registered."; + } else { + // Hash password and insert data + $password_hash = password_hash($password, PASSWORD_DEFAULT); + $sql = "INSERT INTO hospitals (name, license_number, address, phone, email, password_hash, has_transplant_capability) VALUES (?, ?, ?, ?, ?, ?, ?)"; + $stmt = $pdo->prepare($sql); + + try { + $stmt->execute([$name, $license_number, $address, $phone, $email, $password_hash, $has_transplant_capability]); + $message = "Registration successful! Your application is pending verification from an administrator."; + } catch (PDOException $e) { + $error = "Error: " . $e->getMessage(); + } + } + } +} +?> + + + + + + + Hospital Registration - Organ Donation + + + + + + + + +
+
+

Hospital Registration

+ + + + + + + + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ + + + + diff --git a/includes/pexels.php b/includes/pexels.php new file mode 100644 index 0000000..c2b95ff --- /dev/null +++ b/includes/pexels.php @@ -0,0 +1,26 @@ + 0 ? $k : 'Vc99rnmOhHhJAbgGQoKLZtsaIVfkeownoQNbTj78VemUjKh08ZYRbf18'; + } + function pexels_get($url) { + $ch = curl_init(); + curl_setopt_array($ch, [ + CURLOPT_URL => $url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HTTPHEADER => [ 'Authorization: '. pexels_key() ], + CURLOPT_TIMEOUT => 15, + ]); + $resp = curl_exec($ch); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + if ($code >= 200 && $code < 300 && $resp) return json_decode($resp, true); + return null; + } + function download_to($srcUrl, $destPath) { + $data = file_get_contents($srcUrl); + if ($data === false) return false; + if (!is_dir(dirname($destPath))) mkdir(dirname($destPath), 0775, true); + return file_put_contents($destPath, $data) !== false; + } + ?> \ No newline at end of file diff --git a/index.php b/index.php index 7205f3d..dfa39d3 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,132 @@ - - + - - - 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

+ + +
+
+

A Gift of Life, A Legacy of Hope

+

Join our community to make a difference through organ donation.

+ Register as a Donor +
-
- + +
+
+
+
+

For Donors

+

Register as an organ donor and give the gift of life. Your selfless act can save up to eight lives.

+ Register Now +
+
+
+
+

For Hospitals

+

Register your hospital to connect with donors and manage organ requests seamlessly and efficiently.

+ Register Now +
+
+
+
+ + + + - + \ No newline at end of file diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..d074d9e --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ +exec($sql); +} catch (PDOException $e) { + die("Could not create table: " . $e->getMessage()); +} + +$message = ''; +$error = ''; + +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $patient_name = trim($_POST['patient_name']); + $patient_dob = trim($_POST['patient_dob']); + $blood_type = trim($_POST['blood_type']); + $organ_needed = trim($_POST['organ_needed']); + $urgency_level = trim($_POST['urgency_level']); + $contact_phone = trim($_POST['contact_phone']); + $contact_email = trim($_POST['contact_email']); + $hospital_id = $_SESSION['hospital_id']; + + if (empty($patient_name) || empty($patient_dob) || empty($blood_type) || empty($organ_needed) || empty($urgency_level) || empty($contact_phone) || empty($contact_email)) { + $error = "All fields are required."; + } else { + $sql = "INSERT INTO recipients (hospital_id, patient_name, patient_dob, blood_type, organ_needed, urgency_level, contact_phone, contact_email) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; + $stmt = $pdo->prepare($sql); + try { + $stmt->execute([$hospital_id, $patient_name, $patient_dob, $blood_type, $organ_needed, $urgency_level, $contact_phone, $contact_email]); + $message = "Recipient registered successfully!"; + } catch (PDOException $e) { + $error = "Error: " . $e->getMessage(); + } + } +} +?> + + + + + + + Recipient Registration - Organ Donation + + + + + + + + +
+
+

Register New Recipient

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