-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvoting_page.php
155 lines (144 loc) · 6.46 KB
/
voting_page.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
<?php
session_start();
include 'conn.php';
if(empty($_SESSION['voter_name']))
{
header("Location:index.php");
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<title>EVoting - Voting</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">EVoting</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="voting.php">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?php echo $base_url?>vlogout.php">Logout</a>
</li>
</ul>
</div>
</nav>
<!--Submit Vote Modal -->
<div class="modal fade" id="submitvotemodal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Submit Vote</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="" method="post">
<div class="modal-body">
<p>Are you sure you want to give vote to this candidate?</p>
<p>This action is irreversible.</p>
<p>Once you click '<b>Yes</b>', you cannot change your vote.</p>
<input type="hidden" name="candidate_id" id="candidate_id">
<input type="hidden" name="voter_id" id="voter_id">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
<button type="submit" name="submit_vote" class="btn btn-info">Yes</button>
</div>
</form>
</div>
</div>
</div>
<?php
if(isset($_POST['submit_vote']))
{
$candidate_id = $_POST['candidate_id'];
$voter_id = $_POST['voter_id'];
$insert_vote = "INSERT INTO votes (voter_id, can_id) VALUES ('$voter_id','$candidate_id')";
$insert_vote_result = mysqli_query($con, $insert_vote);
if($insert_vote_result == '1')
{
echo '<script>alert("Voted Successfully")</script>';
echo '<script>';
echo 'window.location="'.$base_url.'vlogout.php"';
echo '</script>';
}
else
{
echo '<script>alert("Failed to Vote")</script>';
}
}
?>
<h1 class="text-center mt-2"><u>Candidate List</u></h1>
<div class="container mt-3">
<table class="table table-striped table-hover text-center">
<thead>
<tr>
<th>Candidate ID</th>
<th>Party Symbol</th>
<th>Candidate Image</th>
<th>Name</th>
<th>Vote</th>
</tr>
</thead>
<tbody>
<?php
$fetch_candidate_data = "SELECT * FROM candidates";
$result_candidate_data = mysqli_query($con, $fetch_candidate_data);
if(mysqli_num_rows($result_candidate_data) > 0)
{
while($res = mysqli_fetch_array($result_candidate_data))
{
?>
<tr>
<td class="pt-4"><h1><?php echo $res['can_id']?></h1></td>
<td><img src="<?php echo $base_url?>profile/<?php echo $res['can_party_symbol'] ?>" alt="image" width="100"></td>
<td><img src="<?php echo $base_url?>profile/<?php echo $res['can_image'] ?>" alt="party" width="100"></td>
<td><h3 class="pt-4"><?php echo $res['can_name']?></h3></td>
<td><a href="" data-toggle="modal" data-target="#submitvotemodal" data-candidate_id="<?php echo $res['can_id']?>" data-voter_id="<?php echo $_SESSION['voter_id']?>"><img src="http://icons.iconarchive.com/icons/iconarchive/blue-election/256/Election-Vote-2-icon.png" alt="vote" width="100"></a></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td colspan="5">No Data Available</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<script>
$(document).ready(function () {
$('#submitvotemodal').on('show.bs.modal', function (event) {
// console.log("modal open");
var button = $(event.relatedTarget) // Button that triggered the modal
var candidate_id = button.data('candidate_id')
var voter_id = button.data('voter_id')
var modal = $(this)
modal.find('.modal-body #candidate_id').val(candidate_id)
modal.find('.modal-body #voter_id').val(voter_id)
})
});
</script>
</body>
</html>