summaryrefslogtreecommitdiffstats
path: root/modules-available/roomplanner
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/roomplanner')
-rw-r--r--modules-available/roomplanner/api.inc.php6
-rw-r--r--modules-available/roomplanner/inc/composedroom.inc.php21
-rw-r--r--modules-available/roomplanner/inc/pvsgenerator.inc.php21
-rw-r--r--modules-available/roomplanner/inc/room.inc.php51
-rw-r--r--modules-available/roomplanner/inc/simpleroom.inc.php20
-rw-r--r--modules-available/roomplanner/install.inc.php2
-rw-r--r--modules-available/roomplanner/page.inc.php89
-rw-r--r--modules-available/roomplanner/templates/svg-plan.html26
8 files changed, 125 insertions, 111 deletions
diff --git a/modules-available/roomplanner/api.inc.php b/modules-available/roomplanner/api.inc.php
index 8ddb945c..1af25ca8 100644
--- a/modules-available/roomplanner/api.inc.php
+++ b/modules-available/roomplanner/api.inc.php
@@ -5,14 +5,14 @@ if (Request::any('show') === 'svg') {
$ret = PvsGenerator::generateSvg(Request::any('locationid', false, 'int'),
Request::any('machineuuid', false, 'string'),
Request::any('rotate', 0, 'int'),
- Request::any('scale', 1, 'float'));
+ Request::any('scale', 1, 'float'),
+ Request::any('url', false, 'bool'));
if ($ret === false) {
if (Request::any('fallback', 0, 'int') === 0) {
Header('HTTP/1.1 404 Not Found');
exit;
}
$ret = <<<EOF
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 64 64" height="64" width="64">
<g>
<path d="M 0,0 64,64 Z" style="stroke:#ff0000;stroke-width:5" />
@@ -22,7 +22,7 @@ if (Request::any('show') === 'svg') {
EOF;
}
Header('Content-Type: image/svg+xml');
- die($ret);
+ die('<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $ret);
}
// PVS.ini
diff --git a/modules-available/roomplanner/inc/composedroom.inc.php b/modules-available/roomplanner/inc/composedroom.inc.php
index cdd50984..3ee892db 100644
--- a/modules-available/roomplanner/inc/composedroom.inc.php
+++ b/modules-available/roomplanner/inc/composedroom.inc.php
@@ -98,7 +98,7 @@ class ComposedRoom extends Room
return $this->orientation;
}
- public function subLocationIds()
+ public function subLocationIds(): array
{
return $this->list;
}
@@ -108,7 +108,7 @@ class ComposedRoom extends Room
return $this->controlRoom;
}
- public function machineCount()
+ public function machineCount(): int
{
$sum = 0;
foreach ($this->list as $lid) {
@@ -117,10 +117,9 @@ class ComposedRoom extends Room
return $sum;
}
- public function getSize(&$width, &$height)
+ public function getSize(?int &$width, ?int &$height)
{
$horz = ($this->orientation == 'horizontal');
- $width = $height = 0;
foreach ($this->list as $locId) {
self::$rooms[$locId]->getSize($w, $h);
$width = $horz ? $width + $w : max($width, $w);
@@ -128,7 +127,7 @@ class ComposedRoom extends Room
}
}
- public function getIniClientSection(&$i, $offX = 0, $offY = 0)
+ public function getIniClientSection(int &$i, int $offX = 0, int $offY = 0)
{
if (!$this->enabled)
return false;
@@ -154,10 +153,10 @@ class ComposedRoom extends Room
return $out;
}
- public function getShiftedArray($offX = 0, $offY = 0)
+ public function getShiftedArray(int $offX = 0, int $offY = 0): ?array
{
if (!$this->enabled)
- return false;
+ return null;
if ($this->orientation == 'horizontal') {
$x = 1;
$y = 0;
@@ -168,7 +167,7 @@ class ComposedRoom extends Room
$ret = [];
foreach ($this->list as $locId) {
$new = self::$rooms[$locId]->getShiftedArray($offX, $offY);
- if ($new !== false) {
+ if ($new !== null) {
$ret = array_merge($ret, $new);
self::$rooms[$locId]->getSize($w, $h);
$offX += $w * $x;
@@ -176,7 +175,7 @@ class ComposedRoom extends Room
}
}
if (empty($ret))
- return false;
+ return null;
return $ret;
}
@@ -194,12 +193,12 @@ class ComposedRoom extends Room
return false;
}
- public function isLeaf()
+ public function isLeaf(): bool
{
return false;
}
- public function shouldSkip()
+ public function shouldSkip(): bool
{
return !$this->enabled;
}
diff --git a/modules-available/roomplanner/inc/pvsgenerator.inc.php b/modules-available/roomplanner/inc/pvsgenerator.inc.php
index 0275054b..f3c5c838 100644
--- a/modules-available/roomplanner/inc/pvsgenerator.inc.php
+++ b/modules-available/roomplanner/inc/pvsgenerator.inc.php
@@ -3,7 +3,7 @@
class PvsGenerator
{
- public static function generate()
+ public static function generate(): string
{
/* collect names and build room blocks - filter empty rooms while at it */
$roomNames = array();
@@ -36,7 +36,7 @@ class PvsGenerator
* @param Room $room room/location data as fetched from db
* @return string|false .ini section for room, or false if room is empty
*/
- private static function generateRoomBlock($room)
+ private static function generateRoomBlock(Room $room)
{
$room->getSize($sizeX, $sizeY);
if ($sizeX === 0 || $sizeY === 0)
@@ -78,7 +78,7 @@ class PvsGenerator
* @param float $scale scaling factor for output
* @return string SVG
*/
- public static function generateSvg($locationId = false, $highlightUuid = false, $rotate = 0, $scale = 1)
+ public static function generateSvg($locationId = false, $highlightUuid = false, int $rotate = 0, $scale = 1, $links = false, array $present = null)
{
if ($locationId === false) {
$locationId = Database::queryFirst('SELECT fixedlocationid FROM machine
@@ -91,13 +91,13 @@ class PvsGenerator
}
// Load room
$room = Room::get($locationId);
- if ($room === false)
+ if ($room === null)
return false;
$room->getSize($sizeX, $sizeY);
if ($sizeX === 0 || $sizeY === 0)
return false; // Empty
- $machines = $room->getShiftedArray();
+ $machines = $room->getShiftedArray() ?? [];
$ORIENTATION = ['north' => 2, 'east' => 3, 'south' => 0, 'west' => 1];
if (is_string($highlightUuid)) {
$highlightUuid = strtoupper($highlightUuid);
@@ -105,7 +105,7 @@ class PvsGenerator
// Figure out autorotate
$auto = ($rotate < 0);
if ($auto && $highlightUuid !== false) {
- foreach ($machines as &$machine) {
+ foreach ($machines as $machine) {
if ($machine['machineuuid'] === $highlightUuid) {
$rotate = 4 - $ORIENTATION[$machine['rotation']]; // Reverse rotation
break;
@@ -117,6 +117,8 @@ class PvsGenerator
foreach ($machines as &$machine) {
if ($machine['machineuuid'] === $highlightUuid) {
$machine['class'] = 'hl';
+ } elseif (!empty($present) && !in_array($machine['machineuuid'], $present)) {
+ $machine['class'] = 'muted';
}
$machine['rotation'] = $ORIENTATION[$machine['rotation']] * 90;
}
@@ -140,6 +142,7 @@ class PvsGenerator
'centerY' => $centerY,
'rotate' => $rotate * 90,
'machines' => $machines,
+ 'links' => $links,
'line' => ['x' => $sizeX, 'y' => $sizeY],
], 'roomplanner'); // FIXME: Needs module param if called from api.inc.php
}
@@ -173,14 +176,12 @@ class PvsGenerator
/**
* Get display name for manager of given locationId.
* Hook for "runmode" module to resolve mode name.
- * @param $locationId
- * @return bool|string
*/
- public static function getManagerName($locationId)
+ public static function getManagerName(int $locationId): ?string
{
$names = Location::getNameChain($locationId);
if ($names === false)
- return false;
+ return null;
return implode(' / ', $names);
}
diff --git a/modules-available/roomplanner/inc/room.inc.php b/modules-available/roomplanner/inc/room.inc.php
index 855bdbcf..880cb6d0 100644
--- a/modules-available/roomplanner/inc/room.inc.php
+++ b/modules-available/roomplanner/inc/room.inc.php
@@ -28,11 +28,11 @@ abstract class Room
'SELECT lr.locationid, lr.managerip, lr.tutoruuid, lr.roomplan, m.clientip as tutorip
FROM location_roomplan lr
LEFT JOIN machine m ON (lr.tutoruuid = m.machineuuid)');
- while ($row = $ret->fetch(PDO::FETCH_ASSOC)) {
- $row = self::loadSingleRoom($row);
- if ($row === false)
+ foreach ($ret as $row) {
+ $room = self::loadSingleRoom($row);
+ if ($room === null)
continue;
- self::$rooms[$row->locationId] = $row;
+ self::$rooms[$room->locationId] = $room;
}
foreach (self::$rooms as $room) {
$room->sanitize();
@@ -42,14 +42,14 @@ abstract class Room
/**
* Instantiate ComposedRoom or MachineGroup depending on contents of $row
* @param array $row DB row from location_roomplan.
- * @return Room|false Room instance, false on error
+ * @return ?Room Room instance, null on error
*/
- private static function loadSingleRoom($row)
+ private static function loadSingleRoom(array $row): ?Room
{
$locations = Location::getLocationsAssoc();
settype($row['locationid'], 'int');
if (!isset($locations[$row['locationid']]))
- return false;
+ return null;
if ($locations[$row['locationid']]['isleaf'])
return new SimpleRoom($row);
return new ComposedRoom($row, false);
@@ -59,7 +59,7 @@ abstract class Room
* Get array of all rooms with room plan
* @return Room[]
*/
- public static function getAll()
+ public static function getAll(): array
{
self::init();
return self::$rooms;
@@ -68,9 +68,9 @@ abstract class Room
/**
* Get room instance for given location
* @param int $locationId room to get
- * @return Room|false requested room, false if not configured or not found
+ * @return ?Room requested room, false if not configured or not found
*/
- public static function get($locationId)
+ public static function get(int $locationId): ?Room
{
if (self::$rooms === null) {
$room = Database::queryFirst(
@@ -79,8 +79,10 @@ abstract class Room
LEFT JOIN machine m ON (lr.tutoruuid = m.machineuuid)
WHERE lr.locationid = :lid', ['lid' => $locationId]);
if ($room === false)
- return false;
+ return null;
$room = self::loadSingleRoom($room);
+ if ($room === null)
+ return null;
// If it's a leaf room we probably don't need any other rooms, return it
if ($room->isLeaf())
return $room;
@@ -89,7 +91,7 @@ abstract class Room
}
if (isset(self::$rooms[$locationId]))
return self::$rooms[$locationId];
- return false;
+ return null;
}
public function __construct($row)
@@ -102,35 +104,34 @@ abstract class Room
/**
* @return int number of machines in this room
*/
- abstract public function machineCount();
+ abstract public function machineCount(): int;
/**
* Size of this room, returned by reference.
- * @param int $width OUT width of room
- * @param int $height OUT height of room
+ *
+ * @param int|null $width OUT width of room
+ * @param int|null $height OUT height of room
*/
- abstract public function getSize(&$width, &$height);
+ abstract public function getSize(?int &$width, ?int &$height);
/**
* Get clients in this room in .ini format for PVS.
* Adjusted so the top/left client is at (0|0), which
* is further adjustable with $offX and $offY.
+ *
* @param int $i offset for indexing clients
* @param int $offX positional X offset for clients
* @param int $offY positional Y offset for clients
* @return string|false
*/
- abstract public function getIniClientSection(&$i, $offX = 0, $offY = 0);
+ abstract public function getIniClientSection(int &$i, int $offX = 0, int $offY = 0);
/**
* Get clients in this room as array.
* Adjusted so the top/left client is at (0|0), which
*is further adjustable with $offX and $offY.
- * @param int $offX
- * @param int $offY
- * @return array
*/
- abstract public function getShiftedArray($offX = 0, $offY = 0);
+ abstract public function getShiftedArray(int $offX = 0, int $offY = 0): ?array;
/**
* @return string|false IP address of manager.
@@ -145,12 +146,12 @@ abstract class Room
/**
* @return bool true if this is a simple/leaf room, false for composed rooms.
*/
- abstract public function isLeaf();
+ abstract public function isLeaf(): bool;
/**
* @return bool should this room be skipped from output? true for empty SimpleRoom or disabled ComposedRoom.
*/
- abstract public function shouldSkip();
+ abstract public function shouldSkip(): bool;
/**
* Sanitize this room's data.
@@ -160,7 +161,7 @@ abstract class Room
/**
* @return string get room's name.
*/
- public function locationName()
+ public function locationName(): string
{
return $this->locationName;
}
@@ -168,7 +169,7 @@ abstract class Room
/**
* @return int get room's id.
*/
- public function locationId()
+ public function locationId(): int
{
return $this->locationId;
}
diff --git a/modules-available/roomplanner/inc/simpleroom.inc.php b/modules-available/roomplanner/inc/simpleroom.inc.php
index 78db6c4a..b4d3e744 100644
--- a/modules-available/roomplanner/inc/simpleroom.inc.php
+++ b/modules-available/roomplanner/inc/simpleroom.inc.php
@@ -11,6 +11,7 @@ class SimpleRoom extends Room
private $tutorIp = false;
+ /** @var ?string */
private $managerIp = false;
public function __construct($row)
@@ -21,7 +22,7 @@ class SimpleRoom extends Room
'SELECT machineuuid, clientip, position FROM machine WHERE fixedlocationid = :locationid',
['locationid' => $locationId]);
- while ($clientRow = $ret->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($ret as $clientRow) {
$position = json_decode($clientRow['position'], true);
if ($position === false || !isset($position['gridRow']) || !isset($position['gridCol']))
@@ -55,27 +56,29 @@ class SimpleRoom extends Room
}
}
- public function machineCount()
+ public function machineCount(): int
{
return count($this->machines);
}
- public function getSize(&$width, &$height)
+ public function getSize(?int &$width, ?int &$height)
{
if (empty($this->machines)) {
$width = $height = 0;
return;
}
+ $minX = $minY = $maxX = $maxY = 0;
$this->boundingBox($minX, $minY, $maxX, $maxY);
// client's size that cannot be configured as of today
$width = max($maxX - $minX + self::CLIENT_SIZE, 1);
$height = max($maxY - $minY + self::CLIENT_SIZE, 1);
}
- public function getIniClientSection(&$i, $offX = 0, $offY = 0)
+ public function getIniClientSection(int &$i, int $offX = 0, int $offY = 0): string
{
/* output individual client positions, shift coordinates to requested position */
$out = '';
+ $minX = $minY = $maxX = $maxY = 0;
$this->boundingBox($minX, $minY, $maxX, $maxY);
foreach ($this->machines as $pos) {
$i++;
@@ -86,10 +89,11 @@ class SimpleRoom extends Room
return $out;
}
- public function getShiftedArray($offX = 0, $offY = 0)
+ public function getShiftedArray(int $offX = 0, int $offY = 0): ?array
{
/* output individual client positions, shift coordinates to requested position */
$ret = [];
+ $minX = $minY = $maxX = $maxY = 0;
$this->boundingBox($minX, $minY, $maxX, $maxY);
foreach ($this->machines as $pos) {
$pos['gridCol'] += $offX - $minX;
@@ -100,7 +104,7 @@ class SimpleRoom extends Room
return $ret;
}
- private function boundingBox(&$minX, &$minY, &$maxX, &$maxY)
+ private function boundingBox(int &$minX, int &$minY, int &$maxX, int &$maxY): void
{
if ($this->bb !== false) {
$minX = $this->bb[0];
@@ -130,12 +134,12 @@ class SimpleRoom extends Room
return $this->tutorIp;
}
- public function isLeaf()
+ public function isLeaf(): bool
{
return true;
}
- public function shouldSkip()
+ public function shouldSkip(): bool
{
return empty($this->machines);
}
diff --git a/modules-available/roomplanner/install.inc.php b/modules-available/roomplanner/install.inc.php
index 13365fe1..05fd7589 100644
--- a/modules-available/roomplanner/install.inc.php
+++ b/modules-available/roomplanner/install.inc.php
@@ -47,7 +47,7 @@ if (tableHasColumn('location_roomplan', 'dedicatedmgr')) {
if ($ret === false) {
$res[] = UPDATE_FAILED;
} else {
- while ($row = $ret->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($ret as $row) {
$dedi = $row['dedicatedmgr'] != 0;
$data = json_encode(array('dedicatedmgr' => $dedi));
Database::exec("INSERT IGNORE INTO runmode (machineuuid, module, modeid, modedata, isclient)
diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php
index 8c3beace..94bc3f78 100644
--- a/modules-available/roomplanner/page.inc.php
+++ b/modules-available/roomplanner/page.inc.php
@@ -4,14 +4,14 @@ class Page_Roomplanner extends Page
{
/**
- * @var int locationid of location we're editing
+ * @var ?int locationid of location we're editing, or null if unknown/not set
*/
- private $locationid = false;
+ private $locationid = null;
/**
* @var array location data from location table
*/
- private $location = false;
+ private $location = null;
/**
* @var string action to perform
@@ -25,8 +25,8 @@ class Page_Roomplanner extends Page
private function loadRequestedLocation()
{
- $this->locationid = Request::get('locationid', false, 'integer');
- if ($this->locationid !== false) {
+ $this->locationid = Request::get('locationid', null, 'integer');
+ if ($this->locationid !== null) {
$locs = Location::getLocationsAssoc();
if (isset($locs[$this->locationid])) {
$this->location = $locs[$this->locationid];
@@ -46,11 +46,11 @@ class Page_Roomplanner extends Page
$this->action = Request::any('action', 'show', 'string');
$this->loadRequestedLocation();
- if ($this->locationid === false) {
+ if ($this->locationid === null) {
Message::addError('need-locationid');
Util::redirect('?do=locations');
}
- if ($this->location === false) {
+ if ($this->location === null) {
Message::addError('locations.invalid-location-id', $this->locationid);
Util::redirect('?do=locations');
}
@@ -82,6 +82,9 @@ class Page_Roomplanner extends Page
$config = Database::queryFirst('SELECT roomplan, managerip, tutoruuid
FROM location_roomplan
WHERE locationid = :locationid', ['locationid' => $this->locationid]);
+ if ($config === false) {
+ $config = ['managerip' => '', 'tutoruuid' => ''];
+ }
$runmode = RunMode::getForMode(Page::getModule(), $this->locationid, true);
if (empty($runmode)) {
$config['dedicatedmgr'] = false;
@@ -92,12 +95,6 @@ class Page_Roomplanner extends Page
$data = json_decode($runmode['modedata'], true);
$config['dedicatedmgr'] = (isset($data['dedicatedmgr']) && $data['dedicatedmgr']);
}
- if ($config !== false) {
- $managerIp = $config['managerip'];
- $dediMgr = $config['dedicatedmgr'] ? 'checked' : '';
- } else {
- $dediMgr = $managerIp = '';
- }
$furniture = $this->getFurniture($config);
$subnetMachines = $this->getPotentialMachines();
$machinesOnPlan = $this->getMachinesOnPlan($config['tutoruuid']);
@@ -105,8 +102,8 @@ class Page_Roomplanner extends Page
$canEdit = User::hasPermission('edit', $this->locationid);
$params = [
'location' => $this->location,
- 'managerip' => $managerIp,
- 'dediMgrChecked' => $dediMgr,
+ 'managerip' => $config['managerip'],
+ 'dediMgrChecked' => $config['dedicatedmgr'] ? 'checked' : '',
'subnetMachines' => json_encode($subnetMachines),
'locationid' => $this->locationid,
'roomConfiguration' => json_encode($roomConfig),
@@ -195,7 +192,7 @@ class Page_Roomplanner extends Page
$returnObject = ['machines' => []];
- while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($result as $row) {
if (!Location::isFixedLocationValid($roomLocationId, $row['subnetlocationid']))
continue;
if (empty($row['hostname'])) {
@@ -209,10 +206,10 @@ class Page_Roomplanner extends Page
} elseif ($this->action === 'save') {
// Save roomplan - give feedback if it failed so the window can stay open
$this->loadRequestedLocation();
- if ($this->locationid === false) {
+ if ($this->locationid === null) {
die('Missing locationid in save data');
}
- if ($this->location === false) {
+ if ($this->location === null) {
die('Location with id ' . $this->locationid . ' does not exist.');
}
$this->handleSaveRequest(true);
@@ -229,11 +226,9 @@ class Page_Roomplanner extends Page
if ($leaf !== $this->isLeaf) {
if ($isAjax) {
die('Leaf mode mismatch. Did you restructure locations while editing this room?');
- } else {
- Message::addError('leaf-mode-mismatch');
- Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
- return;
+ Message::addError('leaf-mode-mismatch');
+ Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
if ($this->isLeaf) {
$this->saveLeafRoom($isAjax);
@@ -250,10 +245,9 @@ class Page_Roomplanner extends Page
if (!is_array($config) || !isset($config['furniture']) || !isset($config['computers'])) {
if ($isAjax) {
die('JSON data incomplete');
- } else {
- Message::addError('json-data-invalid');
- Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
+ Message::addError('json-data-invalid');
+ Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
$tutorUuid = Request::post('tutoruuid', '', 'string');
if (empty($tutorUuid)) {
@@ -263,10 +257,9 @@ class Page_Roomplanner extends Page
if ($ret === false) {
if ($isAjax) {
die('Invalid tutor UUID');
- } else {
- Message::addError('invalid-tutor-uuid');
- Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
+ Message::addError('invalid-tutor-uuid');
+ Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
}
$this->saveRoomConfig($config['furniture'], $tutorUuid);
@@ -282,10 +275,9 @@ class Page_Roomplanner extends Page
if ($res === false) {
if ($isAjax) {
die('Error writing config to DB');
- } else {
- Message::addError('db-error');
- Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
+ Message::addError('db-error');
+ Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
}
@@ -302,7 +294,7 @@ class Page_Roomplanner extends Page
* @param array $computers Deserialized json from browser with all the computers
* @param array $oldComputers Deserialized old roomplan from database, used to find removed computers
*/
- protected function saveComputerConfig($computers, $oldComputers)
+ protected function saveComputerConfig(array $computers, array $oldComputers)
{
$oldUuids = [];
@@ -323,12 +315,12 @@ class Page_Roomplanner extends Page
if (!isset($computer['gridRow'])) {
$computer['gridRow'] = 0;
} else {
- $this->sanitizeNumber($computer['gridRow'], 0, 32 * 4);
+ Util::clamp($computer['gridRow'], 0, 32 * 4);
}
if (!isset($computer['gridCol'])) {
$computer['gridCol'] = 0;
} else {
- $this->sanitizeNumber($computer['gridCol'], 0, 32 * 4);
+ Util::clamp($computer['gridCol'], 0, 32 * 4);
}
$position = json_encode(['gridRow' => $computer['gridRow'],
@@ -347,7 +339,7 @@ class Page_Roomplanner extends Page
}
}
- protected function saveRoomConfig($furniture, $tutorUuid)
+ protected function saveRoomConfig(?array $furniture, ?string $tutorUuid)
{
$obj = json_encode(['furniture' => $furniture]);
$managerIp = Request::post('managerip', '', 'string');
@@ -358,13 +350,11 @@ class Page_Roomplanner extends Page
'locationid' => $this->locationid,
'roomplan' => $obj,
'managerip' => $managerIp,
- 'tutoruuid' => $tutorUuid
+ 'tutoruuid' => $tutorUuid,
]);
// See if the client is known, set run-mode
- if (empty($managerIp)) {
- RunMode::deleteMode(Page::getModule(), $this->locationid);
- } else {
- RunMode::deleteMode(Page::getModule(), $this->locationid);
+ RunMode::deleteMode(Page::getModule(), (string)$this->locationid);
+ if (!empty($managerIp)) {
$pc = Statistics::getMachinesByIp($managerIp, Machine::NO_DATA, 'lastseen DESC');
if (!empty($pc)) {
$dedicated = (Request::post('dedimgr') === 'on');
@@ -376,24 +366,27 @@ class Page_Roomplanner extends Page
}
}
- protected function getFurniture($config)
+ protected function getFurniture(array $config): array
{
- if ($config === false)
- return array();
+ if (empty($config['roomplan']))
+ return [];
$config = json_decode($config['roomplan'], true);
if (!is_array($config))
- return array();
+ return [];
return $config;
}
- protected function getMachinesOnPlan($tutorUuid)
+ /**
+ * @return array{computers: array}
+ */
+ protected function getMachinesOnPlan(?string $tutorUuid): array
{
$result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname, position
FROM machine
WHERE fixedlocationid = :locationid',
['locationid' => $this->locationid]);
$machines = [];
- while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($result as $row) {
$machine = [];
$pos = json_decode($row['position'], true);
if ($pos === false || !isset($pos['gridRow']) || !isset($pos['gridCol'])) {
@@ -420,7 +413,7 @@ class Page_Roomplanner extends Page
return ['computers' => $machines];
}
- protected function getPotentialMachines()
+ protected function getPotentialMachines(): array
{
$result = Database::simpleQuery('SELECT m.machineuuid, m.macaddr, m.clientip, m.hostname, l.locationname AS otherroom, m.fixedlocationid
FROM machine m
@@ -429,7 +422,7 @@ class Page_Roomplanner extends Page
$machines = [];
- while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($result as $row) {
if (empty($row['hostname'])) {
$row['hostname'] = $row['clientip'];
}
diff --git a/modules-available/roomplanner/templates/svg-plan.html b/modules-available/roomplanner/templates/svg-plan.html
index a2ecd5a7..c75e01f8 100644
--- a/modules-available/roomplanner/templates/svg-plan.html
+++ b/modules-available/roomplanner/templates/svg-plan.html
@@ -1,4 +1,3 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1"
@@ -18,9 +17,17 @@
stroke-width: .2;
fill: url(#screen);
}
- rect.hl {
+ g.hl rect.scrn {
fill: url(#screenhl);
}
+ g.muted rect.scrn {
+ fill: url(#muted);
+ stroke: #777;
+ }
+ g.muted rect.kb {
+ fill: #eee;
+ stroke: #777;
+ }
]]>
</style>
<defs>
@@ -32,13 +39,20 @@
<stop offset="0%" stop-color="#afa" />
<stop offset="100%" stop-color="#074" />
</radialGradient>
+ <radialGradient id="muted" cx=".4" cy=".3" r="1">
+ <stop offset="0%" stop-color="#fff" />
+ <stop offset="100%" stop-color="#999" />
+ </radialGradient>
</defs>
<g transform="scale({{scale}}) rotate({{rotate}} {{centerX}} {{centerY}})">
<line x1="0" y1="{{line.y}}"
x2="{{line.x}}" y2="{{line.y}}"
style="stroke:#555;stroke-width:.2;opacity:.5" />
{{#machines}}
- <g transform="translate({{gridCol}} {{gridRow}})">
+ {{#links}}
+ <a xlink:href="./?do=statistics&amp;uuid={{machineuuid}}">
+ {{/links}}
+ <g transform="translate({{gridCol}} {{gridRow}})" class="{{class}}">
<rect transform="rotate({{rotation}} 1.9 1.9)"
x=".1"
y="2.6"
@@ -52,9 +66,11 @@
ry=".4"
height="2.2"
width="3.4"
- class="scrn {{class}}"
- />
+ class="scrn" />
</g>
+ {{#links}}
+ </a>
+ {{/links}}
{{/machines}}
</g>
</svg>