diff options
author | Simon Rettberg | 2017-11-14 16:02:44 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-11-14 16:02:44 +0100 |
commit | eebe3608ea1687b6985ca0114094bec0e4bb3191 (patch) | |
tree | 06ec67224526a9a04789e3e189698d695d282996 /modules-available/locations/inc | |
parent | [backup] Show warning on main page when last backup was more than 30 days ago (diff) | |
download | slx-admin-eebe3608ea1687b6985ca0114094bec0e4bb3191.tar.gz slx-admin-eebe3608ea1687b6985ca0114094bec0e4bb3191.tar.xz slx-admin-eebe3608ea1687b6985ca0114094bec0e4bb3191.zip |
[dozmod] Improve location & exam mode detection
Diffstat (limited to 'modules-available/locations/inc')
-rw-r--r-- | modules-available/locations/inc/location.inc.php | 17 |
1 files changed, 13 insertions, 4 deletions
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; } |