-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_order.php
More file actions
273 lines (230 loc) · 11.6 KB
/
Copy pathmy_order.php
File metadata and controls
273 lines (230 loc) · 11.6 KB
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
<?php
require 'dbconnect.php'; // Ensure this file correctly initializes $conn
session_start(); // Start the session
// Check if the user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
$user_id = $_SESSION['user_id'];
// Prepare SQL statement to get orders for the logged-in user, ordered by order_id in descending order
$sql = "SELECT * FROM royale_product_order_tbl WHERE user_id = ? ORDER BY order_id DESC";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $user_id); // Bind the user_id as an integer
$stmt->execute();
$result = $stmt->get_result();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Orders</title>
<?php include 'important.php'; ?>
<link rel="stylesheet" href="css_main/main.css?v=<?php echo time(); ?>">
<link rel="stylesheet" href="css_main/my_order.css?v=<?php echo time(); ?>">
<link rel="shortcut icon" href="system_images/whitelogo.png" type="image/png">
</head>
<body>
<?php include 'navigation.php'; ?>
<main>
<h1 class="hidden"><i class="fa-solid fa-cart-shopping"></i> My Orders</h1>
<div class="toggle-container hidden" style="display:flex; justify-content:flex-end">
<button id="toggle-completed" data-showing="false" style="color:green">
<i class="fa-solid fa-eye"></i> Show Completed
</button>
<button id="toggle-cancelled" data-showing="false" style="color:red">
<i class="fa-solid fa-eye"></i> Show Cancelled
</button>
</div>
<style>
#toggle-completed,
#toggle-cancelled {
padding: 10px 20px;
font-size: 1.4rem;
border: 1px solid var(--box-shadow);
color: var(--text-color);
background-color: var(--second-bgcolor);
cursor: pointer;
transition: background-color 0.3s, transform 0.2s;
margin-left: 10px;
font-weight: bold;
border-radius: 5px;
display: flex;
align-items: center;
gap: 10px;
}
#toggle-completed:hover,
#toggle-cancelled:hover {
transform: scale(1.05);
}
</style>
<div class="order-list">
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$photo_array = explode(',', $row['product_photo']);
$is_completed = $row['order_status'] === 'completed' ? 'true' : 'false';
$is_cancelled = $row['order_status'] === 'cancelled' ? 'true' : 'false';
// Determine the class based on order status
$status_class = '';
if ($row['order_status'] == 'pending') {
$status_class = 'text-gray';
} elseif ($row['order_status'] == 'ongoing') {
$status_class = 'text-blue';
} elseif ($row['order_status'] == 'completed') {
$status_class = 'text-green';
} elseif ($row['order_status'] == 'cancelled') {
$status_class = 'text-red';
}
?>
<div class="order-container hidden" data-completed="<?php echo $is_completed; ?>" data-cancelled="<?php echo $is_cancelled; ?>" data-order-id="<?php echo htmlspecialchars($row['order_id']); ?>">
<!-- Photo gallery -->
<div class="photo-gallery">
<?php
foreach ($photo_array as $photo) {
if (!empty($photo)) {
echo '<img src="admin/products/' . htmlspecialchars($photo) . '" alt="Product Photo">';
}
}
?>
</div>
<!-- Order details -->
<div class="details">
<h3 class="<?php echo $status_class; ?>">
<?php echo htmlspecialchars($row['order_status']); ?>
</h3>
<p><strong>Paid ₱<?php echo htmlspecialchars($row['payment']); ?></strong></p>
<div>
<p><strong>Product:</strong> <?php echo htmlspecialchars($row['product_name']); ?></p>
<p><strong>Type:</strong> <?php echo htmlspecialchars($row['product_type']); ?></p>
<p><strong>Size:</strong> <?php echo htmlspecialchars($row['product_size']); ?></p>
<p><strong>Quantity:</strong> <?php echo htmlspecialchars($row['product_quantity']); ?></p>
<p><strong>Pickup Date:</strong> <?php echo htmlspecialchars($row['pickup_date']); ?></p>
<p><strong>Pickup Time:</strong> <?php echo htmlspecialchars($row['pickup_time']); ?></p>
</div>
<div style="text-align: center;">
<b style="font-size: 1.6rem; font-style: italic; color: gray;"><i class="fa-solid fa-eye"></i> Click to view</b>
</div>
</div>
</div>
<?php
}
} else {
echo "<p style='color: var(--text-color);'>No orders found.</p>";
}
$conn->close();
?>
</div>
<div class="anchor-container">
<a href="index.php?#home">Return</a>
</div>
</main>
<script>
// Toggle completed orders
// Toggle completed orders
document.getElementById('toggle-completed').addEventListener('click', function() {
const completedButton = this;
const cancelledButton = document.getElementById('toggle-cancelled');
const isShowingCompleted = completedButton.getAttribute('data-showing') === 'true';
const orderContainers = document.querySelectorAll('.order-container');
// Reset the "Show Cancelled" button
cancelledButton.setAttribute('data-showing', 'false');
cancelledButton.innerHTML = '<i class="fa-solid fa-eye"></i> Show Cancelled';
orderContainers.forEach(container => {
const isCompleted = container.getAttribute('data-completed') === 'true';
const isCancelled = container.getAttribute('data-cancelled') === 'true';
if (isShowingCompleted) {
// Hide completed orders
if (isCompleted) container.style.display = 'none';
else if (!isCancelled) container.style.display = 'flex'; // Show non-cancelled orders
} else {
// Show only completed orders
if (isCompleted) container.style.display = 'flex';
else container.style.display = 'none';
}
});
completedButton.setAttribute('data-showing', !isShowingCompleted);
completedButton.innerHTML = isShowingCompleted ?
'<i class="fa-solid fa-eye"></i> Show Completed' :
'<i class="fa-solid fa-eye-slash"></i> Hide Completed';
});
// Toggle cancelled orders
document.getElementById('toggle-cancelled').addEventListener('click', function() {
const cancelledButton = this;
const completedButton = document.getElementById('toggle-completed');
const isShowingCancelled = cancelledButton.getAttribute('data-showing') === 'true';
const orderContainers = document.querySelectorAll('.order-container');
// Reset the "Show Completed" button
completedButton.setAttribute('data-showing', 'false');
completedButton.innerHTML = '<i class="fa-solid fa-eye"></i> Show Completed';
orderContainers.forEach(container => {
const isCancelled = container.getAttribute('data-cancelled') === 'true';
const isCompleted = container.getAttribute('data-completed') === 'true';
if (isShowingCancelled) {
// Hide cancelled orders
if (isCancelled) container.style.display = 'none';
else if (!isCompleted) container.style.display = 'flex'; // Show non-completed orders
} else {
// Show only cancelled orders
if (isCancelled) container.style.display = 'flex';
else container.style.display = 'none';
}
});
cancelledButton.setAttribute('data-showing', !isShowingCancelled);
cancelledButton.innerHTML = isShowingCancelled ?
'<i class="fa-solid fa-eye"></i> Show Cancelled' :
'<i class="fa-solid fa-eye-slash"></i> Hide Cancelled';
});
// Initial setup: show only pending and ongoing orders
document.querySelectorAll('.order-container').forEach(container => {
const isCompleted = container.getAttribute('data-completed') === 'true';
const isCancelled = container.getAttribute('data-cancelled') === 'true';
if (isCompleted || isCancelled) {
container.style.display = 'none';
} else {
container.style.display = 'flex';
}
});
// Click event to view order details
document.querySelectorAll('.order-container').forEach(container => {
container.addEventListener('click', function() {
const orderId = this.getAttribute('data-order-id');
window.location.href = `my_order_view.php?order_id=${orderId}`;
});
});
</script>
</body>
</html>
<style>
.toggle-container {
margin: 0 20px 10px 0;
text-align: right;
}
#toggle-completed,
#toggle-cancelled {
padding: 10px 20px;
font-size: 1.4rem;
border: 1px solid var(--box-shadow);
color: var(--text-color);
background-color: var(--second-bgcolor);
cursor: pointer;
transition: background-color 0.3s;
margin-left: 10px;
font-weight: bold;
border-radius: 5px;
}
.text-gray {
color: gray;
}
.text-blue {
color: blue;
}
.text-green {
color: green;
}
.text-red {
color: red;
}
</style>
</body>