summaryrefslogtreecommitdiffstats
path: root/modules-available/locations/baseconfig
diff options
context:
space:
mode:
authorSimon Rettberg2016-05-17 18:14:13 +0200
committerSimon Rettberg2016-05-17 18:14:13 +0200
commit8e729913a8f6258762f4e8049caebc9dbb42a71e (patch)
tree48b1d27787847c012994248e32f5a79695221218 /modules-available/locations/baseconfig
parentGet baseconfig ready for modularization (diff)
downloadslx-admin-8e729913a8f6258762f4e8049caebc9dbb42a71e.tar.gz
slx-admin-8e729913a8f6258762f4e8049caebc9dbb42a71e.tar.xz
slx-admin-8e729913a8f6258762f4e8049caebc9dbb42a71e.zip
Modularized baseconfig fetching (api)
Diffstat (limited to 'modules-available/locations/baseconfig')
-rw-r--r--modules-available/locations/baseconfig/getconfig.inc.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/modules-available/locations/baseconfig/getconfig.inc.php b/modules-available/locations/baseconfig/getconfig.inc.php
new file mode 100644
index 00000000..2643ced6
--- /dev/null
+++ b/modules-available/locations/baseconfig/getconfig.inc.php
@@ -0,0 +1,43 @@
+<?php
+
+// Location handling: figure out location
+$locationId = false; // TODO: machine specific mapping
+if ($locationId === false) {
+ // Fallback to subnets
+ $locationId = Location::getFromIp($ip);
+}
+$matchingLocations = array();
+if ($locationId !== false) {
+ // Get all parents
+ settype($locationId, 'integer');
+ $locations = Location::getLocationsAssoc();
+ $find = $locationId;
+ while (isset($locations[$find]) && !in_array($find, $matchingLocations)) {
+ $matchingLocations[] = $find;
+ $find = (int)$locations[$find]['parentlocationid'];
+ }
+ $configVars["SLX_LOCATIONS"] = implode(' ', $matchingLocations);
+}
+
+// Query location specific settings (from bottom to top)
+if (!empty($matchingLocations)) {
+ // First get all settings for all locations we're in
+ $list = implode(',', $matchingLocations);
+ $res = Database::simpleQuery("SELECT locationid, setting, value FROM setting_location WHERE locationid IN ($list)");
+ $tmp = array();
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $tmp[(int)$row['locationid']][$row['setting']] = $row['value'];
+ }
+ // $matchingLocations contains the location ids sorted from closest to furthest, so we use it to make sure the order
+ // in which they override is correct (closest setting wins, e.g. room setting beats department setting)
+ foreach ($matchingLocations as $lid) {
+ if (!isset($tmp[$lid]))
+ continue;
+ foreach ($tmp[$lid] as $setting => $value) {
+ if (!isset($configVars[$setting])) {
+ $configVars[$setting] = $value;
+ }
+ }
+ }
+ unset($tmp);
+}