summaryrefslogtreecommitdiffstats
path: root/modules/citymanagement/module.inc.php
diff options
context:
space:
mode:
authorJonathan Bauer2016-04-01 16:50:13 +0200
committerJonathan Bauer2016-04-01 16:50:13 +0200
commitdbc0d9614421e064cc62aacf116ebb783c83f2f3 (patch)
tree091844b8578ff1d9ac18edfd3cee3e63210133d7 /modules/citymanagement/module.inc.php
parent[ldapauth] Add homedir conf to ldap wizard (diff)
downloadslx-admin-dbc0d9614421e064cc62aacf116ebb783c83f2f3.tar.gz
slx-admin-dbc0d9614421e064cc62aacf116ebb783c83f2f3.tar.xz
slx-admin-dbc0d9614421e064cc62aacf116ebb783c83f2f3.zip
[merge] merging c3sl / fr - initial commit
Diffstat (limited to 'modules/citymanagement/module.inc.php')
-rw-r--r--modules/citymanagement/module.inc.php81
1 files changed, 81 insertions, 0 deletions
diff --git a/modules/citymanagement/module.inc.php b/modules/citymanagement/module.inc.php
new file mode 100644
index 00000000..acc30bf9
--- /dev/null
+++ b/modules/citymanagement/module.inc.php
@@ -0,0 +1,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('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');
+ }
+}