34981-vm/hospital-registration.php
Flatlogic Bot e59c8581a5 1.0.1
2025-10-15 18:48:09 +00:00

238 lines
12 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
$success_message = '';
$error_message = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
try {
$pdo = db();
// Create table if it doesn't exist
$pdo->exec("CREATE TABLE IF NOT EXISTS hospitals (
id INT AUTO_INCREMENT PRIMARY KEY,
hospital_name VARCHAR(255) NOT NULL,
address VARCHAR(255),
contact_person VARCHAR(255),
contact_email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
specialties TEXT,
accreditation_path VARCHAR(255),
billing_details TEXT,
subscription_plan VARCHAR(50),
logo_path VARCHAR(255),
gallery_paths TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)");
// File upload handling
$upload_dir = 'uploads/hospitals/';
$accreditation_path = null;
if (isset($_FILES['accreditation']) && $_FILES['accreditation']['error'] == UPLOAD_ERR_OK) {
$file_name = uniqid() . '-accreditation-' . basename($_FILES['accreditation']['name']);
$accreditation_path = $upload_dir . $file_name;
if (!move_uploaded_file($_FILES['accreditation']['tmp_name'], $accreditation_path)) {
throw new Exception("Failed to upload accreditation file.");
}
}
$logo_path = null;
if (isset($_FILES['logo']) && $_FILES['logo']['error'] == UPLOAD_ERR_OK) {
$file_name = uniqid() . '-logo-' . basename($_FILES['logo']['name']);
$logo_path = $upload_dir . $file_name;
if (!move_uploaded_file($_FILES['logo']['tmp_name'], $logo_path)) {
throw new Exception("Failed to upload logo file.");
}
}
$gallery_paths = [];
if (isset($_FILES['gallery']['name']) && is_array($_FILES['gallery']['name'])) {
foreach ($_FILES['gallery']['tmp_name'] as $key => $tmp_name) {
if ($_FILES['gallery']['error'][$key] == UPLOAD_ERR_OK) {
$file_name = uniqid() . '-gallery-' . basename($_FILES['gallery']['name'][$key]);
$gallery_path = $upload_dir . $file_name;
if (move_uploaded_file($tmp_name, $gallery_path)) {
$gallery_paths[] = $gallery_path;
}
}
}
}
$gallery_paths_json = json_encode($gallery_paths);
// Hash password
$password_hash = password_hash($_POST['password'], PASSWORD_DEFAULT);
// Insert data
$stmt = $pdo->prepare(
"INSERT INTO hospitals (hospital_name, address, contact_person, contact_email, password, specialties, accreditation_path, billing_details, subscription_plan, logo_path, gallery_paths)
VALUES (:hospital_name, :address, :contact_person, :contact_email, :password, :specialties, :accreditation_path, :billing_details, :subscription_plan, :logo_path, :gallery_paths)"
);
$stmt->bindParam(':hospital_name', $_POST['hospitalName']);
$stmt->bindParam(':address', $_POST['address']);
$stmt->bindParam(':contact_person', $_POST['contactPerson']);
$stmt->bindParam(':contact_email', $_POST['contactEmail']);
$stmt->bindParam(':password', $password_hash);
$stmt->bindParam(':specialties', $_POST['specialties']);
$stmt->bindParam(':accreditation_path', $accreditation_path);
$stmt->bindParam(':billing_details', $_POST['billingDetails']);
$stmt->bindParam(':subscription_plan', $_POST['subscriptionPlan']);
$stmt->bindParam(':logo_path', $logo_path);
$stmt->bindParam(':gallery_paths', $gallery_paths_json);
$stmt->execute();
$success_message = "Registration successful! Your hospital profile will be reviewed shortly.";
} catch (PDOException $e) {
if ($e->getCode() == 23000) { // Integrity constraint violation (duplicate entry)
$error_message = "An account with this email address already exists.";
} else {
$error_message = "Database error: " . $e->getMessage();
}
} catch (Exception $e) {
$error_message = "An error occurred: " . $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 - Medicaltour</title>
<meta name="description" content="Hospital registration for Medicaltour.">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<style>
body {
padding-top: 5rem;
}
</style>
</head>
<body>
<header>
<nav class="navbar navbar-expand-lg fixed-top">
<div class="container">
<a class="navbar-brand" href="index.php">Medicaltour</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="index.php#hero">Home</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#about">About</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#portfolio">Services</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#testimonials">Testimonials</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#contact">Contact</a></li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Register
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="patient-registration.php">Patient</a></li>
<li><a class="dropdown-item" href="doctor-registration.php">Doctor</a></li>
<li><a class="dropdown-item" href="hospital-registration.php">Hospital</a></li>
</ul>
</li>
<li class="nav-item"><a class="nav-link" href="login.php">Login</a></li>
</ul>
</div>
</div>
</nav>
</header>
<main class="container my-5">
<div class="row">
<div class="col-md-8 mx-auto">
<h2 class="text-center mb-4">Hospital Registration</h2>
<?php if ($success_message): ?>
<div class="alert alert-success"><?php echo $success_message; ?></div>
<?php endif; ?>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?php echo $error_message; ?></div>
<?php endif; ?>
<?php if (!$success_message): ?>
<p class="text-center mb-4">Register your hospital to be part of our exclusive network.</p>
<form action="hospital-registration.php" method="post" enctype="multipart/form-data">
<div class="mb-3">
<label for="hospitalName" class="form-label">Hospital Name</label>
<input type="text" class="form-control" id="hospitalName" name="hospitalName" required>
</div>
<div class="mb-3">
<label for="address" class="form-label">Address</label>
<input type="text" class="form-control" id="address" name="address" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="contactPerson" class="form-label">Contact Person</label>
<input type="text" class="form-control" id="contactPerson" name="contactPerson" required>
</div>
<div class="col-md-6 mb-3">
<label for="contactEmail" class="form-label">Contact Email</label>
<input type="email" class="form-control" id="contactEmail" name="contactEmail" required>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="col-md-6 mb-3">
<label for="specialties" class="form-label">Specialties</label>
<input type="text" class="form-control" id="specialties" name="specialties" placeholder="e.g., Cardiology, Neurology">
</div>
</div>
<div class="mb-3">
<label for="accreditation" class="form-label">Accreditation/License Upload</label>
<input class="form-control" type="file" id="accreditation" name="accreditation">
</div>
<div class="mb-3">
<label for="billingDetails" class="form-label">Bank/Billing Details</label>
<textarea class="form-control" id="billingDetails" name="billingDetails" rows="3"></textarea>
</div>
<div class="mb-3">
<label for="subscriptionPlan" class="form-label">Subscription Plan</label>
<select class="form-select" id="subscriptionPlan" name="subscriptionPlan">
<option selected>Choose a plan...</option>
<option value="basic">Basic</option>
<option value="premium">Premium</option>
<option value="enterprise">Enterprise</option>
</select>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="logo" class="form-label">Logo Upload</label>
<input class="form-control" type="file" id="logo" name="logo">
</div>
<div class="col-md-6 mb-3">
<label for="gallery" class="form-label">Image Gallery</label>
<input class="form-control" type="file" id="gallery" name="gallery[]" multiple>
</div>
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary">Register Hospital</button>
</div>
</form>
<?php endif; ?>
</div>
</div>
</main>
<footer class="py-4 bg-dark text-white text-center">
<div class="container">
<p>&copy; 2025 Medicaltour. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>