[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: electionresults.php
<?php include("../functions.php"); $schoolCode = test_input($_GET['schoolCode']); // Get all positions $positions = $new->query("SELECT * FROM positions WHERE schoolCode = '$schoolCode' ORDER BY position_id ASC"); $stmt = $con->prepare("Select * from schools where school_code = ?"); $stmt->execute(array($schoolCode)); $row = $stmt->fetch(); $logo = $row['logo']; $school_name = $row['school_name']; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Election Results</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> </head> <body class="bg-light"> <div class="container my-5"> <h2 class="text-center mb-4">📊 Election Results</h2> <?php while ($pos = $positions->fetch_assoc()) { $position_id = $pos['position_id']; // Fetch candidates for this position $candidates = $new->query("SELECT * FROM candidates WHERE position_id = $position_id AND schoolCode = '$schoolCode'"); $cand_count = $candidates->num_rows; // ✅ Single Candidate (YES/NO system) if ($cand_count === 1) { $cand = $candidates->fetch_assoc(); // Count YES votes (candidate_id match) $yes_result = $new->query("SELECT COUNT(*) AS total_yes FROM votes WHERE position_id = $position_id AND candidate_id = {$cand['candidate_id']}"); $yes_votes = $yes_result->fetch_assoc()['total_yes']; // Count NO votes (NULL candidate_id) $no_result = $new->query("SELECT COUNT(*) AS total_no FROM votes WHERE position_id = $position_id AND schoolCode = '$schoolCode' AND candidate_id IS NULL"); $no_votes = $no_result->fetch_assoc()['total_no']; $total_votes = $yes_votes + $no_votes; $yes_percent = $total_votes > 0 ? round(($yes_votes / $total_votes) * 100, 2) : 0; $no_percent = $total_votes > 0 ? round(($no_votes / $total_votes) * 100, 2) : 0; ?> <div class="card mb-4 shadow-sm"> <div class="card-header bg-primary text-white"> <h5 class="mb-0"><?= htmlspecialchars($pos['position_name']) ?></h5> </div> <div class="card-body"> <div class="mb-2"><strong>Total Votes Cast:</strong> <?= $total_votes ?></div> <div class="table-responsive"> <table class="table table-bordered text-center align-middle"> <thead class="table-dark"> <tr> <th>Option</th> <th>Votes</th> <th>Percentage</th> </tr> </thead> <tbody> <tr class="<?= $yes_votes >= $no_votes ? 'table-success fw-bold' : '' ?>"> <td> <img src="uploads/candidate/<?= htmlspecialchars($cand['picture']) ?>" alt="Candidate" class="rounded-circle me-2" style="width:50px; height:50px; object-fit:cover;"> <?= htmlspecialchars($cand['fullname']) ?> (YES) </td> <td><span class="badge bg-success"><?= $yes_votes ?></span></td> <td><?= $yes_percent ?>%</td> </tr> <tr class="<?= $no_votes > $yes_votes ? 'table-danger fw-bold' : '' ?>"> <td>❌ NO</td> <td><span class="badge bg-danger"><?= $no_votes ?></span></td> <td><?= $no_percent ?>%</td> </tr> </tbody> </table> </div> <!-- Chart --> <center> <div style="width:300px; height:300px"> <canvas id="chart_<?= $pos['position_id'] ?>"></canvas> </div> </center> <script> const ctx<?= $pos['position_id'] ?> = document.getElementById("chart_<?= $pos['position_id'] ?>"); new Chart(ctx<?= $pos['position_id'] ?>, { type: "pie", data: { labels: ["YES", "NO"], datasets: [{ data: [<?= $yes_votes ?>, <?= $no_votes ?>], backgroundColor: ["rgba(25, 135, 84, 0.7)", "rgba(220, 53, 69, 0.7)"] }] }, options: { responsive: true, maintainAspectRatio: false, // ✅ keeps it inside the fixed div cutout: "65%", plugins: { legend: { position: "bottom" }, title: { display: true, text: "YES / NO Breakdown" } } } }); </script> </div> </div> <?php } else { // ✅ Multiple candidates $candidates = $new->query(" SELECT c.candidate_id, c.fullname, c.picture, COUNT(v.vote_id) AS total_votes FROM candidates c LEFT JOIN votes v ON c.candidate_id = v.candidate_id WHERE c.position_id = $position_id GROUP BY c.candidate_id ORDER BY total_votes DESC "); $rows = []; $total_votes_cast = 0; while ($cand = $candidates->fetch_assoc()) { $rows[] = $cand; $total_votes_cast += $cand['total_votes']; } $max_votes = 0; foreach ($rows as $cand) { if ($cand['total_votes'] > $max_votes) { $max_votes = $cand['total_votes']; } } $labels = array_map(fn($c) => $c['fullname'], $rows); $votes = array_map(fn($c) => $c['total_votes'], $rows); ?> <div class="card mb-4 shadow-sm"> <div class="card-header bg-primary text-white"> <h5 class="mb-0"><?= htmlspecialchars($pos['position_name']) ?></h5> </div> <div class="card-body"> <div class="mb-2"><strong>Total Votes Cast:</strong> <?= $total_votes_cast ?></div> <div class="table-responsive"> <table class="table table-bordered text-center align-middle"> <thead class="table-dark"> <tr> <th>Candidate</th> <th>Votes</th> <th>Percentage</th> <th>Status</th> </tr> </thead> <tbody> <?php foreach ($rows as $cand): $percentage = $total_votes_cast > 0 ? round(($cand['total_votes'] / $total_votes_cast) * 100, 2) : 0; $isWinner = ($cand['total_votes'] == $max_votes && $max_votes > 0); ?> <tr class="<?= $isWinner ? 'table-success fw-bold' : '' ?>"> <td> <img src="uploads/candidate/<?= htmlspecialchars($cand['picture']) ?>" alt="Candidate" class="rounded-circle me-2" style="width:50px; height:50px; object-fit:cover;"> <?= htmlspecialchars($cand['fullname']) ?> </td> <td><span class="badge bg-success"><?= $cand['total_votes'] ?></span></td> <td><?= $percentage ?>%</td> <td> <?php if ($isWinner): ?> 🏆 <span class="badge bg-warning text-dark">Winner</span> <?php else: ?> <span class="badge bg-secondary">—</span> <?php endif; ?> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> <!-- Chart --> <canvas id="chart_<?= $pos['position_id'] ?>" height="120"></canvas> <script> const ctxM<?= $pos['position_id'] ?> = document.getElementById("chart_<?= $pos['position_id'] ?>"); new Chart(ctxM<?= $pos['position_id'] ?>, { type: "bar", data: { labels: <?= json_encode($labels) ?>, datasets: [{ label: "Votes", data: <?= json_encode($votes) ?>, backgroundColor: "rgba(13, 110, 253, 0.7)" }] }, options: { responsive: true, plugins: { legend: { display: false }, title: { display: true, text: "Vote Distribution" } }, scales: { y: { beginAtZero: true, stepSize: 1 } } } }); </script> </div> </div> <?php } } ?> </div> </body> </html>
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.74 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002