1 | <?php
|
---|
2 |
|
---|
3 | session_start();
|
---|
4 |
|
---|
5 | if(!isset($_SESSION['user_ID']) || !isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
|
---|
6 | header("Location: ./Log In.php");
|
---|
7 | }
|
---|
8 |
|
---|
9 | require './connect.php';
|
---|
10 |
|
---|
11 | if(!isset($_GET['order_id'])) {
|
---|
12 | header('Location: ./PendingOrders.php');
|
---|
13 | }
|
---|
14 |
|
---|
15 | $res = mysqli_query($conn, "SELECT * FROM orders WHERE id = {$_GET['order_id']}; ");
|
---|
16 | $order = $res->fetch_assoc();
|
---|
17 | $order_items = mysqli_query($conn, "SELECT * FROM order_item WHERE order_id={$_GET['order_id']};");
|
---|
18 | $total_price = 0;
|
---|
19 | $products = [];
|
---|
20 |
|
---|
21 | foreach($order_items as $item) {
|
---|
22 | $product_name = mysqli_query($conn, "SELECT name FROM products INNER JOIN order_item ON products.product_id = order_item.product_id WHERE order_item.id={$item['id']};")->fetch_assoc()['name'];
|
---|
23 | $total_price = $total_price + ($item['quantity']*$item['price']);
|
---|
24 | $products[] = ['Product Name' => $product_name, 'Quantity' => $item['quantity'], 'Price per unit' => $item['price'], 'Product ID' => $item['product_id']];
|
---|
25 | }
|
---|
26 | ?>
|
---|
27 |
|
---|
28 |
|
---|
29 | <!DOCTYPE html>
|
---|
30 | <html lang="en">
|
---|
31 | <head>
|
---|
32 | <meta charset="UTF-8">
|
---|
33 | <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
---|
34 | <link rel="stylesheet" href="./CSS/ViewOrder.css">
|
---|
35 | <title>Order</title>
|
---|
36 | </head>
|
---|
37 | <body>
|
---|
38 | <div class="container">
|
---|
39 | <div class="card">
|
---|
40 | <div class="card-header">
|
---|
41 | Order Number
|
---|
42 | </div>
|
---|
43 | <div class="card-value">
|
---|
44 | <?php echo $order['id'] ?>
|
---|
45 | </div>
|
---|
46 | </div>
|
---|
47 | <div class="card">
|
---|
48 | <div class="card-header">
|
---|
49 | User ID
|
---|
50 | </div>
|
---|
51 | <div class="card-value">
|
---|
52 | <?php echo $order['user_id'] ?>
|
---|
53 | </div>
|
---|
54 | </div>
|
---|
55 | <div class="card">
|
---|
56 | <div class="card-header">
|
---|
57 | Order Date
|
---|
58 | </div>
|
---|
59 | <div class="card-value">
|
---|
60 | <?php echo $order['order_date'] ?>
|
---|
61 | </div>
|
---|
62 | </div>
|
---|
63 | <div class="card">
|
---|
64 | <div class="card-header">
|
---|
65 | Shipped Date
|
---|
66 | </div>
|
---|
67 | <div class="card-value">
|
---|
68 | <?php echo $order['shipped_date'] ?>
|
---|
69 | </div>
|
---|
70 | </div>
|
---|
71 | <div class="card">
|
---|
72 | <div class="card-header">
|
---|
73 | Arrived Date
|
---|
74 | </div>
|
---|
75 | <div class="card-value">
|
---|
76 | <?php echo $order['arrived_date'] ?>
|
---|
77 | </div>
|
---|
78 | </div>
|
---|
79 | <div class="card">
|
---|
80 | <div class="card-header">
|
---|
81 | Status
|
---|
82 | </div>
|
---|
83 | <div class="card-value">
|
---|
84 | <?php
|
---|
85 | switch($order['status']) {
|
---|
86 | case 'p':
|
---|
87 | echo 'PENDING';
|
---|
88 | break;
|
---|
89 | case 'a':
|
---|
90 | echo 'ACTIVE';
|
---|
91 | break;
|
---|
92 | case 'd':
|
---|
93 | echo 'DELIVERED';
|
---|
94 | break;
|
---|
95 | default:
|
---|
96 | echo 'INVALID';
|
---|
97 | break;
|
---|
98 | }
|
---|
99 | ?>
|
---|
100 | </div>
|
---|
101 | </div>
|
---|
102 | <div class="card">
|
---|
103 | <div class="card-header">
|
---|
104 | Address
|
---|
105 | </div>
|
---|
106 | <div class="card-value">
|
---|
107 | <?php echo $order['address'] ?>
|
---|
108 | </div>
|
---|
109 | </div>
|
---|
110 | <div class="card">
|
---|
111 | <div class="card-header">
|
---|
112 | City
|
---|
113 | </div>
|
---|
114 | <div class="card-value">
|
---|
115 | <?php echo $order['city'] ?>
|
---|
116 | </div>
|
---|
117 | </div>
|
---|
118 | <div class="card">
|
---|
119 | <div class="card-header">
|
---|
120 | Postal Code
|
---|
121 | </div>
|
---|
122 | <div class="card-value">
|
---|
123 | <?php echo $order['postal_code'] ?>
|
---|
124 | </div>
|
---|
125 | </div>
|
---|
126 | <div class="card">
|
---|
127 | <div class="card-header">
|
---|
128 | Phone Number
|
---|
129 | </div>
|
---|
130 | <div class="card-value">
|
---|
131 | <?php echo $order['phone_number'] ?>
|
---|
132 | </div>
|
---|
133 | </div>
|
---|
134 | <div class="card">
|
---|
135 | <div class="card-header">
|
---|
136 | Name
|
---|
137 | </div>
|
---|
138 | <div class="card-value">
|
---|
139 | <?php echo $order['name'] ?>
|
---|
140 | </div>
|
---|
141 | </div>
|
---|
142 | <div class="card">
|
---|
143 | <div class="card-header">
|
---|
144 | Surname
|
---|
145 | </div>
|
---|
146 | <div class="card-value">
|
---|
147 | <?php echo $order['surname'] ?>
|
---|
148 | </div>
|
---|
149 | </div>
|
---|
150 | <div class="card">
|
---|
151 | <div class="card-header">
|
---|
152 | Price
|
---|
153 | </div>
|
---|
154 | <div class="card-value">
|
---|
155 | <?php echo '$'.$total_price ?>
|
---|
156 | </div>
|
---|
157 | </div>
|
---|
158 | <br>
|
---|
159 | <br>
|
---|
160 | <?php
|
---|
161 | foreach($products as $product) {
|
---|
162 | ?>
|
---|
163 |
|
---|
164 | <div class="product">
|
---|
165 |
|
---|
166 | <?php
|
---|
167 | foreach($product as $key => $value) {
|
---|
168 | ?>
|
---|
169 | <div class="card">
|
---|
170 | <div class="card-header">
|
---|
171 | <?php echo $key ?>
|
---|
172 | </div>
|
---|
173 | <div class="card-value">
|
---|
174 | <?php
|
---|
175 | if($key == 'Price per unit') echo '$';
|
---|
176 | echo $value
|
---|
177 | ?>
|
---|
178 | </div>
|
---|
179 | </div>
|
---|
180 | <?php
|
---|
181 | }
|
---|
182 | ?>
|
---|
183 | </div>
|
---|
184 | <br>
|
---|
185 | <br>
|
---|
186 | <?php
|
---|
187 | }
|
---|
188 |
|
---|
189 | ?>
|
---|
190 | </div>
|
---|
191 | </body>
|
---|
192 | </html> |
---|