From edfdd9853514df499f8311089a11338eeb9ce21c Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Mon, 16 Feb 2026 02:56:35 +0000 Subject: [PATCH] Autosave: 20260216-025634 --- api/create_election.php | 3 +- api/manage_election_action.php | 46 +++++ api/update_election_status.php | 6 +- dashboard.php | 271 ++++++++++++++++++++++++++- manage_candidates.php | 201 ++++++++++++-------- view_election.php | 323 ++++++++++++++++++++------------- 6 files changed, 642 insertions(+), 208 deletions(-) create mode 100644 api/manage_election_action.php diff --git a/api/create_election.php b/api/create_election.php index 61e59bc..b463627 100644 --- a/api/create_election.php +++ b/api/create_election.php @@ -24,7 +24,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { audit_log('Created election', 'elections', $id); - header("Location: ../view_election.php?id=$id&success=1"); + $redirect = $_POST['redirect'] ?? "../view_election.php?id=$id&success=1"; + header("Location: $redirect"); exit; } catch (Exception $e) { die("Error: " . $e->getMessage()); diff --git a/api/manage_election_action.php b/api/manage_election_action.php new file mode 100644 index 0000000..0227cd2 --- /dev/null +++ b/api/manage_election_action.php @@ -0,0 +1,46 @@ +prepare($sql); + $stmt->execute($params); + + audit_log("Election Managed: Status=$status, EndTime=$end_time", 'elections', $id); + + header("Location: ../dashboard.php?success=Election updated successfully"); + exit; + } catch (Exception $e) { + die($e->getMessage()); + } +} diff --git a/api/update_election_status.php b/api/update_election_status.php index 9697604..53f5cf9 100644 --- a/api/update_election_status.php +++ b/api/update_election_status.php @@ -18,9 +18,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $stmt->execute([$status, $id]); audit_log("Updated election status to $status", 'elections', $id); - - header("Location: ../view_election.php?id=$id&success=1"); + + $redirect = $_POST['redirect'] ?? "../view_election.php?id=$id&success=1"; + header("Location: $redirect"); exit; + } catch (Exception $e) { die($e->getMessage()); } diff --git a/dashboard.php b/dashboard.php index b352062..80057c2 100644 --- a/dashboard.php +++ b/dashboard.php @@ -3,11 +3,18 @@ require_once 'auth_helper.php'; require_login(); $user = get_user(); -$pdo = db(); -$electionId = get_active_election_id(); -$election = get_active_election(); + $pdo = db(); + $electionId = get_active_election_id(); + $election = get_active_election(); + + // For Election Management Section + $allElections = []; + if (in_array($user['role'], ['Admin', 'Adviser', 'Officer'])) { + $allElections = $pdo->query("SELECT * FROM elections WHERE archived = FALSE ORDER BY created_at DESC")->fetchAll(); + } + + // Statistics (Filtered by Election) -// Statistics (Filtered by Election) $totalVoters = $pdo->prepare("SELECT COUNT(*) FROM election_assignments WHERE election_id = ? AND role_in_election = 'Voter'"); $totalVoters->execute([$electionId]); $totalVoters = $totalVoters->fetchColumn(); @@ -64,6 +71,81 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Online Election System + @@ -74,6 +156,16 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Online Election System
+ +
+ +
+ + +
+ +
+

Election Dashboard

@@ -83,6 +175,73 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Online Election System
+ + +
+
+
Election Control Center
+ +
+ + + + + + + + + + + + + + + + + + + +
Election TitleStatusCurrent End TimeActions
+ + + + + + +
+ +
+ + + + +
+ +
+ + + + +
+ + + + + +
+
+
+ +
@@ -243,5 +402,109 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Online Election System updateSectionChart(trackFilter.value); } + + + + + + + + diff --git a/manage_candidates.php b/manage_candidates.php index 55df0eb..1be4afb 100644 --- a/manage_candidates.php +++ b/manage_candidates.php @@ -26,94 +26,137 @@ $users = $pdo->query("SELECT id, name, student_id FROM users WHERE role = 'Voter Manage Candidates | <?= htmlspecialchars($position['name']) ?> + + - + + - - + + -
-
+
+ + +
+
-

Candidates for

-

+

Candidates for

+

-
+ +
-
-
-

Add Candidate

-
- - -
- - -
-
- - -
-
- - -
- -
+
+
+

Add New Candidate

+
+ + + +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
-
-

Current Candidates

- -

No candidates added yet.

- - - - - - - - - - - - - - - - - - - - -
StudentPartyApprovedActions
-
- -
- - - - -
- - -
-
- +
+
+

Registered Candidates

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Student InfoParty AffiliationStatusActions
+
+ + No candidates have been registered for this position yet. +
+
+
+
+ +
+
+
+
+
+
+
+ + + + + + + + +
+ + +
+
+
-
+
+
+ + + diff --git a/view_election.php b/view_election.php index 1729589..63d25b9 100644 --- a/view_election.php +++ b/view_election.php @@ -34,176 +34,254 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Online Election System - + + - - + + -
-
-
+
+ + +
+
-

-

-
- Status: | - Period: to -
+

+

-
+
- +
- +
- +
-
-
-
-
-
-

Positions

- - - -
- - - - -
-

No positions defined yet.

+
+
+
+
+
- - - - - - - - - - - - prepare("SELECT COUNT(*) FROM candidates WHERE position_id = ?"); - $cStmt->execute([$pos['id']]); - $cCount = $cStmt->fetchColumn(); - ?> - - - - - - - - -
Position NameMax VotesCandidatesActions
- Candidates -
- + Status +
+
+ + + +
-
-
-
-

Quick Stats

+
+
+
+ +
+ Election Period +
+
+ +
+
+ +
+
+
+ +
+ Total Participation +
prepare("SELECT COUNT(DISTINCT voter_id) FROM votes WHERE election_id = ?"); $vStmt->execute([$id]); $votesCount = $vStmt->fetchColumn(); ?> -
-
Total Votes Cast
-
+
Votes Cast
+
+
+ +
+
+
+

Positions & Structure

+ + +
-
- prepare("SELECT COUNT(*) FROM candidates WHERE election_id = ?"); - $canStmt->execute([$id]); - $candidatesTotal = $canStmt->fetchColumn(); - ?> -
Total Candidates
-
+ + + +
+ + + + + + + + + + + + + + + + prepare("SELECT COUNT(*) FROM candidates WHERE position_id = ?"); + $cStmt->execute([$pos['id']]); + $cCount = $cStmt->fetchColumn(); + ?> + + + + + + + + + +
Position NameMax VotesCandidatesActions
+
+ + No positions defined yet. Start by adding one. +
+
+ Vote 1 ? 's' : '' ?> + +
+
+ +
+
+ + Manage Candidates + + +
+
+
+ +
+
+

Quick Stats

+ +
+
+
+
Total Candidates
+ prepare("SELECT COUNT(*) FROM candidates WHERE election_id = ?"); + $canStmt->execute([$id]); + $candidatesTotal = $canStmt->fetchColumn(); + ?> +
+
+
+ +
+
+ +
+
+
Voter Turnout
+
+
+
+ +
+
+
+
+ +
+

Need Help?

+

Manage your election structure by adding positions and assigning candidates to them. Once ready, you can launch the election.

+ View Reports
-
+
-