-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshipping.php
424 lines (375 loc) · 14.2 KB
/
shipping.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
<?php
// session_start();
include('server.php');
if (!isset($_SESSION['username'])) {
$_SESSION['msg'] = "You must log in first";
header('location: signin.php');
}
if(!isset($_SESSION['checkout']))
{
$_SESSION['msg'] = "You must add items to your cart first";
header('location: pantry.php');
}
$weight = 0;
$price = 0;
$tax = 0;
$orderTot = 0;
if(isset($_SESSION["weight"]) && isset($_SESSION["price"]) && isset($_SESSION["tax"]) && isset($_SESSION["orderTot"]))
{
$weight = $_SESSION["weight"];
$price = $_SESSION["price"];
$tax = $_SESSION["tax"];
$orderTot = $_SESSION["orderTot"];
}
// User Profile Contents
$username = $_SESSION['username']['username'];
$query = "SELECT * FROM customer_profile WHERE username='$username';";
$results = mysqli_query($db, $query);
if(mysqli_num_rows($results) == 1) {
$profile = mysqli_fetch_assoc($results);
$firstName = $profile['first_name'];
$lastName = $profile['last_name'];
$address = $profile['address'];
$city = $profile['city'];
$state = $profile['state'];
$zipcode = $profile['zipcode'];
$card_type = $profile['card_type'];
$card_number = $profile['card_number'];
$cvc = $profile['cvc'];
$expiration_date = $profile['expiration_date'];
} else if(mysqli_num_rows($results) == 0) {
$profile = mysqli_fetch_assoc($results);
$firstName = "-";
$lastName = "-";
$address = "-";
$city = "-";
$state = "-";
$zipcode = "-";
$card_type = "-";
$card_number = "-";
$cvc = "-";
$expiration_date = "-";
}
if(!empty($_GET["action"]))
{
switch($_GET["action"])
{
case "proceed":
$_SESSION["proceed"] = "true";
header('location: payment.php');
break;
case "pantry":
unset($_SESSION["checkout"]);
header('location: pantry.php');
break;
case "home":
unset($_SESSION["complete"]);
unset($_SESSION["checkout"]);
unset($_SESSION["proceed"]);
unset($_SESSION["confirm"]);
header('location: home.php');
break;
case "about":
unset($_SESSION["complete"]);
unset($_SESSION["checkout"]);
unset($_SESSION["proceed"]);
unset($_SESSION["confirm"]);
header('location: home.php#about');
break;
case "team":
unset($_SESSION["complete"]);
unset($_SESSION["checkout"]);
unset($_SESSION["proceed"]);
unset($_SESSION["confirm"]);
header('location: home.php#about');
break;
case "contact":
unset($_SESSION["complete"]);
unset($_SESSION["checkout"]);
unset($_SESSION["proceed"]);
unset($_SESSION["confirm"]);
header('location: home.php#contact');
break;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<!-- Site Properties -->
<title>Something Simple</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.3/semantic.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.3/semantic.css">
<link href="https://fonts.googleapis.com/css?family=Pacifico" rel="stylesheet">
<style type="text/css">
body {
min-height: 700px;
padding: 0.5em 0em;
background: #F5EAD1 url('images/web-graphics/leaf-watermark.png');
background-size: 600px;
background-repeat: no-repeat;
background-position: left bottom;
left: -2em;
bottom: -2em;
}
#shipping .container {
margin-bottom: 2em;
}
#shipping .container .header span {
font-family: 'Pacifico', cursive;
}
#shipping .container .header i {
padding: 0 0.5em;
}
#shipping .container .right .button {
margin: 0 1em !important;
}
#shipping .navbar .container .right h3 {
margin: 0 1em !important;
}
#shipping .container .row h1 {
font-size: 5em;
margin-bottom: 0.5em;
font-family: 'Pacifico', cursive;
}
#shipping .container .message {
margin-bottom: 2em;
}
#shipping .container .field {
margin-bottom: 1em;
}
#shipping .container .column {
margin-bottom: 0;
}
/* .image {
width: 217.5px;
height: 217.5px;
} */
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.3/semantic.js"></script>
</head>
<body>
<div class="pusher">
<!-- MASTER HEAD -->
<section id="shipping">
<!-- NAV BAR -->
<div class="navbar">
<div class="ui container">
<div class="ui large secondary menu">
<div class="header item">
<span>something simple.</span>
<i class="leaf icon"></i>
</div>
<a class="item" href="shipping.php?action=home">Home</a>
<a href="shipping.php?action=about" class="item">About</a>
<a href="shipping.php?action=team" class="item">Team</a>
<a href="shipping.php?action=contact" class="item">Contact</a>
<div class="right item">
<h3>Welcome, <?php echo $_SESSION['username']['username']; ?>!</h3>
<a class="ui primary button" href="profile.php">Profile</a>
<a class="ui negative button" href="pantry.php?action=logout">Log Out</a>
</div>
</div>
</div>
</div>
<div class="ui container">
<div class="row">
<h1>Shipping</h1>
</div>
<div class="row">
<div class="ui four small steps">
<a href="shipping.php?action=pantry" class="completed link step">
<i class="cart icon"></i>
<div class="content">
<div class="title">Pantry</div>
<div class="description">Choose items to order</div>
</div>
</a>
<div class="active step">
<i class="truck icon"></i>
<div class="content">
<div class="title">Shipping</div>
<div class="description">Choose your shipping options</div>
</div>
</div>
<div class="disabled step">
<i class="payment icon"></i>
<div class="content">
<div class="title">Billing</div>
<div class="description">Enter billing information</div>
</div>
</div>
<div class="disabled step">
<i class="info icon"></i>
<div class="content">
<div class="title">Confirm Order</div>
</div>
</div>
</div>
</div>
</div>
<div class="ui raised segment container">
<div class="ui grid">
<div class="ui ten wide column">
<div class="ui info message">
Please enter your shipping information.
</div>
<div class="ui container">
<form method="post" actions="shipping.php" class="ui form">
<div class="ui grid">
<div class="eight wide column">
<div class="field">
<label>First Name</label>
<input type="text" name="first_name" value=<?php echo $firstName; ?>>
<input type="hidden" name="username" value=<?php echo $username;?>>
</div>
</div>
<div class="eight wide column">
<div class="field">
<label>Last Name</label>
<input type="text" name="last_name" value=<?php echo $lastName; ?>>
<input type="hidden" name="username" value=<?php echo $username;?>>
</div>
</div>
</div>
<!-- CARDHOLDER'S NAME -->
<!-- CARDHOLDER'S ADDRESS -->
<div class="field">
<label>Address</label>
<input type="text" name="address" id="street_number" onFocus="geolocate()" value="<?php echo $address; ?>">
</div>
<div class="ui grid">
<div class="ui nine wide column field">
<label>City</label>
<input type="text" name="city" id = "locality" value="<?php echo $city; ?>">
</div>
<div class="ui three wide column field">
<label>State</label>
<input type="text" name="state" id = "administrative_area_level_1" value="<?php echo $state; ?>">
</div>
<div class="ui four wide column field">
<label>Zip Code</label>
<input type="text" name="zipcode" id="postal_code" value="<?php echo $zipcode; ?>">
</div>
<div class="ui left aligned container">
<button type="submit" class="ui big green submit button" onmouseover="inRangeValidation()" name="shipping_update">Save</button>
</div>
<script>
// Validation for checking if the address is in the range of two county, Santa Clara and S
function inRangeValidation(){
//All Cities in Santa Clara County
var SantaClaraCounty = ["campbell", "cupertino", "gilroy", "los altos", "milpitas", "monta sereno", "morgan hill", "mountain view", "palo alto", "san jose", "santa clara", "sratoga", "sunnyvale"];
//All Cities in San Mateo County
var SanMateoCounty = ["atherton","belmont", "brisbane", "burlingame", "colma", "daly city", "east palo alto", "foster city", "half moon bay", "hillsborough", "menlo park", "millbrae", "pacifica", "portola valley", "redwood city", "san bruno", "san carlos", "san mateo", "searsville", "south san francisco" , "woodside"];
// Checking
if(!SantaClaraCounty.includes(document.getElementById("locality").value.toLowerCase()) && !SanMateoCounty.includes(document.getElementById("locality").value.toLowerCase())){
alert("Address must be in Santa Clara County or San Mateo County");
return false;
}
return true;
}
</script>
</div>
</form>
</div>
</div>
<div class="ui six wide column">
<h1>Order Summary</h1>
<div class="ui grid">
<!-- WEIGHT -->
<div class="row">
<div class="ten wide column">
<span>Weight:</span>
</div>
<div class="six wide column right floated right aligned">
<span><?php echo $weight." lbs"; ?></span>
</div>
</div>
<!-- TOTAL BEFORE TAX -->
<div class="row">
<div class="ten wide column">
<span>Total before tax:</span>
</div>
<div class="six wide column right floated right aligned">
<span><?php echo "$ ".number_format($price, 2); ?></span>
</div>
</div>
<!-- ESTIMATED TAX -->
<div class="row">
<div class="ten wide column">
<span>Estimated tax:</span>
</div>
<div class="six wide column right floated right aligned">
<span><?php echo "$ ".number_format($tax, 2); ?></span>
</div>
</div>
<!-- ORDER TOTAL -->
<div class="row">
<div class="ten wide column">
<span><h3>Order Total:</h3></span>
</div>
<div class="six wide column right floated right aligned">
<span><h3><?php echo "$ ".number_format($orderTot, 2); ?></h3></span>
</div>
</div>
<!-- BUTTON -->
<div class="row">
<div class="sixteen wide column">
<?php
if(mysqli_num_rows($results) == 0 || $firstName == "-" || $lastName == "-" || $address == "-" || $city == "-" || $state == "-" || $zipcode == "-")
{
echo"<button class='ui disabled fluid green button'>Proceed to payment</button>";
}
else
{
echo "<a href='shipping.php?action=proceed'>
<button class='ui fluid green button'>Proceed to payment</button>
</a>";
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<script>
$(document)
.ready(function() {
$('.ui.dropdown')
.dropdown({
on: 'click'
})
;
})
;
</script>
<script>
function initAutoComplete(){
autocomplete = new google.maps.places.Autocomplete(
/** @type {!HTMLInputElement} */(document.getElementById('street_number')),
{types: ['geocode']});
}
function geolocate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var geolocation = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var circle = new google.maps.Circle({
center: geolocation,
radius: position.coords.accuracy
});
autocomplete.setBounds(circle.getBounds());
});
}
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAZU_P11ldjxwdBWYQSX6Gzj-5aeoEUAUo&libraries=places&callback=initAutoComplete"
async defer></script>
</body>
</html>