-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.php
More file actions
579 lines (488 loc) · 19.9 KB
/
menu.php
File metadata and controls
579 lines (488 loc) · 19.9 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
<?php
require_once "header.php";
session_start();
if(!isset($_SESSION['myusername'])) {
header("location:index.php");
}
require_once "config.php";
require_once "common.php";
?>
<style>
.food-table.table>tbody>tr>td {
vertical-align: middle;
padding: 8px;
}
.food-c {
color: #d43f3a;
font-size: 18px;
}
</style>
<script>
angular.module('app', [])
.controller('menuCtrl', function($scope, $http) {
var vm = this;
vm.test = "this is a test";
vm.cart = {};
// Autofill
vm.autofill = function() {
var url = 'autofill.php';
$http.get(url)
.success(function (response) {
//alert(response);
if (response == 0)
{
$('#myModal').modal('show');
}
else if (response == 1)
{
// Update page.
location.reload();
//window.location.replace("menu.php");
}
})
.error(function(){
//console.log("E R R O R");
});
};
// Cleanup Order
vm.cleanupOrders = function() {
var url = "cleanup_orders.php";
$http.get(url)
.success(function (response) {
location.reload();
})
.error(function(){
//console.log("E R R O R");
});
};
// Calculate Price Sum.
vm.calculatePriceSum = function(date) {
var url = "CalculatePriceSum.php?date=" + date;
$http.get(url)
.success(function (response) {
result = JSON.stringify(response);
//alert(result);
result = JSON.parse(result);
// Update Price Sum.
document.getElementById("priceSum" + date).innerHTML = result.day_sum + ' руб.';
// Update Total Price Sum.
document.getElementById("totalPriceForWeek" + result.week_number).innerHTML = 'Всего: ' + result.week_sum + ' руб.';
// Update Average Price Sum.
document.getElementById("averagePriceForWeek" + + result.week_number).innerHTML = 'Средн.: ' + result.average + ' руб.';
})
.error(function(){
//console.log("E R R O R");
});
};
vm.addToCart = function(id, date) {
vm.cart[id] = vm.cart[id] ? ++vm.cart[id] : 1;
var url = "AddToCart.php?dishId=" + id;
$http.post(url)
.success(function (response) {
$("#menuItemCounter" + id).animateCss('bounceIn');
// Update Items Count.
document.getElementById("menuItemCount" + id).innerHTML = response;
// Update Price Sum.
vm.calculatePriceSum(date);
/*
var container = document.getElementById("datesPaginator");
var content = container.innerHTML;
container.innerHTML= content;
*/
})
.error(function(){
//console.log("E R R O R");
});
};
vm.RemoveFromCart = function(id, buttonColour, date, filter) {
vm.cart[id] = vm.cart[id] ? --vm.cart[id] : 0;
var url = "RemoveFromCart.php?dishId=" + id;
$http.post(url)
.success(function (itemsCount) {
// Update Items Count.
document.getElementById("menuItemCount" + id).innerHTML = itemsCount;
// Update Price Sum.
vm.calculatePriceSum(date);
if (itemsCount == 0 && filter)
{
location.reload();
}
// Update Price Sum.
/*
var container = document.getElementById("datesPaginator");
var content = container.innerHTML;
container.innerHTML= content;
*/
})
.error(function(){
//console.log("E R R O R");
});
};
});
$('form').submit(function(){
alert($(this["options"]).val());
return false;
});
$(window).load(function(){
$('#ModalNotification').modal('show');
});
// Tooltip: http://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_tooltip&stacked=h
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
</script>
<body ng-app="app" ng-controller="menuCtrl as vm">
<!-- Display Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Автозаполнение</h4>
</div>
<div class="modal-body">
<p>В Вашем меню нет незаполненных дней.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
</div>
</div>
</div>
</div>
<?php
####################################################################################################
# Save current Menu filter
$menu_filter = $_SERVER['REQUEST_URI'];
$sql = "UPDATE users SET MenuFilter = \"$menu_filter\" WHERE Id = $user_id";
$result = $conn->query($sql);
####################################################################################################
# 1. Display Navigation Bar
print $navigationBar;
# 2. Display Modal if necessary
if (isset($_SESSION['modal_title']) and isset($_SESSION['modal_text'])) {
print ' <!--<br>modal_title: ' . $_SESSION['modal_title'] . '<br>modal_text:' . $_SESSION['modal_text'] . '<br>-->
<div id="Modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">' . $_SESSION['modal_title'] . '</h4>
</div>
<div class="modal-body">
<p>' . $_SESSION['modal_text'] . '</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
<!--alert("Вы ничего пока не заказали.");-->
<!--alert(' . $_SESSION['modal_text'] . ');-->
$("#Modal").modal("show");
</script>';
unset($_SESSION['modal_title']);
unset($_SESSION['modal_text']);
}
# 3. Initialize Page title
print '<div align="center"><h1>Меню</h1></div>';
# 4. Show Modal with Notifications
$sql = "SELECT ShowNotification FROM $table_users WHERE Id = $user_id";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
$showNotification = $row["ShowNotification"];
}
if ($showNotification == 1) {
# 4.1 Disable displaying notification
$sql = "UPDATE $table_users SET ShowNotification = 0 WHERE Id = $user_id";
$result = $conn->query($sql);
# 4.2 Display notification
print ' <div class="container">
<div class="modal fade" id="ModalNotification" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Что нового...</h4>
</div>
<div class="modal-body">
<!-- MESSAGE START -->
<!-- Update 30.10.2016-->
<div><h3><table class="table"><tr class="info"><td align="center">Версия от 30.10.2016</td></tr></tbody></table></h3></div>
На странице <a href="menu.php" target="_blank">«Меню»</a> добавлена кнопка «Распечатать заказ»:
<div align="center"><a href="menu.php" target="_blank"><img src="img\update20161030_printButton.png"></a></div>
<hr>
<p>На странице авторизации теперь отображается общее количество заказов:
<div align="center"><img src="img\update20161030_loginPage.png"></div>
<hr>
<!-- MESSAGE END -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
</div>
</div>
</div>
</div>
</div>';
}
# 5. Get Current Page Date.
$date = isset($_GET['date']) ? $_GET['date'] : '';
error_log('menu.php: date: ' . $date, 0);
# 6. Check, if Filter by Order applied.
$filter = isset($_GET['filter']) ? $_GET['filter'] : '';
$filter_btn_all_state = '';
$filter_btn_filtered_state = '';
# 7. Check, if Filter by Company applied.
$company = isset($_GET['company']) ? $_GET['company'] : '';
$filter_by_company_cimus = '';
$filter_by_company_adam = '';
$filter_custom = '';
# 8. Set Filter button properties depending on filter
if ($filter === '' and $company === '') {
$filter_btn_all_state = 'info active';
$filter_btn_filtered_state = 'default';
$filter_by_company_cimus = 'default';
$filter_by_company_adam = 'default';
$filter_custom = 'default';
}
else if ($filter === 'filtered') {
$filter_btn_all_state = 'default';
$filter_btn_filtered_state = 'info active';
$filter_by_company_cimus = 'default';
$filter_by_company_adam = 'default';
$filter_custom = 'default';
}
else if ($filter === 'custom') {
$filter_btn_all_state = 'default';
$filter_btn_filtered_state = 'default';
$filter_by_company_cimus = 'default';
$filter_by_company_adam = 'default';
$filter_custom = 'info active';
}
else if ($company === 'Цимус') {
$filter_btn_all_state = 'default';
$filter_btn_filtered_state = 'default';
$filter_by_company_cimus = 'info active';
$filter_by_company_adam = 'default';
$filter_custom = 'default';
}
else if ($company === 'Адам') {
$filter_btn_all_state = 'default';
$filter_btn_filtered_state = 'default';
$filter_by_company_cimus = 'default';
$filter_by_company_adam = 'info active';
$filter_custom = 'default';
}
# 9. Disable Send button for Test User
$send_button_type = "";
if ($role_id == 3) {
$send_button_type = ' disabled="disabled"';
}
# 10. Create Buttons Panel.
print '<div class="container-fluid">
<div class="panel-footer row">
<div class="col-sm-7 text-left">
<form action="?filter=&date=&company=" method="get">
<div class="btn-group">
<button type="submit" name="filter" value="" class="btn btn-' . $filter_btn_all_state . '"><span class="glyphicon glyphicon-filter"></span> Без фильтров</button>
<button type="submit" name="company" value="Цимус" class="btn btn-' . $filter_by_company_cimus . '"><span class="glyphicon glyphicon-filter"></span> Цимус</button>
<button type="submit" name="company" value="Адам" class="btn btn-' . $filter_by_company_adam . '"><span class="glyphicon glyphicon-filter"></span> Адам</button>
<button type="submit" name="filter" value="filtered" class="btn btn-' . $filter_btn_filtered_state . '"><span class="glyphicon glyphicon-filter"></span> Мой заказ</button>
<button type="submit" name="filter" value="custom" class="btn btn-' . $filter_custom . '"><span class="glyphicon glyphicon-filter"></span> Ручной фильтр</button>
<input type="hidden" value="' . $date . '" name="date">
</div>
</form>
</div>
<div class="col-sm-2 text-center">
<a href="#" data-toggle="tooltip" title="Автозаполнить заказ"><button ng-click="vm.autofill()" type="submit" class="btn btn btn-warning"><span class="glyphicon glyphicon-flash"></span> </button></a>
<a href="#" data-toggle="tooltip" title="Очистить заказ"><button ng-click="vm.cleanupOrders()" type="submit" class="btn btn btn-danger"><span class="glyphicon glyphicon-trash"></span> </button></a>
<a href="print.user.php" target="_blank" data-toggle="tooltip" title="Распечатать заказ"><button type="submit" class="btn btn btn-info"><span class="glyphicon glyphicon-print"></span> </button></a>
</div>
<div class="col-sm-2 text-right">
<form ng-submit="excelSubmitted=true" action="menu.sendEmail.php" method="get">
<input type="hidden" name="date" value="' . $date . '"/>
<button ng-disabled="excelSubmitted" type="submit" class="btn btn-success"' . $send_button_type . '"><span class="glyphicon glyphicon-send"></span> Отправить Excel Сергею/Адаму</button>
</form>
</div>
</div>
</div>';
$food_table_rows_colours = array('success', 'info', 'warning');
$sql = "SELECT DISTINCT Date FROM $table_food WHERE DATE >= CURDATE() ORDER BY Date ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
$paging_date = isset($_GET['date']) ? $_GET['date'] : '';
$_SESSION['paging_date'] = $paging_date;
# 11. Create Pagination.
$total_price = 0;
$average = 0;
$days_count = 0;
$week_number = 0;
$last_day = '';
print '<form action="" method="post">
<div class="container" align="center">
<ul class="pagination pagination-sm">';
$daysofweek = array();
while($row = $result->fetch_assoc()) {
# 11.1. Get Price Sum for Pagination.
$sum = 0;
$sql_price_sum = "SELECT SUM($table_food.Price * $table_orders.Count) AS TotalPrice FROM $table_food LEFT OUTER JOIN $table_orders ON $table_food.Id=$table_orders.MenuItemId WHERE $table_food.Date = '" . $row["Date"] . "' AND $table_orders.UserId = $user_id";
$result_price_sum = $conn->query($sql_price_sum);
while($row_price_sum = $result_price_sum->fetch_assoc()) {
$sum = $row_price_sum["TotalPrice"];
}
if ($sum == Null)
{
$sum = 0;
}
$dayofweek = day_of_week($row["Date"]);
# 11.2. Add Pagination Splitter if new week is started.
$dayofweek_dgt = date('w', strtotime($row["Date"]));
foreach ($daysofweek as &$day_nmbr) {
if ($dayofweek_dgt == $day_nmbr or $dayofweek_dgt <= $day_nmbr)
{
# 11.3 Add Total Price Pagination.
$average = intval($total_price / $days_count);
print '<li class="disabled"><a href="#"><div id="totalPriceForWeek' . $week_number . '">Всего: ' . $total_price . ' руб.</div><br><div id="averagePriceForWeek' . $week_number . '">Средн.: ' . $average . ' руб.</div></a></li>';
$total_price = 0;
$days_count = 0;
$week_number++;
# 11.4. Add Pagination Splitter if new week is started.
print '</ul>
<ul class="pagination pagination-sm">';
// Cleanup the array.
$daysofweek = array();
break;
}
}
array_push($daysofweek, $dayofweek_dgt);
// Show first table when open Menu page.
if ($paging_date === '')
{
$paging_date = $row["Date"];
}
// Make selected page active.
$page_active = '';
if ($row["Date"] === $paging_date)
{
$page_active = ' class="active"';
}
print '<li' . $page_active . '><a href="?date=' . $row["Date"] . '&filter=' . $filter . '&company=' . $company . '">' . $dayofweek . "<br>" . $row["Date"] . '<div id="priceSum' . $row["Date"] . '">' . $sum . ' руб.</div></a></li>';
// Calculate total price.
$total_price = $total_price + $sum;
// Days Count.
$days_count++;
$last_day = $row["Date"];
}
# 11.5 Add Total Price Pagination.
$average = intval($total_price / $days_count);
print '<li class="disabled"><a href="#"><div id="totalPriceForWeek' . $week_number . '">Всего: ' . $total_price . ' руб.</div><br><div id="averagePriceForWeek' . $week_number . '">Средн.: ' . $average . ' руб.</div></a></li>';
print ' </ul>
</div>
</form>';
# 12.1. Create Table with Dishes.
print '<table class="table table-hover"
<thead>
<tr>
<th width="30"></th>
<th width="100"><div class="text-center">Категория</div></th>
<th width="500"><div class="text-center">Блюдо</div></th>
<th width="60"><div class="text-center">Вес (гр.)</div></th>
<th width="65"><div class="text-center">Цена (р.)</div></th>
<th width="100"><div class="text-center">Поставщик</div></th>
<th width="50"><div class="text-center">Добавить / удалить</div></th>
</tr>
</thead>
<tbody><tbody></table>';
# 12.2 Add Scrollbar (in case of displaying full menu).
if ($filter === '' or $filter === 'custom') {
print '<div class="scrollit">';
}
print '<table class="food-table table table-hover">
<thead></thead>
<tbody>';
# 12.3. Query DB for Dishes depending on Filter.
$sql1 = '';
if ($filter === '') {
if ($company === '') {
$sql1 = "SELECT * FROM $table_food WHERE Date = '$paging_date' ORDER BY Company DESC, Id ASC";
}
else {
$sql1 = "SELECT * FROM $table_food WHERE Date = '$paging_date' AND Company = \"" . $company . "\" ORDER BY Id ASC";
}
}
else if ($filter === 'filtered') {
$sql1 = "SELECT * FROM $table_food
LEFT OUTER JOIN $table_orders ON $table_food.Id=$table_orders.MenuItemId
WHERE $table_food.Date = '$paging_date' AND $table_orders.UserId = $user_id
ORDER BY $table_food.Id";
}
else if ($filter === 'custom') {
$sql2 = "SELECT FoodType, Company, Priority FROM $table_filters WHERE UserId = $user_id AND Enabled = 1 ORDER BY Priority ASC";
$result2 = $conn->query($sql2);
$sql_where = '';
$sql_case = 'ORDER BY CASE ';
while($row2 = $result2->fetch_assoc()) {
$sql_where .= '(Type = "' . $row2["FoodType"] . '" AND Company = "' . $row2["Company"] . '") OR ';
$sql_case .= 'WHEN TYPE = "' . $row2["FoodType"] . '" THEN ' . $row2["Priority"] . ' ';
}
if ($sql_where === '') {
$sql1 = "";
}
else {
$sql_where = substr($sql_where, 0, -3);
$sql1 = "SELECT * FROM food WHERE Date = '$paging_date' AND ($sql_where) $sql_case END ASC";
}
}
if ($sql1 === "") {
}
else {
$result1 = $conn->query($sql1);
$i = 0;
$previous_food_type = '';
while($row1 = $result1->fetch_assoc()) {
if ($previous_food_type === '' or $previous_food_type === $row1["Type"])
{
}
else
{
$i++;
}
if ($i >= count($food_table_rows_colours))
{
$i = 0;
}
# 12.4 Get the Items Count.
$itemsCount = 0;
$sql2 = "SELECT * FROM $table_orders WHERE UserId = $user_id AND MenuItemId = " . $row1["Id"];
$result2 = $conn->query($sql2);
while($row2 = $result2->fetch_assoc()) {
$itemsCount = $row2["Count"];
}
print '<tr ng-init="vm.cart[' . $row1["Id"] . ']=' . $itemsCount . '" ng-class="{\'row-active\': vm.cart[' . $row1["Id"] . '] > 0}" class="' . $food_table_rows_colours[$i] . '">
<td width="35" style="padding:8px 0 0 8px;vertical-align:top;"><div id="menuItemCounter' . $row1["Id"] . '" ng-show="vm.cart[' . $row1["Id"] . ']>0 && \''.$filter.'\'!==
\'filtered\'" class="fa fa-check menu-item-counter ng-cloak food-c"></div></td>
<td width="100" align="center">' . $row1["Type"] . '</td>
<td width="500">' . $row1["Name"] . '<br>' . $row1["Contain"] . '</td>
<td width="50" align="center">' . $row1["Weight"] . '</td>
<td width="50" align="center">' . $row1["Price"] . '</td>
<td width="100" align="center">' . $row1["Company"] . '</td>
<td width="80" align="center"><button ng-click="vm.addToCart(' . $row1["Id"] . ', \'' . $paging_date . '\')" type="submit" name="' . $row1["Id"] . '" value="' . $row1["Id"] . '" class="btn btn btn-' . $food_table_rows_colours[$i] . ' btn-xs"><span class="glyphicon glyphicon-plus"></span></button> <button id="minus' . $row1["Id"] . '" ng-click="vm.RemoveFromCart(' . $row1["Id"] . ', ' . $food_table_rows_colours[$i] . ', \'' . $paging_date . '\', \'' . $filter . '\')" type="submit" name="' . $row1["Id"] . '" value="' . $row1["Id"] . '" class="btn btn btn-' . $food_table_rows_colours[$i] . ' btn-xs"><span class="glyphicon glyphicon-minus"></span></button><p style="margin:0;" id="menuItemCount' . $row1["Id"] . '" class="text-muted">' . $itemsCount . '</p></td>
</tr>';
$previous_food_type = $row1["Type"];
}
}
print '</tbody></table></div>';
# 13.1 Add Scrollbar (in case of displaying full menu).
if ($filter === '' or $filter === 'custom') {
print '</div>';
}
print '</div></div>';
}
else
{
print '<br><br>Меню пока отсутствует.';
}
require_once "footer.php";
?>