-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewVotingPeriods.jsp
123 lines (117 loc) · 4.12 KB
/
viewVotingPeriods.jsp
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.pollify.VotingPeriod" %>
<%@ page import="javax.servlet.http.HttpSession" %>
<%
if (session != null && session.getAttribute("username") != null) {
if (!"admin".equals(session.getAttribute("role"))) { // Check if the user is not admin
response.sendRedirect("accessDenied.jsp"); // Redirect if the role is not admin
return; // Stop further processing
}
} else {
response.sendRedirect("login.jsp"); // Redirect to login if session is null
return; // Stop further processing
}
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>View Voting Periods</title>
<link rel="stylesheet" href="css/user_page.css">
<link rel="stylesheet" href="css/navbar.css">
<link
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
rel="stylesheet"
/>
<style>
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 10px;
text-align: left;
border: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<%
String username = (session != null) ? (String) session.getAttribute("username") : null; // Get the username if session exists
%>
<nav>
<div class="logo">Pollify</div>
<div class="menu">
<% if(username == null) { %>
<a href="home.jsp">Home</a>
<a href="register.jsp">Register</a>
<a href="login.jsp">Login</a>
<% } else { %>
<a>Welcome, <%= username %>!</a>
<a href="logout.jsp">Logout</a> <!-- Link to logout servlet -->
<% } %>
</div>
</nav>
<div class="container">
<div class="sidebar">
<h2>Admin</h2>
<ul>
<li><a href="adminDashboard.jsp">
<i class="fas fa-calendar"></i> Set Voting Period
</a></li>
<li><a href="pendingResult" onclick="loadContent('declareResult')">
<i class="fas fa-trophy"></i> Declare Result
</a></li>
<li><a href="approveCandidate" onclick="loadContent('approveCandidate')">
<i class="fas fa-thumbs-up"></i> Approve Candidate
</a></li>
<li><a href="#" class="active">
<i class="fas fa-history"></i> View Voting Periods
</a></li>
<li><a href="sendNotification.jsp">
<i class="fas fa-bell"></i> Send Notification
</a></li>
</ul>
</div>
<div class="content">
<h1>Voting Periods</h1>
<table>
<tr>
<th>ID</th>
<th>Start Time</th>
<th>End Time</th>
<th>Active</th>
</tr>
<%
// Retrieve the list of voting periods from the request
List<VotingPeriod> votingPeriods = (List<VotingPeriod>) request.getAttribute("votingPeriods");
if (votingPeriods != null && !votingPeriods.isEmpty()) {
for (VotingPeriod period : votingPeriods) {
%>
<tr>
<td><%= period.getId() %></td>
<td><%= period.getStartTime() %></td>
<td><%= period.getEndTime() %></td>
<td><%= period.isActive() ? "Yes" : "No" %></td>
</tr>
<%
}
} else {
%>
<tr>
<td colspan="4">No voting periods found.</td>
</tr>
<%
}
%>
</table>
</div>
</div>
</body>
</html>