diff options
author | Simon Rettberg | 2016-12-06 19:19:28 +0100 |
---|---|---|
committer | Simon Rettberg | 2016-12-06 19:19:28 +0100 |
commit | 99ae0bdb3b663b2a3c222b7a6413c742f0151dd3 (patch) | |
tree | 720963f6be0ac4a32666e322f743d9ffa16aa2bb /modules-available/roomplanner/page.inc.php | |
parent | [roomplanner] Update locationid -> fixedlocationid (diff) | |
download | slx-admin-99ae0bdb3b663b2a3c222b7a6413c742f0151dd3.tar.gz slx-admin-99ae0bdb3b663b2a3c222b7a6413c742f0151dd3.tar.xz slx-admin-99ae0bdb3b663b2a3c222b7a6413c742f0151dd3.zip |
[roomplanner] Show if PC is already placed in another room
Diffstat (limited to 'modules-available/roomplanner/page.inc.php')
-rw-r--r-- | modules-available/roomplanner/page.inc.php | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php index de82a985..1ddbdc30 100644 --- a/modules-available/roomplanner/page.inc.php +++ b/modules-available/roomplanner/page.inc.php @@ -234,7 +234,12 @@ class Page_Roomplanner extends Page while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $machine = []; $pos = json_decode($row['position'], true); - // TODO: Check if pos is valid (has required keys) + if ($pos === false || !isset($pos['gridRow']) || !isset($pos['gridCol'])) { + // Missing/incomplete position information - reset + Database::exec("UPDATE machine SET fixedlocationid = NULL, position = '' WHERE machineuuid = :uuid", + array('uuid' => $row['machineuuid'])); + continue; + } $machine['muuid'] = $row['machineuuid']; $machine['ip'] = $row['clientip']; @@ -255,13 +260,16 @@ class Page_Roomplanner extends Page protected function getPotentialMachines() { - $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname ' - . 'FROM machine WHERE locationid = :locationid', ['locationid' => $this->locationid]); + $result = Database::simpleQuery('SELECT m.machineuuid, m.macaddr, m.clientip, m.hostname, l.locationname AS otherroom + FROM machine m + LEFT JOIN location l ON (m.fixedlocationid = l.locationid AND m.subnetlocationid <> m.fixedlocationid) + WHERE subnetlocationid = :locationid', ['locationid' => $this->locationid]); $machines = []; while ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $row['combined'] = implode(' ', array_values($row)); + // For searching + $row['combined'] = $row['machineuuid'] . ' ' . $row['macaddr'] . ' ' . $row['clientip'] . ' ' . $row['hostname']; $machines[] = $row; } |