summaryrefslogtreecommitdiffstats
path: root/modules-available
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
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')
-rw-r--r--modules-available/locationinfo/api.inc.php86
-rw-r--r--modules-available/locationinfo/install.inc.php18
-rw-r--r--modules-available/locationinfo/lang/de/module.json5
-rw-r--r--modules-available/locationinfo/lang/de/template-tags.json28
-rw-r--r--modules-available/locationinfo/lang/en/module.json5
-rw-r--r--modules-available/locationinfo/lang/en/template-tags.json28
-rw-r--r--modules-available/locationinfo/lang/pt/template-tags.json3
-rw-r--r--modules-available/locationinfo/page.inc.php97
-rw-r--r--modules-available/locationinfo/style.css47
-rw-r--r--modules-available/locationinfo/templates/_page.html4
-rw-r--r--modules-available/locationinfo/templates/location-info.html203
-rw-r--r--modules-available/locationinfo/templates/pcsubtable.html22
12 files changed, 520 insertions, 26 deletions
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 @@
<?php
-echo json_encode(array(
- 'key' => '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 @@
+<?php
+
+$res = array();
+
+$res[] = tableCreate('locationinfo', '
+ `locationid` INT(11) NOT NULL,
+ `hidden` BOOLEAN NOT NULL DEFAULT 0,
+ `computers` BLOB DEFAULT NULL,
+ PRIMARY KEY (`locationid`)
+');
+
+// Create response for browser
+
+if (in_array(UPDATE_DONE, $res)) {
+ finalResponse(UPDATE_DONE, 'Tables created successfully');
+}
+
+finalResponse(UPDATE_NOOP, 'Everything already up to date');
diff --git a/modules-available/locationinfo/lang/de/module.json b/modules-available/locationinfo/lang/de/module.json
index 166909c3..2fd14353 100644
--- a/modules-available/locationinfo/lang/de/module.json
+++ b/modules-available/locationinfo/lang/de/module.json
@@ -1,4 +1,3 @@
{
- "module_name": "Mein erstes Modul",
- "page_title": "Mein erster Seitentitel"
-} \ No newline at end of file
+ "module_name": "Infoscreen"
+}
diff --git a/modules-available/locationinfo/lang/de/template-tags.json b/modules-available/locationinfo/lang/de/template-tags.json
index ce98ce38..843beb5a 100644
--- a/modules-available/locationinfo/lang/de/template-tags.json
+++ b/modules-available/locationinfo/lang/de/template-tags.json
@@ -1,3 +1,27 @@
{
- "lang_hello": "Hallo"
-} \ No newline at end of file
+ "lang_mainHeader": "Infoscreen",
+
+ "lang_locationName": "Name",
+ "lang_locationID": "ID",
+ "lang_locationIsHidden": "Versteckt",
+ "lang_locationInUse": "In Benutzung / Gesamt",
+ "lang_locationSettings": "Einstellungen",
+
+
+ "lang_pcID": "ID",
+ "lang_pcX": "X",
+ "lang_pcY": "Y",
+ "lang_pcInUse": "In Benutzung",
+
+ "lang_day": "Tag",
+ "lang_openingTime": "Öffnungszeit",
+ "lang_closingTime": "Schließungszeit",
+
+ "lang_shortMonday": "Mo",
+ "lang_shortTuesday": "Di",
+ "lang_shortWednesday": "Mi",
+ "lang_shortThursday": "Do",
+ "lang_shortFriday": "Fr",
+ "lang_shortSaturday": "Sa",
+ "lang_shortSunday": "So"
+}
diff --git a/modules-available/locationinfo/lang/en/module.json b/modules-available/locationinfo/lang/en/module.json
index b2bcbb0c..2fd14353 100644
--- a/modules-available/locationinfo/lang/en/module.json
+++ b/modules-available/locationinfo/lang/en/module.json
@@ -1,4 +1,3 @@
{
- "module_name": "My first module",
- "page_title": "My first page title"
-} \ No newline at end of file
+ "module_name": "Infoscreen"
+}
diff --git a/modules-available/locationinfo/lang/en/template-tags.json b/modules-available/locationinfo/lang/en/template-tags.json
index c30739e5..4c4d1d38 100644
--- a/modules-available/locationinfo/lang/en/template-tags.json
+++ b/modules-available/locationinfo/lang/en/template-tags.json
@@ -1,3 +1,27 @@
{
- "lang_hello": "Hello"
-} \ No newline at end of file
+ "lang_mainHeader": "Infoscreen",
+
+ "lang_locationName": "Name",
+ "lang_locationID": "ID",
+ "lang_locationIsHidden": "Hidden",
+ "lang_locationInUse": "In use / total",
+ "lang_locationSettings": "Settings",
+
+
+ "lang_pcID": "ID",
+ "lang_pcX": "X",
+ "lang_pcY": "Y",
+ "lang_pcInUse": "In Use",
+
+ "lang_day": "Day",
+ "lang_openingTime": "Opening time",
+ "lang_closingTime": "Closing time",
+
+ "lang_shortMonday": "Mon",
+ "lang_shortTuesday": "Tue",
+ "lang_shortWednesday": "Wed",
+ "lang_shortThursday": "Thu",
+ "lang_shortFriday": "Fri",
+ "lang_shortSaturday": "Sat",
+ "lang_shortSunday": "Sun"
+}
diff --git a/modules-available/locationinfo/lang/pt/template-tags.json b/modules-available/locationinfo/lang/pt/template-tags.json
deleted file mode 100644
index e7981844..00000000
--- a/modules-available/locationinfo/lang/pt/template-tags.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "lang_hello": "Olá"
-} \ No newline at end of file
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),
));
}
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 @@
-<div style="border:5px solid red">
- <h1>{{lang_hello}}, {{foo}}</h1>
- ** {{now}} **
-</div> \ 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 @@
+<div>
+<h1>{{lang_mainHeader}}</h1>
+
+<!-- The Modal -->
+<div id="popup" class="modal">
+ <!-- Modal content -->
+ <div class="modal-content">
+ <span class="close" onclick="closePopup()">x</span>
+ <label id=1></label>
+ <br>
+
+ <!-- vvvv TEST STUFF vvvv-->
+ <table class="table table-condensed locations" style="margin-bottom:0px">
+ <tr>
+ <th>{{lang_day}}</th>
+ <th>{{lang_openingTime}}</th>
+ <th>{{lang_closingTime}}</th>
+ </tr>
+
+ <tr>
+ <td>Monday</td>
+ <td>08:00</td>
+ <td>16:00</td>
+ </tr>
+
+ <tr>
+ <td>MO, DI, MI, DO, FR, SA</td>
+ <td>08:00</td>
+ <td>21:00</td>
+ </tr>
+
+ <tr>
+ <td>SO</td>
+ <td>10:00</td>
+ <td>12:00</td>
+ </tr>
+
+ <tr>
+ <td>MON, TUE, WED, THU, FRI, SAT, SUN</td>
+ <td>10:00</td>
+ <td>12:00</td>
+ </tr>
+
+ <tr>
+ <td>
+ <label><input type="checkbox" value="Monday">{{lang_shortMonday}}</label>
+ <label><input type="checkbox" value="Tuesday">{{lang_shortTuesday}}</label>
+ <label><input type="checkbox" value="Wednesday">{{lang_shortWednesday}}</label>
+ <label><input type="checkbox" value="Thursday">{{lang_shortThursday}}</label>
+ <label><input type="checkbox" value="Friday">{{lang_shortFriday}}</label>
+ <label><input type="checkbox" value="Saturday">{{lang_shortSaturday}}</label>
+ <label><input type="checkbox" value="Sunday">{{lang_shortSunday}}</label>
+ </td>
+ <td>
+ <label><input type="text" onkeypress="return isNumber(event)" style="width:35px;"> :</label>
+ <input type="text" onkeypress="return isNumber(event)" style="width:35px;">
+ </td>
+ <td>
+ <label><input type="text" onkeypress="return isNumber(event)" style="width:35px;"> :</label>
+ <input type="text" onkeypress="return isNumber(event)" style="width:35px;">
+ </td>
+ </tr>
+ </table>
+
+ <!-- ^^^^ TEST STUFF ^^^^-->
+
+ <button class="btn btn-success btn-sm">Add</button>
+ <button class="btn btn-sm btn-danger">Delete</button>
+
+
+ <br><br>
+ <button class="btn btn-primary">Save</button>
+ <div class="divider"></div>
+ <button class="btn btn-sm btn-danger" onclick="closePopup()">Cancel</button>
+ </div>
+
+</div>
+<script>
+
+// Get the modal
+var modal = document.getElementById('popup');
+
+// Get the button that opens the modal
+var btn = document.getElementById("myBtn");
+
+// Get the <span> element that closes the modal
+var span = document.getElementsByClassName("close")[0];
+
+// When the user clicks on the button, open the modal
+function openPopup(locID) {
+ modal.style.display = "block";
+
+ $('#1').text('Location ID: ' + locID);
+}
+
+// When the user clicks on <span> (x), close the modal
+function closePopup() {
+ modal.style.display = "none";
+}
+
+// When the user clicks anywhere outside of the modal, close it
+window.onclick = function(event) {
+ if (event.target == modal) {
+ modal.style.display = "none";
+ }
+}
+</script>
+
+<table class="table table-condensed locations" style="margin-bottom:0px">
+
+ <tr>
+ <th>{{lang_locationID}}</th>
+ <th>{{lang_locationInUse}}</th>
+ <th width=50>{{lang_locationIsHidden}}</th>
+ <th width=50>{{lang_locationSettings}}</th>
+ </tr>
+
+{{#list}}
+ <tr class="tablerow" onclick="slxOpenLocationInfo(this, {{locationid}})">
+ <td>
+ <div style="display:inline-block;width:{{depth}}em"></div>
+ <a href="#" >{{locationid}}<b class="caret"></b></a>
+ </td>
+ <td>{{inUse}} / {{totalPcs}}</td>
+ <!-- <td>{{hidden}}</td> -->
+ <!-- <td><form><input type="checkbox" id={{locationid}} value={{hidden}}></form></td> -->
+ <td id={{locationid}} onclick="event.cancelBubble = true;" align="center"></td>
+ <script>
+ var cbh = document.getElementById('{{locationid}}');
+ var cb = document.createElement('input');
+ cb.type = 'checkbox';
+
+ cbh.appendChild(cb);
+ cb.id = 'cb' + {{locationid}};
+ cb.value = {{hidden}};
+ if ({{hidden}} == 1) {
+ cb.checked = true;
+ }
+ cb.addEventListener("click", function() { cbClick(this, {{locationid}}); });
+ </script>
+
+ <td><button onclick="event.cancelBubble = true; openPopup({{locationid}})">{{lang_locationSettings}}</button></td>
+
+ </tr>
+{{/list}}
+
+</table>
+
+<script type="text/javascript"><!--
+
+function isNumber(evt) {
+ evt = (evt) ? evt : window.event;
+ var charCode = (evt.which) ? evt.which : evt.keyCode;
+ if (charCode > 31 && (charCode < 48 || charCode > 57)) {
+ return false;
+ }
+ return true;
+}
+
+var x = false;
+
+var lastPcSubTable = false;
+
+function cbClick(cb, locID) {
+ // TODO TOGGLE CB and set db Value
+ //alert("TODO set db value and toggle cb: " + locID);
+ var value;
+
+ if (cb.checked == true) {
+ value = 1;
+ } else {
+ value = 0;
+ }
+ window.location.href = "?do=locationinfo&action=hide&id=" + locID + "&value=" + value;
+}
+
+function slxOpenLocationInfo(e, locationId) {
+ if (lastPcSubTable !== false) {
+ lastPcSubTable.hide();
+ $(lastPcSubTable).prev().removeClass('active slx-bold');
+ }
+
+ var existing = $('#subtable' + locationId);
+ if (existing.length > 0) {
+ if (existing.is(lastPcSubTable)) {
+ lastPcSubTable = false;
+ } else {
+ existing.show();
+ $(e).closest('tr').addClass('active slx-bold');
+ lastPcSubTable = existing;
+ }
+ return;
+ }
+
+ var td = $('<td>').attr('colspan', '2').css('padding', '0px 0px 12px');
+ var tr = $('<tr>').attr('id', 'subtable' + locationId);
+ tr.append(td);
+ $(e).closest('tr').addClass('active slx-bold').after(tr);
+ td.load("?do=locationinfo&action=pcsubtable&id=" + locationId);
+ lastPcSubTable = tr;
+}
+ // -->
+</script>
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 @@
+<div>
+<br>
+<table style="margin-bottom:0px">
+ <tr>
+ <th width=120>{{lang_pcID}}</th>
+ <th width=50>{{lang_pcX}}</th>
+ <th width=50>{{lang_pcY}}</th>
+ <th width=20>{{lang_pcInUse}}</th>
+ </tr>
+
+{{#list}}
+ <tr class="tablerow">
+ <td>{{id}}</td>
+ <td>{{x}}</td>
+ <td>{{y}}</td>
+ <td align="center">{{inUse}}</td>
+ </tr>
+{{/list}}
+
+</table>
+<br>
+</div>