-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewOrder.php
150 lines (136 loc) · 5.49 KB
/
viewOrder.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
<?php include "components/footer.php" ?>
<?php include "components/navbar.php" ?>
<?php include "php/helper.php" ?>
<?php
if(!isset($_REQUEST["id"])){
header("location: orders.php");
}
//if user is not signed in
if(!isSigned()){
header("Location: signin.php");
}
//get user email
$email = getSignedEmail();
$id = $_REQUEST["id"];
$order = get("SELECT * FROM orders WHERE order_id=\"$id\" AND email=\"$email\"");
//order details
$status = $order["status"];
$date = $order?explode(" ", $order["date"])[0]:"";
$time = $order?explode(" ", $order["date"])[1]:"";
$grandTotal = number_format($order["total_price"], 2);
// var_dump($order);
$orderItems = execute("SELECT B.name, B.isbn, B.author, B.price, O.quantity, O.quantity * B.price 'total' FROM order_items O RIGHT OUTER JOIN books B ON O.isbn=B.isbn WHERE O.order_id=\"$id\"");
function getOrderItemList(){
global $orderItems;
foreach ($orderItems as $item) {
$name=$item["name"];
$isbn=$item["isbn"];
$author=$item["author"];
$price=$item["price"];
$quantity=$item["quantity"];
$total=$item["total"];
$imageName = get("SELECT image FROM book_images WHERE isbn=$isbn")["image"];
$row = "
<tr class='align-middle'>
<td>
<div class='d-flex'>
<div class=''>
<img src='data/$imageName' alt='image' style='max-width: 4rem;'>
</div>
<div class='d-grid align-items-center ms-3'>
<div>
<a href='view.php?isbn=$isbn' class='no-link'><strong>$name</strong></a><br>
<span><small>By: $author <br>($isbn)</small></span>
</div>
</div>
</div>
</td>
<td><strong>$price</strong></td>
<td><strong>$quantity</strong></td>
<td><strong>$total</strong></td>
</tr>
";
echo $row;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- custom css -->
<link rel="stylesheet" href="css/orders.css">
<title>BookBae | View Order</title>
<style>
.no-link{
text-decoration: none;
color: black;
}
.bottom-section{
border-radius: 20px;
background-color: #87574b10;
}
</style>
</head>
<body>
<!-- Navbar starts -->
<?php navbar(""); ?>
<!-- Navbar ends -->
<!-- Page content starts -->
<!-- when invalid order id -->
<div class="text-center my-5 <?php echo $order?"d-none":""; ?>">
<h1>Invalid order id...!</h1>
<a href="orders.php" class="btn bg-brown text-white mt-2"><strong>All orders</strong></a>
</div>
<div class="container my-3 <?php echo !$order?"d-none":""; ?>">
<div class="row">
<div class="col">
<h2><?php echo "Order #".$id; ?></h2>
<div class="hr mb-3"></div>
<span class="font-SF-Pro text-secondary"><?php echo "On $date at $time"; ?></span><br>
<span class='badge <?php echo getStatus($status); ?>'><strong><?php echo $status; ?></strong></span>
<h3 class="text-brown my-2"><?php echo "Rs. $grandTotal"; ?></h3>
</div>
<div class="col-auto d-flex align-items-center d-none d-md-block">
<a href="orders.php" class="btn bg-brown text-white"><i class="bi bi-arrow-left"></i> <strong>All orders</strong></a>
</div>
</div>
<div class="table-responsive mt-3">
<table class="table table-hover overflow-scroll">
<thead class="text-secondary">
<tr>
<th scope="col" style="min-width:5rem;">BOOK</th>
<th scope="col" style="min-width:5rem;">PRICE</th>
<th scope="col" style="min-width:5rem;">QTY</th>
<th scope="col" style="min-width:5rem;">TOTAL</th>
</tr>
</thead>
<tbody>
<?php getOrderItemList(); ?>
</tbody>
</table>
</div>
<section class="bottom-section my-4 p-4 px-5">
<div class="row">
<div class="col-sm-5 mb-4 mb-md-0">
<h4>Order notes</h4>
<div class="input-group">
<textarea class="form-control font-sf-pro text-secondary" rows="3" placeholder="No custon notes" disabled><?php echo $order['note']; ?></textarea>
</div>
</div>
<div class="col"></div>
<div class="col-sm-5 col-md-3 d-grid align-items-center">
<h3 class="text-brown"><?php echo "Total: Rs. $grandTotal"; ?></h3>
</div>
</div>
</section>
</div>
<!-- Page content ends -->
<!-- Footer starts -->
<?php footer(); ?>
<!-- Footer ends -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>