130 lines
5.8 KiB
PHP
130 lines
5.8 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// Check if user is logged in and has the 'staff' role
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'staff') {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
$error_message = '';
|
|
$success_message = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
// Basic validation
|
|
if (empty($_POST['first_name']) || empty($_POST['last_name']) || empty($_POST['email'])) {
|
|
$error_message = 'Please fill in all required fields.';
|
|
} else {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("INSERT INTO residents (first_name, last_name, email, phone_number, date_of_birth, program, status) VALUES (?, ?, ?, ?, ?, ?, ?)");
|
|
$stmt->execute([
|
|
$_POST['first_name'],
|
|
$_POST['last_name'],
|
|
$_POST['email'],
|
|
$_POST['phone_number'] ?? null,
|
|
$_POST['date_of_birth'] ?? null,
|
|
$_POST['program'] ?? 'General Support',
|
|
$_POST['status'] ?? 'Active'
|
|
]);
|
|
$success_message = "Resident '" . htmlspecialchars($_POST['first_name']) . " " . htmlspecialchars($_POST['last_name']) . "' has been successfully added.";
|
|
} catch (PDOException $e) {
|
|
$error_message = 'Database error: Could not add resident. ' . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>New Resident Intake - Continuum of Healing</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
|
<div class="container-fluid">
|
|
<a class="navbar-brand" href="staff_dashboard.php">Continuum of Healing</a>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="staff_dashboard.php">Dashboard</a>
|
|
</li>
|
|
</ul>
|
|
<a href="logout.php" class="btn btn-outline-light">Logout</a>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container mt-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="h2">New Resident Intake Form</h1>
|
|
<a href="staff_dashboard.php" class="btn btn-secondary">← Back to Dashboard</a>
|
|
</div>
|
|
|
|
<?php if ($error_message): ?>
|
|
<div class="alert alert-danger"><?php echo $error_message; ?></div>
|
|
<?php endif; ?>
|
|
<?php if ($success_message): ?>
|
|
<div class="alert alert-success"><?php echo $success_message; ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<form method="POST" action="resident_intake.php">
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="first_name" class="form-label">First Name</label>
|
|
<input type="text" class="form-control" id="first_name" name="first_name" required>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label for="last_name" class="form-label">Last Name</label>
|
|
<input type="text" class="form-control" id="last_name" name="last_name" required>
|
|
</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label">Email</label>
|
|
<input type="email" class="form-control" id="email" name="email" required>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="phone_number" class="form-label">Phone Number</label>
|
|
<input type="tel" class="form-control" id="phone_number" name="phone_number">
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label for="date_of_birth" class="form-label">Date of Birth</label>
|
|
<input type="date" class="form-control" id="date_of_birth" name="date_of_birth">
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="program" class="form-label">Program</label>
|
|
<select class="form-select" id="program" name="program">
|
|
<option>General Support</option>
|
|
<option>Transitional Housing</option>
|
|
<option>Outreach</option>
|
|
<option>Aftercare</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label for="status" class="form-label">Status</label>
|
|
<select class="form-select" id="status" name="status">
|
|
<option>Active</option>
|
|
<option>Inactive</option>
|
|
<option>Pending</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary-custom">Add Resident</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|