-
Notifications
You must be signed in to change notification settings - Fork 0
/
basket.php
394 lines (326 loc) · 15.9 KB
/
basket.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
<?php
session_start();
//disallows any and all access to this page UNLESS you sign in
include("connect.php");
include("functions.php");
if (!isset($_SESSION['id'])) {
header("Location:login.php");
}
if (!isset($SESSION['basket'])) {
empty($_SESSION['basket']);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Basket </title>
<!--
The following code links this webpage to the css file, JavaScript file and to font awesome
-->
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="https://kit.fontawesome.com/c035b66456.js" crossorigin="anonymous"></script>
<script src="js/scripts.js"></script>
<!-- This is the line you need -->
<link rel="icon" type="image/x-icon" href="images/favicon.ico">
<style>
.row {
display: -ms-flexbox;
/* IE10 */
display: flex;
-ms-flex-wrap: wrap;
/* IE10 */
flex-wrap: wrap;
margin: 0 -16px;
}
.col-25 {
-ms-flex: 25%;
/* IE10 */
flex: 25%;
}
.col-50 {
-ms-flex: 50%;
/* IE10 */
flex: 50%;
}
.col-75 {
-ms-flex: 75%;
/* IE10 */
flex: 75%;
}
.col-25,
.col-50,
.col-75 {
padding: 0 16px;
}
.containerBilling {
background-color: #747474;
padding: 5px 20px 15px 20px;
border-radius: 3px;
}
input[type=text] {
width: 100%;
margin-bottom: 20px;
padding: 12px;
border-radius: 3px;
}
.containerBilling label {
margin-bottom: 10px;
display: block;
}
.containerBilling .icon-container {
margin-bottom: 20px;
padding: 7px 0;
font-size: 24px;
}
label {
color: white;
}
.containerBilling a {
color: #2196F3;
}
.containerBilling hr {
border: 1px solid lightgrey;
}
.containerBilling span.price {
float: right;
color: grey;
}
</style>
</head>
<body>
<!-- MAIN NAV BAR -->
<div class="navbar">
<a href="index.php"><img src="images/Logo.png" class="logo"></a>
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="basicWeb.php">Games</a></li>
<li><a href="aboutUs.php">About Us</a></li>
<li><a href="contactUs.php">Contact Us</a></li>
<li><a href="userorders.php">View My Orders</a></li>
<?php
if (isset($_SESSION["id"])) {
echo "<li><a href='logout.php'>Log Out</a></li>";
} else {
echo "<li><a href='login.php'>Log In</a></li>";
}
if (isset($_SESSION["id"])) {
echo '<li><a href="basket.php"><i class="fa-solid fa-basket-shopping"></i> </a></li>';
} else {
echo '<li><a href="login.php"><i class="fa-solid fa-basket-shopping"></i> </a></li>';
// echo '<li> <script> alert ("You need to login to add to the basket!!!");window.location="basicWeb.php"</script> <i class="fa-solid fa-basket-shopping"></i></li>';
}
?>
</ul>
</div>
<!-- END OFMAIN NAV BAR -->
<script>
</script>
<div class="detailsBoxB">
<!-- BASKET CONTAINING THE BASKET-->
<h2 style="text-align:center; margin-top:10px; color:white;"> Your Basket </h2>
<!--
The following php block checks whether the cart variable is empty, and if so, displays an appropriate message to the user
The else statement displays the contents of the cart variable in a table
-->
<?php
# If the session variable is empty, a suitable message is displayed to the user
if (empty($_SESSION['basket'])) {
?>
<ul>
<?php
echo "<br><br>";
echo "<h2 style='text-align:center;'>Basket is empty, continue shopping </ul></h2>";
echo "<br><br><br><br><br>";
} else {
?>
<!--
The following table displays the contents of the cart
The table also contains a button which allows the user to remove products from the cart
-->
<table class="basket-table">
<thead>
<tr>
<th> PRODUCT </th>
<th> SUBTOTAL
<th> </th>
</tr>
</thead>
<tbody>
<?php
# The following is a session variable which holds the total price of the order
$_SESSION['totalPrice'] = 0;
# The following is a session variable which creates an empty array
$_SESSION['totalProducts'] = array();
# The foreach loop allows us to iterate over the session array
foreach ($_SESSION['basket'] as $keys => $values) {
?>
<!--
The following code displays the php variables derived from the session array
This also contains a button which removes products from the basket
-->
<tr>
<td> <?php echo $values["productName"]; ?> </td>
<td> £<?php echo $values["productPrice"]; ?> </td>
<td>
<!-- The following code is a hyperlink to a php file, which sends the productId -->
<a href="removingFromBasket.php?action=remove&id=<?php echo $values['productId']; ?>">
<div class="removeButton">
<i style="color:white;" class="fa-solid fa-trash"></i>
</div>
</a>
</td>
</tr>
<?php
# The session variable that was created above is updated, by adding the new value and the original value
$_SESSION['totalPrice'] = $_SESSION['totalPrice'] + $values["productPrice"];
# The session array created above is updated, with the current contents and the productId being pushed
array_push($_SESSION['totalProducts'], $values["productId"]);
# This session variabel holds the number of items that are currently stored in the basket
$_SESSION['basketItems'] = count($_SESSION['basket']);
}
?>
</tbody>
</table>
<!--
The following paragraph displays the number of items in the basket, and the total price
Session variables are used to update and display both the price and the number of items
A checkout button has also been included, which will take the user to the checkout page
-->
<h2 style="margin-left:40px;">Number of item(s) in the basket: <?php echo $_SESSION['basketItems'] ?></h2>
<br>
<h2 style="margin-left:40px;"> The total for this order is: £<?php echo $_SESSION['totalPrice'] ?></h2>
<br><br>
<?php
}
?>
<!-- Billing Address -->
<?php
if (isset($_POST['SubmitButton'])) {
$name = $_POST['name'];
$billingemail = $_POST['billingemail'];
$nameOnCard = $_POST['nameOnCard'];
$address = $_POST['address'];
$debitCardNumber = $_POST['debitCardNumber'];
$city = $_POST['city'];
$county = $_POST['county'];
$postcode = $_POST['postcode'];
$expyear = $_POST['expyear'];
$expmonth = $_POST['expmonth'];
$cvv = $_POST['cvv'];
$product = $_POST['productName'];
$productprice = $_POST['price'];
$sql = "insert into `billingdetails` (name, billingemail, nameOnCard, address,debitCardNumber, city, county, postcode, expyear, expmonth, cvv, product,productPrice,date)
values('$name','$billingemail','$nameOnCard','$address','$debitCardNumber','$city','$county ','$postcode','$expyear','$expmonth','$cvv','$product','$productprice',CURRENT_TIME())";
$result = mysqli_query($con, $sql);
if ($result) {
echo "<script> alert('Order Has Been Placed'); window.location ='basicWeb.php'</script>";
} else {
die(mysqli_errno($con));
}
unset($_SESSION['basket']);
}
?>
<h2 style="text-align:center; color:white;">Fill in your details</h2>
<div class="row">
<div class="col-75">
<div class="containerBilling">
<form method="post">
<div class="row">
<div class="col-50">
<h3 style="color:white;">Billing Address</h3>
<label for="name"><i class="fa fa-user"></i> Full Name</label>
<input type="text" class="formInput" id="fname" name="name" placeholder="Kaladin Stormblessed" autocomplete="off">
<label for="email"><i class="fa fa-envelope"></i> Email</label>
<input type="text" class="formInput" id="email" name="billingemail" placeholder="salaris@example.com" autocomplete="off">
<label for="address"><i class="fa fa-address-card-o"></i> Address</label>
<input type="text" class="formInput" id="adr" name="address" placeholder="70A Leoforos Makariou" autocomplete="off">
<label for="city"><i class="fa fa-institution"></i> City</label>
<input type="text" class="formInput" id="city" name="city" placeholder="Aradippou" autocomplete="off">
<div class="row">
<div class="col-50">
<label for="state">County</label>
<input type="text" class="formInput" id="state" name="county" placeholder="West Midlands" autocomplete="off">
</div>
<div class="col-50">
<label for="zip">Post Code</label>
<input type="text" class="formInput" id="zip" name="postcode" placeholder="B23.." autocomplete="off">
</div>
</div>
</div>
<div class="col-50">
<h3 style="color:white;">Payment</h3>
<label for="fname">Accepted Cards</label>
<div class="icon-container">
<i class="fa fa-cc-visa" style="color:navy;"></i>
<i class="fa fa-cc-amex" style="color:blue;"></i>
<i class="fa fa-cc-mastercard" style="color:red;"></i>
<i class="fa fa-cc-discover" style="color:orange;"></i>
</div>
<label for="cname">Name on Card</label>
<input type="text" class="formInput" id="cname" name="nameOnCard" placeholder="Ash Ketchum" autocomplete="off">
<label for="ccnum">Debit card number</label>
<input type="text" class="formInput" id="ccnum" name="debitCardNumber" placeholder="1111-2222-3333-4444" autocomplete="off">
<label for="expmonth">Exp Month</label>
<input type="text" class="formInput" id="expmonth" name="expmonth" placeholder="09" autocomplete="off">
<div class="row">
<div class="col-50">
<label for="expyear">Exp Year</label>
<input type="text" class="formInput" id="expyear" name="expyear" placeholder="2029" autocomplete="off">
</div>
<div class="col-50">
<label for="cvv">CVV</label>
<input type="text" class="formInput" id="cvv" name="cvv" placeholder="999" autocomplete="off">
</div>
</div>
<input type="hidden" name="productName" value="<?php echo $values["productName"]; ?>">
<input type="hidden" name="price" value="<?php echo $values["productPrice"]; ?>">
</div>
</div>
<label>
<input type="checkbox" checked="checked" name="sameadr"> Shipping address same as billing
</label>
<button type="submit" class="submitButton" name="SubmitButton">Place Order</button>
</form>
</div>
</div>
</div>
<!-- Billing Address END -->
</div>
</div>
</div>
</body>
<!---Footer--->
<footer class="footer">
<div class="container">
<div class="row">
<div class="footer-col">
<h4>find us</h4>
<ul>
<li>Store location:</li>
<li>59-61 Station St, Birmingham B5 4DY</li>
</ul>
</div>
<div class="footer-col">
<h4>follow us</h4>
<div class="social-links">
<a href="#"><i class="fab fa-facebook-f"></i></a>
<a href="#"><i class="fab fa-twitter"></i></a>
<a href="#"><i class="fab fa-instagram"></i></a>
</div>
</div>
<div class="footer-col">
<h4>help</h4>
<ul>
<li><a href="/aboutUs.php">about us</a></li>
<li><a href="/contactUs.php">Contact Us</a></li>
<br>
<li>Games4U.org</li>
<li>DISCLAIMER: We do not own these pictures, they belong to their own sources, respectivly.</li>
</ul>
</div>
</div>
</div>
</footer>
<!-- end of footer -->
</html>