[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: ballot.php
<?php include("functions.php"); $schoolCode = test_input($_GET['schoolCode']); // $sql = "SELECT * FROM schools WHERE school_code = '$schoolCode' LIMIT 1"; // $result = mysqli_query($new, $sql); // if (mysqli_num_rows($result) > 0) {} $positions = mysqli_query($new, "SELECT * FROM positions WHERE schoolCode = '$schoolCode' ORDER BY position_id ASC"); $all_positions = []; while ($pos = mysqli_fetch_assoc($positions)) { $pid = $pos['position_id']; $cands = mysqli_query($new, "SELECT * FROM candidates WHERE position_id=$pid and schoolCode = '$schoolCode' ORDER BY fullname ASC"); $pos['candidates'] = []; while ($cand = mysqli_fetch_assoc($cands)) { $pos['candidates'][] = $cand; } $all_positions[] = $pos; } // Check if form was submitted if ($_SERVER["REQUEST_METHOD"] == "POST") { if (!isset($_POST['votes']) || empty($_POST['votes'])) { die("No votes submitted."); } // Prevent double voting $check = $conn->prepare("SELECT has_voted FROM students WHERE student_id = ?"); $check->bind_param("i", $student_id); $check->execute(); $check->bind_result($has_voted); $check->fetch(); $check->close(); if ($has_voted) { die("You have already voted. Multiple voting is not allowed."); } // Insert votes $stmt = $conn->prepare("INSERT INTO votes (student_id, position_id, candidate_id) VALUES (?, ?, ?)"); foreach ($_POST['votes'] as $position_id => $candidate_id) { $stmt->bind_param("iii", $student_id, $position_id, $candidate_id); $stmt->execute(); } $stmt->close(); // Mark student as voted $update = $conn->prepare("UPDATE students SET has_voted = 1 WHERE student_id = ?"); $update->bind_param("i", $student_id); $update->execute(); $update->close(); echo "<h3>✅ Thank you for voting! Your vote has been recorded.</h3>"; } //header("location:index.php"); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Student Voting Ballot</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"> <style> body { background: #f5f7fa; font-family: "Segoe UI", Tahoma, sans-serif; } .ballot-container { max-width: 1100px; margin: auto; background: #fff; border-radius: 1rem; box-shadow: 0 6px 20px rgba(0,0,0,0.1); padding: 2rem; } .candidate-card { border-radius: 1rem; overflow: hidden; border: 2px solid transparent; transition: all 0.3s ease; cursor: pointer; height: 100%; } .candidate-card:hover { transform: translateY(-5px); box-shadow: 0 6px 20px rgba(0,0,0,0.15); } .candidate-card img { width: 50px%; height: 200px; object-fit: cover; } .candidate-card .card-body { text-align: center; padding: 1rem; } .candidate-card h6 { margin: 0; font-weight: 600; font-size: 1rem; } .selected { border-color: #0d6efd !important; box-shadow: 0 0 0 4px rgba(13,110,253,0.2); } .step-header { font-size: 1.3rem; font-weight: 700; margin-bottom: 1.5rem; color: #333; text-align: center; } .nav-buttons { margin-top: 2rem; display: flex; justify-content: space-between; } .candidate-card img { width: 100%; height: 200px; /* fixed height */ object-fit: contain; /* keep full image visible */ background: #f8f9fa; /* light gray background for empty space */ padding: 10px; /* spacing around image */ } </style> </head> <body> <div class="container py-5"> <div class="ballot-container"> <h3 class="text-center mb-4">🗳 Student Voting Ballot</h3> <form method="POST" id="voteForm"> <div id="ballot-container"> <?php foreach ($all_positions as $index => $pos): ?> <div class="ballot-step" style="display: <?= $index==0 ? 'block':'none' ?>;"> <div class="step-header"><?= htmlspecialchars($pos['position_name']) ?></div> <div class="row g-4"> <?php foreach ($pos['candidates'] as $cand): ?> <div class="col-md-4 col-sm-6"> <div class="card candidate-card" onclick="selectCandidate(<?= $pos['position_id'] ?>, <?= $cand['candidate_id'] ?>, this)"> <img src="uploads/candidate/<?= $cand['picture'] ?>" alt="Candidate"> <div class="card-body"> <h6><?= htmlspecialchars($cand['fullname']) ?></h6> </div> </div> </div> <?php endforeach; ?> </div> <input type="hidden" name="vote[<?= $pos['position_id'] ?>]" id="vote-<?= $pos['position_id'] ?>"> <div class="nav-buttons"> <?php if ($index > 0): ?> <button type="button" class="btn btn-outline-secondary" onclick="prevStep()">⬅ Previous</button> <?php else: ?> <div></div> <?php endif; ?> <?php if ($index < count($all_positions)-1): ?> <button type="button" class="btn btn-primary" onclick="nextStep()">Next ➡</button> <?php else: ?> <button type="submit" class="btn btn-success">Submit Vote ✅</button> <?php endif; ?> </div> </div> <?php endforeach; ?> </div> </form> </div> </div> <script> let currentStep = 0; let steps = document.querySelectorAll(".ballot-step"); function showStep(n) { steps.forEach((step, i) => step.style.display = (i === n ? "block" : "none")); } function nextStep() { if (currentStep < steps.length-1) { currentStep++; showStep(currentStep); } } function prevStep() { if (currentStep > 0) { currentStep--; showStep(currentStep); } } function selectCandidate(positionId, candidateId, element) { let cards = element.closest(".row").querySelectorAll(".candidate-card"); cards.forEach(card => card.classList.remove("selected")); element.classList.add("selected"); document.getElementById("vote-"+positionId).value = candidateId; } </script> </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.81 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