-
Notifications
You must be signed in to change notification settings - Fork 1
/
vercode-list-function.php
483 lines (457 loc) · 24.5 KB
/
vercode-list-function.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// we will only start the session with session_start() IF the session isn"t started yet //
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
?>
<?php
// including the conn.php to establish connection with database //
include "conn.php";
?>
<?php
// Begin of the function: Verification Code's Verification Form: Disable //
// First we check the form has submitted or not //
if (isset($_POST['submit-list-disA'])) {
// If it is, then we will retreive data from the input forms //
$verid = $_POST["verid"];
$dis_acccode = mysqli_real_escape_string($con, $_POST['dis-acccode']);
$dis_pw = mysqli_real_escape_string($con, $_POST['dis-pw']);
// Taking the current time //
date_default_timezone_set("Etc/GMT-8");
$now = date("Y-m-d H:i:s");
// Variable to store Error Message //
$error = '';
// Sorting out the query related to the function //
// Verify the user is an admin or not //
$VERFYADMIN = "SELECT * FROM user
WHERE status = 2 AND active = 1 AND account_code = '".md5($dis_acccode)."' AND password = '".md5($dis_pw)."'";
$VERFYADMINQ = mysqli_query($con, $VERFYADMIN);
//***BEGIN OF PROCESS***//
if (mysqli_num_rows($VERFYADMINQ) < 1) {
// if the admin is not verified, then inform the user and send him back to admin panel //
echo "<script>alert('ALERT: Information unable to be verified. Please try again.');";
echo "window.location.href='admin_panel.html';</script>";
exit(0);
} else {
// begin the process of disabling the verification code //
while (list($key,$val) = @each ($verid)) {
// first we check the verification code exists in database or not //
$VERCODEEX = "SELECT * FROM verification_code
WHERE verification_id = $val AND code_active = 1";
$VERCODEEXQ = mysqli_query($con, $VERCODEEX);
if (mysqli_num_rows($VERCODEEXQ) < 1) {
// if we are unable to retrieve the data of the verification code then something must gone wrong //
echo "<script>alert('WARNING: Unable to retrieve the data. Please try again.');";
echo "</script>";
} else {
while ($row = mysqli_fetch_array($VERCODEEXQ)) {
// these variables will be used in the latter part //
$userid = $row["user_id_code"];
}
// if the verification code existing in the database then we will start to disable the code //
$DISABLEVER = "UPDATE verification_code SET code_active = 0 WHERE verification_id = ?";
// then we will start to update the information //
$stmt = $con->prepare($DISABLEVER);
$stmt->bind_param("i", $val);
$stmt->execute();
if (($stmt->error) == FALSE) {
// if there is no error then close the previous statement //
$stmt->close();
// then according to the concept of our system, anyone which is under the verification code that is not active will automatically disabled //
$suspended_reason = "Account Disabled due to Verification Code being disabled by an Admin, ID: ".$_SESSION['user_id'].". For more information please do contact with the Administrator.";
$DISABLEUSER = "UPDATE user SET active = 0, suspended_reason = '".$suspended_reason."' WHERE user_id = ?";
// then we will start to update the information //
$stmt = $con->prepare($DISABLEUSER);
$stmt->bind_param("i", $userid);
$stmt->execute();
if (($stmt->error) == FALSE) {
// if there is no error then close the previous statement //
$stmt->close();
// if we have reached this point then the disable process is a success //
echo "<script>alert('Notice: Disable Successful for Verification ID: ".$val.".');";
echo "</script>";
} else {
// if we are unable to disable the verification code then something must gone wrong //
echo "<script>alert('WARNING: Unable to disable the related User Account ID: ".$userid.". Please try again. Possible Error: ".mysqli_error($con)."');";
echo "</script>";
}
} else {
// if we are unable to disable the verification code then something must gone wrong //
echo "<script>alert('WARNING: Unable to disable the Verification Code. Please try again. Possible Error: ".mysqli_error($con)."');";
echo "</script>";
}
}
}
// if the process is entirely over then alert the admin //
echo "<script>alert('Notice: All disable process is now complete. Now returning to Admin Panel.');";
echo "window.location.href='admin_panel.html';</script>";
}
//***END OF PROCESS***//
}
// End of the function: Verification Code's Verification Form: Disable //
?>
<?php
// Begin of the function: Verification Code's Verification Form: Reset //
// First we check the form has submitted or not //
if (isset($_POST['submit-list-resA'])) {
// If it is, then we will retreive data from the input forms //
$verid = $_POST["verid"];
$res_acccode = mysqli_real_escape_string($con, $_POST['res-acccode']);
$res_pw = mysqli_real_escape_string($con, $_POST['res-pw']);
// Taking the current time //
date_default_timezone_set("Etc/GMT-8");
$now = date("Y-m-d H:i:s");
// Variable to store Error Message //
$error = '';
// Sorting out the query related to the function //
// Verify the user is an admin or not //
$VERFYADMIN = "SELECT * FROM user
WHERE status = 2 AND active = 1 AND account_code = '".md5($res_acccode)."' AND password = '".md5($res_pw)."'";
$VERFYADMINQ = mysqli_query($con, $VERFYADMIN);
//***BEGIN OF PROCESS***//
if (mysqli_num_rows($VERFYADMINQ) < 1) {
// if the admin is not verified, then inform the user and send him back to admin panel //
echo "<script>alert('ALERT: Information unable to be verified. Please try again.');";
echo "window.location.href='admin_panel.html';</script>";
exit(0);
} else {
// begin the process of resetting the verification code //
// P.S: Resetting the Verification Code means reset the code back to "factory version", where the user account under the code will be disabled and the verification code itself will be not under any user account //
while (list($key,$val) = @each ($verid)) {
// first we check the verification code exists in database or not //
$VERCODEEX = "SELECT * FROM verification_code
WHERE verification_id = $val";
$VERCODEEXQ = mysqli_query($con, $VERCODEEX);
if (mysqli_num_rows($VERCODEEXQ) < 1) {
// if we are unable to retrieve the data of the verification code then something must gone wrong //
echo "<script>alert('WARNING: Unable to retrieve the data. Please try again.');";
echo "</script>";
} else {
while ($row = mysqli_fetch_array($VERCODEEXQ)) {
// these variables will be used in the latter part //
if (isset($row["user_id_code"])) {
$userid = $row["user_id_code"];
}
}
// if the verification code existing in the database then we will start to resetting the code //
$RESETVER = "UPDATE verification_code SET code_active = 1, code_used = 0, user_id_code = NULL WHERE verification_id = ?";
// then we will start to update the information //
$stmt = $con->prepare($RESETVER);
$stmt->bind_param("i", $val);
$stmt->execute();
if (($stmt->error) == FALSE) {
// if there is no error then close the previous statement //
$stmt->close();
// then if the verification_code is under some user account then we will disable that user //
if (isset($userid)) {
// then we will start to disable the user that was under the verification code //
$suspended_reason = "Account Disabled due to Verification Code being reset by an Admin, ID: ".$_SESSION['user_id'].". For more information please do contact with the Administrator.";
$DISABLEUSER = "UPDATE user SET active = 0, suspended_reason = '".$suspended_reason."', verification_code = NULL WHERE user_id = ?";
// then we will start to update the information //
$stmt = $con->prepare($DISABLEUSER);
$stmt->bind_param("i", $userid);
$stmt->execute();
if (($stmt->error) == FALSE) {
// if there is no error then close the previous statement //
$stmt->close();
} else {
// if we are unable to disable the verification code then something must gone wrong //
echo "<script>alert('WARNING: Unable to disable the related User Account ID: ".$userid.". Please try again. Possible Error: ".mysqli_error($con)."');";
echo "</script>";
}
}
// if we have reached this point then the reset process is a success //
echo "<script>alert('Notice: Reset Successful for Verification ID: ".$val.".');";
echo "</script>";
} else {
// if we are unable to disable the verification code then something must gone wrong //
echo "<script>alert('WARNING: Unable to disable the Verification Code. Please try again. Possible Error: ".mysqli_error($con)."');";
echo "</script>";
}
}
}
// if the process is entirely over then alert the admin //
echo "<script>alert('Notice: All reset process is now complete. Now returning to Admin Panel.');";
echo "window.location.href='admin_panel.html';</script>";
}
//***END OF PROCESS***//
}
// End of the function: Verification Code's Verification Form: Reset //
?>
<?php
// Begin of the function: Verification Code's Verification Form: Delete //
// First we check the form has submitted or not //
if (isset($_POST['submit-list-delA'])) {
// If it is, then we will retreive data from the input forms //
$verid = $_POST["verid"];
$del_acccode = mysqli_real_escape_string($con, $_POST['del-acccode']);
$del_pw = mysqli_real_escape_string($con, $_POST['del-pw']);
// Taking the current time //
date_default_timezone_set("Etc/GMT-8");
$now = date("Y-m-d H:i:s");
// Variable to store Error Message //
$error = '';
// Sorting out the query related to the function //
// Verify the user is an admin or not //
$VERFYADMIN = "SELECT * FROM user
WHERE status = 2 AND active = 1 AND account_code = '".md5($del_acccode)."' AND password = '".md5($del_pw)."'";
$VERFYADMINQ = mysqli_query($con, $VERFYADMIN);
//***BEGIN OF PROCESS***//
if (mysqli_num_rows($VERFYADMINQ) < 1) {
// if the admin is not verified, then inform the user and send him back to admin panel //
echo "<script>alert('ALERT: Information unable to be verified. Please try again.');";
echo "window.location.href='admin_panel.html';</script>";
exit(0);
} else {
// begin the process of resetting the verification code //
// P.S: Resetting the Verification Code means reset the code back to "factory version", where the user account under the code will be disabled and the verification code itself will be not under any user account //
while (list($key,$val) = @each ($verid)) {
// first we check the verification code exists in database or not //
$VERCODEEX = "SELECT * FROM verification_code
WHERE verification_id = $val";
$VERCODEEXQ = mysqli_query($con, $VERCODEEX);
if (mysqli_num_rows($VERCODEEXQ) < 1) {
// if we are unable to retrieve the data of the verification code then something must gone wrong //
echo "<script>alert('WARNING: Unable to retrieve the data. Please try again.');";
echo "</script>";
} else {
while ($row = mysqli_fetch_array($VERCODEEXQ)) {
// these variables will be used in the latter part //
if (isset($row["user_id_code"])) {
$userid = $row["user_id_code"];
}
}
// if the verification code existing in the database then we will start to delete the code //
// But first we have to update the related Foreign Keys: registered_admin_id AND user_id_code to NULL due to SYNTAX in phpMyAdmin that doesn't allow deletion if there's a connected foreign key //
$NULLVER = "UPDATE verification_code SET registered_admin_id = NULL, user_id_code = NULL WHERE verification_id = ?";
// then we will start to update the information //
$stmt = $con->prepare($NULLVER);
$stmt->bind_param("i", $val);
$stmt->execute();
if (($stmt->error) == FALSE) {
// if there is no error then close the previous statement //
$stmt->close();
// if there is a value inside the $userid then this means there is a user under the verification code. We will make the Foreign Key within the table which related to verification_code table to become NULL //
if (isset($userid)) {
// we go to the user table make the Foreign Key: verification_code which related with the verification_code table to NULL so we only can start the deletion process, but depends on whether the user_id_code originally got a value or not //
$NULLUSE = "UPDATE user SET verification_code = NULL WHERE user_id = ?";
// then we will start to update the information //
$stmt = $con->prepare($NULLUSE);
$stmt->bind_param("i", $userid);
$stmt->execute();
if (($stmt->error) == FALSE) {
// if there is no error then close the previous statement //
$stmt->close();
} else {
// if we are unable to update the user's info then something must gone wrong //
echo "<script>alert('WARNING: Unable to update the User_ID: ".$userid.". Please try again. Possible Error: ".mysqli_error($con)."');";
echo "</script>";
$stmt->close();
exit(0);
}
}
// if the Foreign Keys were updated then proceed the deletion process //
$DELETEVER = "DELETE FROM verification_code WHERE verification_id = ?";
// then we will start to delete the code //
$stmt = $con->prepare($DELETEVER);
$stmt->bind_param("i", $val);
$stmt->execute();
if (($stmt->error) == FALSE) {
// if there is no error then close the previous statement //
$stmt->close();
// if there is a value inside the $userid then this means there is a user under the verification code. We will disable that user account based on the concept of our system //
if (isset($userid)) {
// then we will start to disable the user that was under the verification code //
$suspended_reason = "Account Disabled due to Verification Code being deleted by an Admin, ID: ".$_SESSION['user_id'].". For more information please do contact with the Administrator.";
$DISABLEUSER = "UPDATE user SET active = 0, suspended_reason = '".$suspended_reason."', verification_code = NULL WHERE user_id = ?";
// then we will start to update the information //
$stmt = $con->prepare($DISABLEUSER);
$stmt->bind_param("i", $userid);
$stmt->execute();
if (($stmt->error) == FALSE) {
// if there is no error then close the previous statement //
$stmt->close();
} else {
// if we are unable to disable the verification code then something must gone wrong //
echo "<script>alert('WARNING: Unable to disable the related User Account ID: ".$userid.". Please try again. Possible Error: ".mysqli_error($con)."');";
echo "</script>";
$stmt->close();
exit(0);
}
}
// if we have reached this point then the reset process is a success //
echo "<script>alert('Notice: Deletion Successful for Verification ID: ".$val.".');";
echo "</script>";
} else {
// if we are unable to disable the verification code then something must gone wrong //
echo "<script>alert('WARNING: Unable to delete the Verification Code. Please try again. Possible Error: ".mysqli_error($con)."');";
echo "</script>";
}
} else {
// if we are unable to update the verification code's info then something must gone wrong //
echo "<script>alert('WARNING: Unable to update the Verification_ID: ".$val.". Please try again. Possible Error: ".mysqli_error($con)."');";
echo "</script>";
}
}
}
// if the process is entirely over then alert the admin //
echo "<script>alert('Notice: All deletion process is now complete. Now returning to Admin Panel.');";
echo "window.location.href='admin_panel.html';</script>";
}
//***END OF PROCESS***//
}
// End of the function: Verification Code's Verification Form: Delete //
?>
<?php
// Begin of the function: Verification Code's Verification Form: Registration //
// First we check the form has submitted or not //
if (isset($_POST['submit-list-regA'])) {
// If it is, then we will retreive data from the input forms //
$reg_acccode = mysqli_real_escape_string($con, $_POST['reg-acccode']);
$reg_pw = mysqli_real_escape_string($con, $_POST['reg-pw']);
$reg_role = mysqli_real_escape_string($con, $_POST['vercode-role']);
$reg_vercode = mysqli_real_escape_string($con, $_POST['vercode-new']);
// Taking the current time //
date_default_timezone_set("Etc/GMT-8");
$now = date("Y-m-d H:i:s");
// Variable to store Error Message //
$error = '';
// Sorting out the query related to the function //
// Verify the user is an admin or not //
$VERFYADMIN = "SELECT * FROM user
WHERE status = 2 AND active = 1 AND account_code = '".md5($reg_acccode)."' AND password = '".md5($reg_pw)."'";
$VERFYADMINQ = mysqli_query($con, $VERFYADMIN);
//***BEGIN OF PROCESS***//
if (mysqli_num_rows($VERFYADMINQ) < 1) {
// if the admin is not verified, then inform the user and send him back to admin panel //
echo "<script>alert('ALERT: Information unable to be verified. Please try again.');";
echo "window.location.href='admin_panel.html';</script>";
exit(0);
} else {
// begin the process of registering the verification code //
$adminid = $_SESSION["user_id"];
$code_active = 1;
$code_used = 0;
$REGVER = "INSERT INTO verification_code (verification_code, code_active, code_used, code_status, registered_date, registered_admin_id)
VALUES (?,?,?,?,?,?)";
$stmt = $con->prepare($REGVER);
$stmt->bind_param("sssssi", $reg_vercode, $code_active, $code_used, $reg_role, $now, $adminid);
$stmt->execute();
if (($stmt->error) == FALSE) {
// if there is no error then close the previous statement //
$stmt->close();
// if we have reached this point then the registration is a success //
echo "<script>alert('Notice: New verification code registered.');";
echo "</script>";
} else {
// if we are unable to insert the new verification code then something must gone wrong //
echo "<script>alert('WARNING: Unable to register the new verification code. Please try again. Possible Error: ".mysqli_error($con)."');";
echo "</script>";
exit(0);
}
// if the process is entirely over then alert the admin //
echo "<script>alert('Notice: All registration process of the verification code is now complete. Now returning to Admin Panel.');";
echo "window.location.href='admin_panel.html';</script>";
}
//***END OF PROCESS***//
}
// End of the function: Verification Code's Verification Form: Registration //
?>
<?php
// Begin of the function: Verification Code's Verification Form: Enable //
// First we check the form has submitted or not //
if (isset($_POST['submit-list-enableS'])) {
// If it is, then we will retreive data from the input forms //
$verid = $_POST["verid"];
$enable_acccode = mysqli_real_escape_string($con, $_POST['enable-acccode']);
$enable_pw = mysqli_real_escape_string($con, $_POST['enable-pw']);
// Taking the current time //
date_default_timezone_set("Etc/GMT-8");
$now = date("Y-m-d H:i:s");
// Variable to store Error Message //
$error = '';
// Sorting out the query related to the function //
// Verify the user is an admin or not //
$VERFYADMIN = "SELECT * FROM user
WHERE status = 2 AND active = 1 AND account_code = '".md5($enable_acccode)."' AND password = '".md5($enable_pw)."'";
$VERFYADMINQ = mysqli_query($con, $VERFYADMIN);
//***BEGIN OF PROCESS***//
if (mysqli_num_rows($VERFYADMINQ) < 1) {
// if the admin is not verified, then inform the user and send him back to admin panel //
echo "<script>alert('ALERT: Information unable to be verified. Please try again.');";
echo "window.location.href='admin_panel.html';</script>";
exit(0);
} else {
// begin the process of disabling the verification code //
while (list($key,$val) = @each ($verid)) {
// first we check the verification code exists in database or not //
$VERCODEEX = "SELECT * FROM verification_code
WHERE verification_id = $val";
$VERCODEEXQ = mysqli_query($con, $VERCODEEX);
if (mysqli_num_rows($VERCODEEXQ) < 1) {
// if we are unable to retrieve the data of the verification code then something must gone wrong //
echo "<script>alert('WARNING: Unable to retrieve the data. Please try again.');";
echo "</script>";
} else {
while ($row = mysqli_fetch_array($VERCODEEXQ)) {
$code_active = $row["code_active"];
// these variables will be used in the latter part //
if (isset($row["user_id_code"])) {
$userid = $row["user_id_code"];
}
}
// before entering the process we first check the verification code is truly inactive or not //
if ($code_active > 0) {
// if the code is already active then tell the user this ID is already active //
echo "<script>alert('Notice: Verification_ID: ".$val." already active.');";
echo "</script>";
} else {
// if its not then we proceed the process //
// if the verification code existing in the database then we will start to enable the code //
$ENABLEVER = "UPDATE verification_code SET code_active = 1 WHERE verification_id = ?";
// then we will start to update the information //
$stmt = $con->prepare($ENABLEVER);
$stmt->bind_param("i", $val);
$stmt->execute();
if (($stmt->error) == FALSE) {
// if there is no error then close the previous statement //
$stmt->close();
// if the vercode has been reactivated then we have to check and enable the user under the vercode as well //
if (isset($userid)) {
$ENABLEUSER = "UPDATE user SET active = 1 WHERE user_id = ?";
// then we will start to update the information //
$stmt = $con->prepare($ENABLEUSER);
$stmt->bind_param("i", $userid);
$stmt->execute();
if (($stmt->error) == FALSE) {
// if there is no error then close the previous statement //
echo "<script>alert('Notice: User_ID: ".$userid." which under Verification ID: ".$val." is reactivated.');";
echo "</script>";
$stmt->close();
} else {
// if we are unable to disable the verification code then something must gone wrong //
echo "<script>alert('WARNING: Unable to reactivate the related User Account ID: ".$userid.". Please try again. Possible Error: ".mysqli_error($con)."');";
echo "</script>";
}
}
// if we have reached this point then the enable process is a success //
echo "<script>alert('Notice: Enable Successful for Verification ID: ".$val.".');";
echo "</script>";
} else {
// if we are unable to disable the verification code then something must gone wrong //
echo "<script>alert('WARNING: Unable to enable the Verification Code. Please try again. Possible Error: ".mysqli_error($con)."');";
echo "</script>";
}
}
}
}
// if the process is entirely over then alert the admin //
echo "<script>alert('Notice: All enable process is now complete. Now returning to Admin Panel.');";
echo "window.location.href='admin_panel.html';</script>";
}
//***END OF PROCESS***//
}
// End of the function: Verification Code's Verification Form: Enable //
?>