Candidate Management
Managing = htmlspecialchars($election['title']) ?>
prepare("SELECT COUNT(*) FROM candidates WHERE election_id = ?"); $totalCandidates->execute([$electionId]); $totalCandidates = $totalCandidates->fetchColumn(); $uniquePositions = $pdo->prepare("SELECT COUNT(*) FROM positions WHERE election_id = ?"); $uniquePositions->execute([$electionId]); $uniquePositions = $uniquePositions->fetchColumn(); $activeParties = $pdo->prepare("SELECT COUNT(*) FROM parties WHERE election_id = ?"); $activeParties->execute([$electionId]); $activeParties = $activeParties->fetchColumn(); // Candidates by Position $posStats = $pdo->prepare("SELECT p.name, COUNT(c.id) as count FROM positions p LEFT JOIN candidates c ON p.id = c.position_id WHERE p.election_id = ? GROUP BY p.id ORDER BY p.sort_order"); $posStats->execute([$electionId]); $posStats = $posStats->fetchAll(PDO::FETCH_ASSOC); // Candidates by Party $partyStats = $pdo->prepare("SELECT p.name as party_name, COUNT(c.id) as count FROM parties p LEFT JOIN candidates c ON p.name = c.party_name AND c.election_id = p.election_id WHERE p.election_id = ? GROUP BY p.id ORDER BY count DESC"); $partyStats->execute([$electionId]); $partyStats = $partyStats->fetchAll(PDO::FETCH_ASSOC); // Filters $search = $_GET['search'] ?? ''; $filterPosition = $_GET['position'] ?? 'All Positions'; $filterParty = $_GET['party'] ?? 'All Parties'; // Main Query $query = "SELECT c.*, u.name as user_name, u.email as user_email, u.student_id, u.grade_level, u.track, p.name as position_name FROM candidates c JOIN users u ON c.user_id = u.id JOIN positions p ON c.position_id = p.id WHERE c.election_id = ?"; $params = [$electionId]; if ($search) { $query .= " AND (u.name LIKE ? OR u.email LIKE ? OR c.party_name LIKE ?)"; $params[] = "%$search%"; $params[] = "%$search%"; $params[] = "%$search%"; } if ($filterPosition !== 'All Positions') { $query .= " AND p.name = ?"; $params[] = $filterPosition; } if ($filterParty !== 'All Parties') { $query .= " AND c.party_name = ?"; $params[] = $filterParty; } $query .= " ORDER BY p.sort_order, u.name"; $stmt = $pdo->prepare($query); $stmt->execute($params); $candidates = $stmt->fetchAll(); // Options for Modals/Filters $allPositions = $pdo->prepare("SELECT * FROM positions WHERE election_id = ? ORDER BY sort_order"); $allPositions->execute([$electionId]); $allPositions = $allPositions->fetchAll(); $allParties = $pdo->prepare("SELECT * FROM parties WHERE election_id = ? ORDER BY name"); $allParties->execute([$electionId]); $allParties = $allParties->fetchAll(); $allVoters = $pdo->query("SELECT id, name, student_id FROM users WHERE role = 'Voter' ORDER BY name")->fetchAll(); $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Online Election System for Senior High School'; ?>
Managing = htmlspecialchars($election['title']) ?>