summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules-available/locationinfo/clientscript.js13
-rw-r--r--modules-available/locationinfo/page.inc.php86
-rw-r--r--modules-available/locationinfo/templates/ajax-config-location.html14
-rw-r--r--modules-available/locationinfo/templates/page-locations.html16
-rw-r--r--modules-available/locations/inc/location.inc.php41
-rw-r--r--style/default.css2
6 files changed, 147 insertions, 25 deletions
diff --git a/modules-available/locationinfo/clientscript.js b/modules-available/locationinfo/clientscript.js
index b18cc5bd..a2a8ee1f 100644
--- a/modules-available/locationinfo/clientscript.js
+++ b/modules-available/locationinfo/clientscript.js
@@ -113,6 +113,12 @@ function submitLocationSettings(event) {
'openingtime': $t.find('.i-openingtime').val(),
'closingtime': $t.find('.i-closingtime').val()
};
+ for (var i = 0; i < allDays.length; ++i) {
+ if ($t.find('.i-' + allDays[i]).is(':checked')) {
+ entry['days'].push(allDays[i]);
+ }
+ }
+ if (entry.openingtime.length === 0 && entry.closingtime.length === 0 && entry.days.length === 0) return; // Also ignore empty lines
s = getTime(entry.openingtime);
e = getTime(entry.closingtime);
if (s === false) {
@@ -123,16 +129,11 @@ function submitLocationSettings(event) {
$t.find('.i-closingtime').addClass('red-bg');
badFormat = true;
}
- if (badFormat) return;
- for (var i = 0; i < allDays.length; ++i) {
- if ($t.find('.i-' + allDays[i]).is(':checked')) {
- entry['days'].push(allDays[i]);
- }
- }
if (entry.days.length === 0) {
$t.find('.days-box').addClass('red-bg');
badFormat = true;
}
+ if (badFormat) return;
schedule.push(entry);
});
}
diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php
index fe53bc99..333e5c48 100644
--- a/modules-available/locationinfo/page.inc.php
+++ b/modules-available/locationinfo/page.inc.php
@@ -100,6 +100,15 @@ class Page_LocationInfo extends Page
}
$serverlocationid = Request::post('serverlocationid', '', 'string');
+ $recursive = (Request::post('recursive', '', 'string') !== '');
+ if (empty($serverlocationid) && !$recursive) {
+ $insertServerId = null;
+ $ignoreServer = 1;
+ } else {
+ $insertServerId = $serverid;
+ $ignoreServer = 0;
+ }
+
// Opening times
$openingtimes = Request::post('openingtimes', '', 'string');
if ($openingtimes !== '') {
@@ -140,14 +149,34 @@ class Page_LocationInfo extends Page
}
Database::exec("INSERT INTO `locationinfo_locationconfig` (locationid, serverid, serverlocationid, openingtime, lastcalendarupdate)
- VALUES (:id, :serverid, :serverlocationid, :openingtimes, 0)
- ON DUPLICATE KEY UPDATE serverid = VALUES(serverid), serverlocationid = VALUES(serverlocationid),
+ VALUES (:id, :insertserverid, :serverlocationid, :openingtimes, 0)
+ ON DUPLICATE KEY UPDATE serverid = IF(:ignore_server AND serverid IS NULL, NULL, :serverid), serverlocationid = VALUES(serverlocationid),
openingtime = VALUES(openingtime), lastcalendarupdate = 0", array(
'id' => $locationid,
+ 'insertserverid' => $insertServerId,
'serverid' => $serverid,
'openingtimes' => $openingtimes,
'serverlocationid' => $serverlocationid,
+ 'ignore_server' => $ignoreServer,
));
+
+ if (!$recursive)
+ return true;
+
+ // Recursive overwriting of serverid
+ $children = Location::getRecursiveFlat($locationid);
+ $array = array();
+ foreach ($children as $loc) {
+ $array[] = $loc['locationid'];
+ }
+ if (!empty($array)) {
+ Database::exec("UPDATE locationinfo_locationconfig
+ SET serverid = :serverid, lastcalendarupdate = IF(serverid <> :serverid, 0, lastcalendarupdate)
+ WHERE locationid IN (:locations)", array(
+ 'serverid' => $serverid,
+ 'locations' => $array,
+ ));
+ }
return true;
}
@@ -336,20 +365,40 @@ class Page_LocationInfo extends Page
$locations = Location::getLocations(0, 0, false, true);
// Get hidden state of all locations
- $dbquery = Database::simpleQuery("SELECT li.locationid, li.serverid, li.serverlocationid, li.openingtime, li.lastcalendarupdate
- FROM `locationinfo_locationconfig` AS li");
+ $dbquery = Database::simpleQuery("SELECT li.locationid, li.serverid, li.serverlocationid, li.openingtime, li.lastcalendarupdate, cb.servername
+ FROM `locationinfo_locationconfig` AS li
+ LEFT JOIN `locationinfo_coursebackend` AS cb USING (serverid)");
while ($row = $dbquery->fetch(PDO::FETCH_ASSOC)) {
$locid = (int)$row['locationid'];
- $hasTable = is_array(json_decode($row['openingtime'], true));
- $hasBackend = !empty($row['serverid']) && !empty($row['serverlocationid']);
+ $glyph = !empty($row['openingtime']) ? 'ok' : '';
+ $backend = '';
+ if (!empty($row['serverid']) && !empty($row['serverlocationid'])) {
+ $backend = $row['servername'] . '(' . $row['serverlocationid'] . ')';
+ }
$locations[$locid] += array(
- 'hasTable' => $hasTable,
- 'hasBackend' => $hasBackend,
+ 'openingGlyph' => $glyph,
+ 'backend' => $backend,
'lastCalendarUpdate' => $row['lastcalendarupdate'], // TODO
);
}
+ $stack = array();
+ $depth = -1;
+ foreach ($locations as &$location) {
+ while ($location['depth'] <= $depth) {
+ array_pop($stack);
+ $depth--;
+ }
+ while ($location['depth'] > $depth) {
+ $depth++;
+ array_push($stack, empty($location['openingGlyph']) ? '' : 'arrow-up');
+ }
+ if ($depth > 0 && empty($location['openingGlyph'])) {
+ $location['openingGlyph'] = $stack[$depth - 1];
+ }
+ }
+
Render::addTemplate('page-locations', array(
'list' => array_values($locations),
));
@@ -430,11 +479,32 @@ class Page_LocationInfo extends Page
$locConfig = Database::queryFirst("SELECT serverid, serverlocationid, openingtime FROM `locationinfo_locationconfig` WHERE locationid = :id", array('id' => $id));
if ($locConfig !== false) {
$openingtimes = json_decode($locConfig['openingtime'], true);
+ } else {
+ $locConfig = array('serverid' => null, 'serverlocationid' => '');
}
if (!isset($openingtimes) || !is_array($openingtimes)) {
$openingtimes = array();
}
+ // Preset serverid from parent if none is set
+ if (is_null($locConfig['serverid'])) {
+ $chain = Location::getLocationRootChain($id);
+ if (!empty($chain)) {
+ $res = Database::simpleQuery("SELECT serverid, locationid FROM locationinfo_locationconfig
+ WHERE locationid IN (:locations) AND serverid IS NOT NULL", array('locations' => $chain));
+ $chain = array_flip($chain);
+ $best = false;
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ if ($best === false || $chain[$row['locationid']] < $chain[$best['locationid']]) {
+ $best = $row;
+ }
+ }
+ if ($best !== false) {
+ $locConfig['serverid'] = $best['serverid'];
+ }
+ }
+ }
+
// get Server / ID list
$res = Database::simpleQuery("SELECT serverid, servername FROM locationinfo_coursebackend ORDER BY servername ASC");
$serverList = array();
diff --git a/modules-available/locationinfo/templates/ajax-config-location.html b/modules-available/locationinfo/templates/ajax-config-location.html
index 2cbad89d..b42ff98d 100644
--- a/modules-available/locationinfo/templates/ajax-config-location.html
+++ b/modules-available/locationinfo/templates/ajax-config-location.html
@@ -116,6 +116,20 @@
</div>
</div>
<div class="row">
+ <div class="col-sm-3"></div>
+ <div class="col-sm-7">
+ <div class="checkbox">
+ <input type="checkbox" name="recursive" id="recursive-check">
+ <label for="recursive-check">{{lang_recursiveServerSet}}</label>
+ </div>
+ </div>
+ <div class="col-sm-2">
+ <a class="btn btn-default helptext" title="{{lang_recursiveSetTooltip}}">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ </div>
+</div>
+<div class="row">
<div class="col-sm-3">
{{lang_roomId}}
</div>
diff --git a/modules-available/locationinfo/templates/page-locations.html b/modules-available/locationinfo/templates/page-locations.html
index 436aa8d5..27c2d9a2 100644
--- a/modules-available/locationinfo/templates/page-locations.html
+++ b/modules-available/locationinfo/templates/page-locations.html
@@ -3,27 +3,21 @@
<tr>
<th>{{lang_locationName}}</th>
- <th width="50">{{lang_openingTime}}</th>
- <th width="50">{{lang_locationSettings}}</th>
+ <th>{{lang_openingTime}}</th>
+ <th>{{lang_locationSettings}}</th>
</tr>
{{#list}}
<tr>
<td>
<div style="display:inline-block;width:{{depth}}em"></div>
- <a href="#" class="loc-name" data-locationid="{{locationid}}">{{locationname}}</a>
+ <a href="#" class="loc-name {{^depth}}slx-bold{{/depth}}" data-locationid="{{locationid}}">{{locationname}}</a>
</td>
<td>
- <a class="btn btn-sm btn-default" role="button" style="width: 100%"
- onclick="loadTimeModal({{locationid}}, '{{locationname}}');">
- <span style="margin-right: 5px;" class="glyphicon glyphicon-time"></span>
- </a>
+ {{backend}}
</td>
<td>
- <a class="btn btn-sm btn-default" role="button" style="width: 100%;"
- onclick="loadLocationConfigModal({{locationid}}, '{{locationname}}');">
- <span style="margin-right: 5px;" class="glyphicon glyphicon-cog"></span>
- </a>
+ <span class="glyphicon glyphicon-{{openingGlyph}}"></span>
</td>
</tr>
diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php
index aff2dec5..85b7e47f 100644
--- a/modules-available/locations/inc/location.inc.php
+++ b/modules-available/locations/inc/location.inc.php
@@ -130,6 +130,47 @@ class Location
return array_values($rows);
}
+ /**
+ * Get nested array of all the locations and children of given locationid(s).
+ *
+ * @param int[]|int $idList List of location ids
+ * @param bool $locationTree used in recursive calls, don't pass
+ * @return array list of passed locations plus their children
+ */
+ public static function getRecursive($idList, $locationTree = false)
+ {
+ if (!is_array($idList)) {
+ $idList = array($idList);
+ }
+ if ($locationTree === false) {
+ $locationTree = self::getTree();
+ }
+ $ret = array();
+ foreach ($locationTree as $location) {
+ if (in_array($location['locationid'], $idList)) {
+ $ret[] = $location;
+ } elseif (!empty($location['children'])) {
+ $ret = array_merge($ret, self::getRecursive($idList, $location['children']));
+ }
+ }
+ return $ret;
+ }
+
+ /**
+ * Get flat array of all the locations and children of given locationid(s).
+ *
+ * @param int[]|int $idList List of location ids
+ * @return array list of passed locations plus their children
+ */
+ public static function getRecursiveFlat($idList)
+ {
+ $ret = self::getRecursive($idList);
+ if (!empty($ret)) {
+ $ret = self::flattenTree($ret);
+ }
+ return $ret;
+ }
+
public static function buildTree($elements, $parentId = 0)
{
$branch = array();
diff --git a/style/default.css b/style/default.css
index 35b61277..52ded3ae 100644
--- a/style/default.css
+++ b/style/default.css
@@ -477,6 +477,8 @@ it only applies if they're in a container that has the checkbox class */
.checkbox {
padding-left: 20px;
+ margin-top: 5px;
+ margin-bottom: 2px;
}
.checkbox label {
display: inline-block;