35311-vm/calendar.php
2025-10-30 00:25:31 +00:00

123 lines
5.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
session_start();
require_once 'db/config.php';
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'resident') {
header("Location: index.php");
exit;
}
$pdo = db();
// Fetch the logged-in resident's id
$stmt = $pdo->prepare("SELECT id FROM residents WHERE user_id = ?");
$stmt->execute([$_SESSION['user_id']]);
$resident = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$resident) {
// Handle case where resident profile is not found
die("Resident profile not found.");
}
$resident_id = $resident['id'];
// Basic Calendar Logic
$month = isset($_GET['month']) ? (int)$_GET['month'] : date('m');
$year = isset($_GET['year']) ? (int)$_GET['year'] : date('Y');
$today = date('Y-m-d');
$first_day_of_month = mktime(0, 0, 0, $month, 1, $year);
$days_in_month = date('t', $first_day_of_month);
$day_of_week = date('w', $first_day_of_month);
// Fetch appointments for the month
$stmt = $pdo->prepare("SELECT * FROM appointments WHERE resident_id = ? AND MONTH(start_time) = ? AND YEAR(start_time) = ? ORDER BY start_time");
$stmt->execute([$resident_id, $month, $year]);
$appointments = [];
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$day = date('j', strtotime($row['start_time']));
$appointments[$day][] = $row;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Appointment Calendar - 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">
<style>
.calendar-day { min-height: 120px; }
.calendar-day-np { background-color: #f5f5f5; }
.appointment { font-size: 0.8em; padding: 2px 5px; margin-bottom: 3px; border-radius: 3px; background-color: #e3f2fd; border-left: 3px solid #2196F3; }
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="resident_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="resident_dashboard.php">Dashboard</a></li>
<li class="nav-item"><a class="nav-link" href="messages.php">Messages</a></li>
<li class="nav-item"><a class="nav-link" href="resources.php">Resource Library</a></li>
<li class="nav-item"><a class="nav-link active" href="calendar.php">Calendar</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">Appointment Calendar</h1>
<div>
<a href="?month=<?php echo date('m', strtotime('-1 month', $first_day_of_month)); ?>&year=<?php echo date('Y', strtotime('-1 month', $first_day_of_month)); ?>" class="btn btn-sm btn-outline-secondary"> Prev</a>
<span class="mx-2 h4"><?php echo date('F Y', $first_day_of_month); ?></span>
<a href="?month=<?php echo date('m', strtotime('+1 month', $first_day_of_month)); ?>&year=<?php echo date('Y', strtotime('+1 month', $first_day_of_month)); ?>" class="btn btn-sm btn-outline-secondary">Next </a>
</div>
</div>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr class="text-center">
<th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th>
</tr>
</thead>
<tbody>
<tr>
<?php for ($i = 0; $i < $day_of_week; $i++): ?>
<td class="calendar-day-np"></td>
<?php endfor; ?>
<?php for ($day = 1; $day <= $days_in_month; $day++): ?>
<?php if ($day_of_week == 7): ?>
</tr><tr>
<?php $day_of_week = 0; ?>
<?php endif; ?>
<td class="calendar-day <?php echo date('Y-m-d', mktime(0,0,0,$month,$day,$year)) == $today ? 'table-primary' : ''; ?>">
<strong><?php echo $day; ?></strong>
<?php if (isset($appointments[$day])): ?>
<?php foreach ($appointments[$day] as $appointment): ?>
<div class="appointment" title="<?php echo htmlspecialchars($appointment['description']); ?>">
<?php echo date('g:ia', strtotime($appointment['start_time'])); ?> - <?php echo htmlspecialchars($appointment['title']); ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
</td>
<?php $day_of_week++; ?>
<?php endfor; ?>
<?php for ($i = $day_of_week; $i < 7; $i++): ?>
<td class="calendar-day-np"></td>
<?php endfor; ?>
</tr>
</tbody>
</table>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>