-
Notifications
You must be signed in to change notification settings - Fork 1
/
brand-list-function.php
388 lines (370 loc) · 19.1 KB
/
brand-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
<?php
// 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: Brand's Verification Form: Disable //
// First we check the form has submitted or not //
// P.S: Did not change any of the variable names because its unecessary //
if (isset($_POST['submit-list-dis-bran'])) {
// If it is, then we will retreive data from the input forms //
$branid = $_POST["branid"];
$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 brand //
while (list($key,$val) = @each ($branid)) {
// first we check the brand exists in database or not //
$VERCODEEX = "SELECT * FROM meal_brand
WHERE brand_id = $val AND active = 1";
$VERCODEEXQ = mysqli_query($con, $VERCODEEX);
if (mysqli_num_rows($VERCODEEXQ) < 1) {
// if we are unable to retrieve the data of the brand then something must gone wrong //
echo "<script>alert('WARNING: Unable to retrieve the data, or the record is already disabled. Please try again.');";
echo "</script>";
} else {
// if the brand existing in the database then we will start to disable the record //
$DISABLEVER = "UPDATE meal_brand SET active = 0 WHERE brand_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, any meal which is under the brand that is not active will automatically disabled //
$DISABLEUSER = "UPDATE meal SET active = 0 WHERE meal_brand_id = ?";
// then we will start to update the information //
$stmt = $con->prepare($DISABLEUSER);
$stmt->bind_param("i", $val);
$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 Brand ID: ".$val.".');";
echo "</script>";
} else {
// if we are unable to disable the brand then something must gone wrong //
echo "<script>alert('WARNING: Unable to disable the related meal. Please try again. Possible Error: ".mysqli_error($con)."');";
echo "</script>";
}
} else {
// if we are unable to disable the brand then something must gone wrong //
echo "<script>alert('WARNING: Unable to disable the brand. 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: Brand's Verification Form: Delete //
// First we check the form has submitted or not //
if (isset($_POST['submit-list-del-bran'])) {
// If it is, then we will retreive data from the input forms //
$branid = $_POST["branid"];
$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 deleting the brand //
while (list($key,$val) = @each ($branid)) {
// first we check the brand exists in database or not //
$VERCODEEX = "SELECT * FROM meal_brand
WHERE brand_id = $val";
$VERCODEEXQ = mysqli_query($con, $VERCODEEX);
if (mysqli_num_rows($VERCODEEXQ) < 1) {
// if we are unable to retrieve the data of the brand then something must gone wrong //
echo "<script>alert('WARNING: Unable to retrieve the data of the brand. Please try again.');";
echo "</script>";
} else {
// if the brand existing in the database then we will start to delete the code //
// But first we have to update the related Foreign Keys: admin_id to NULL due to SYNTAX in phpMyAdmin that doesn't allow deletion if there's a connected foreign key //
$NULLVER = "UPDATE meal_brand SET admin_id = NULL WHERE brand_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();
// now we go to the meal table make the Foreign Key: meal_brand_id which related with the meal_brand table to NULL and disable them at the same time so we only can start the deletion process, and disable them at the same time since under our system's concept any meal thats under the related brand once deleted/disabled, will be disabled as well //
$NULLUSE = "UPDATE meal SET meal_brand_id = NULL, active = 0 WHERE meal_brand_id = ?";
// then we will start to update the information //
$stmt = $con->prepare($NULLUSE);
$stmt->bind_param("i", $val);
$stmt->execute();
if (($stmt->error) == FALSE) {
// if there is no error then close the previous statement //
$stmt->close();
// the finally, set the final table that contain the Foreign Key: meal_brand_id from transaction_record table //
// now we go to the meal table make the Foreign Key: meal_brand_id which related with the meal_brand table to NULL and disable them at the same time so we only can start the deletion process //
$NULLRECORD = "UPDATE transaction_record SET meal_brand_id = NULL WHERE meal_brand_id = ?";
// then we will start to update the information //
$stmt = $con->prepare($NULLRECORD);
$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 Foreign Keys were updated then proceed the deletion process //
$DELETEVER = "DELETE FROM meal_brand WHERE brand_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 we have reached this point then the reset process is a success //
echo "<script>alert('Notice: Deletion Successful for Brand ID: ".$val.".');";
echo "</script>";
} else {
// if we are unable to delete the brand then something must gone wrong //
echo "<script>alert('WARNING: Unable to delete the brand. Please try again. Possible Error: ".mysqli_error($con)."');";
echo "</script>";
}
} else {
// if we are unable to update the user's info then something must gone wrong //
echo "<script>alert('WARNING: Unable to update the related transaction record table. Please try again. Possible Error: ".mysqli_error($con)."');";
echo "</script>";
}
} else {
// if we are unable to update the user's info then something must gone wrong //
echo "<script>alert('WARNING: Unable to update the related meals. 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 Brand_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: Brand's Verification Form: Delete //
?>
<?php
// Begin of the function: Brand's Verification Form: Registration //
// First we check the form has submitted or not //
if (isset($_POST['submit-list-reg-bran'])) {
// 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_bran_name = mysqli_real_escape_string($con, $_POST['reg-bran-name']);
// defining the input of the image //
if(file_exists($_FILES['bran-img']['tmp_name']) || is_uploaded_file($_FILES['bran-img']['tmp_name'])) {
// Define Photo Uploads' path and variables //
$target_dir = "/APU/SDP/image/";
$target_file = $target_dir . basename($_FILES["bran-img"]["name"]);
$imageFileType = pathinfo ($target_file, PATHINFO_EXTENSION);
//check if image file is a actual image or fake image
$check = getimagesize($_FILES["bran-img"]["tmp_name"]);
if($check !== false) {
echo "<script>alert('File is an image - " . $check["mime"] . ".');</script>";
} else {
echo "<script>alert('File is not an image.Please try again!');</script>";
echo "window.location.href='admin_panel.html';</script>";
}
//Allow certain file formats
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
echo "<script>alert('Sorry, only JPG, JPEG, PNG & GIF files are allowed.Please try again!');</script>";
echo "window.location.href='admin_panel.html';</script>";
}
} else {
$target_file = NULL;
}
// 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 brand //
$adminid = $_SESSION["user_id"];
$code_active = 1;
$code_used = 0;
$REGBRAN = "INSERT INTO meal_brand (brand_image, brand_name, registered_date, admin_id, active)
VALUES (?,?,?,?,?)";
$stmt = $con->prepare($REGBRAN);
$stmt->bind_param("sssis", $target_file, $reg_bran_name, $now, $adminid, $code_active);
$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 brand registered.');";
echo "</script>";
} else {
// if we are unable to insert the new brand then something must gone wrong //
echo "<script>alert('WARNING: Unable to register the new brand. 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 brand 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: Brand's Verification Form: Enable //
// First we check the form has submitted or not //
if (isset($_POST['submit-list-enable-bran'])) {
// If it is, then we will retreive data from the input forms //
$branid = $_POST["branid"];
$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 enabling the brand //
while (list($key,$val) = @each ($branid)) {
// first we check the verification code exists in database or not //
$VERCODEEX = "SELECT * FROM meal_brand
WHERE brand_id = $val";
$VERCODEEXQ = mysqli_query($con, $VERCODEEX);
if (mysqli_num_rows($VERCODEEXQ) < 1) {
// if we are unable to retrieve the data of the brand then something must gone wrong //
echo "<script>alert('WARNING: Unable to retrieve the data of the brand. Please try again.');";
echo "</script>";
} else {
while ($row = mysqli_fetch_array($VERCODEEXQ)) {
$brand_active = $row["active"];
}
// before entering the process we first check the brand is truly inactive or not //
if ($brand_active > 0) {
// if the code is already active then tell the user this ID is already active //
echo "<script>alert('Notice: Brand_ID: ".$val." already active.');";
echo "</script>";
} else {
// if its not then we proceed the process //
// if the brand existing in the database then we will start to enable the code //
$ENABLEVER = "UPDATE meal_brand SET active = 1 WHERE brand_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();
// now we start to enable back the meals under the related brand //
$CHECKMEAL = "SELECT * FROM meal WHERE meal_brand_id = $val";
$CHECKMEALQ = mysqli_query($con, $CHECKMEAL);
if (mysqli_num_rows($CHECKMEALQ) < 1) {
// if we are unable to retrieve the data of the brand then something must gone wrong, or there's no meal under the brand yet //
echo "<script>alert('Notice: There's no meal under the related Brand ID: ".$val.".');";
echo "</script>";
} else {
// if there is then we will start to enable the related meals back //
$ENABLEMEAL = "UPDATE meal SET active = 1 WHERE meal_brand_id = ?";
// then we will start to update the information //
$stmt = $con->prepare($ENABLEMEAL);
$stmt->bind_param("i", $val);
$stmt->execute();
if (($stmt->error) == FALSE) {
// if there is no error then close the previous statement //
$stmt->close();
echo "<script>alert('Notice: Enable Successful for meals under Brand ID: ".$val.".');";
echo "</script>";
} else {
// if we are unable to enable the meals then something must gone wrong //
echo "<script>alert('WARNING: Unable to enable the meals under Brand ID: ".$val.". 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 Brand ID: ".$val.".');";
echo "</script>";
} else {
// if we are unable to enable the brand then something must gone wrong //
echo "<script>alert('WARNING: Unable to enable the Brand 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 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 //
?>