-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvote_details.php
198 lines (177 loc) · 10.2 KB
/
vote_details.php
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
include 'config/dbconnection.php';
include 'config/session.php';
$status = 1;
$query = $conn->prepare("SELECT * FROM election WHERE status = ?");
$query->bind_param('i', $status);
$exec = $query->execute();
$temp = $query->get_result();
$show_results = $temp->fetch_assoc();
if ($show_results) {
$check_election = $show_results['id'];
// Check if user has already voted
$user_id = $_SESSION['login_id'];
$sqlz = "SELECT * FROM votes WHERE voter_id = '$user_id' AND election_id = '$check_election'";
$resultz = mysqli_query($conn, $sqlz);
if (mysqli_num_rows($resultz) == 0) {
echo "<script> location.href = 'index.php?page=vote' </script>";
exit();
}
$stmt = $conn->prepare("
SELECT c.*, cat.name AS category_name, e.title AS election_name, e.id AS election_id, e.created_at AS end_time, v.voter_id AS voter_id
FROM candidates c
JOIN categories cat ON c.category_id = cat.id
JOIN election e ON c.election_id = e.id
LEFT JOIN votes v ON e.id = v.election_id AND c.category_id = v.category_id AND c.id = v.candidate_id
WHERE e.status = ? AND voter_id = ?
");
$stmt->bind_param('ii', $status, $user_id);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
if ($row) {
$election_title = $row['election_name'];
$election_id = $row['election_id'];
$end_time = $row['end_time'];
?>
<div class="pagetitle">
<h1><?php echo $election_title; ?></h1>
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="index.php">Home</a></li>
<li class="breadcrumb-item active">Vote Details</li>
</ol>
</nav>
</div><!-- End Page Title -->
<section class="section dashboard row">
<h1 class="vote-details-title">You Aready Voted For </h1>
<div class="col-xxl-4 col-xl-12">
<!-- One Vote For Two Candidates -->
<div class="d-flex align-items-center row">
<?php
$categories = array();
foreach ($result as $key => $value) {
if (!empty($value['fellow_candidate_name'])) {
$categories[$value['category_name']][] = $value;
}
}
foreach ($categories as $categoryName => $categoryCandidates) {
?>
<div class="">
<div class="card info-card candidates-card">
<div class="card-body">
<h5 class="card-title"><?php echo $categoryName; ?></h5>
<!-- List of candidates -->
<?php
foreach ($categoryCandidates as $key => $candidate) {
?>
<div class="d-flex align-items-center row pt-3 pb-2"> <!-- test-x -->
<?php if ($candidate['candidate_photo']) { ?>
<div class="col-6 d-flex flex-column align-items-center justify-content-center">
<div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
<img class="card-icon rounded-circle" src="assets/img/profile/candidate/<?php echo $candidate['candidate_photo']; ?>" alt="Candidate Photo">
</div>
<span class="d-flex small small-text pt-2 text-nowrap text-sm-start text-md-center fw-bold"><?php echo $candidate['name']; ?></span>
</div>
<?php } else { ?>
<div class="col-6 d-flex flex-column align-items-center justify-content-center">
<div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
<i class="bi bi-person"></i>
</div>
<span class="d-flex small small-text pt-2 text-nowrap text-sm-start text-md-center fw-bold"><?php echo $candidate['name']; ?></span>
</div>
<?php }
if ($candidate['fellow_candidate_photo']) { ?>
<div class="col-6 d-flex flex-column align-items-center justify-content-center">
<div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
<img class="card-icon rounded-circle" src="assets/img/profile/candidate/<?php echo $candidate['fellow_candidate_photo']; ?>" alt="Candidate Photo">
</div>
<span class="d-flex small small-text pt-2 text-nowrap text-sm-start text-md-center fw-bold"><?php echo $candidate['fellow_candidate_name']; ?></span>
</div>
<?php } else { ?>
<div class="col-6 d-flex flex-column align-items-center justify-content-center">
<div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
<i class="bi bi-person"></i>
</div>
<span class="d-flex small small-text pt-2 text-nowrap text-sm-start text-md-center fw-bold"><?php echo $candidate['fellow_candidate_name']; ?></span>
</div>
<?php } ?>
</div>
<?php
}
?>
<!-- End List of candidates -->
</div>
</div>
</div>
<?php
}
?>
</div>
<!-- One Vote For One Candidates -->
<div class="row">
<?php
$categories = array();
foreach ($result as $key => $value) {
if (empty($value['fellow_candidate_name'])) {
$categories[$value['category_name']][] = $value;
}
} ?>
<?php
foreach ($categories as $categoryName => $categoryCandidates) {
?>
<div class="col-lg-4 col-md-6">
<div class="card info-card candidates-card px-4">
<h5 class="card-title"><?php echo $categoryName; ?></h5>
<div class="card-body row">
<!-- List of candidates -->
<?php
foreach ($categoryCandidates as $key => $out) {
if ($out['candidate_photo']) { ?>
<div class="col-6 card-icon rounded-circle d-flex align-items-center justify-content-center">
<img class="card-icon rounded-circle" src="assets/img/profile/candidate/<?php echo $out['candidate_photo']; ?>" alt="Candidate Photo">
</div>
<?php } else { ?>
<div class="col-6 card-icon rounded-circle d-flex align-items-center justify-content-center">
<i class="bi bi-person"></i>
</div>
<?php } ?>
<div class="col-6 ms-2 me-auto">
<div class="pt-2 text-nowrap text-center fw-bold"><?php echo $out['name']; ?></div>
</div>
<?php
}
?>
<!-- End List of candidates -->
</div>
</div>
</div>
<?php
}
?>
</div>
<div class="d-flex justify-content-center">
<a href="index.php?page=results" class="btn btn-primary">View Results</a>
</div>
</div>
</section>
<?php }
} else { ?>
<div class="container">
<div class="pagetitle">
<h1>Online Voting System</h1>
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="index.php">Home</a></li>
<li class="breadcrumb-item active">Vote Details</li>
</ol>
</nav>
</div><!-- End Page Title -->
<!-- .No active election section -->
<section class="section error-404 d-flex flex-column align-items-center justify-content-center">
<img src="assets/img/img-2.svg" class="img-fluid py-5" alt="No active election!" style="max-width: 320px">
<h2>No active election now, See you next time.</h2>
<a class="btn" href="controllers/app.php?action=logout">Logout</a>
</section>
</div><!-- /.No active election section -->
<?php } ?>