-
Notifications
You must be signed in to change notification settings - Fork 1
/
cart.php
282 lines (215 loc) · 8.51 KB
/
cart.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- Important to make website responsive -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Restaurant Website</title>
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> -->
<!-- Link our CSS file -->
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<!-- Navbar Section Starts Here -->
<?php session_start(); require('navbar.php'); ?>
<!-- Navbar Section Ends Here -->
<!-- fOOD sEARCH Section Starts Here -->
<section class="food-search text-center">
<div class="container">
<h1>Cart</h1>
</div>
</section>
<!-- fOOD sEARCH Section Ends Here -->
<!-------------------------------------------------------------------------------------------------------------------------->
<!-------------------------------------- MAIN BODY ------------------------------------------------------------------------->
<!-------------------------------------------------------------------------------------------------------------------------->
<!-------------------------------------------------------------------------------------------------------------------------->
<!-- MAIN CODE TO ACCESS AND OUTPUT EACH ITEM -->
<!-- fOOD cart Section Starts Here -->
<section class="food-menu">
<div class="container">
<h2 class="text-center"></h2>
</div>
<div class="clearfix"></div>
</div>
</section>
<div>
<?php
include 'connect.php';
// // if(isset($_SESSION["cart"])){
// // print_r('HIII');
// // } else {
// // echo '<script>window.location="cart.php"</script>';
// }
// } else {
if(isset($_POST["dic"]) || isset($_POST["q"]))
{
$oid = 0;
$sql= "SELECT oid FROM orders WHERE uid=".$_SESSION["uid"]." AND orderState=0 AND isPaid=0";
$res = $db->query($sql);
if($res==True){while ($obj = $res -> fetch_object()){
$sql1= "DELETE FROM order_details WHERE oid=".intval($obj->oid);
$sql2= "DELETE FROM orders WHERE uid=".$_SESSION["uid"]." AND orderState=0 AND isPaid=0";
$db->query($sql1);
$db->query($sql2);
$_SESSION["oid"] = $obj->oid;
} ;}
if(isset($_POST["q"]))
{
// print_r('HI HereToo'.$_POST["storeCheckout"]);
$sql= "INSERT INTO orders(uid,orderPlaceDate, arriveIn, orderState, orderNote, isPaid, orderedRestaurant)
VALUES
(".$_SESSION["uid"].",NOW(), '35', '0', 'none', '0', 'MCD');";
mysqli_query($db, $sql);
$sql= "SELECT oid FROM orders WHERE uid=".$_SESSION["uid"]." AND orderState=0 AND isPaid=0";
$res = $db->query($sql);
if($res==True){$obj = $res->fetch_object();$oid=$obj->oid;$_SESSION["oid"] = $obj->oid;}
}
if(isset($_POST["q"]))
$decode = json_decode($_POST["storeCheckout"],true);
else
$decode = json_decode($_POST["store"],true);
// print_r($decode);
$total = 0;
echo '<h3>Your Cart</h3>' ;
?>
<table class="table table-striped">
<thead class="thead-dark">
<tr>
<th width="40%">Food Name</th>
<th width="10%">Quantity</th>
<th width="20%">Price Details</th>
<th width="15%">Order Total</th>
<th width="5%">Action</th>
</tr>
</thead>
<?php
foreach($decode as $id => $quan)
{
$temp = $decode;
$sql= "SELECT * FROM menu WHERE mid=".$id;
$res = $db->query($sql);
if($res==True)
{
while ($obj = $res -> fetch_object())
{ //print_r($obj);
if(isset($_POST["q"]))
{
$sql= "INSERT INTO order_details(mid, oid, quantity, item_total) VALUES(".intval($obj->mid).",".intval($oid).",".intval($quan).",".floatval(number_format($quan *
$obj->foodPrice, 2)).")";
mysqli_query($db, $sql);
}
echo '<br><br>';
?>
<tr>
<td><?php echo $obj->foodName; ?></td>
<td><?php echo $quan?></td>
<td>$<?php echo $obj->foodPrice; ?></td>
<td>$<?php echo number_format($quan *
$obj->foodPrice, 2); ?></td>
<?php if(!isset($_POST["q"])) {?>
<td><form method="post" action="cart.php?action=dic">
<input type="hidden" name="store" value=<?php unset($temp[$obj->mid]); echo json_encode($temp); ?> id="store" />
<input class="btn btn-primary" id="del" name="dic" type = "submit" value='Remove' />
</form>
<?php }?>
</td>
</tr>
<?php
$total = $total + ($quan * $obj->foodPrice);
}}}
?>
<tr>
<td colspan="3" align="right">Total</td>
<td align="right">$<?php echo number_format($total, 2); ?></td>
<td></td>
</tr>
</table>
<?php if(isset($_POST["q"]))
{
$sql= "UPDATE orders
SET order_total =".number_format($total, 2).", orderNote=".json_encode($_POST['note'])."
WHERE oid=".intval($_SESSION['oid'])." AND uid=".intval($_SESSION['uid']).";";
mysqli_query($db, $sql);
}
?>
<?php
}
?>
<?php
// if(isset($_SESSION["cart"])){
// unset($_SESSION["cart"]);
// } else {
// $item_array = array(
// 'food_id' => $_GET["id"],
// 'item_name' => $_POST["item_name"],
// 'item_price' => $_POST["item_price"],
// 'item_id' => $_POST["item_id"],
// 'item_quantity' => $_POST["quantity"]
// );
// $_SESSION["cart"]= $item_array;} -->
// if(isset($_POST["add"])){
// if(isset($_SESSION["cart"])){
// $item_array_id = array_column($_SESSION["cart"], "food_id");
// if(!in_array($_GET["id"], $item_array_id)){
// $count = count($_SESSION["cart"]);
// $item_array = array(
// 'food_id' => $_GET["id"],
// 'item_name' => $_POST["item_name"],
// 'item_price' => $_POST["item_price"],
// 'item_id' => $_POST["item_id"],
// 'item_quantity' => $_POST["quantity"]
// );
// $_SESSION["cart"][$count] = $item_array;
// } else {
// echo '<script>window.location="cart.php"</script>';
// }
// } else {
// $item_array = array(
// 'food_id' => $_GET["id"],
// 'item_name' => $_POST["item_name"],
// 'item_price' => $_POST["item_price"],
// 'item_id' => $_POST["item_id"],
// 'item_quantity' => $_POST["quantity"]
// );
// $_SESSION["cart"][0] = $item_array;
// }
// }
//?>
<?php
if(!isset($_POST["q"])) {
echo '
<form method="post" action="cart.php?action=q">
<input id="note" name="note" type = "textbox" style= "height: 42px; width : 300px;" placeholder= "Add Notes(optional)" />
<input type="hidden" name="storeCheckout" value='.json_encode($decode).' id="store" />
<input class="btn btn-primary" id="del" name="q" type = "submit" value="Checkout" />
</form>';}
include 'payment.php';
?>
</div>
<!-- fOOD cart Section Ends Here -->
<!-- social Section Starts Here -->
<section class="social">
<div class="container text-center">
<ul>
<li>
<a href="#"><img src="https://img.icons8.com/fluent/50/000000/facebook-new.png"/></a>
</li>
<li>
<a href="#"><img src="https://img.icons8.com/fluent/48/000000/instagram-new.png"/></a>
</li>
<li>
<a href="https://github.com/keerat21"><img src="images/gitIcon.gif" width="50" height="50"/></a>
</li>
</ul>
</div>
</section>
<!-- social Section Ends Here -->
<!-- footer Section Starts Here -->
<section class="footer">
<div class="container text-center">
<p>All rights reserved. University project.Current page work done onit By <a href="https://github.com/keerat21">Keerat Tanwar</a></p>
</div>
</section>
</body>
</html>