summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/locationinfo')
-rw-r--r--modules-available/locationinfo/api.inc.php26
-rw-r--r--modules-available/locationinfo/frontend/frontendscript.js2
-rw-r--r--modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php2
-rw-r--r--modules-available/locationinfo/inc/infopanel.inc.php3
-rw-r--r--modules-available/locationinfo/inc/locationinfo.inc.php2
-rw-r--r--modules-available/locationinfo/lang/de/template-tags.json5
-rw-r--r--modules-available/locationinfo/lang/en/template-tags.json3
-rw-r--r--modules-available/locationinfo/page.inc.php81
-rwxr-xr-xmodules-available/locationinfo/templates/frontend-default.html1
-rw-r--r--modules-available/locationinfo/templates/frontend-summary.html32
-rw-r--r--modules-available/locationinfo/templates/page-locations.html6
-rw-r--r--modules-available/locationinfo/templates/page-panels.html14
12 files changed, 124 insertions, 53 deletions
diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php
index ceaf04c0..ad71de8b 100644
--- a/modules-available/locationinfo/api.inc.php
+++ b/modules-available/locationinfo/api.inc.php
@@ -49,15 +49,11 @@ function HandleParameters()
/**
* Get last config modification timestamp for given panel.
- * This was planned to be smart and check the involved locations,
- * even going up the location tree if the opening time schedule
- * is inherited, but this would still be incomplete by design, as
- * it wouldn't react to the linked room plan being considered
- * for changes, or added/removed PCs etc. So rather than giving
- * an incomplete "clever" design for detecting changes, we only
- * consider direct editing of the panel now. So the advice would
- * simply be "if you want the panel to reload automatically, hit
- * the edit button and click save". Might even add a shortcut
+ * This is incomplete however, as it wouldn't react to the
+ * linked room plan being edited, or added/removed PCs
+ * etc. So the advice would simply be "if you want the
+ * panel to reload automatically, hit the edit button
+ * and click save". Might even add a shortcut
* reload-button to the list of panels at some point.
*
* @param string $paneluuid panels uuid
@@ -65,13 +61,21 @@ function HandleParameters()
*/
function getLastChangeTs($paneluuid)
{
- $panel = Database::queryFirst('SELECT lastchange FROM locationinfo_panel WHERE paneluuid = :paneluuid',
+ $panel = Database::queryFirst('SELECT lastchange, locationids FROM locationinfo_panel WHERE paneluuid = :paneluuid',
compact('paneluuid'));
if ($panel === false) {
http_response_code(404);
die('Panel not found');
}
- return (int)$panel['lastchange'];
+ $lastChange = array((int)$panel['lastchange']);
+ if (!empty($panel['locationids'])) {
+ $res = Database::simpleQuery('SELECT lastchange FROM locationinfo_locationconfig
+ WHERE locationid IN (:locs)', array('locs' => explode(',', $panel['locationids'])));
+ while (($lc = $res->fetchColumn()) !== false) {
+ $lastChange[] = (int)$lc;
+ }
+ }
+ return max($lastChange);
}
/**
diff --git a/modules-available/locationinfo/frontend/frontendscript.js b/modules-available/locationinfo/frontend/frontendscript.js
index cc5c6827..bad6a8ed 100644
--- a/modules-available/locationinfo/frontend/frontendscript.js
+++ b/modules-available/locationinfo/frontend/frontendscript.js
@@ -45,7 +45,7 @@ function toInt(str) {
* @param {Array} globalConfig
* @returns {string} printable time
*/
-function GetTimeDiferenceAsString(a, b, globalConfig = null) {
+function GetTimeDiferenceAsString(a, b, globalConfig) {
if (!a || !b) {
return "";
}
diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php
index adff8b1b..94c967de 100644
--- a/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php
+++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php
@@ -137,5 +137,3 @@ class CourseBackend_Dummy extends CourseBackend
}
}
-
-?>
diff --git a/modules-available/locationinfo/inc/infopanel.inc.php b/modules-available/locationinfo/inc/infopanel.inc.php
index 12b6aec7..edeb9ccf 100644
--- a/modules-available/locationinfo/inc/infopanel.inc.php
+++ b/modules-available/locationinfo/inc/infopanel.inc.php
@@ -12,7 +12,7 @@ class InfoPanel
*/
public static function getConfig($paneluuid, &$config)
{
- $panel = Database::queryFirst('SELECT panelname, panelconfig, paneltype, locationids, lastchange FROM locationinfo_panel WHERE paneluuid = :paneluuid',
+ $panel = Database::queryFirst('SELECT panelname, panelconfig, paneltype, locationids FROM locationinfo_panel WHERE paneluuid = :paneluuid',
compact('paneluuid'));
if ($panel === false) {
@@ -68,7 +68,6 @@ class InfoPanel
}
self::appendOpeningTimes($config['locations'], $lids);
- $config['ts'] = (int)$panel['lastchange'];
$config['locations'] = array_values($config['locations']);
$config['time'] = date('Y-n-j-G-') . (int)date('i') . '-' . (int)(date('s'));
diff --git a/modules-available/locationinfo/inc/locationinfo.inc.php b/modules-available/locationinfo/inc/locationinfo.inc.php
index 2ed3622d..e3d7db3d 100644
--- a/modules-available/locationinfo/inc/locationinfo.inc.php
+++ b/modules-available/locationinfo/inc/locationinfo.inc.php
@@ -11,9 +11,7 @@ class LocationInfo
*/
public static function getPcState($pc)
{
- $logintime = (int)$pc['logintime'];
$lastseen = (int)$pc['lastseen'];
- $lastboot = (int)$pc['lastboot'];
$NOW = time();
if ($pc['state'] === 'OFFLINE' && $NOW - $lastseen > 21 * 86400) {
diff --git a/modules-available/locationinfo/lang/de/template-tags.json b/modules-available/locationinfo/lang/de/template-tags.json
index be2814d6..b305f800 100644
--- a/modules-available/locationinfo/lang/de/template-tags.json
+++ b/modules-available/locationinfo/lang/de/template-tags.json
@@ -10,8 +10,6 @@
"lang_checkConnection": "Verbindung pr\u00fcfen",
"lang_closed": "Geschlossen",
"lang_closingTime": "Schlie\u00dfungszeit",
- "lang_config": "Einstellungen",
- "lang_configupdateTooltip": "Zeit nach der die Einstellungen aktualisiert werden (in Minuten)",
"lang_createPanel": "Panel anlegen",
"lang_credentials": "Anmeldung",
"lang_day": "Tag",
@@ -25,8 +23,8 @@
"lang_ecoMode": "E-Ink Modus",
"lang_ecoTooltip": "Anstelle der Farb-basierten PC-Status Bilder, werden Symbol-basierte PC Bilder verwendet",
"lang_editDefaultPanelHints": "Hier k\u00f6nnen Sie ein Panel (z.B. digitales T\u00fcrschild) in Aussehen und Funktionsweise definieren. Um im Kalender \u00d6ffnungszeiten anzeigen zu k\u00f6nnen, m\u00fcssen Sie im Tab \"Raum-\/Ortsbezogene Einstellungen\" f\u00fcr den ausgew\u00e4hlten Raum entsprechend \u00d6ffnungszeiten eintragen. Damit im Kalender Veranstaltungen und andere Termine angezeigt werden k\u00f6nnen, muss ein funktionierendes Backend konfiguriert und den ausgew\u00e4hlten R\u00e4umen zugewiesen worden sein.",
- "lang_editSummaryPanelHints": "Hier k\u00f6nnen Sie ein Summary-Panel definieren. Das Panel zeigt eine Übersicht der in den R\u00e4umen enthalten PCs.",
"lang_editPanel": "Panel bearbeiten",
+ "lang_editSummaryPanelHints": "Hier k\u00f6nnen Sie ein Summary-Panel definieren. Das Panel zeigt eine \u00dcbersicht der in den R\u00e4umen enthalten PCs.",
"lang_editUrlPanelHints": "Hier k\u00f6nnen Sie konfigurieren, welche URL das Panel aufrufen soll. Dies erm\u00f6glicht Ihnen z.B. in Eingangsbereichen aktuelle Meldungen der Hochschule oder sonstige Webseiten anzuzeigen.",
"lang_entryName": "Name",
"lang_error": "Fehler",
@@ -38,6 +36,7 @@
"lang_insecureSsl": "Unsicheres SSL",
"lang_language": "Sprache",
"lang_languageTooltip": "Legt die Sprache der angezeigten Oberfl\u00e4che fest",
+ "lang_lastCalendarUpdate": "Kalender Update",
"lang_locationName": "Name",
"lang_locationSettings": "Raum-\/Ortsbezogene Einstellungen",
"lang_locations": "Orte",
diff --git a/modules-available/locationinfo/lang/en/template-tags.json b/modules-available/locationinfo/lang/en/template-tags.json
index be927ee4..5679e8b8 100644
--- a/modules-available/locationinfo/lang/en/template-tags.json
+++ b/modules-available/locationinfo/lang/en/template-tags.json
@@ -10,8 +10,6 @@
"lang_checkConnection": "Check connection",
"lang_closed": "Closed",
"lang_closingTime": "Closing time",
- "lang_config": "Config",
- "lang_configupdateTooltip": "Time interval the config gets updated (in minutes)",
"lang_createPanel": "Create panel",
"lang_credentials": "Login",
"lang_day": "Day",
@@ -38,6 +36,7 @@
"lang_insecureSsl": "Insecure SSL",
"lang_language": "Language",
"lang_languageTooltip": "The language the frontend uses",
+ "lang_lastCalendarUpdate": "Calendar update",
"lang_locationName": "Name",
"lang_locationSettings": "Location specific settings",
"lang_locations": "Locations",
diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php
index c6aa0860..22a21951 100644
--- a/modules-available/locationinfo/page.inc.php
+++ b/modules-available/locationinfo/page.inc.php
@@ -129,8 +129,8 @@ class Page_LocationInfo extends Page
}
$serverlocationid = Request::post('serverlocationid', '', 'string');
- $recursive = (Request::post('recursive', '', 'string') !== '');
- if (empty($serverlocationid) && !$recursive) {
+ $changeServerRecursive = (Request::post('recursive', '', 'string') !== '');
+ if (empty($serverlocationid) && !$changeServerRecursive) {
$insertServerId = null;
$ignoreServer = 1;
} else {
@@ -170,12 +170,16 @@ class Page_LocationInfo extends Page
$mangled[] = $entry;
}
if (empty($mangled)) {
- $openingtimes = '';
+ $openingtimes = null;
} else {
$openingtimes = json_encode($mangled);
}
}
}
+ $NOW = time();
+ // Check if openingtimes changed
+ $res = Database::queryFirst('SELECT openingtime FROM locationinfo_locationconfig WHERE locationid = :locationid', compact('locationid'));
+ $otChanged = $res === false || $res['openingtime'] !== $openingtimes;
Database::exec("INSERT INTO `locationinfo_locationconfig` (locationid, serverid, serverlocationid, openingtime, lastcalendarupdate, lastchange)
VALUES (:id, :insertserverid, :serverlocationid, :openingtimes, 0, :now)
@@ -187,27 +191,66 @@ class Page_LocationInfo extends Page
'openingtimes' => $openingtimes,
'serverlocationid' => $serverlocationid,
'ignore_server' => $ignoreServer,
- 'now' => time(),
+ 'now' => $NOW,
));
- if (!$recursive)
- return true;
-
- // Recursive overwriting of serverid
- $children = Location::getRecursiveFlat($locationid);
- $array = array();
- foreach ($children as $loc) {
- $array[] = $loc['locationid'];
+ if ($otChanged) {
+ $tree = Location::getLocationsAssoc();
+ $todo = array();
+ $done = array();
+ foreach ($tree as $l) {
+ if ($l['parentlocationid'] == $locationid) {
+ $todo[] = $l['locationid'];
+ }
+ }
+ while (!empty($todo)) {
+ $loc = array_pop($todo);
+ if (in_array($loc, $done))
+ continue;
+ $done[] = $loc;
+ // See if this one inherits
+ $res = Database::queryFirst('SELECT openingtime FROM locationinfo_locationconfig WHERE locationid = :loc', compact('loc'));
+ if ($res === false) {
+ $res = Database::exec('INSERT INTO locationinfo_locationconfig (locationid, lastchange)
+ VALUES (:locationid, :now) ON DUPLICATE KEY UPDATE lastchange = :now',
+ array('locationid' => $loc, 'now' => $NOW));
+ } elseif (strlen($res['openingtime']) < 5) {
+ $res = Database::exec('UPDATE locationinfo_locationconfig SET lastchange = :now, openingtime = NULL
+ WHERE locationid = :locationid',
+ array('locationid' => $loc, 'now' => $NOW));
+ } else {
+ $res = 0;
+ }
+ if ($res > 0) {
+ // Row was updated, which means the openingtime column was empty, which means the openingtime is inherited, descend further
+ $todo = array_merge($todo, $tree[$loc]['children']);
+ foreach ($tree as $l) {
+ if ($l['parentlocationid'] == $loc) {
+ $todo[] = $l['locationid'];
+ }
+ }
+ }
+ }
}
- if (!empty($array)) {
- Database::exec("UPDATE locationinfo_locationconfig
+
+ if ($changeServerRecursive) {
+ // 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), lastchange = :now
WHERE locationid IN (:locations)", array(
'serverid' => $serverid,
'locations' => $array,
- 'now' => time(),
- ));
+ 'now' => $NOW,
+ ));
+ }
}
+
return true;
}
@@ -392,7 +435,7 @@ class Page_LocationInfo extends Page
$credentialsOk = $serverInstance->setCredentials($serverid, json_decode($dbresult['credentials'], true));
if ($credentialsOk) {
- $connectionOk = $serverInstance->checkConnection();
+ $serverInstance->checkConnection();
}
LocationInfo::setServerError($serverid, $serverInstance->getError());
@@ -465,7 +508,7 @@ class Page_LocationInfo extends Page
$locations[$locid] += array(
'openingGlyph' => $glyph,
'backend' => $backend,
- 'lastCalendarUpdate' => $row['lastcalendarupdate'], // TODO
+ 'lastCalendarUpdate' => Util::prettyTime($row['lastcalendarupdate']), // TODO
'backendMissing' => !CourseBackend::exists($row['servertype']),
);
}
@@ -478,8 +521,8 @@ class Page_LocationInfo extends Page
$depth--;
}
while ($location['depth'] > $depth) {
+ array_push($stack, empty($location['openingGlyph']) && ($depth === -1 || empty($stack[$depth])) ? '' : 'arrow-up');
$depth++;
- array_push($stack, empty($location['openingGlyph']) ? '' : 'arrow-up');
}
if ($depth > 0 && empty($location['openingGlyph'])) {
$location['openingGlyph'] = $stack[$depth - 1];
diff --git a/modules-available/locationinfo/templates/frontend-default.html b/modules-available/locationinfo/templates/frontend-default.html
index 92cad055..e457f68d 100755
--- a/modules-available/locationinfo/templates/frontend-default.html
+++ b/modules-available/locationinfo/templates/frontend-default.html
@@ -369,6 +369,7 @@ optional:
</div>
</body>
+<!--suppress RedundantIfStatementJS -->
<script type="text/javascript">
var rooms = {};
var lastRoomUpdate = 0;
diff --git a/modules-available/locationinfo/templates/frontend-summary.html b/modules-available/locationinfo/templates/frontend-summary.html
index ec5d8aab..4105dd16 100644
--- a/modules-available/locationinfo/templates/frontend-summary.html
+++ b/modules-available/locationinfo/templates/frontend-summary.html
@@ -226,8 +226,8 @@
queryRooms();
nextUpdate = 1000;
}
- for (property in rooms) {
- upDateRoomState(rooms[property]);
+ if (nextUpdate !== 1000) {
+ queryPanelChange();
}
clearTimeout(timeout);
setTimeout(update, nextUpdate);
@@ -267,7 +267,9 @@
}
ComputeCurrentState(rooms[json[i].id]);
}
- update();
+ for (property in rooms) {
+ upDateRoomState(rooms[property]);
+ }
}
/**
@@ -765,6 +767,30 @@
});
}
+ /**
+ * Checks whether the panel has been edited and reloads
+ * the entire page if so.
+ */
+ function queryPanelChange() {
+ $.ajax({
+ url: "{{dirprefix}}api.php?do=locationinfo&get=timestamp&uuid={{uuid}}",
+ dataType: 'json',
+ cache: false,
+ timeout: 5000,
+ success: function (result) {
+ if (!result || !result.ts) {
+ console.log('Warning: get=timestamp didnt return json with ts field');
+ return;
+ }
+ if (config.ts && config.ts !== result.ts) {
+ // Change
+ window.location.reload(true);
+ }
+ config.ts = result.ts;
+ }
+ })
+ }
+
</script>
</head>
<body>
diff --git a/modules-available/locationinfo/templates/page-locations.html b/modules-available/locationinfo/templates/page-locations.html
index de8dab7e..b30ef2ed 100644
--- a/modules-available/locationinfo/templates/page-locations.html
+++ b/modules-available/locationinfo/templates/page-locations.html
@@ -7,6 +7,7 @@
<tr>
<th>{{lang_locationName}}</th>
<th>{{lang_backend}}</th>
+ <th>{{lang_lastCalendarUpdate}}</th>
<th>{{lang_openingtimes}}</th>
</tr>
</thead>
@@ -25,6 +26,11 @@
{{backend}}
</td>
<td>
+ {{#backend}}
+ {{lastCalendarUpdate}}
+ {{/backend}}
+ </td>
+ <td>
<span class="glyphicon glyphicon-{{openingGlyph}}"></span>
</td>
</tr>
diff --git a/modules-available/locationinfo/templates/page-panels.html b/modules-available/locationinfo/templates/page-panels.html
index f374e456..e17b6584 100644
--- a/modules-available/locationinfo/templates/page-panels.html
+++ b/modules-available/locationinfo/templates/page-panels.html
@@ -11,8 +11,8 @@
{{#hasRunmode}}
<th class="slx-smallcol">{{lang_runmodeTHead}}</th>
{{/hasRunmode}}
- <th class="slx-smallcol"></th>
- <th class="slx-smallcol"></th>
+ <th class="slx-smallcol">{{lang_edit}}</th>
+ <th class="slx-smallcol">{{lang_delete}}</th>
</tr>
</thead>
<tbody>
@@ -43,13 +43,11 @@
<td>
<a class="btn btn-default btn-xs" href="?do=locationinfo&amp;show=edit-panel&amp;uuid={{paneluuid}}">
<span class="glyphicon glyphicon-cog"></span>
- {{lang_edit}}
</a>
</td>
<td>
<button type="submit" name="uuid" value="{{paneluuid}}" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-trash"></span>
- {{lang_delete}}
</button>
</td>
</tr>
@@ -58,16 +56,16 @@
</tbody>
</table>
-<div>
- <a class="btn btn-sm btn-success" href="?do=locationinfo&amp;show=edit-panel&amp;uuid=new-default">
+<div class="buttonbar text-right">
+ <a class="btn btn-success" href="?do=locationinfo&amp;show=edit-panel&amp;uuid=new-default">
<span class="glyphicon glyphicon-plus"></span>
{{lang_defaultPanel}}
</a>
- <a class="btn btn-sm btn-success" href="?do=locationinfo&amp;show=edit-panel&amp;uuid=new-summary">
+ <a class="btn btn-success" href="?do=locationinfo&amp;show=edit-panel&amp;uuid=new-summary">
<span class="glyphicon glyphicon-plus"></span>
{{lang_summaryPanel}}
</a>
- <a class="btn btn-sm btn-success" href="?do=locationinfo&amp;show=edit-panel&amp;uuid=new-url">
+ <a class="btn btn-success" href="?do=locationinfo&amp;show=edit-panel&amp;uuid=new-url">
<span class="glyphicon glyphicon-plus"></span>
{{lang_urlPanel}}
</a>