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
|
<?php
class Page_Citymanagement extends Page
{
private $page;
protected function doPreprocess()
{
User::load();
$p = Request::get('page');
if($p != false)
$this->page = $p;
else
$this->page = 1;
switch(Request::post('action')){
case "edit":
$this->edit(Request::post('cityid'),Request::post('name'));
break;
case "create":
$this->create(Request::post('name'));
break;
case "delete":
$this->delete(Request::post('cityid'));
break;
}
if (!User::hasPermission('superadmin')) {
Message::addError('main.no-permission');
Util::redirect('?do=Main');
}
}
protected function doRender()
{
// load every city
$cities = array();
$res = Database::simpleQuery("SELECT cityid, name FROM cities ORDER BY cityid DESC");
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
$cities[] = array(
'id' => $row['cityid'],
'name' => $row['name'],
);
}
$pag = new Pagination($cities,$this->page);
Render::addTemplate('page-citymanagement', array(
'cities' => $pag->getItems(),
'pages' => $pag->getPagination()
));
}
private function edit($cityid, $newname){
$data = array (
'cityid' => $cityid,
'name' => $newname,
);
Database::exec ( 'UPDATE cities SET name = :name WHERE cityid = :cityid', $data );
Message::addSuccess('update-city');
}
private function create($name){
$data = array (
'name' => $name,
);
Database::exec('INSERT INTO cities(name) VALUES( :name )',$data);
Message::addSuccess('add-city');
}
private function delete($cityid){
$data = array (
'cityid' => $cityid
);
Database::exec ( 'DELETE FROM cities WHERE cityid = :cityid', $data );
Message::addSuccess('delete-city');
}
}
|