-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.php
More file actions
109 lines (101 loc) · 4.29 KB
/
dashboard.php
File metadata and controls
109 lines (101 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
require_once 'config/database.php';
require_once 'includes/auth.php';
if (!is_logged_in()) {
header('Location: index.php');
exit();
}
$db = new Database();
$conn = $db->connect();
// Update Fetch active elections query
$stmt = $conn->prepare("
SELECT *,
CASE
WHEN NOW() > end_date THEN 'ended'
WHEN NOW() BETWEEN start_date AND end_date AND is_active = true THEN 'active'
ELSE 'upcoming'
END as status
FROM elections
WHERE is_active = true
ORDER BY start_date DESC");
$stmt->execute();
$active_elections = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Get published elections for results
$stmt = $conn->prepare("SELECT * FROM elections WHERE is_published = true");
$stmt->execute();
$published_elections = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html>
<head>
<title>Voting Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="#">Online Voting System</a>
<div class="navbar-nav ms-auto">
<a href="profile.php" class="nav-link">
<i class="fas fa-user"></i> My Profile
</a>
<a href="logout.php" class="nav-link">Logout</a>
</div>
</div>
</nav>
<div class="container mt-4">
<?php if (isset($_SESSION['vote_message'])): ?>
<div class="alert alert-info alert-dismissible fade show">
<?= htmlspecialchars($_SESSION['vote_message']) ?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php unset($_SESSION['vote_message']); ?>
<?php endif; ?>
<h2>Active Elections</h2>
<?php if (empty($active_elections)): ?>
<div class="alert alert-info">No active elections at the moment.</div>
<?php else: ?>
<div class="row">
<?php foreach ($active_elections as $election): ?>
<div class="col-md-6 mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title"><?= htmlspecialchars($election['title']) ?></h5>
<p class="card-text"><?= htmlspecialchars($election['description']) ?></p>
<?php if($election['status'] === 'ended'): ?>
<span class="badge bg-secondary mb-2">Ended</span>
<?php else: ?>
<a href="vote.php?election_id=<?= $election['id'] ?>"
class="btn btn-primary">Cast Vote</a>
<?php endif; ?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<!-- Add Published Results Section -->
<h2 class="mt-4">Published Results</h2>
<?php if (empty($published_elections)): ?>
<div class="alert alert-info">No published results available.</div>
<?php else: ?>
<div class="row">
<?php foreach ($published_elections as $election): ?>
<div class="col-md-6 mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title"><?= htmlspecialchars($election['title']) ?></h5>
<p class="card-text"><?= htmlspecialchars($election['description']) ?></p>
<a href="public_results.php?id=<?= $election['id'] ?>"
class="btn btn-info">View Results</a>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>