-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotas_admin-products.php
131 lines (74 loc) · 1.98 KB
/
rotas_admin-products.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
<?php
use \Hcode\PageAdmin;
use \Hcode\Model\User;
use \Hcode\Model\Product;
$app->get("/admin/products", function(){
User::verifyLogin();
//$products = Product::listAll();
$search = (isset($_GET['search'])) ? $_GET['search'] : "";
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
if($search != ''){
$pagination = Product::getPageSearch($search, $page);
}else{
$pagination = Product::getPage($page);
}
$pages = [];
for($x = 0; $x < $pagination['pages']; $x++)
{
array_push($pages, [
'href'=>'/admin/products?'.http_build_query([
'page'=>$x+1,
'search'=>$search
]),
'text'=>$x+1
]);
}
$page = new PageAdmin();
$page->setTpl("products", [
"products"=>$pagination['data'],
"search"=>$search,
"pages"=>$pages
]);
});
$app->get("/admin/products/create", function(){
User::verifyLogin();
$products = Product::listAll();
$page = new PageAdmin();
$page->setTpl("products-create");
});
$app->post("/admin/products/create", function(){
User::verifyLogin();
$product = new product();
$product->setData($_POST);
$product->save();
header("Location: /admin/products");
exit;
});
$app->get("/admin/products/:idproduct", function($idproduct){//editar
User::verifyLogin();
$product = new product();
$product->get((int)$idproduct);
$page = new PageAdmin();
$page->setTpl("products-update", [
'product'=>$product->getValues()
]);
});
$app->post("/admin/products/:idproduct", function($idproduct){//editar
User::verifyLogin();
$product = new product();
$product->get((int)$idproduct);
$product->setData($_POST);
$product->save();
$product->setPhoto($_FILES["file"]);//metodo para fazer upload
header('Location: /admin/products');
exit;
});
$app->get("/admin/products/:idproduct/delete", function($idproduct){//editar
User::verifyLogin();
$product = new product();
$product->get((int)$idproduct);
$product->delete();
header('Location: /admin/products');
exit;
});
?>