[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: studentballot.php
<?php include("functions.php"); // ini_set('display_errors', 1); // ini_set('display_startup_errors', 1); // error_reporting(E_ALL); $s_code = $_SESSION['s_code_Xw2119904']; if(!isset($_SESSION['voting_code'])){ header("location:auth.php?schoolCode=$s_code"); } else { } $myvotingcode = $_SESSION['voting_code']; $schoolCode = test_input($_GET['schoolCode']); $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; } if ($_SERVER["REQUEST_METHOD"] == "POST") { if (!isset($_POST['votes']) || empty($_POST['votes'])) { die("No votes submitted."); } // $school_code = $_POST['school_code']; // Prevent double voting $check = $new->prepare("SELECT vote FROM enrol_details WHERE voting_code = ? and s_code = ? and vote IS NOT NULL"); $check->bind_param("is", $myvotingcode, $schoolCode); $check->execute(); $check->bind_result($vote); $check->fetch(); $check->close(); if ($vote) { die("You have already voted. Multiple voting is not allowed."); } // Insert votes foreach ($_POST['votes'] as $position_id => $candidate_id) { // Convert "0" (NO vote) to NULL if ($candidate_id === "0") { $candidate_id = null; } $stmt = $new->prepare("INSERT INTO votes (student_id, position_id, candidate_id, schoolCode) VALUES (?, ?, ?, ?)"); $stmt->bind_param("iiis", $myvotingcode, $position_id, $candidate_id, $schoolCode); $stmt->execute(); } // Mark student as voted $update = $new->prepare("UPDATE enrol_details SET vote = 'yes' WHERE voting_code = ?"); $update->bind_param("s", $myvotingcode); $update->execute(); $update->close(); unset($_SESSION['voting_code']); // clear voting code echo "<h3>✅ Thank you for voting! Your vote has been recorded.</h3>"; echo "<script> setTimeout(function(){ window.location.href = 'auth'; // change to your redirect page }, 2000); </script>"; } //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' ?>;" data-position="<?= $pos['position_id'] ?>"> <div class="step-header"> <?= htmlspecialchars($pos['position_name']) ?> </div> <div class="row g-4"> <?php if (count($pos['candidates']) === 1): ?> <!-- ✅ Single Candidate - Show YES/NO --> <?php $cand = $pos['candidates'][0]; ?> <div class="col-md-6 col-sm-12"> <div class="card candidate-card"> <img src="uploads/candidate/<?= $cand['picture'] ?>" alt="Candidate"> <div class="card-body text-center"> <h6><?= htmlspecialchars($cand['fullname']) ?></h6> </div> </div> </div> <input type="hidden" name="school_code" value="<?php echo $schoolCode;?>"> <div class="col-md-6 col-sm-12 d-flex flex-column justify-content-center"> <div class="btn-group" role="group"> <input type="radio" class="btn-check" name="votes[<?= $pos['position_id'] ?>]" id="yes-<?= $pos['position_id'] ?>" value="<?= $cand['candidate_id'] ?>" required> <label class="btn btn-outline-success" for="yes-<?= $pos['position_id'] ?>">✅ YES</label> <input type="radio" class="btn-check" name="votes[<?= $pos['position_id'] ?>]" id="no-<?= $pos['position_id'] ?>" value="0" required> <label class="btn btn-outline-danger" for="no-<?= $pos['position_id'] ?>">❌ NO</label> </div> </div> <?php else: ?> <!-- ✅ Multiple Candidates --> <?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 text-center"> <h6><?= htmlspecialchars($cand['fullname']) ?></h6> </div> </div> </div> <?php endforeach; ?> <input type="hidden" name="votes[<?= $pos['position_id'] ?>]" id="vote-<?= $pos['position_id'] ?>"> <?php endif; ?> </div> <input type="hidden" name="school_code" value="<?php echo $schoolCode;?>"> <!-- ✅ Navigation Buttons --> <div class="nav-buttons mt-3"> <?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="validateAndNext(<?= $pos['position_id'] ?>)">Next ➡</button> <?php else: ?> <button type="submit" class="btn btn-success" onclick="return validateBeforeSubmit()">Submit Vote ✅</button> <?php endif; ?> </div> </div> <?php endforeach; ?> </div> </form> </div> </div> <script> let currentStep = 0; const steps = document.querySelectorAll(".ballot-step"); function showStep(index) { steps.forEach((step, i) => step.style.display = i === index ? "block" : "none"); currentStep = index; } function selectCandidate(positionId, candidateId, element) { document.getElementById("vote-" + positionId).value = candidateId; // Highlight selection document.querySelectorAll(`[data-position="${positionId}"] .candidate-card`) .forEach(card => card.classList.remove("selected")); element.classList.add("selected"); } function validateAndNext(positionId) { const step = steps[currentStep]; // Check if a vote has been selected let valid = false; // Case 1: Single candidate (radio YES/NO) const radios = step.querySelectorAll(`input[name="votes[${positionId}]"]`); if (radios.length > 0) { radios.forEach(r => { if (r.checked) valid = true; }); } // Case 2: Multiple candidates (hidden input set by selectCandidate) const hidden = document.getElementById("vote-" + positionId); if (hidden && hidden.value !== "") { valid = true; } if (!valid) { alert("⚠ Please select an option before proceeding."); return; } showStep(currentStep + 1); } function prevStep() { if (currentStep > 0) showStep(currentStep - 1); } function validateBeforeSubmit() { // Final check before submit const hiddenInputs = document.querySelectorAll("input[name^='votes']"); for (let input of hiddenInputs) { if (input.type === "hidden" && input.value === "") { alert("⚠ Please complete all selections before submitting."); return false; } if (input.type === "radio") { const radios = document.getElementsByName(input.name); let checked = false; for (let r of radios) { if (r.checked) checked = true; } if (!checked) { alert("⚠ Please complete all selections before submitting."); return false; } } } return true; } </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: 60.07 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