-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_orders.php
123 lines (103 loc) · 3.09 KB
/
view_orders.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
<?php
require 'core_login.php';
require 'database_connect.php';
if(loggedin())
{
$query = "SELECT order_id, order_total, status, order_time FROM `orders` WHERE user_id=".$_SESSION['user_id']." ORDER BY order_id DESC";
$query_run = mysqli_query($connect,$query);
?>
<h1>All Orders</h1>
<ol type="1" id="orders">
<?php
while($row = mysqli_fetch_assoc($query_run))
{
if($row['status']=='0')
{
$status = 'Order Received';
}
else if($row['status']=='1')
{
$status = 'Preparing';
}
else if($row['status']=='2')
{
$status = 'Awaiting Delivery';
}
else if($row['status']=='3')
{
$status = 'Out for Delivery';
}
else if($row['status']=='4')
{
$status = 'Delivered';
}
else if($row['status']=='5' || $row['status']=='6')
{
$status = 'Cancelled';
}
?>
<li>
<b>Order ID: </b><?php echo $row['order_id']; ?> |
<b>Status: </b><span class="order-status"><?php echo $status; ?></span>
<br><br>
<b>Bill Amount: </b>₹<?php echo $row['order_total']; ?> |
<b>Order Time: </b><?php echo $row['order_time']; ?>
<br><br>
<form style="display: inline-block;" action="order_details.php" id="<?php echo $row['order_id']; ?>" method="POST">
<input type="hidden" name="order" value="<?php echo $row['order_id']; ?>">
<input type="submit" value="Order Details" form="<?php echo $row['order_id']; ?>">
</form>
<span class="cancel-span">
<?php
if($status == 'Order Received')
{
?>
<form style="display: inline-block;" action="order_cancel.php" id="<?php echo $row['order_id'].'_c'; ?>" method="POST" onsubmit="return confirm('Are you sure you want to cancel your order?');">
<input type="hidden" name="order" value="<?php echo $row['order_id']; ?>">
<input type="submit" value="Cancel Order">
</form>
<?php
}
?>
</span>
<hr>
<br>
</li>
<?php
}
?>
</ol>
<script type="text/javascript">
setInterval(function() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var response = this.responseText;
response = JSON.parse(response);
var cancel = document.getElementsByClassName('cancel-span');
var stat = document.getElementsByClassName('order-status');
for(var i=0; i<cancel.length; i++)
{
stat[i].innerHTML = response[i].status;
if(response[i].status == 'Order Received')
{
cancel[i].innerHTML = '<form style="display: inline-block;" action="order_cancel.php" id="' + response[i].id + '_c' + '" method="POST" onsubmit="return confirm(\'Are you sure you want to cancel your order?\');"><input type="hidden" name="order" value="' + response[i].id + '"><input type="submit" value="Cancel Order"></form>';
}
else
{
cancel[i].innerHTML = '';
}
}
}
};
xmlhttp.open("GET","update_orders.php?req=1",true);
xmlhttp.send();
}, 10000);
</script>
<?php
}
else
{
header('Location: login.php');
}
?>