From 2a8c8de7a3980b3948fa7277d89dd2edb17358f8 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Thu, 17 Nov 2016 09:24:57 -0800 Subject: First functions added to the locationinfo AdminPanel. Api is can now return the infos with or without coordinates. --- modules-available/locationinfo/page.inc.php | 97 +++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 4 deletions(-) (limited to 'modules-available/locationinfo/page.inc.php') 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), )); } -- cgit v1.2.3-55-g7522