summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/page.inc.php
diff options
context:
space:
mode:
authorJannik Schönartz2016-11-17 18:24:57 +0100
committerJannik Schönartz2016-11-17 18:24:57 +0100
commit2a8c8de7a3980b3948fa7277d89dd2edb17358f8 (patch)
treebc458f88f84e64a7558fd5503209da4f771b3a17 /modules-available/locationinfo/page.inc.php
parent[locationinfo] Skeleton for new module (diff)
downloadslx-admin-2a8c8de7a3980b3948fa7277d89dd2edb17358f8.tar.gz
slx-admin-2a8c8de7a3980b3948fa7277d89dd2edb17358f8.tar.xz
slx-admin-2a8c8de7a3980b3948fa7277d89dd2edb17358f8.zip
First functions added to the locationinfo AdminPanel. Api is can now return the infos with or without coordinates.
Diffstat (limited to 'modules-available/locationinfo/page.inc.php')
-rw-r--r--modules-available/locationinfo/page.inc.php97
1 files changed, 93 insertions, 4 deletions
diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php
index ff73107a..f6b4b661 100644
--- a/modules-available/locationinfo/page.inc.php
+++ b/modules-available/locationinfo/page.inc.php
@@ -3,13 +3,14 @@
class Page_LocationInfo extends Page
{
+ private $action;
+
/**
* Called before any page rendering happens - early hook to check parameters etc.
*/
protected function doPreprocess()
{
User::load();
-
if (!User::isLoggedIn()) {
Message::addError('main.no-permission');
Util::redirect('?do=Main'); // does not return
@@ -21,9 +22,97 @@ class Page_LocationInfo extends Page
*/
protected function doRender()
{
- Render::addTemplate('_page', array(
- 'foo' => 'bar',
- 'now' => date('d.m.Y H:i:s')
+ $getAction = Request::get('action');
+ if (empty($getAction)) {
+ Util::redirect('?do=locationinfo&action=infoscreen');
+ }
+
+ if ($getAction === 'infoscreen') {
+ $this->getInfoScreenTable();
+ }
+
+ if($getAction == 'updateroomdb') {
+ $this->updateInfoscreenDb();
+ Util::redirect('?do=locationinfo&action=infoscreen');
+ }
+
+ if ($getAction === 'hide') {
+ $roomId = Request::get('id');
+ $hiddenValue = Request::get('value');
+ $this->toggleHidden($roomId, $hiddenValue);
+ Util::redirect('?do=locationinfo&action=infoscreen');
+ }
+ }
+
+ protected function toggleHidden($id, $val) {
+ Database::exec("UPDATE `locationinfo` SET hidden = $val WHERE locationid = $id");
+ }
+
+ protected function getInfoScreenTable() {
+
+ $dbquery = Database::simpleQuery("SELECT * FROM `locationinfo`");
+
+ $pcs = array();
+ while($roominfo=$dbquery->fetch(PDO::FETCH_ASSOC)) {
+ $data = array();
+ $data['locationid'] = $roominfo['locationid'];
+ $data['hidden'] = $roominfo['hidden'];
+
+ $inUseCounter = 0;
+ $totalPcCounter = 0;
+ $data['computers'] = json_decode($roominfo['computers'], true);
+
+ foreach ($data['computers'] as $value) {
+ if ($value['inUse'] == 1) {
+ $inUseCounter++;
+ }
+ $totalPcCounter++;
+ }
+ $data['inUse'] = $inUseCounter;
+ $data['totalPcs'] = $totalPcCounter;
+ $pcs[] = $data;
+ }
+
+ Render::addTemplate('location-info', array(
+ 'list' => array_values($pcs),
+ ));
+ }
+
+ protected function updateInfoscreenDb() {
+ $dbquery = Database::simpleQuery("SELECT DISTINCT locationid FROM `machine` WHERE locationid IS NOT NULL");
+ while($roominfo=$dbquery->fetch(PDO::FETCH_ASSOC)) {
+ $this->updatePcInfos($roominfo['locationid']);
+ }
+ }
+
+ /**
+ * AJAX
+ */
+ protected function doAjax()
+ {
+ User::load();
+ if (!User::isLoggedIn()) {
+ die('Unauthorized');
+ }
+ $action = Request::any('action');
+ if ($action === 'pcsubtable') {
+ $id = Request::any('id');
+ $this->ajaxShowLocation($id);
+
+ }
+ }
+
+ private function ajaxShowLocation($id)
+ {
+ $dbquery = Database::simpleQuery("SELECT * FROM `locationinfo` WHERE locationid = $id");
+
+ $data = array();
+ while($roominfo=$dbquery->fetch(PDO::FETCH_ASSOC)) {
+ $data = json_decode($roominfo['computers'], true);
+ }
+
+ echo Render::parse('pcsubtable', array(
+ 'list' => array_values($data),
));
}