forked from heyabhiraj/CANMANsys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyorders.php
126 lines (109 loc) · 6.38 KB
/
myorders.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
<?php
$pageName = "My Orders";
session_start();
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header("Location: login.php");
exit;
}
include('./admin/function.php');
$items = getDayMenu();
// Check if the orderId is set in the query string
if (isset($_GET["orderId"])) {
$orderId = $_GET["orderId"];
$newstatus = 'Cancelled';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home - <?php echo $_SESSION['fname']; ?> </title>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
<script>
function cancelOrder() {
// Add your cancel order logic here, such as sending an AJAX request to cancel the order
var confirmCancel = confirm("Are you sure you want to cancel the order?");
if (confirmCancel) {
var a = <?php updateOrderStatus($orderId , $newstatus); ?>;
}
}
</script>
</head>
<body>
<div class="h-20 p-5">
<div class="flex p-5 mb-1 items-center justify-around bg-white ">
<!-- Left side Logo -->
<h1 class="text-4xl text-yellow-600 drop-shadow-lg"> <a href="">CANMANsys </a></h1>
<!-- Right side buttons -->
<div class="flex items-center">
<button class="bg-black text-white rounded-full px-4 py-2" onclick='window.location.href="logout.php"'>logOut</button>
</div>
</div>
<div class=" bg-orange-100 rounded-lg h-900 w-auto p-2 drop-shadow-lg">
<?php
include('./navbar.php');
?>
<p class="text-md m-4 text-end"><a class="underline" href="./menu.php"> View Menu </a></p>
<?php
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$pageSize = 5;
$rows = MyPastOrders($page, $pageSize);
if (!empty($rows)) {
foreach ($rows as $i) { ?>
<div class="flex justify-center">
<div class="w-full md:w-2/4 mb-6 rounded-lg bg-white p-3 shadow-md sm:flex sm:justify-start">
<img src="img.svg" alt="product-image" class="items-center rounded-lg sm:w-40">
<div class="sm:ml-4 sm:flex sm:w-full sm:justify-between">
<div class="flex flex-col items-center">
<span class="inline-block px-2 text-sm"> Bill ID : <?php echo $i['bill_id']; ?> </span>
<h2 class="text-md m-2 font-bold text-gray-900"> <?php echo $i['item_quantity']; ?> X <?php echo $i['item_name']; ?> </h2>
<span class="inline-block mt-6 px-2 text-sm text-white bg-black rounded"> Date : <?php echo $i['created_at']; ?> </span>
<span class="inline-block mt-2 px-2 text-sm rounded"> MODE : <?php echo $i['payment_mode']; ?> </span>
</div>
<div class="flex flex-col items-center">
<p class="text-xl text-center font-bold text-green-700"> ₹ <?php echo $i['order_amount']; ?> </p>
<?php
if ($i['order_status'] === 'pending') {
// If the order status is 'pending', render the cancel button
echo ' <span class="inline-block md:mt-10 px-2 py-1 text-sm text-white bg-gray-600 rounded"> Status : ' . $i['order_status'] . '</span>';
echo '<a href="myorders.php?cancelled&orderId='. $i['order_id'] .'" onclick="cancelOrder()" class="mt-2 bg-red-600 hover:bg-red-700 px-2 py-1 text-white font-bold rounded" > Cancel </a>';
} else if ($i['order_status'] === 'cooking') {
echo '<span class="inline-block md:mt-10 px-2 py-1 text-sm text-white bg-green-700 rounded"> Status : ' . $i['order_status'] . '</span>';
} else if ($i['order_status'] === 'delivered') {
echo '<span class="inline-block md:mt-10 px-2 py-1 text-sm text-white bg-black rounded"> Status : ' . $i['order_status'] . '</span>';
} else {
echo '<span class="inline-block md:mt-10 px-2 py-1 text-sm text-white bg-gray-500 rounded"> Status : ' . $i['order_status'] . '</span>';
}
?>
</div>
</div>
</div>
</div> <?php }
$totalOrders = count(MyPastOrders(1, PHP_INT_MAX));
// Calculate total number of pages
$totalPages = ceil($totalOrders / $pageSize); // Display pagination links
echo '<ul class="flex justify-center -space-x-px text-sm h-8">';
if ($page > 1) {
echo "<li><a class='flex items-center justify-center px-3 h-8 leading-tight text-gray-500 bg-white border border-gray-300' href='?page=" . ($page - 1) . "'>Previous</a></li>";
}
// Page number links
for ($i = 1; $i <= $totalPages; $i++) {
$activeClass = ($i == $page) ? "active" : "bg-yellow-600";
echo "<li class='$activeClass bg-gray-600'><a class='flex items-center justify-center px-3 h-8 text-white border border-gray-300' href='?page=" . $i . "'>" . $i . "</a></li>";
}
if ($page < $totalPages) {
echo "<li><a class='flex items-center justify-center px-3 h-8 leading-tight text-gray-500 bg-white border border-gray-300 ' href='?page=" . ($page + 1) . "'>Next</a></li>";
}
echo '</ul>';
} else {
echo "No Past orders";
} ?>
</div>
</div>
</div>
</body>
</html>