prepare(" SELECT e.* FROM elections e JOIN election_assignments ea ON e.id = ea.election_id WHERE ea.user_id = ? AND e.status = 'Ongoing' AND e.archived = FALSE AND e.end_date_and_time > CURRENT_TIMESTAMP "); $stmt->execute([$user['id']]); $activeElections = $stmt->fetchAll(); // Filter out elections where the user has already voted $votedElectionsStmt = $pdo->prepare("SELECT election_id FROM votes WHERE voter_id = ?"); $votedElectionsStmt->execute([$user['id']]); $votedIds = $votedElectionsStmt->fetchAll(PDO::FETCH_COLUMN); $eligibleElections = array_filter($activeElections, function($e) use ($votedIds) { return !in_array($e['id'], $votedIds); }); if (count($eligibleElections) === 1) { $singleElection = reset($eligibleElections); header("Location: ballot.php?id=" . $singleElection['id']); exit; } // If no eligible elections but they were assigned to some active ones, they've already voted if (count($eligibleElections) === 0 && count($activeElections) > 0) { if (!isset($_GET['success']) && !isset($_GET['error'])) { header("Location: index.php?error=already_voted"); exit; } } // For voters, only show their assigned elections in the list $elections = $activeElections; } else { $elections = $pdo->query("SELECT * FROM elections WHERE archived = FALSE ORDER BY created_at DESC")->fetchAll(); } $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Online Election System for Senior High School'; ?>
Manage your school elections and voting sessions.
No elections found. Create your first election to get started.
Setup Election| Title | Status | Period | Actions |
|---|---|---|---|
|
= htmlspecialchars($election['title']) ?>
= htmlspecialchars($election['description']) ?>
|
= htmlspecialchars($election['status']) ?> |
= date('M d, H:i', strtotime($election['start_date_and_time'])) ?> -
= date('M d, H:i', strtotime($election['end_date_and_time'])) ?>
|
View Vote |