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/api.inc.php | 86 ++++++++-
modules-available/locationinfo/install.inc.php | 18 ++
modules-available/locationinfo/lang/de/module.json | 5 +-
.../locationinfo/lang/de/template-tags.json | 28 ++-
modules-available/locationinfo/lang/en/module.json | 5 +-
.../locationinfo/lang/en/template-tags.json | 28 ++-
.../locationinfo/lang/pt/template-tags.json | 3 -
modules-available/locationinfo/page.inc.php | 97 +++++++++-
modules-available/locationinfo/style.css | 47 +++++
.../locationinfo/templates/_page.html | 4 -
.../locationinfo/templates/location-info.html | 203 +++++++++++++++++++++
.../locationinfo/templates/pcsubtable.html | 22 +++
12 files changed, 520 insertions(+), 26 deletions(-)
create mode 100644 modules-available/locationinfo/install.inc.php
delete mode 100644 modules-available/locationinfo/lang/pt/template-tags.json
create mode 100644 modules-available/locationinfo/style.css
delete mode 100644 modules-available/locationinfo/templates/_page.html
create mode 100644 modules-available/locationinfo/templates/location-info.html
create mode 100644 modules-available/locationinfo/templates/pcsubtable.html
(limited to 'modules-available/locationinfo')
diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php
index 0d84ebce..be202546 100644
--- a/modules-available/locationinfo/api.inc.php
+++ b/modules-available/locationinfo/api.inc.php
@@ -1,7 +1,83 @@
'value',
- 'number' => 123,
- 'list' => array(1,2,3,4,5,6,'foo')
-));
+HandleParameters();
+
+function HandleParameters() {
+ $getAction = $_GET['action'];
+
+ if ($getAction == "roominfo") {
+ $getRoomID = $_GET['id'];
+ $getCoords = $_GET['coords'];
+
+ if (empty($getCoords)) {
+ $getCoords = '0';
+ }
+ getRoomInfoJson($getRoomID, $getCoords);
+ }
+}
+
+function getRoomInfoJson($locationID, $coords) {
+ $error = false;
+
+ $dbquery = Database::simpleQuery("SELECT hidden FROM `locationinfo` WHERE locationid = $locationID");
+
+ while($roominfo=$dbquery->fetch(PDO::FETCH_ASSOC)) {
+ $hidden = $roominfo['hidden'];
+ if ($hidden === '0') {
+ $error = false;
+ } else {
+ $error = true;
+ }
+ }
+ $pcs = getPcInfos($locationID, $coords);
+
+ if (empty($pcs)) {
+ $error = true;
+ }
+
+ if ($error === false) {
+ echo $pcs;
+ } else {
+ echo "ERROR";
+ }
+}
+
+function getPcInfos($locationID, $coords) {
+
+ $dbquery;
+
+ if ($coords === '1') {
+ $dbquery = Database::simpleQuery("SELECT machineuuid, position, logintime FROM `machine` WHERE locationid = $locationID");
+ } else {
+ $dbquery = Database::simpleQuery("SELECT machineuuid, logintime FROM `machine` WHERE locationid = $locationID");
+ }
+
+ $pcs = array();
+
+ while($pc=$dbquery->fetch(PDO::FETCH_ASSOC)) {
+
+ $computer = array();
+
+ $computer['id'] = $pc['machineuuid'];
+
+ if ($coords === '1') {
+ $position = json_decode($pc['position'], true);
+ $computer['x'] = $position['gridRow'];
+ $computer['y'] = $position['gridCol'];
+ }
+
+ $computer['inUse'] = 0;
+
+ if ($pc['logintime'] > 0) {
+ $computer['inUse'] = 1;
+ }
+
+ $pcs[] = $computer;
+ }
+
+ $str = json_encode($pcs, true);
+
+ return $str;
+}
+
+?>
diff --git a/modules-available/locationinfo/install.inc.php b/modules-available/locationinfo/install.inc.php
new file mode 100644
index 00000000..807e2826
--- /dev/null
+++ b/modules-available/locationinfo/install.inc.php
@@ -0,0 +1,18 @@
+ '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),
));
}
diff --git a/modules-available/locationinfo/style.css b/modules-available/locationinfo/style.css
new file mode 100644
index 00000000..2169efa2
--- /dev/null
+++ b/modules-available/locationinfo/style.css
@@ -0,0 +1,47 @@
+/* The Modal (background) */
+.modal {
+ display: none; /* Hidden by default */
+ position: fixed; /* Stay in place */
+ z-index: 1; /* Sit on top */
+ left: 0;
+ top: 0;
+ width: 100%; /* Full width */
+ height: 100%; /* Full height */
+ overflow: auto; /* Enable scroll if needed */
+ background-color: rgb(0,0,0); /* Fallback color */
+ background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
+}
+
+/* Modal Content/Box */
+.modal-content {
+ background-color: #fefefe;
+ margin: 15% auto; /* 15% from the top and centered */
+ padding: 20px;
+ border: 1px solid #888;
+ width: 40%; /* Could be more or less, depending on screen size */
+}
+
+/* The Close Button */
+.close {
+ color: #aaa;
+ float: right;
+ font-size: 28px;
+ font-weight: bold;
+}
+
+.close:hover,
+.close:focus {
+ color: black;
+ text-decoration: none;
+ cursor: pointer;
+}
+
+.tablerow:hover {
+ background-color: #F2F2F2;
+}
+
+.divider{
+ width:50px;
+ height:auto;
+ display:inline-block;
+}
diff --git a/modules-available/locationinfo/templates/_page.html b/modules-available/locationinfo/templates/_page.html
deleted file mode 100644
index dfc941ae..00000000
--- a/modules-available/locationinfo/templates/_page.html
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
{{lang_hello}}, {{foo}}
- ** {{now}} **
-
\ No newline at end of file
diff --git a/modules-available/locationinfo/templates/location-info.html b/modules-available/locationinfo/templates/location-info.html
new file mode 100644
index 00000000..9e4e886d
--- /dev/null
+++ b/modules-available/locationinfo/templates/location-info.html
@@ -0,0 +1,203 @@
+
+
{{lang_mainHeader}}
+
+
+
+
+
+
+
+
+ {{lang_locationID}}
+ {{lang_locationInUse}}
+ {{lang_locationIsHidden}}
+ {{lang_locationSettings}}
+
+
+{{#list}}
+
+
+
+ {{locationid}}
+
+ {{inUse}} / {{totalPcs}}
+
+
+
+
+
+ {{lang_locationSettings}}
+
+
+{{/list}}
+
+
+
+
diff --git a/modules-available/locationinfo/templates/pcsubtable.html b/modules-available/locationinfo/templates/pcsubtable.html
new file mode 100644
index 00000000..0359813b
--- /dev/null
+++ b/modules-available/locationinfo/templates/pcsubtable.html
@@ -0,0 +1,22 @@
+
+
+
+
+ {{lang_pcID}}
+ {{lang_pcX}}
+ {{lang_pcY}}
+ {{lang_pcInUse}}
+
+
+{{#list}}
+
+ {{id}}
+ {{x}}
+ {{y}}
+ {{inUse}}
+
+{{/list}}
+
+
+
+
--
cgit v1.2.3-55-g7522