From eebe3608ea1687b6985ca0114094bec0e4bb3191 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 14 Nov 2017 16:02:44 +0100 Subject: [dozmod] Improve location & exam mode detection --- modules-available/locations/inc/location.inc.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'modules-available/locations') 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; } -- cgit v1.2.3-55-g7522