summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/api.inc.php
diff options
context:
space:
mode:
authorJannik Schönartz2016-11-23 20:27:36 +0100
committerJannik Schönartz2016-11-23 20:27:36 +0100
commit9b121b58a98ac1f19ec67a1707b7e9a0fa6607b9 (patch)
tree0772b94cab503a56db1c4abe9ce1d6ef29de7987 /modules-available/locationinfo/api.inc.php
parentfrontend: fix (diff)
downloadslx-admin-9b121b58a98ac1f19ec67a1707b7e9a0fa6607b9.tar.gz
slx-admin-9b121b58a98ac1f19ec67a1707b7e9a0fa6607b9.tar.xz
slx-admin-9b121b58a98ac1f19ec67a1707b7e9a0fa6607b9.zip
Api openingtime is now returning the parent times if the current has no own times. Api action=config now returns the value from the database. New colum has to be added.
Diffstat (limited to 'modules-available/locationinfo/api.inc.php')
-rw-r--r--modules-available/locationinfo/api.inc.php44
1 files changed, 36 insertions, 8 deletions
diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php
index 2b3a4ca2..464ca2df 100644
--- a/modules-available/locationinfo/api.inc.php
+++ b/modules-available/locationinfo/api.inc.php
@@ -15,6 +15,22 @@ function HandleParameters() {
} elseif ($getAction == "openingtime") {
$getRoomID = Request::get('id', 0, 'int');
getOpeningTimes($getRoomID);
+ } elseif ($getAction == "config") {
+ $getRoomID = Request::get('id', 0, 'int');
+ getConfig($getRoomID);
+ }
+}
+
+function getConfig($locationID) {
+ $dbquery = Database::simpleQuery("SELECT config FROM `location_info` WHERE locationid = :locationID", array('locationID' => $locationID));
+ $config = array();
+ while($dbresult=$dbquery->fetch(PDO::FETCH_ASSOC)) {
+ $config = json_decode($dbresult['config'], true);
+ }
+ if (empty($config)) {
+ echo json_encode(array());
+ } else {
+ echo json_encode($config);
}
}
@@ -31,6 +47,18 @@ function checkIfHidden($locationID) {
}
}
+function getOpeningTimesFromParent($locationID) {
+ $dbquery = Database::simpleQuery("SELECT parentlocationid FROM `location` WHERE locationid = :locationID", array('locationID' => $locationID));
+ while($dbdata=$dbquery->fetch(PDO::FETCH_ASSOC)) {
+ $parentlocationid = $dbdata['parentlocationid'];
+ }
+ if ($parentlocationid == 0) {
+ echo json_encode(array());
+ }else {
+ echo getOpeningTimes($parentlocationid);
+ }
+}
+
function getOpeningTimes($locationID) {
$error = checkIfHidden($locationID);
if ($error == true) {
@@ -44,6 +72,11 @@ function getOpeningTimes($locationID) {
$dbresult = json_decode($dbdata['openingtime'], true);
}
+ if (count($dbresult) == 0) {
+ getOpeningTimesFromParent($locationID);
+ return;
+ }
+
$weekarray = array ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
foreach ($weekarray as $d) {
@@ -57,15 +90,10 @@ function getOpeningTimes($locationID) {
$arr['HourOpen'] = $openTime[0];
$arr['MinutesOpen'] = $openTime[1];
- //$arr['HourOpen'] = $day['openingtime'][0] . $day['openingtime'][1];
- //$arr['MinutesOpen'] = $day['openingtime'][3] . $day['openingtime'][4];
$closeTime = explode(':', $day['closingtime']);
$arr['HourClose'] = $closeTime[0];
$arr['MinutesClose'] = $closeTime[1];
- //$arr['HourClose'] = $day['closingtime'][0] . $day['closingtime'][1];
- //$arr['MinutesClose'] = $day['closingtime'][3] . $day['closingtime'][4];
-
$array[] = $arr;
}
}
@@ -87,7 +115,7 @@ function getRoomInfoJson($locationID, $coords) {
$error = true;
}
- if ($error === false) {
+ if ($error == false) {
echo $pcs;
} else {
echo "ERROR";
@@ -97,7 +125,7 @@ function getRoomInfoJson($locationID, $coords) {
function getPcInfos($locationID, $coords) {
$dbquery;
- if ($coords === '1') {
+ if ($coords == '1') {
$dbquery = Database::simpleQuery("SELECT machineuuid, position, logintime FROM `machine` WHERE locationid = :locationID" , array('locationID' => $locationID));
} else {
$dbquery = Database::simpleQuery("SELECT machineuuid, logintime FROM `machine` WHERE locationid = :locationID" , array('locationID' => $locationID));
@@ -111,7 +139,7 @@ function getPcInfos($locationID, $coords) {
$computer['id'] = $pc['machineuuid'];
- if ($coords === '1') {
+ if ($coords == '1') {
$position = json_decode($pc['position'], true);
$computer['x'] = $position['gridRow'];
$computer['y'] = $position['gridCol'];