summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/api.inc.php
diff options
context:
space:
mode:
authorJannik Schönartz2017-02-21 02:38:26 +0100
committerJannik Schönartz2017-02-21 02:38:26 +0100
commit601faab88b09699ef454aac094b60de8a80a7168 (patch)
tree261bddc6a74a7bf84a3200c0bd6ba8771ef78e82 /modules-available/locationinfo/api.inc.php
parentOpeningtime fix. Forgot to format parent openingtime (diff)
downloadslx-admin-601faab88b09699ef454aac094b60de8a80a7168.tar.gz
slx-admin-601faab88b09699ef454aac094b60de8a80a7168.tar.xz
slx-admin-601faab88b09699ef454aac094b60de8a80a7168.zip
API: roominfo is now supporting mutliple id.
Diffstat (limited to 'modules-available/locationinfo/api.inc.php')
-rw-r--r--modules-available/locationinfo/api.inc.php81
1 files changed, 48 insertions, 33 deletions
diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php
index dd1e976f..78c9f197 100644
--- a/modules-available/locationinfo/api.inc.php
+++ b/modules-available/locationinfo/api.inc.php
@@ -6,12 +6,13 @@ function HandleParameters() {
$getAction = Request::get('action', 0, 'string');
if ($getAction == "roominfo") {
- $getRoomID = Request::get('id', 0, 'int');
+ $roomIDs = Request::get('id', 0, 'string');
+ $array = getMultipleInformations($roomIDs);
$getCoords = Request::get('coords', 0, 'string');
if (empty($getCoords)) {
$getCoords = '0';
}
- getRoomInfoJson($getRoomID, $getCoords);
+ echo getRoomInfo($array, $getCoords);
} elseif ($getAction == "openingtime") {
$roomIDs = Request::get('id', 0, 'string');
$array = getMultipleInformations($roomIDs);
@@ -230,52 +231,66 @@ function checkIfHidden($locationID) {
return false;
}
-function getRoomInfoJson($locationID, $coords) {
- $error = checkIfHidden($locationID);
+// ########## <Roominfo> ##########
- $pcs = getPcInfos($locationID, $coords);
+function getRoomInfo($idList, $coords) {
- if (empty($pcs)) {
- $error = true;
- }
+ // Build SQL query for multiple ids.
+ $query = "SELECT locationid, machineuuid, position, logintime, lastseen, lastboot FROM `machine` WHERE ";
+ $or = false;
+ foreach($idList as $id) {
+ if (checkIfHidden($id)) {
+ continue;
+ }
+ if ($or) {
+ $query .= " OR ";
+ }
- if ($error == true) {
- echo "ERROR";
- } else {
- echo $pcs;
+ $query .= "locationid = " . $id;
+ $or = true;
}
-}
-function getPcInfos($locationID, $coords) {
- if ($coords == '1') {
- $dbquery = Database::simpleQuery("SELECT machineuuid, position, logintime, lastseen, lastboot FROM `machine` WHERE locationid = :locationID" , array('locationID' => $locationID));
- } else {
- $dbquery = Database::simpleQuery("SELECT machineuuid, logintime, lastseen, lastboot FROM `machine` WHERE locationid = :locationID" , array('locationID' => $locationID));
- }
+ $query .= " ORDER BY locationid ASC";
+ // Execute query.
+ $dbquery = Database::simpleQuery($query);
+ $dbresult = array();
- $pcs = array();
+ $currentlocationid = 0;
- while($pc=$dbquery->fetch(PDO::FETCH_ASSOC)) {
+ $lastentry;
+ $pclist = array();
+ while($dbdata=$dbquery->fetch(PDO::FETCH_ASSOC)) {
- $computer = array();
+ // Add the data in the array if locationid changed
+ if ($dbdata['locationid'] != $currentlocationid && $currentlocationid != 0) {
+ $data['id'] = $currentlocationid;
+ $data['computer'] = $pclist;
+ $dbresult[] = $data;
+ $pclist = array();
+ }
- $computer['id'] = $pc['machineuuid'];
+ $pc['id'] = $dbdata['machineuuid'];
- if ($coords == '1') {
- $position = json_decode($pc['position'], true);
- $computer['x'] = $position['gridCol'];
- $computer['y'] = $position['gridRow'];
- }
+ // Add coordinates if bool = true.
+ if ($coords == '1') {
+ $position = json_decode($dbdata['position'], true);
+ $pc['x'] = $position['gridCol'];
+ $pc['y'] = $position['gridRow'];
+ }
- $computer['pcState'] = LocationInfo::getPcState($pc);
+ $pc['pcState'] = LocationInfo::getPcState($dbdata);
+ $pclist[] = $pc;
- $pcs[] = $computer;
+ // Save the last entry to add this at the end.
+ $lastentry['id'] = $dbdata['locationid'];
+ $lastentry['computer'] = $pclist;
+ $currentlocationid = $dbdata['locationid'];
}
+ $dbresult[] = $lastentry;
- $str = json_encode($pcs, true);
-
- return $str;
+ return json_encode($dbresult, true);
}
+// ########## </Roominfo> ##########
// ########## <Openingtime> ##########