-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyorder.php
209 lines (169 loc) · 7.37 KB
/
myorder.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
<?php
include './assets/dbconnect.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_POST['deleteId'])){
$deleteId = $_POST['deleteId'];
$sql2 = "DELETE FROM `orders` WHERE `orders`.`order_id` = $deleteId";
$result2 = mysqli_query($conn, $sql2);
if ($result2) {
header('location:myorder.php');
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>My Orders</title>
<style>
.form-control:focus,
button:focus {
border-color: rgba(0, 0, 0, 0.8);
box-shadow: none;
outline: 0 none;
}
button {
background: #ffe500;
color: black;
}
.navbarsearch {
width: 450px;
}
.myorder {
background: rgb(226, 225, 225);
}
.order-list {
background: rgb(255, 255, 255);
margin: 15px auto;
border-radius: 8px;
}
.product{
width:100%;
}
.product-item{
width:70%;
}
.orderdate{
width:30%;
}
.empty{
min-height:55vh;
/* width: 100vw; */
background: rgb(255, 255, 255);
border-radius: 10px;
margin:20px;
}
</style>
</head>
<body>
<?php include './assets/navbar.php';
$user_id = $_SESSION['userid'];
if(isset($_SESSION['loggedin']) && $_SESSION['loggedin']== true){
$sql = "SELECT DISTINCT `order_id` FROM `orders` WHERE `user_id` = '$user_id' ORDER BY `order_date` DESC" ;
$result = mysqli_query($conn, $sql);
$num = mysqli_num_rows($result);
}
else{
header('location:login.php');
}
?>
<!-- delete modal -->
<div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="deleteModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModalLabel">Are you sure you want to cancel this Order?</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="myorder.php" method="POST">
<input type="hidden" name="deleteId" id="deleteId">
<div class="mb-2 ">
<p> Order id : <strong><span id="deleteorder"></span></strong></p>
</div>
<div class="mt-3">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-danger">Delete</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php
if($num == 0){
echo '<div class="empty d-flex align-items-center justify-content-center flex-column">
<h4>Your Order is Empty.</h4>
<a href="./index.php" class="btn btn-primary mt-3">Shopping Now</a>
</div>';
}
else{
echo '<div class="myorder overflow-hidden">
<div class="order-list container py-2 px-4">
<div class="d-flex flex-column">
<h4>My Orders</h4>
</div>
</div>';
while($row = mysqli_fetch_assoc($result)){
$order_id = $row['order_id'];
$sql2 = "SELECT * FROM `orders` WHERE `order_id` = '$order_id'" ;
$result2 = mysqli_query($conn, $sql2);
$sql4 = "SELECT * FROM `orders` WHERE `order_id` = '$order_id'";
$result4 = mysqli_query($conn, $sql4);
$row4 = mysqli_fetch_assoc($result4);
$order_date = $row4['order_date'];
echo '<div class="order-list container py-2 px-4">
<div class="product d-flex my-2 overflow-hidden flex-column">
<div class="d-flex justify-content-between" >
<h5>Order id: '.$order_id.'</h5>
<h5>Order Date : '.$order_date.'</h5>
<button class="btn btn-sm btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal" onclick="del(' . $order_id .')">Cancel Order</button>
</div><hr class="my-1">';
while($row2 = mysqli_fetch_assoc($result2)){
$pid = $row2['product_id'];
$order_price = $row2['order_total_price'];
$link = "'/shopping/orderdetail.php?orderid=$order_id'";
$sql3 = "SELECT * FROM `products` WHERE `product_id` = $pid";
$result3 = mysqli_query($conn, $sql3);
$row3 = mysqli_fetch_assoc($result3);
$seller = $row3['product_seller'];
$pname = $row3['product_name'];
$pimage = $row3['product_image'];
echo ' <div class="product-item d-flex my-2 overflow-hidden" >
<div class="product-photo border-0">
<div class="m-2 overflow-hidden d-flex justify-content-center" style="width: 150px;">
<img src="./admin/'.$pimage.'" style="width: 100px; object-fit: fill;" class="mx-auto "alt="...">
</div>
</div>
<div class="product-info px-3 py-2">
<h5 onclick="location.href='.$link.';" style="cursor: pointer;">'.$pname.'</h5>
</div>
</div> ';
}
echo '<hr class="my-1"> <h5 class="px-2 pt-2">Total Price : ' . $order_price . ' </h5></div></div>';
}
echo '</div>';
}
?>
<?php include './assets/footer.php'; ?>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4"
crossorigin="anonymous"></script>
<script>
function del(id) {
let row = document.getElementById("row-" + id);
let deleteorder = document.getElementById("deleteorder");
deleteorder.innerHTML = id;
let deleteId = document.getElementById("deleteId");
deleteId.value = id;
}
</script>
</body>
</html>