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/statistics.php
<?php
session_start();
require 'config/db.php';

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

if (!isset($_SESSION['user_id'])) {
    header('Location: login.php');
    exit();
}

// Set the default time period to 'month'
$time_period = $_GET['time_period'] ?? 'month';

// Fetch alert statistics grouped by type and time period
$time_condition = '';
if ($time_period == 'week') {
    $time_condition = "AND timestamp >= DATE_SUB(NOW(), INTERVAL 1 WEEK)";
} elseif ($time_period == 'month') {
    $time_condition = "AND timestamp >= DATE_SUB(NOW(), INTERVAL 1 MONTH)";
} elseif ($time_period == 'year') {
    $time_condition = "AND timestamp >= DATE_SUB(NOW(), INTERVAL 1 YEAR)";
}

$stmt = $pdo->prepare("
    SELECT type, COUNT(*) AS count
    FROM alerts
    WHERE 1=1 $time_condition
    GROUP BY type
");
$stmt->execute();
$alert_counts = $stmt->fetchAll(PDO::FETCH_ASSOC);

$alert_types = [];
$alert_counts_data = [];
foreach ($alert_counts as $alert) {
    $alert_types[] = $alert['type'];
    $alert_counts_data[] = $alert['count'];
}
?>

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

<!-- Time Period Form -->
<form method="GET" action="statistics.php">
    <label for="time_period">View Statistics By:</label>
    <select name="time_period" id="time_period" onchange="this.form.submit()">
        <option value="week" <?= $time_period == 'week' ? 'selected' : '' ?>>Last Week</option>
        <option value="month" <?= $time_period == 'month' ? 'selected' : '' ?>>Last Month</option>
        <option value="year" <?= $time_period == 'year' ? 'selected' : '' ?>>Last Year</option>
    </select>
</form>

<!-- Chart Section -->
<canvas id="alertChart" width="400" height="200"></canvas>

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

<!-- Chart.js Script -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
    const ctx = document.getElementById('alertChart').getContext('2d');
    const alertChart = new Chart(ctx, {
        type: 'bar', // Change to 'pie' for a pie chart
        data: {
            labels: <?= json_encode($alert_types) ?>,
            datasets: [{
                label: 'Number of Alerts',
                data: <?= json_encode($alert_counts_data) ?>,
                backgroundColor: ['#FF6384', '#36A2EB', '#FFCE56', '#4BC0C0'], // Custom colors for each type
                borderWidth: 1
            }]
        },
        options: {
            scales: {
                y: {
                    beginAtZero: true
                }
            },
            plugins: {
                legend: {
                    display: true
                }
            }
        }
    });
</script>

Youez - 2016 - github.com/yon3zu
LinuXploit