170 lines
8.3 KiB
PHP
170 lines
8.3 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
$pdo = db();
|
|
|
|
// Create hospitals table if it doesn't exist
|
|
try {
|
|
$sql = "
|
|
CREATE TABLE IF NOT EXISTS hospitals (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(255) NOT NULL,
|
|
license_number VARCHAR(255) NOT NULL,
|
|
address TEXT NOT NULL,
|
|
phone VARCHAR(20) NOT NULL,
|
|
email VARCHAR(255) NOT NULL UNIQUE,
|
|
password_hash VARCHAR(255) NOT NULL,
|
|
has_transplant_capability BOOLEAN NOT NULL DEFAULT 0,
|
|
status VARCHAR(50) DEFAULT 'Pending Verification',
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
)";
|
|
$pdo->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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Hospital Registration - Organ Donation</title>
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
<style>
|
|
body {
|
|
font-family: 'Poppins', sans-serif;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body class="bg-gray-100">
|
|
|
|
<nav class="bg-white shadow-md">
|
|
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
|
<div class="flex justify-between h-16">
|
|
<div class="flex">
|
|
<a href="index.php" class="flex-shrink-0 flex items-center">
|
|
<span class="font-bold text-xl text-blue-600">OrganConnect</span>
|
|
</a>
|
|
</div>
|
|
<div class="flex items-center">
|
|
<a href="index.php" class="px-3 py-2 rounded-md text-sm font-medium text-gray-700 hover:bg-gray-200">Home</a>
|
|
<a href="donor_registration.php" class="px-3 py-2 rounded-md text-sm font-medium text-gray-700 hover:bg-gray-200">Become a Donor</a>
|
|
<a href="hospital_registration.php" class="px-3 py-2 rounded-md text-sm font-medium text-blue-600 bg-blue-100">Hospital Portal</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container mx-auto px-4 py-12">
|
|
<div class="max-w-2xl mx-auto bg-white p-8 rounded-lg shadow-lg">
|
|
<h1 class="text-3xl font-bold text-center text-gray-800 mb-6">Hospital Registration</h1>
|
|
|
|
<?php if ($message): ?>
|
|
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative mb-4" role="alert">
|
|
<span class="block sm:inline"><?php echo htmlspecialchars($message); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if ($error): ?>
|
|
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4" role="alert">
|
|
<span class="block sm:inline"><?php echo htmlspecialchars($error); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!$message): ?>
|
|
<form action="hospital_registration.php" method="POST" class="space-y-6">
|
|
<div>
|
|
<label for="name" class="block text-sm font-medium text-gray-700">Hospital Name</label>
|
|
<input type="text" name="name" id="name" required class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm">
|
|
</div>
|
|
<div>
|
|
<label for="license_number" class="block text-sm font-medium text-gray-700">Official License Number</label>
|
|
<input type="text" name="license_number" id="license_number" required class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm">
|
|
</div>
|
|
<div>
|
|
<label for="address" class="block text-sm font-medium text-gray-700">Full Address</label>
|
|
<textarea name="address" id="address" rows="3" required class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"></textarea>
|
|
</div>
|
|
<div>
|
|
<label for="phone" class="block text-sm font-medium text-gray-700">Contact Phone</label>
|
|
<input type="tel" name="phone" id="phone" required class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm">
|
|
</div>
|
|
<div>
|
|
<label for="email" class="block text-sm font-medium text-gray-700">Contact Email</label>
|
|
<input type="email" name="email" id="email" required class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm">
|
|
</div>
|
|
<div>
|
|
<label for="password" class="block text-sm font-medium text-gray-700">Create Password</label>
|
|
<input type="password" name="password" id="password" required class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm">
|
|
</div>
|
|
<div class="flex items-start">
|
|
<div class="flex items-center h-5">
|
|
<input id="has_transplant_capability" name="has_transplant_capability" type="checkbox" value="1" class="focus:ring-blue-500 h-4 w-4 text-blue-600 border-gray-300 rounded">
|
|
</div>
|
|
<div class="ml-3 text-sm">
|
|
<label for="has_transplant_capability" class="font-medium text-gray-700">Our facility has transplant capabilities</label>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<button type="submit" class="w-full flex justify-center py-3 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
|
|
Register Hospital
|
|
</button>
|
|
</div>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<footer class="bg-white">
|
|
<div class="max-w-7xl mx-auto py-4 px-4 sm:px-6 lg:px-8">
|
|
<div class="flex justify-between items-center">
|
|
<p class="text-center text-gray-500 text-sm">© <?php echo date("Y"); ?> OrganConnect. All rights reserved.</p>
|
|
<a href="admin/" class="text-sm text-gray-500 hover:text-gray-700">Admin Login</a>
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
|
|
</body>
|
|
</html>
|