summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/api.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/api.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/api.inc.php')
-rw-r--r--modules-available/locationinfo/api.inc.php86
1 files changed, 81 insertions, 5 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;
+}
+
+?>