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 ++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 5 deletions(-) (limited to 'modules-available/locationinfo/api.inc.php') 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; +} + +?> -- cgit v1.2.3-55-g7522