diff options
author | Jannik Schönartz | 2017-01-29 08:18:18 +0100 |
---|---|---|
committer | Jannik Schönartz | 2017-01-29 08:18:18 +0100 |
commit | d311bddd350fde9c35d8a04351accee9d6e0af1d (patch) | |
tree | 61d4ce981790760bdf10a756233e4b4a12208bd6 /modules-available/locationinfo | |
parent | frontend: added function to generate parent div (diff) | |
download | slx-admin-d311bddd350fde9c35d8a04351accee9d6e0af1d.tar.gz slx-admin-d311bddd350fde9c35d8a04351accee9d6e0af1d.tar.xz slx-admin-d311bddd350fde9c35d8a04351accee9d6e0af1d.zip |
API: Adde a method for multi handle ids and a method for returning the room tree.
Diffstat (limited to 'modules-available/locationinfo')
-rw-r--r-- | modules-available/locationinfo/api.inc.php | 45 | ||||
-rw-r--r-- | modules-available/locationinfo/inc/locationinfo.inc.php | 1 |
2 files changed, 46 insertions, 0 deletions
diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php index ddbd1304..296354c4 100644 --- a/modules-available/locationinfo/api.inc.php +++ b/modules-available/locationinfo/api.inc.php @@ -21,9 +21,54 @@ function HandleParameters() { } elseif ($getAction == "calendar") { $getRoomID = Request::get('id', 0, 'int'); getCalendar($getRoomID); + } elseif ($getAction == "roomtree") { + $roomIDS = Request::get('ids', 0, 'string'); + getRoomTree($roomIDS); } } +function getMultipleInformations($roomids) { + $idList = explode(',', $roomids); + $filteredIdList = array_filter($idList, 'is_numeric'); + return $filteredIdList; +} + +function getRoomTree($ids) { + $idList = getMultipleInformations($ids); + $roomTree = array(); + foreach ($idList as $id) { + $dbquery = Database::simpleQuery("SELECT locationname FROM `location` WHERE locationid=:locationID", array('locationID' => $id)); + $dbresult=$dbquery->fetch(PDO::FETCH_ASSOC); + + $a['id'] = $id; + $a['name'] = $dbresult['locationname']; + $a['childs'] = getChildsRecursive($id); + $roomTree[] = $a; + } + + echo json_encode($roomTree); +} + +function getChildsRecursive($id) { + $dbquery = Database::simpleQuery("SELECT locationid, locationname FROM `location` WHERE parentlocationid=:locationID", array('locationID' => $id)); + $array = array(); + $dbarray = array(); + + while($dbresult=$dbquery->fetch(PDO::FETCH_ASSOC)) { + $dbarray[] = $dbresult; + } + + foreach ($dbarray as $db) { + $i = $db['locationid']; + $a['id'] = $i; + $a['name'] = $db['locationname']; + $a['childs'] = getChildsRecursive($i); + $array[] = $a; + } + + return $array; +} + function randomCalendarGenerator() { $randNum = rand(3, 7); diff --git a/modules-available/locationinfo/inc/locationinfo.inc.php b/modules-available/locationinfo/inc/locationinfo.inc.php index d4bd2b0a..7ef06f8b 100644 --- a/modules-available/locationinfo/inc/locationinfo.inc.php +++ b/modules-available/locationinfo/inc/locationinfo.inc.php @@ -11,6 +11,7 @@ class LocationInfo * [2] = OFF * [3] = 10 days offline (BROKEN?) */ + // TODO USE STATE NAME instead of numbers $logintime = (int)$pc['logintime']; $lastseen = (int)$pc['lastseen']; |