124 lines
5.7 KiB
PHP
124 lines
5.7 KiB
PHP
<?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">© <?= 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>
|