230 lines
11 KiB
PHP
230 lines
11 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
session_start();
|
|
|
|
// Auth Check - everyone logged in can see events
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$db = db();
|
|
$school_id = $_SESSION['school_id'];
|
|
$user_id = $_SESSION['user_id'];
|
|
$user_role = $_SESSION['role'];
|
|
$message = '';
|
|
$pageTitle = 'School Events | SOMS';
|
|
|
|
// Handle Event Creation
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['create_event'])) {
|
|
if (in_array($user_role, ['Admin', 'Teacher', 'Super Admin'])) {
|
|
$title = $_POST['title'] ?? '';
|
|
$description = $_POST['description'] ?? '';
|
|
$event_type = $_POST['event_type'] ?? 'Meeting';
|
|
$start_datetime = $_POST['start_datetime'] ?? '';
|
|
$end_datetime = $_POST['end_datetime'] ?? '';
|
|
$location = $_POST['location'] ?? '';
|
|
|
|
if ($title && $start_datetime && $end_datetime) {
|
|
try {
|
|
$stmt = $db->prepare("INSERT INTO events (title, description, event_type, start_datetime, end_datetime, location, created_by, school_id)
|
|
VALUES (:title, :description, :event_type, :start_datetime, :end_datetime, :location, :created_by, :school_id)");
|
|
$stmt->execute([
|
|
'title' => $title,
|
|
'description' => $description,
|
|
'event_type' => $event_type,
|
|
'start_datetime' => $start_datetime,
|
|
'end_datetime' => $end_datetime,
|
|
'location' => $location,
|
|
'created_by' => $user_id,
|
|
'school_id' => $school_id
|
|
]);
|
|
$message = "Event created successfully!";
|
|
} catch (Exception $e) {
|
|
$message = "Error: " . $e->getMessage();
|
|
}
|
|
} else {
|
|
$message = "Please fill in all required fields.";
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fetch Upcoming Events
|
|
$stmt = $db->prepare("SELECT e.*, u.email as creator_email
|
|
FROM events e
|
|
JOIN users u ON e.created_by = u.id
|
|
WHERE e.school_id = :school_id AND e.end_datetime >= NOW()
|
|
ORDER BY e.start_datetime ASC");
|
|
$stmt->execute(['school_id' => $school_id]);
|
|
$upcoming_events = $stmt->fetchAll();
|
|
|
|
// Fetch Past Events
|
|
$stmt = $db->prepare("SELECT e.*, u.email as creator_email
|
|
FROM events e
|
|
JOIN users u ON e.created_by = u.id
|
|
WHERE e.school_id = :school_id AND e.end_datetime < NOW()
|
|
ORDER BY e.start_datetime DESC LIMIT 10");
|
|
$stmt->execute(['school_id' => $school_id]);
|
|
$past_events = $stmt->fetchAll();
|
|
|
|
include 'includes/header.php';
|
|
?>
|
|
|
|
<div class="container pb-5">
|
|
<div class="row mb-4">
|
|
<div class="col-md-8">
|
|
<h2 class="h4 mb-1">School Events & Scheduling</h2>
|
|
<p class="text-muted small">Stay updated with meetings, conferences, and school holidays.</p>
|
|
</div>
|
|
<?php if (in_array($user_role, ['Admin', 'Teacher', 'Super Admin'])): ?>
|
|
<div class="col-md-4 text-md-end">
|
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addEventModal">
|
|
<i class="bi bi-calendar-plus me-2"></i>Schedule Event
|
|
</button>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php if ($message): ?>
|
|
<div class="alert alert-info alert-dismissible fade show" role="alert">
|
|
<?= htmlspecialchars($message) ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="row">
|
|
<!-- Upcoming Events -->
|
|
<div class="col-lg-8">
|
|
<div class="card shadow-sm border-0 mb-4">
|
|
<div class="card-header bg-white py-3">
|
|
<h5 class="mb-0">Upcoming Events</h5>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<?php if (empty($upcoming_events)): ?>
|
|
<div class="p-5 text-center text-muted">
|
|
<i class="bi bi-calendar-event display-4 mb-3 d-block"></i>
|
|
<p>No upcoming events scheduled.</p>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="list-group list-group-flush">
|
|
<?php foreach ($upcoming_events as $event): ?>
|
|
<div class="list-group-item p-4">
|
|
<div class="d-flex w-100 justify-content-between align-items-start mb-2">
|
|
<div>
|
|
<span class="badge bg-soft-primary text-primary mb-2"><?= htmlspecialchars($event['event_type']) ?></span>
|
|
<h5 class="mb-1"><?= htmlspecialchars($event['title']) ?></h5>
|
|
</div>
|
|
<small class="text-muted">
|
|
<?= date('D, d M Y', strtotime($event['start_datetime'])) ?>
|
|
</small>
|
|
</div>
|
|
<p class="mb-2 text-muted"><?= nl2br(htmlspecialchars($event['description'])) ?></p>
|
|
<div class="d-flex align-items-center small text-muted">
|
|
<span class="me-3"><i class="bi bi-clock me-1"></i> <?= date('H:i', strtotime($event['start_datetime'])) ?> - <?= date('H:i', strtotime($event['end_datetime'])) ?></span>
|
|
<?php if ($event['location']): ?>
|
|
<span class="me-3"><i class="bi bi-geo-alt me-1"></i> <?= htmlspecialchars($event['location']) ?></span>
|
|
<?php endif; ?>
|
|
<span><i class="bi bi-person me-1"></i> <?= htmlspecialchars($event['creator_email']) ?></span>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Past Events / Sidebar -->
|
|
<div class="col-lg-4">
|
|
<div class="card shadow-sm border-0 mb-4">
|
|
<div class="card-header bg-white py-3">
|
|
<h5 class="mb-0">Recently Concluded</h5>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<?php if (empty($past_events)): ?>
|
|
<div class="p-4 text-center text-muted small">
|
|
No past events found.
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="list-group list-group-flush small">
|
|
<?php foreach ($past_events as $event): ?>
|
|
<div class="list-group-item border-0 border-bottom">
|
|
<div class="fw-bold"><?= htmlspecialchars($event['title']) ?></div>
|
|
<div class="text-muted"><?= date('d M Y', strtotime($event['start_datetime'])) ?></div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card bg-primary text-white shadow-sm border-0">
|
|
<div class="card-body">
|
|
<h6>Need a Private Meeting?</h6>
|
|
<p class="small mb-0">Parents can request specific slots for parent-teacher conferences via the direct message system in the Hub.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Add Event Modal -->
|
|
<div class="modal fade" id="addEventModal" tabindex="-1" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<form method="POST">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Schedule New Event</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div class="mb-3">
|
|
<label class="form-label">Event Title *</label>
|
|
<input type="text" name="title" class="form-control" required placeholder="e.g. Parent-Teacher Conference">
|
|
</div>
|
|
<div class="row mb-3">
|
|
<div class="col-md-6">
|
|
<label class="form-label">Event Type</label>
|
|
<select name="event_type" class="form-select">
|
|
<option value="Meeting">Meeting</option>
|
|
<option value="Conference">Conference</option>
|
|
<option value="Workshop">Workshop</option>
|
|
<option value="Holiday">Holiday</option>
|
|
<option value="Other">Other</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label">Location</label>
|
|
<input type="text" name="location" class="form-control" placeholder="e.g. Room 102 / Zoom">
|
|
</div>
|
|
</div>
|
|
<div class="row mb-3">
|
|
<div class="col-md-6">
|
|
<label class="form-label">Start Date & Time *</label>
|
|
<input type="datetime-local" name="start_datetime" class="form-control" required>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label">End Date & Time *</label>
|
|
<input type="datetime-local" name="end_datetime" class="form-control" required>
|
|
</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Description</label>
|
|
<textarea name="description" class="form-control" rows="3" placeholder="Additional details about the event..."></textarea>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
|
<button type="submit" name="create_event" class="btn btn-primary">Create Event</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<style>
|
|
.bg-soft-primary { background-color: rgba(13, 110, 253, 0.1); }
|
|
</style>
|
|
|
|
<?php include 'includes/footer.php'; ?>
|