-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproducts.php
542 lines (449 loc) · 19.5 KB
/
products.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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
<!DOCTYPE html>
<html lang="en">
<?php
session_start();
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
$mail = new PHPMailer(true);
$hostName = "localhost";
$userName = "root";
$password = "";
$databaseName = "food_park";
$conn = new mysqli($hostName, $userName, $password, $databaseName);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$select_query2 = "select * from shops";
$result_select2 = mysqli_query($conn, $select_query2);
?>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link href="https://fonts.googleapis.com/css?family=Poppins:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i&display=swap" rel="stylesheet">
<link rel="icon" href="assets/images/icon.png" type="image/gif" sizes="16x16">
<title>A's Kai Garden Foodpark</title>
<link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/font-awesome.css">
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<button style="right: 0;position:fixed;bottom:0; padding: 10px; margin: 10px; Border: none; Background-color: #ed3b3b; color: white; font-weight: bold; border-radius: 10px; font-size: 20px;" type="button" class="btn btn-primary" data-toggle="modal" data-target="#itemModal"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Cart</button>
<!-- ***** Preloader Start ***** -->
<div id="js-preloader" class="js-preloader">
<div class="preloader-inner">
<span class="dot"></span>
<div class="dots">
<span></span>
<span></span>
<span></span>
</div>
</div>
</div>
<!-- ***** Preloader End ***** -->
<!-- ***** Header Area Start ***** -->
<header class="header-area header-sticky">
<div class="container">
<div class="row">
<div class="col-12">
<nav class="main-nav">
<!-- ***** Logo Start ***** -->
<a href="index.php" class="logo">A's Kai Garden <em> Food Park</em></a>
<!-- ***** Logo End ***** -->
<!-- ***** Menu Start ***** -->
<ul class="nav">
<li><a href="index.php">Home</a></li>
<li><a href="products.php" class="active">Products</a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">About</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="about.php">About Us</a>
<a class="dropdown-item" href="blog.php">Blog</a>
</div>
</li>
<li><a href="contact.php">Contact</a></li>
</ul>
<a class='menu-trigger'>
<span>Menu</span>
</a>
<!-- ***** Menu End ***** -->
</nav>
</div>
</div>
</div>
</header>
<!-- ***** Header Area End ***** -->
<!-- ***** Call to Action Start ***** -->
<section class="section section-bg" id="call-to-action" style="background-image: url(assets/images/banner-image-1-1920x500.jpg)">
<div class="container">
<div class="row">
<div class="col-lg-10 offset-lg-1">
<div class="cta-content">
<br>
<br>
<h2>Our <em>Products</em></h2>
<p>Explore and Search for our Products</p>
</div>
</div>
</div>
</div>
</section>
<!-- ***** Call to Action End ***** -->
<!-- ***** Fleet Starts ***** -->
<section class="section" id="trainers">
<div class="container">
<br>
<br>
<form action ='' method = "GET">
<div class="row">
<div class="input-group mb-3 col-10">
<input type="text" name="search" value="<?php if(isset($_GET['search'])) {echo $_GET['search']; }?>" class="form-control" placeholder="Search Menu">
<button type="submit" class="btn btn-primary">Search</button>
</div>
<div class="col-2 text-right">
<a href="products.php" class="btn btn-primary w-75">Reset</a>
</div>
</div>
<div class="row">
<div class="col md-6">
<div class="input-group mb-3">
<select id="store" name="store" class="form-control cc-cvc" value="" >
<option value="">---Select Option---</option>
<?php while($row2 = mysqli_fetch_array($result_select2)):;?>
<option value="<?php echo $row2[0];?>"><?php echo $row2[1];?></option>
<?php endwhile;?>
</select>
<button type = "submit" class = "btn btn-primary">
Filter
</button>
</div>
</div>
<div class="col md-6">
<div class="input-group mb-3">
<select name = "sort_alpha_price" class = "form-control">
<option value="">---Select Option---</option>
<option value="a-z" <?php if (isset($_GET['sort_alpha_price']) && $_GET['sort_alpha_price'] == "a-z"){echo "Selected"; }?>> A-Z (Ascending Order)</option>
<option value="z-a" <?php if (isset($_GET['sort_alpha_price']) && $_GET['sort_alpha_price'] == "z-a"){echo "Selected"; }?>> Z-A (Descending Order)</option>
<option value="l-h" <?php if (isset($_GET['sort_alpha_price']) && $_GET['sort_alpha_price'] == "l-h"){echo "Selected"; }?>> Lowest-Highest Price (Ascending Order)</option>
<option value="h-l" <?php if (isset($_GET['sort_alpha_price']) && $_GET['sort_alpha_price'] == "h-l"){echo "Selected"; }?>> Highest-Lowest Price (Descending Order)</option>
</select>
<button type = "submit" class = "btn btn-primary">
Sort
</button>
</div>
</div>
</div>
</form>
<div class="row">
<?php
$hostName = "localhost";
$userName = "root";
$password = "";
$databaseName = "food_park";
$conn = new mysqli($hostName, $userName, $password, $databaseName);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$db= $conn;
$tableName="foods";
$columns= ['foodID', 'foodName','foodPrice','foodType',];
$fetchData = fetch_data($db, $tableName, $columns);
function fetch_data($db, $tableName, $columns){
if(empty($db)){
$msg= "Database connection error";
}elseif (empty($columns) || !is_array($columns)) {
$msg="columns Name must be defined in an indexed array";
}elseif(empty($tableName)){
$msg= "Table Name is empty";
}else{
$columnName = implode(", ", $columns);
$sort_parameter = "foodID";
$sort_option ="ASC";
$store_filter = "";
if(isset($_GET['sort_alpha_price']))
{
if($_GET['sort_alpha_price'] == "a-z")
{
$sort_parameter = "foodName";
$sort_option = "ASC";
}
elseif($_GET['sort_alpha_price'] == "z-a")
{
$sort_parameter = "foodName";
$sort_option = "DESC";
}
elseif($_GET['sort_alpha_price'] == "l-h")
{
$sort_parameter = "foodPrice";
$sort_option = "ASC";
}
elseif($_GET['sort_alpha_price'] == "h-l")
{
$sort_parameter = "foodPrice";
$sort_option = "DESC";
}
}
if (isset($_GET['search']))
{
$search_value = $_GET["search"];
$store_filter = $_GET['store'];
if ($store_filter == ""){
$query = "SELECT ".$columnName." FROM $tableName"." WHERE foodName LIKE '%$search_value%' ORDER BY $sort_parameter $sort_option";
}
else{
$query = "SELECT ".$columnName." FROM $tableName"." WHERE foodName LIKE '%$search_value%' AND RID = $store_filter ORDER BY $sort_parameter $sort_option";
}
if(empty($query)){
$msg= "Product not found.";
}
}
else{
$query = "SELECT ".$columnName." FROM $tableName"." ORDER BY $sort_parameter $sort_option";
}
$result = $db->query($query);
if($result== true){
if ($result->num_rows > 0) {
$row= mysqli_fetch_all($result, MYSQLI_ASSOC);
$msg= $row;
} else {
$msg= "No Data Found";
}
}else{
$msg= mysqli_error($db);
}
}
return $msg;
}
if(is_array($fetchData)){
$sn=1;
foreach($fetchData as $data){
?>
<div class="col-lg-4">
<form action="" method="post">
<div class="trainer-item">
<div class="image-thumb">
<img src="assets/prodimg/<?php echo $data['foodName']??'';?>.jpg" alt="">
</div>
<div class="down-content">
<span>
<?php echo $data['foodPrice']??''; ?>
</span>
<h4><?php echo $data['foodName']??''; ?></h4>
<p><?php echo $data['foodType']??''; ?></p>
<button type="submit" class="btn btn-primary" data-toggle="modal" data-target="#itemModal"
data-name="<?php echo $data['foodName']?>"
data-type="<?php echo $data['foodType']?>"
data-price="<?php echo $data['foodPrice']?>"
data-index="<?php echo $sn?>" name="<?php echo $sn?>btn">
+ Add to Cart
</button>
</div>
<?php
if(isset($_POST[$sn.'btn'])){
$conn->query("INSERT INTO cart (fname, ftype, fprice) VALUES ('".$data['foodName']."','".$data['foodType']."','".$data['foodPrice']."')");
echo "<script>alert('Added to cart!')</script>;";
}?>
</div>
</form>
</div>
<?php
$sn++;}}else{
echo $fetchData;
}?>
</div>
<br>
<nav>
<ul class="pagination pagination-lg justify-content-center">
<li class="page-item">
<a class="page-link" href="#" aria-label="Previous">
<span aria-hidden="true">«</span>
<span class="sr-only">Previous</span>
</a>
</li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item">
<a class="page-link" href="#" aria-label="Next">
<span aria-hidden="true">»</span>
<span class="sr-only">Next</span>
</a>
</li>
</ul>
</nav>
</div>
</section>
<?php
if(isset($_POST[$sn.'btn'])){
$_SESSION['name'] = "qqqqqq";
echo "<script>alert('Sent!')</script>;";
}
?>
<!-- ***** Fleet Ends ***** -->
<!-- ***** Cart Modal Start **** -->
<form action="" method="post">
<div class="modal fade m-6" id="itemModal" tabindex="-1" role="dialog" aria-labelledby="itemModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content p-4">
<div class="modal-header">
<h4>Cart</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="container-fluid">
<div class="row">
<table class="table table-bordered p-2">
<thead>
<th scope="col">Name</th>
<th scope="col">Type</th>
<th scope="col">Price</th>
</tr>
</thead>
<tbody>
<div class="row m-2">
<?php
$db= $conn;
$tableName="cart";
$columns= ['id', 'fname', 'ftype', 'fprice'];
function fetch_data30($db, $tableName, $columns){
if(empty($db)){
$msg= "Database connection error";
}elseif (empty($columns) || !is_array($columns)) {
$msg="columns Name must be defined in an indexed array";
}elseif(empty($tableName)){
$msg= "Table Name is empty";
}else{
$columnName = implode(", ", $columns);
$query = "SELECT ".$columnName." FROM $tableName"." ORDER BY id Asc";
$result = $db->query($query);
if($result== true){
if ($result->num_rows > 0) {
$row= mysqli_fetch_all($result, MYSQLI_ASSOC);
$msg= $row;
} else {
$msg= "Your Cart is Empty.";
}
}else{
$msg= mysqli_error($db);
}
}
return $msg;
}
$fetchData = fetch_data30($db, $tableName, $columns);
if(is_array($fetchData)){
$sn=1;
foreach($fetchData as $data){
?>
<tr>
<th scope="col"><?php echo $data['fname'];?></th>
<th scope="col"><?php echo $data['ftype'];?></th>
<th scope="col"><?php echo $data['fprice'];?></th>
</tr>
<?php
$sn++;}}else{
echo $fetchData;
}?>
</div>
</tbody>
</table>
</div>
<div class="form-group row">
<label for="customerName" class="col-sm-4 col-form-label">Name</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="customerName" name="cName" placeholder="Enter name">
</div>
</div>
<div class="form-group row">
<label for="customerNo" class="col-sm-4 col-form-label">Phone No.</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="customerNo" name="cNum" placeholder="Enter phone number">
</div>
</div>
<div class="row text-center">
<button type="submit" name="reset" style="margin:10px; border: none; Background-color: black; color: white; font-weight: bold; height: 40px;">Reset Cart</button>
<button type="submit" name="checkout" style="margin:10px; border: none; Background-color: black; color: white; font-weight: bold; height: 40px;">Checkout</button>
</div>
</div>
</div>
</div>
</div>
</form>
<?php
if(isset($_POST['reset'])){
$conn->query("DELETE FROM cart");
echo "<script>alert('Cart Resetted!')</script>;";
}
if(isset($_POST['checkout'])){
$selectQuery = "SELECT * FROM `cart` ORDER BY `id` ASC";
$result = mysqli_query($conn,$selectQuery);
if(mysqli_num_rows($result) > 0){
while($row = $result->fetch_assoc()){
$string = $string."<br>Item: ".$row['fname']." <br>Price: ".$row['fprice']."<br>";
}
}else{
echo "<script>console.log('try')</script>";
}
$csname = $_POST['cName'];
$csnum = $_POST['cNum'];
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'qjvqmndusrdvsscj';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('[email protected]');
$mail->addAddress("[email protected]");
$mail->isHTML(true);
$mail->Subject = "New Order from $csname";
$mail->Body = "<b>Order</b>".$string."<hr><b>Contact Information</b><br>Name: $csname <br>Phone No.: $csnum";
$mail->send();
echo "<script>alert('Sent!')</script>;";
$conn->query("INSERT INTO history (hfname, hftype, hfprice) SELECT fname, ftype, fprice from cart");
$conn->query("DELETE FROM cart");
echo "window.location.href = 'products.php'";
}
?>
</div>
</div>
</div>
<!-- ***** Cart Modal End **** -->
<!-- ***** Footer Start ***** -->
<footer>
<div class="container">
<div class="row">
<div class="col-lg-12">
<p>
BSU - CICS Lipa - GROUP Project
</p>
</div>
</div>
</div>
</footer>
<!-- jQuery -->
<script src="assets/js/jquery-2.1.0.min.js"></script>
<!-- Bootstrap -->
<script src="assets/js/popper.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<!-- Plugins -->
<script src="assets/js/scrollreveal.min.js"></script>
<script src="assets/js/waypoints.min.js"></script>
<script src="assets/js/jquery.counterup.min.js"></script>
<script src="assets/js/imgfix.min.js"></script>
<script src="assets/js/mixitup.js"></script>
<script src="assets/js/accordions.js"></script>
<!-- Global Init -->
<script src="assets/js/custom.js"></script>
</body>
</html>
<?php
// Account details
;
?>
</body>
</html>