| Server IP : 173.209.174.21 / Your IP : 216.73.216.89 Web Server : Apache/2.4.58 (Ubuntu) System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : nodor ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/wcsd/School-alert/Backup files/ |
Upload File : |
<?php
session_start();
require 'config/db.php';
// Enable error reporting for debugging
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Check if the user is logged in; if not, redirect to login page
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit();
}
// Fetch all schools
$stmt = $pdo->prepare("SELECT * FROM schools ORDER BY name ASC");
$stmt->execute();
$schools = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Prepare active and resolved alerts for each school
$alerts_by_school = [];
foreach ($schools as $school) {
// Initialize empty arrays to avoid undefined index notices
$alerts_by_school[$school['school_id']]['active'] = [];
$alerts_by_school[$school['school_id']]['resolved'] = [];
$alerts_by_school[$school['school_id']]['school_name'] = $school['name'];
// Active alerts for this school
$stmt = $pdo->prepare("SELECT * FROM alerts WHERE school_id = ? AND status = 'active' ORDER BY timestamp DESC");
$stmt->execute([$school['school_id']]);
$alerts_by_school[$school['school_id']]['active'] = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Resolved alerts for this school
$stmt = $pdo->prepare("SELECT * FROM alerts WHERE school_id = ? AND status = 'resolved' ORDER BY timestamp DESC");
$stmt->execute([$school['school_id']]);
$alerts_by_school[$school['school_id']]['resolved'] = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
?>
<?php include __DIR__ . '/views/header.php'; ?>
<h2>Dashboard</h2>
<div class="dashboard-columns">
<!-- Active Alerts Column -->
<div class="column active-alerts">
<h3>Active Alerts</h3>
<?php foreach ($alerts_by_school as $school_id => $school_data): ?>
<h4><?= htmlspecialchars($school_data['school_name']) ?></h4>
<?php if (empty($school_data['active'])): ?>
<p>No active alerts for this school.</p>
<?php else: ?>
<?php foreach ($school_data['active'] as $alert): ?>
<div class="alert blinking-alert">
<h4>Alert Type: <?= htmlspecialchars($alert['type']) ?></h4>
<p>Message: <?= htmlspecialchars($alert['message']) ?></p>
<p><small>Timestamp: <?= $alert['timestamp'] ?></small></p>
<form action="acknowledge.php" method="POST">
<input type="hidden" name="alert_id" value="<?= $alert['alert_id'] ?>">
<button type="submit">Acknowledge</button>
</form>
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
</div>
<!-- Old Events Column -->
<div class="column old-alerts">
<h3>Old Events</h3>
<?php foreach ($alerts_by_school as $school_id => $school_data): ?>
<h4><?= htmlspecialchars($school_data['school_name']) ?></h4>
<?php if (empty($school_data['resolved'])): ?>
<p>No old events for this school.</p>
<?php else: ?>
<?php foreach ($school_data['resolved'] as $alert): ?>
<div class="alert old-alert">
<h4>Alert Type: <?= htmlspecialchars($alert['type']) ?></h4>
<p>Message: <?= htmlspecialchars($alert['message']) ?></p>
<p><small>Timestamp: <?= $alert['timestamp'] ?></small></p>
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
</div>
</div>
<?php include __DIR__ . '/views/footer.php'; ?>