-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkout.php
112 lines (107 loc) · 5.69 KB
/
checkout.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
<!DOCTYPE html>
<html lang="en">
<?php
// the shopping order needs sessions, to start one
/*
Array of session(
order => array (
book_isbn (get from $_POST['book_isbn']) => number of books
),
items => 0,
total_price => '0.00'
)
*/
session_start();
require_once "./functions/database_functions.php";
require_once "./functions/cart_functions.php";
$conn = db_connect();
if(isset($_SESSION['order']) && (array_count_values($_SESSION['order']))){
require './template/header.php';
?>
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800"><a href="index.php">EBFA Bookstore</a> > Purchase</h1>
</div>
<div class="card mb-4 py-3 border-left-primary">
<div class="card-body">
<table class="table">
<tr>
<th>Item</th>
<th>Type</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
</tr>
<?php
foreach($_SESSION['order'] as $isbn => $qty){
$conn = db_connect();
$book = ($isbn < 0) ? getBook($conn, -$isbn) : getBook($conn, $isbn);
?>
<tr>
<tr>
<td>
<a href="book.php?ISBN=<?php echo $book['ISBN']; ?>" >
<?php echo $book['Title'] . " by " . $book['Publisher']; ?>
</a>
</td>
<td><?php echo ($isbn < 0) ? "Rent" : "Buy" ?></td>
<td><?php echo "$" . $book['Price'] * (($isbn < 0) ? 0.1 : 1); ?></td>
<td><?php echo $qty, " ", ($isbn < 0) ? "week(s)" : "book(s)" ?></td>
<td><?php echo "$" . $qty * $book['Price'] * (($isbn < 0) ? 0.1 : 1); ?></td>
</tr>
<?php } ?>
<tr>
<th> </th>
<th> </th>
<th> </th>
<th><?php echo $_SESSION['total_items']; ?></th>
<th><?php echo "$" . $_SESSION['total_price']; ?></th>
</tr>
</table>
</div>
</div>
<div class="card mb-4 py-3 border-left-primary">
<div class="card-body">
<form method="post" action="purchase.php" class="form-horizontal">
<?php if(isset($_SESSION['err']) && $_SESSION['err'] == 1){ ?>
<p class="text-danger">All fields have to be filled</p>
<?php } ?>
<p> Check your personal information below. If anything is not true, click <a href="#" class="text-decoration-none">here</a> to edit. </p>
<div class="row mb-4">
<div class="col-lg-6">
<p class="m0">Name</p>
<p class="ml-4 font-weight-bold">Nguyễn Hoàng Dũng</p>
<p class="m0">Phone number</p>
<p class="ml-4 font-weight-bold">0981538824</p>
<p class="m0">Address</p>
<p class="ml-4 font-weight-bold">286 Ly Thuong Kiet Street, Ward 7, District 10</p>
</div>
<div class="col-lg-6">
<p class="m0">City</p>
<p class="ml-4 font-weight-bold">Ho Chi Minh City</p>
<p class="m0">State/Country</p>
<p class="ml-4 font-weight-bold">Vietnam</p>
<p class="m0">Payment Method</p>
<div class="col-6">
<select name="inputState" class="form-control sm-3">
<option selected>Bank Transfer</option>
<option>Credit Card 1: VISA ACB</option>
<option>Credit Card 2: VISA PPL</option>
</select>
</div>
</div>
</div>
</form>
<p>Please press Purchase to confirm your information, or <a href="index.php" class="text-decoration-none">Continue Shopping</a> to add or remove items.</p>
<?php
} else {
echo "<p class=\"text-warning\">Your cart is empty! Please make sure you add some books in it!</p>";
}
if(isset($conn)){ mysqli_close($conn); }
require_once "./template/footer.php";
?>
</div>
</div>
<?php
require './template/footer.php';
?>