-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
271 lines (217 loc) · 7.86 KB
/
index.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<!-- //http://localhost/Online-Voting-System/index.php -->
<?php
require_once("admin/config.php");
$fetchingElections = mysqli_query($db, "SELECT * FROM elections") OR die(mysqli_error($db));
while($data = mysqli_fetch_assoc($fetchingElections))
{
$stating_date = $data['s_date'];
$ending_date = $data['ending_date'];
$curr_date = date("Y-m-d");
$election_id = $data['id'];
$status = $data['status'];
// Active = Expire = Ending Date
// InActive = Active = Starting Date
if($status == "Active")
{
$date1=date_create($curr_date);
$date2=date_create($ending_date);
$diff=date_diff($date1,$date2);
if((int)$diff->format("%R%a") < 0)
{
// Update!
mysqli_query($db, "UPDATE elections SET status = 'Expired' WHERE id = '". $election_id ."'") OR die(mysqli_error($db));
}
}else if($status == "InActive")
{
$date1=date_create($curr_date);
$date2=date_create($stating_date);
$diff=date_diff($date1,$date2);
if((int)$diff->format("%R%a") <= 0)
{
// Update!
mysqli_query($db, "UPDATE elections SET status = 'Active' WHERE id = '". $election_id ."'") OR die(mysqli_error($db));
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Online Voting System</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<link rel="stylesheet" href="./assets/css/login.css">
<link rel="stylesheet" href="./assets/css/style.css">
</head>
<!--Coded with love by Mutiullah Samim-->
<body>
<div class="container h-100">
<div class="d-flex justify-content-center h-100">
<div class="user_card">
<div class="d-flex justify-content-center">
<div class="brand_logo_container">
<img src="./assets/images/logo.gif" class="brand_logo" alt="Logo">
</div>
</div>
<?php
if(isset($_GET['sign-up']))
{
?>
<div class="d-flex justify-content-center form_container">
<form method="POST">
<div class="input-group mb-3">
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-user"></i></span>
</div>
<input type="text" name="su_username" class="form-control input_user" placeholder="Username" required />
</div>
<div class="input-group mb-2">
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-key"></i></span>
</div>
<input type="text" name="su_contact_no" class="form-control input_pass" placeholder="Contact no" required />
</div>
<div class="input-group mb-2">
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-key"></i></span>
</div>
<input type="password" name="su_password" class="form-control input_pass" placeholder="Password" required />
</div>
<div class="input-group mb-2">
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-key"></i></span>
</div>
<input type="password" name="su_confirm_password" class="form-control input_pass" placeholder="Confirm password" required />
</div>
<div class="d-flex justify-content-center mt-3 login_container">
<button type="submit" name="sign_up_btn" class="btn login_btn">Sign up</button>
</div>
</form>
</div>
<div class="mt-4">
<div class="d-flex justify-content-center links">
Already created account? <a href="index.php" class="ml-2">Sign in</a>
</div>
</div>
<?php
}else{
?>
<div class="d-flex justify-content-center form_container">
<form method="POST">
<div class="input-group mb-3">
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-user"></i></span>
</div>
<input type="text" name="Contact_no" class="form-control input_user" placeholder="Contact Number" require/>
</div>
<div class="input-group mb-2">
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-key"></i></span>
</div>
<input type="password" name="password" class="form-control input_pass" placeholder="password" required/>
</div>
<div class="d-flex justify-content-center mt-3 login_container">
<button type="submit" name="loginBtn" class="btn login_btn">Login</button>
</div>
</form>
</div>
<div class="mt-4">
<div class="d-flex justify-content-center links">
Don't have an account? <a href="?sign-up=1" class="ml-2">Sign Up</a>
</div>
<div class="d-flex justify-content-center links">
<a href="#">Forgot your password?</a>
</div>
</div>
<?php
}
?>
<?php
if(isset($_GET['registered']))
{
?>
<span class="bg-white text-success text-center my-3"> Your account has been created successfully</span>
<?php
} else if(isset($_GET['invalid']))
{
?>
<span class="bg-white text-danger text-center my-3"> Password mismatched,Please try again</span>
<?php
}
else if(isset($_GET['not_registered']))
{
?>
<span class="bg-white text-warning text-center my-3"> Sorry,You are not registered</span>
<?php
}
else if(isset($_GET['invalid_access']))
{
?>
<span class="bg-white text-danger text-center my-3"> Invalid username or password</span>
<?php
}
?>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-cuYeSxntonz0PPNlHhBs68uyIAVpIIOZZ5JqeqvYYIcEL727kskC66kF92t6Xl2V" crossorigin="anonymous"></script>
<script src="assets/js/jquery.min.js"></script>
</body>
</html>
<?php
require_once("admin/config.php");
if(isset($_POST['sign_up_btn']))
{
$su_username=mysqli_real_escape_string($db,$_POST['su_username']);
$su_contact_no=mysqli_real_escape_string($db,$_POST['su_contact_no']);
$su_password=mysqli_real_escape_string($db,sha1($_POST['su_password']));
$su_confirm_password=mysqli_real_escape_string($db,sha1($_POST['su_confirm_password']));
$user_role="Voter";
if($su_password==$su_confirm_password){
//query
mysqli_query($db, "INSERT INTO users(username,Contact_no,password,user_role)
Values('".$su_username."','".$su_contact_no."','".$su_password."','".$user_role."' )")
or die(mysqli_error($db));
?>
<script> location.assign("index.php?sign-up=1®istered=1"); </script>
<?php
}else{
?>
<script> location.assign("index.php?sign-up=1&invalid=1"); </script>
<?php
}
}else if(isset($_POST['loginBtn']))
{
$Contact_no=mysqli_real_escape_string($db,$_POST['Contact_no']);
$password=mysqli_real_escape_string($db,sha1($_POST['password']));
//query
$fetchingData =mysqli_query($db, "SELECT * FROM users WHERE Contact_no = '". $Contact_no ."'") or die(mysqli_error($db));
if(mysqli_num_rows($fetchingData) >0 )
{
$data = mysqli_fetch_assoc($fetchingData);
if($Contact_no==$data['Contact_no'] and $password==$data['password'])
{session_start();
$_SESSION['user_role']= $data['user_role'];
$_SESSION['username']= $data['username'];
$_SESSION['user_id']= $data['id'];
if($data['user_role']== "Admin")
{$_SESSION['key']="AdminKey";
?>
<script> location.assign("admin/index.php?homepage=1"); </script>
<?php
}else{$_SESSION['key']="VotersKey";
?>
<script> location.assign("voters/index.php"); </script>
<?php
}
}else{
?>
<script> location.assign("index.php?invalid_access=1"); </script>
<?php
}
}else{
?>
<script> location.assign("index.php?sign-up=1¬_registered=1"); </script>
<?php
}
}
?>