diff options
author | Simon Rettberg | 2016-05-03 19:03:09 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-05-03 19:03:09 +0200 |
commit | 50404f3b23b7fd6aeae4c9d2f6df0ea25e984e66 (patch) | |
tree | 05e99fdffa696434960d7c77966c0bc36d6339e8 /modules-available/citymanagement | |
parent | Second half of merge.... (diff) | |
download | slx-admin-50404f3b23b7fd6aeae4c9d2f6df0ea25e984e66.tar.gz slx-admin-50404f3b23b7fd6aeae4c9d2f6df0ea25e984e66.tar.xz slx-admin-50404f3b23b7fd6aeae4c9d2f6df0ea25e984e66.zip |
WIP
Diffstat (limited to 'modules-available/citymanagement')
6 files changed, 203 insertions, 0 deletions
diff --git a/modules-available/citymanagement/config.json b/modules-available/citymanagement/config.json new file mode 100644 index 00000000..aff54b3a --- /dev/null +++ b/modules-available/citymanagement/config.json @@ -0,0 +1,4 @@ +{ + "enabled":"false", + "permission":"0" +} diff --git a/modules-available/citymanagement/lang/en/module.json b/modules-available/citymanagement/lang/en/module.json new file mode 100644 index 00000000..ba6c5c44 --- /dev/null +++ b/modules-available/citymanagement/lang/en/module.json @@ -0,0 +1,14 @@ +{ + "lang_cancelConfirm": "Do you really want to remove this city?", + "lang_cityInfo": "Here you can create new cities for the website, besides editing or removing the existing ones", + "lang_cityPage": "Manage cities", + "lang_cityname": "City name", + "lang_close": "Close", + "lang_create": "Create", + "lang_edit": "Edit", + "lang_editcity": "Edit City", + "lang_operations": "Operations", + "lang_remove": "Remove", + "lang_save": "Save", + "module_name": "Management" +}
\ No newline at end of file diff --git a/modules-available/citymanagement/lang/en/templates/citymanagement.json b/modules-available/citymanagement/lang/en/templates/citymanagement.json new file mode 100644 index 00000000..27bb60c0 --- /dev/null +++ b/modules-available/citymanagement/lang/en/templates/citymanagement.json @@ -0,0 +1,13 @@ +{ + "lang_cancelConfirm": "Do you really want to remove this city?", + "lang_cityInfo":"Here you can create new cities for the website, besides editing or removing the existing ones", + "lang_cityPage":"Manage cities", + "lang_cityname":"City name", + "lang_close": "Close", + "lang_create": "Create", + "lang_edit":"Edit", + "lang_editcity":"Edit City", + "lang_operations": "Operations", + "lang_remove": "Remove", + "lang_save": "Save" +} diff --git a/modules-available/citymanagement/lang/pt/module.json b/modules-available/citymanagement/lang/pt/module.json new file mode 100644 index 00000000..c514f437 --- /dev/null +++ b/modules-available/citymanagement/lang/pt/module.json @@ -0,0 +1,14 @@ +{ + "lang_cancelConfirm": "Deseja realmente remover a cidade?", + "lang_cityInfo": "Nesta se\u00e7\u00e3o voc\u00ea poder\u00e1 criar cidades para o site, al\u00e9m de editar ou remover cidades existentes", + "lang_cityPage": "Gerenciar cidades", + "lang_cityname": "Nome da cidade", + "lang_close": "Fechar", + "lang_create": "Criar", + "lang_edit": "Editar", + "lang_editcity": "Editar Cidade", + "lang_operations": "Opera\u00e7\u00f5es", + "lang_remove": "Remover", + "lang_save": "Salvar", + "module_name": "Gerenciamento" +}
\ No newline at end of file diff --git a/modules-available/citymanagement/page.inc.php b/modules-available/citymanagement/page.inc.php new file mode 100644 index 00000000..acc30bf9 --- /dev/null +++ b/modules-available/citymanagement/page.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'); + } +} diff --git a/modules-available/citymanagement/templates/page-citymanagement.html b/modules-available/citymanagement/templates/page-citymanagement.html new file mode 100644 index 00000000..6d7750cf --- /dev/null +++ b/modules-available/citymanagement/templates/page-citymanagement.html @@ -0,0 +1,77 @@ +<div class="panel panel-default" style="border-color:#333;"> + <div class="panel-heading" style="border-color:#333;background-color:#333;background-image: none;color:#FFF;"> + <div class="panel-title">{{lang_cityPage}}</div> + </div> + <div class="panel-body"> + <p> + {{lang_cityInfo}} + </p> + + </div> + <table class="table"> + <tr> + <form method="post" action="?do=Citymanagement"> + <input type="hidden" name="action" value="create"> + <input type="hidden" name="token" value="{{token}}"> + <td><input class="form-control" name="name" type="text" placeholder="{{lang_cityname}}"></td> + <td><input class="btn btn-primary" type="submit" value="{{lang_create}}"></td> + </form> + </tr> + <tr> + <th style="text-align: center;">ID</th> + <th style="text-align: center;">{{lang_cityname}}</th> + <th colspan="4">{{lang_operations}}</th> + </tr> + {{#cities}} + <tr> + <td><input class="form-control" type="text" disabled="disabled" value="{{id}}" size="3"></td> + <td><input class="form-control" type="text" disabled="disabled" value="{{name}}"></td> + <td colspan="4"> + <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#city{{id}}"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span> {{lang_edit}}</button> + <form method="post" action="?do=Citymanagement" style="display:inline-block;"> + <input type="hidden" name="action" value="delete"> + <input type="hidden" name="cityid" value="{{id}}"> + <input type="hidden" name="token" value="{{token}}"> + <button class="btn btn-danger" type="submit" onclick="return confirm('{{lang_cancelConfirm}}');"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> {{lang_remove}}</a> + </form> + </td> + </tr> + {{/cities}} + <tr> + <td colspan="6"> + <ul class="pagination" style="margin:10px 0;"> + {{#pages}} + <li class="{{class}}"><a href="?do=Citymanagement&page={{page}}">{{page}}</a></li> + {{/pages}} + </ul> + </td> + </tr> + </table> +</div> +{{#cities}} +<div class="modal fade" id="city{{id}}" tabindex="-1" role="dialog"> + <div class="modal-dialog"> + <div class="modal-content"> + <div class="modal-header"><h4 class="modal-title">{{lang_editcity}}</h4></div> + <div class="modal-body"> + <form method="post" action=""> + <input type="hidden" name="action" value="edit"> + <input type="hidden" name="token" value="{{token}}"> + <div class="form-group"> + <label for="cityid">ID</label> + <input type="text" class="form-control" name="cityid" readonly="readonly" value="{{id}}"> + </div> + <div class="form-group"> + <label for="cityid">{{lang_cityname}}</label> + <input type="text" class="form-control" name="name" placeholder="{{lang_cityname}}" value="{{name}}"> + </div> + <div class="modal-footer"> + <input class="btn btn-primary" type="submit" value="{{lang_save}}"> + <a class="btn btn-default" data-dismiss="modal">{{lang_close}}</a> + </div> + </form> + </div> + </div> + </div> +</div> +{{/cities}} |