-
Notifications
You must be signed in to change notification settings - Fork 0
/
employee_orders.php
215 lines (168 loc) · 5.38 KB
/
employee_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
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
<?php
require 'employee_core.php';
require 'database_connect.php';
if(loggedin())
{
$username = getuserfield('username');
$firstname = getuserfield('firstname');
$surname = getuserfield('surname');
echo '<b><i>'.$username.'</i></b><br>';
echo 'You\'re logged in, '.$firstname.' '.$surname.'.<br><br>';
?>
<a href="employee_change.php">Change Password</a>
<br>
<a href="employee_logout.php"><b>Logout</b></a>
<br><br>
<?php
$query = "SELECT order_id FROM orders WHERE status != 4 AND status != 6 ORDER BY order_id";
$query_run = mysqli_query($connect,$query);
?>
<script type="text/javascript">
setInterval(function() {
setTimeout(function() {
for(var i=0; i<document.getElementsByClassName('sub-btn').length; i++)
{
document.getElementsByClassName('sub-btn')[i].setAttribute('disabled', '');
}
}, 8500);
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("table").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","getorders.php?req=1",true);
xmlhttp.send();
}, 10000);
setInterval(function() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("id_list").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","getorders.php?req=2",true);
xmlhttp.send();
}, 10000);
</script>
<form action="order_edit.php" autocomplete="off" method="POST">
<label for="order_id">Order #: </label>
<input name="order_id" id="order_id" list="id_list" required>
<datalist id="id_list">
<?php
while($row = mysqli_fetch_assoc($query_run))
{
?><option value="<?php echo $row['order_id'] ?>"><?php echo $row['order_id']; ?></option><?php
}
?>
</datalist>
<label for="order_status">Status: </label>
<input name="status" id="order_status" list="status_list" required>
<datalist id="status_list">
<option value="0">Order Received</option>
<option value="1">Preparing</option>
<option value="2">Awaiting Delivery</option>
<option value="3">Out for Delivery</option>
<option value="4">Delivered</option>
<option value="5">Cancelled</option>
<option value="6">Cancelled (Acknowledged)</option>
</datalist>
<input type="hidden" name="override" value="yes">
<input type="submit" value="Change Status">
</form>
<p><a href="employee_all_orders.php">View all orders</a></p>
<table cellspacing="5" id="table">
<tr>
<th>Order #</th>
<th>Username</th>
<th>Order Details</th>
<th>Total</th>
<th>Address</th>
<th>Contact</th>
<th>Status</th>
<th>Time</th>
<th>Change</th>
</tr>
<?php
$query = "SELECT orders.order_id, users.username, orders.order_list, orders.order_quantity, orders.order_total, orders.address, orders.contact, orders.status, orders.order_time FROM orders LEFT JOIN users ON orders.user_id = users.id WHERE orders.status != 4 AND orders.status != 6 ORDER BY orders.order_id DESC";
$query_run = mysqli_query($connect,$query);
while($row = mysqli_fetch_assoc($query_run))
{
$list = explode(" ", $row['order_list']);
$quantity = explode(" ", $row['order_quantity']);
$count = count($list);
$query = "SELECT item, cost FROM menu WHERE id=";
for($i=0; $i<$count; $i++)
{
$query = $query.$list[$i]." OR id=";
}
$query = $query."0";
$query_run2 = mysqli_query($connect,$query);
$details = "";
$q_count = 0;
while($row2 = mysqli_fetch_assoc($query_run2))
{
$details = $details.$row2['item']." x".$quantity[$q_count].", ";
$q_count++;
}
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']=='5')
{
$status = 'Cancelled';
}
?>
<form action="order_edit.php" method="POST" id="<?php echo $row['order_id']; ?>">
<input type="hidden" name="order_id" value="<?php echo $row['order_id']; ?>">
<input type="hidden" name="status" value="<?php echo ((int)$row['status'] + 1); ?>">
</form>
<tr>
<td><?php echo $row['order_id']; ?></td>
<td><i><?php echo $row['username']; ?></i></td>
<td><?php echo $details; ?></td>
<td><?php echo $row['order_total']; ?></td>
<td style="padding: 10px 0;"><?php echo nl2br("$row[address]"); ?></td>
<td><?php echo $row['contact']; ?></td>
<td><b><?php echo $status ?></b></td>
<td><?php echo $row['order_time']; ?></td>
<td>
<form action="order_edit.php" method="POST" id="<?php echo $row['order_id']; ?>">
<input type="hidden" name="order_id" value="<?php echo $row['order_id']; ?>">
<input type="hidden" name="status" value="<?php echo ((int)$row['status'] + 1); ?>">
<input class="sub-btn" type="submit" value="Next Status">
</form>
</td>
</tr>
<?php
}
?>
</table>
<script type="text/javascript">
setTimeout(function() {
for(var i=0; i<document.getElementsByClassName('sub-btn').length; i++)
{
document.getElementsByClassName('sub-btn')[i].setAttribute('disabled', '');
}
}, 8500);
</script>
<?php
}
else
{
header('Location: employee_login.php');
}
?>