-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathadmin-orders.php
129 lines (80 loc) · 2.11 KB
/
admin-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
<?php
use \Hcode\PageAdmin;
use \Hcode\Model\User;
use \Hcode\Model\Order;
use \Hcode\Model\OrderStatus;
$app->get("/admin/orders/:idorder/status", function($idorder){
User::verifyLogin();
$order = new Order();
$order->get((int)$idorder);
$page = new PageAdmin();
$page->setTpl("order-status", [
'order'=>$order->getValues(),
'status'=>OrderStatus::listAll(),
'msgSuccess'=>Order::getSuccess(),
'msgError'=>Order::getError()
]);
});
$app->post("/admin/orders/:idorder/status", function($idorder){
User::verifyLogin();
if (!isset($_POST['idstatus']) || !(int)$_POST['idstatus'] > 0) {
Order::setError("Informe o status atual.");
header("Location: /admin/orders/".$idorder."/status");
exit;
}
$order = new Order();
$order->get((int)$idorder);
$order->setidstatus((int)$_POST['idstatus']);
$order->save();
Order::setSuccess("Status atualizado.");
header("Location: /admin/orders/".$idorder."/status");
exit;
});
$app->get("/admin/orders/:idorder/delete", function($idorder){
User::verifyLogin();
$order = new Order();
$order->get((int)$idorder);
$order->delete();
header("Location: /admin/orders");
exit;
});
$app->get("/admin/orders/:idorder", function($idorder){
User::verifyLogin();
$order = new Order();
$order->get((int)$idorder);
$cart = $order->getCart();
$page = new PageAdmin();
$page->setTpl("order", [
'order'=>$order->getValues(),
'cart'=>$cart->getValues(),
'products'=>$cart->getProducts()
]);
});
$app->get("/admin/orders", function(){
User::verifyLogin();
$search = (isset($_GET['search'])) ? $_GET['search'] : "";
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
if ($search != '') {
$pagination = Order::getPageSearch($search, $page);
} else {
$pagination = Order::getPage($page);
}
$pages = [];
for ($x = 0; $x < $pagination['pages']; $x++)
{
array_push($pages, [
'href'=>'/admin/orders?'.http_build_query([
'page'=>$x+1,
'search'=>$search
]),
'text'=>$x+1
]);
}
$page = new PageAdmin();
$page->setTpl("orders", [
"orders"=>$pagination['data'],
"search"=>$search,
"pages"=>$pages
]);
});
?>