summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2017-11-14 16:02:44 +0100
committerSimon Rettberg2017-11-14 16:02:44 +0100
commiteebe3608ea1687b6985ca0114094bec0e4bb3191 (patch)
tree06ec67224526a9a04789e3e189698d695d282996
parent[backup] Show warning on main page when last backup was more than 30 days ago (diff)
downloadslx-admin-eebe3608ea1687b6985ca0114094bec0e4bb3191.tar.gz
slx-admin-eebe3608ea1687b6985ca0114094bec0e4bb3191.tar.xz
slx-admin-eebe3608ea1687b6985ca0114094bec0e4bb3191.zip
[dozmod] Improve location & exam mode detection
-rw-r--r--modules-available/dozmod/api.inc.php8
-rw-r--r--modules-available/locations/inc/location.inc.php17
2 files changed, 18 insertions, 7 deletions
diff --git a/modules-available/dozmod/api.inc.php b/modules-available/dozmod/api.inc.php
index de0883a6..74aaa003 100644
--- a/modules-available/dozmod/api.inc.php
+++ b/modules-available/dozmod/api.inc.php
@@ -149,10 +149,12 @@ function getListForLocations($locationIds, $raw)
$key = 'lectures_' . cache_hash($locationIds);
$examMode = Request::get('exams', 'normal-mode', 'string') !== 'normal-mode';
$clientServerMismatch = false;
- if ($raw && Module::isAvailable('exams')) {
+ if (Module::isAvailable('exams')) {
// If we have the exam mode module, we can enforce a server side check and make sure it agrees with the client
$serverExamMode = Exams::isInExamMode($locationIds);
- $clientServerMismatch = ($serverExamMode !== $examMode);
+ if ($raw) {
+ $clientServerMismatch = ($serverExamMode !== $examMode);
+ }
$examMode = $serverExamMode;
}
// Only enforce exam mode validity check if the client requests the raw xml data
@@ -276,7 +278,7 @@ if (substr($ip, 0, 7) === '::ffff:') {
/* lookup location id(s) */
-$location_ids = Location::getFromIp($ip);
+$location_ids = Location::getFromIp($ip, true);
$location_ids = Location::getLocationRootChain($location_ids);
if ($resource === 'list') {
diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php
index 1dae4deb..476f4c68 100644
--- a/modules-available/locations/inc/location.inc.php
+++ b/modules-available/locations/inc/location.inc.php
@@ -255,16 +255,25 @@ class Location
* Ignores any manually assigned locationid (fixedlocationid).
*
* @param string $ip IP address of client
+ * @param bool $honorRoomPlanner consider a fixed location assigned manually by roomplanner
* @return bool|int locationid, or false if no match
*/
- public static function getFromIp($ip)
+ public static function getFromIp($ip, $honorRoomPlanner = false)
{
if (Module::get('statistics') !== false) {
// Shortcut - try to use subnetlocationid in machine table
- $ret = Database::queryFirst("SELECT subnetlocationid FROM machine WHERE clientip = :ip", compact('ip'));
+ if ($honorRoomPlanner) {
+ $ret = Database::queryFirst("SELECT locationid AS loc FROM machine
+ WHERE clientip = :ip
+ ORDER BY lastseen DESC LIMIT 1", compact('ip'));
+ } else {
+ $ret = Database::queryFirst("SELECT subnetlocationid AS loc FROM machine
+ WHERE clientip = :ip
+ ORDER BY lastseen DESC LIMIT 1", compact('ip'));
+ }
if ($ret !== false) {
- if ($ret['subnetlocationid'] > 0) {
- return (int)$ret['subnetlocationid'];
+ if ($ret['loc'] > 0) {
+ return (int)$ret['loc'];
}
return false;
}