diff options
author | Simon Rettberg | 2016-09-07 17:22:48 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-09-07 17:22:48 +0200 |
commit | 8445a6feb0f3b35b66eebd6e0476cd9f4b35992a (patch) | |
tree | c6339683a48c612b0d0d5654dd8b3a5706ef0834 | |
parent | [sysconfig] Improve design, hide more controls in location-specific view, get... (diff) | |
parent | Merge branch 'modularization' of git.openslx.org:openslx-ng/slx-admin into mo... (diff) | |
download | slx-admin-8445a6feb0f3b35b66eebd6e0476cd9f4b35992a.tar.gz slx-admin-8445a6feb0f3b35b66eebd6e0476cd9f4b35992a.tar.xz slx-admin-8445a6feb0f3b35b66eebd6e0476cd9f4b35992a.zip |
Merge branch 'modularization' of dnbd3:openslx-ng/slx-admin into modularization
-rw-r--r-- | modules-available/roomplanner/inc/pvsgenerator.inc.php | 154 | ||||
-rw-r--r-- | modules-available/roomplanner/page.inc.php | 10 | ||||
-rw-r--r-- | modules-available/sysconfig/templates/custom-upload.html | 8 |
3 files changed, 171 insertions, 1 deletions
diff --git a/modules-available/roomplanner/inc/pvsgenerator.inc.php b/modules-available/roomplanner/inc/pvsgenerator.inc.php new file mode 100644 index 00000000..21ee199b --- /dev/null +++ b/modules-available/roomplanner/inc/pvsgenerator.inc.php @@ -0,0 +1,154 @@ +<?php + +define('X', 0); +define('Y', 1); + +class PvsGenerator +{ + + public static function generate() + { + + if (!Module::isAvailable('locations')) { + die('sorry, but the locations module is required'); + } + + + + /* get all rooms */ + $rooms = array(); + $ret = Database::simpleQuery( + 'SELECT l.locationid, l.locationname, l.managerip, l.tutoruuid, m.clientip as tutorip ' + .'FROM location l LEFT JOIN machine m on l.tutoruuid = m.machineuuid', []); + while ($row = $ret->fetch(PDO::FETCH_ASSOC)) { + if (Location::isLeaf($row['locationid'])) { + $rooms[] = $row; + } + } + /* collect names */ + $roomNames = array(); + + foreach($rooms as $room) { + $roomNames[] = $room['locationname']; + } + + /* add [General]-block */ + $config = "[General]\n"; + $config .= 'rooms=' . implode(', ', $roomNames) . "\n"; + $config .= "allowClientQuit=True\n"; // TODO: remove this + $config .= "showLockDesktopButton=True\n"; // TODO: Make this configurable (or not) + $config .= "\n\n"; + + /* foreach room generate room-block */ + foreach($rooms as $room) { + $config .= PvsGenerator::generateRoomBlock($room); + $config .= "\n"; + } + + return $config; + } + + private static function generateRoomBlock($room) + { + $out = '[' . $room['locationname'] . "]\n"; + + + /* find all clients in that room */ + $machines = PvsGenerator::getMachines($room['locationid']); + /* manager */ + $mgr = $room['managerip']; + $tutor = $room['tutorip']; + if ($mgr) { + $out .= 'mgrIP=' . $mgr . "\n"; + } + /* tutor */ + if ($tutor) { + $out .= 'tutorIP' . $tutor . "\n"; + } + + /* grid */ + $out .= PvsGenerator::generateGrid($machines); + + return $out; + } + + private static function generateGrid($machines) + { + $out = ""; + + /* this is a virtual grid, we first need this to do some optimizations */ + $grid = array(); + /* add each contained client with position and ip */ + foreach ($machines as $machine) { + $grid[$machine['clientip']] = [$machine['gridCol'], $machine['gridRow']]; + } + /* find bounding box */ + PvsGenerator::boundingBox($grid, $minX, $minY, $maxX, $maxY); + $clientSizeX = 4; /* TODO: optimize */ + $clientSizeY = 4; /* TODO: optimize */ + $sizeX = max($maxX - $minX + $clientSizeX, 1); /* never negative */ + $sizeY = max($maxY - $minY + $clientSizeY, 1); /* and != 0 to avoid divide-by-zero in pvsmgr */ + + /* zoom all clients into bounding box */ + foreach ($grid as $ip => $pos) { + $newX = $grid[$ip][X] - $minX; + $newY = $grid[$ip][Y] - $minY; + $grid[$ip] = [$newX, $newY]; + } + + $out .= "gridSize=@Size($sizeX $sizeY)\n"; + $out .= "clientSize=@Size($clientSizeX $clientSizeY)\n"; + $out .= "client\\size=" . count($grid) . "\n"; + + $i = 1; + foreach ($grid as $ip => $pos) { + $out .= "client\\" . $i . "\\ip=$ip\n"; + $out .= "client\\" . $i++ . "\\pos=@Point(" . $pos[X] . ' ' . $pos[Y] . ")\n"; + } + + return $out; + + } + + + + private static function getMachines($roomid) { + $ret = Database::simpleQuery( + 'SELECT clientip, position FROM machine WHERE locationid = :locationid', + ['locationid' => $roomid]); + + $machines = array(); + + while ($row = $ret->fetch(PDO::FETCH_ASSOC)) { + $position = json_decode($row['position'], true); + + $machine = array(); + $machine['clientip'] = $row['clientip']; + $machine['gridRow'] = $position['gridRow']; + $machine['gridCol'] = $position['gridCol']; + $machine['tutor'] = false; /* TODO: find out if machine is default tutor */ + $machine['manager'] = false; /* TODO: find out if machine is manager */ + + $machines[] = $machine; + } + + return $machines; + + } + + private static function boundingBox($grid, &$minX, &$minY, &$maxX, &$maxY ) { + $minX = PHP_INT_MAX; /* PHP_INT_MIN is only avaiable since PHP 7 */ + $maxX = ~PHP_INT_MAX; + $minY = PHP_INT_MAX; + $maxY = ~PHP_INT_MAX; + + foreach ($grid as $pos) { + $minX = min($minX, $pos[X]); + $maxX = max($maxX, $pos[X]); + $minY = min($minY, $pos[Y]); + $maxY = max($maxY, $pos[Y]); + } + } + +} + diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php index 7043f054..2d3b5187 100644 --- a/modules-available/roomplanner/page.inc.php +++ b/modules-available/roomplanner/page.inc.php @@ -55,6 +55,16 @@ class Page_Roomplanner extends Page protected function doRender() { + /* deliver the pvs.ini file temporarily here */ + /* TODO: Move this to api.inc.php */ + if (Request::get('pvs', false, 'bool')) { + /* return a pvs-file */ + echo "<pre>"; + echo PvsGenerator::generate($locationid); + echo "</pre>"; + die(); + } + if ($this->action === 'show') { /* do nothing */ Dashboard::disable(); diff --git a/modules-available/sysconfig/templates/custom-upload.html b/modules-available/sysconfig/templates/custom-upload.html index c453a97d..51677f8b 100644 --- a/modules-available/sysconfig/templates/custom-upload.html +++ b/modules-available/sysconfig/templates/custom-upload.html @@ -14,5 +14,11 @@ </span> </div> <p class="help-block">{{lang_supportedFiles}}: .tar.gz, .tar.bz2, .zip</p> - <button type="submit" class="btn btn-primary">{{lang_upload}}</button> + + <div class="btn-group"> + <a class="btn btn-default" href="?do=SysConfig&action=addmodule">{{lang_back}}</a> + </div> + <div class="btn-group pull-right"> + <button type="submit" class="btn btn-primary">{{lang_upload}}</button> + </div> </form> |