summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2016-09-07 19:13:24 +0200
committerSimon Rettberg2016-09-07 19:13:24 +0200
commit78c2407ba64007256f61328e2c58daa3bd49cd97 (patch)
treef2f05b1794a83e9c59782cf5b615fab0a3072feb
parent[sysconfig] Confirm dialog for deletion; show success message after deleting ... (diff)
downloadslx-admin-78c2407ba64007256f61328e2c58daa3bd49cd97.tar.gz
slx-admin-78c2407ba64007256f61328e2c58daa3bd49cd97.tar.xz
slx-admin-78c2407ba64007256f61328e2c58daa3bd49cd97.zip
[roomplanner] Add managerip field, move mgr/tutor fields to location_roomplanner table, add to install.inc.php
-rw-r--r--modules-available/roomplanner/inc/pvsgenerator.inc.php11
-rw-r--r--modules-available/roomplanner/install.inc.php29
-rw-r--r--modules-available/roomplanner/js/init.js7
-rw-r--r--modules-available/roomplanner/page.inc.php25
-rw-r--r--modules-available/roomplanner/templates/page.html5
5 files changed, 62 insertions, 15 deletions
diff --git a/modules-available/roomplanner/inc/pvsgenerator.inc.php b/modules-available/roomplanner/inc/pvsgenerator.inc.php
index 21ee199b..fafd07c5 100644
--- a/modules-available/roomplanner/inc/pvsgenerator.inc.php
+++ b/modules-available/roomplanner/inc/pvsgenerator.inc.php
@@ -18,10 +18,13 @@ class PvsGenerator
/* 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', []);
+ 'SELECT l.locationid, l.locationname, lr.managerip, lr.tutoruuid, m.clientip as tutorip '
+ .'FROM location l '
+ .'INNER JOIN location_roomplan lr ON (l.locationid = lr.locationid)'
+ .'LEFT JOIN machine m ON (lr.tutoruuid = m.machineuuid)');
while ($row = $ret->fetch(PDO::FETCH_ASSOC)) {
- if (Location::isLeaf($row['locationid'])) {
+ if (Location::isLeaf($row['locationid'])) { // TODO: This creates extra queries, optimize?
+ $row['locationname'] = str_replace(',', ';', $row['locationname']); // comma probably not the best sep here
$rooms[] = $row;
}
}
@@ -63,7 +66,7 @@ class PvsGenerator
}
/* tutor */
if ($tutor) {
- $out .= 'tutorIP' . $tutor . "\n";
+ $out .= 'tutorIP=' . $tutor . "\n";
}
/* grid */
diff --git a/modules-available/roomplanner/install.inc.php b/modules-available/roomplanner/install.inc.php
index f20985d9..0a6c3729 100644
--- a/modules-available/roomplanner/install.inc.php
+++ b/modules-available/roomplanner/install.inc.php
@@ -3,12 +3,37 @@
$res = array();
-$res[] = tableCreate('location_roomplan', '
+$res[] = tableCreate('location_roomplan', "
`locationid` INT(11) NOT NULL,
+ `managerip` varchar(45) CHARACTER SET ascii DEFAULT '',
+ `tutoruuid` char(36) CHARACTER SET ascii DEFAULT NULL,
`roomplan` BLOB DEFAULT NULL,
- PRIMARY KEY (`locationid`)');
+ PRIMARY KEY (`locationid`),
+ KEY `tutoruuid` (`tutoruuid`)");
+
+if (!tableHasColumn('location_roomplan', 'managerip')) {
+ $ret = Database::exec("ALTER TABLE `location_roomplan` ADD COLUMN `managerip` varchar(45) CHARACTER SET ascii DEFAULT '' AFTER locationid") !== false;
+ if ($ret === false) {
+ finalResponse(UPDATE_FAILED, 'Adding managerip to location_roomplan failed: ' . Database::lastError());
+ }
+ $res[] = UPDATE_DONE;
+}
+if (!tableHasColumn('location_roomplan', 'tutoruuid')) {
+ $ret = Database::exec("ALTER TABLE `location_roomplan` ADD COLUMN `tutoruuid` char(36) CHARACTER SET ascii DEFAULT NULL AFTER managerip,"
+ . " ADD KEY `tutoruuid` (`tutoruuid`)") !== false;
+ if ($ret === false) {
+ finalResponse(UPDATE_FAILED, 'Adding tutoruuid to location_roomplan failed: ' . Database::lastError());
+ }
+ $res[] = UPDATE_DONE;
+}
+if (in_array(UPDATE_DONE, $res)) {
+ Database::exec("ALTER TABLE `location_roomplan`
+ ADD CONSTRAINT `location_roomplan_ibfk_1` FOREIGN KEY (`locationid`) REFERENCES `location` (`locationid`) ON DELETE CASCADE");
+ Database::exec("ALTER TABLE `location_roomplan`
+ ADD CONSTRAINT `location_roomplan_ibfk_2` FOREIGN KEY (`tutoruuid`) REFERENCES `machine` (`machineuuid`) ON DELETE SET NULL ON UPDATE CASCADE");
+}
if (in_array(UPDATE_DONE, $res)) {
finalResponse(UPDATE_DONE, 'Table created successfully');
diff --git a/modules-available/roomplanner/js/init.js b/modules-available/roomplanner/js/init.js
index 67090cc2..83f94390 100644
--- a/modules-available/roomplanner/js/init.js
+++ b/modules-available/roomplanner/js/init.js
@@ -21,13 +21,18 @@ function initRoomplanner() {
});
$("#saveBtn").click(function() {
+ var managerip = $('#manager-ip').val().trim();
+ if (managerip.length !== 0 && !(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(managerip))) {
+ alert('Invalid IP address format');
+ return;
+ }
$('#saveBtn').prop('disabled', true);
$('#error-msg').hide();
$('#success-msg').hide();
$('#saving-msg').show();
var serializedCurrent = roomplanner.serialize();
$.post('?do=roomplanner&locationid=' + locationId,
- { token: TOKEN, action: 'save', serializedRoom: serializedCurrent }
+ { token: TOKEN, action: 'save', serializedRoom: serializedCurrent, managerip: managerip }
).done(function ( data ) {
if (data.indexOf('SUCCESS') !== -1) {
window.close();
diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php
index 2d3b5187..8826615d 100644
--- a/modules-available/roomplanner/page.inc.php
+++ b/modules-available/roomplanner/page.inc.php
@@ -60,7 +60,7 @@ class Page_Roomplanner extends Page
if (Request::get('pvs', false, 'bool')) {
/* return a pvs-file */
echo "<pre>";
- echo PvsGenerator::generate($locationid);
+ echo PvsGenerator::generate();
echo "</pre>";
die();
}
@@ -68,12 +68,19 @@ class Page_Roomplanner extends Page
if ($this->action === 'show') {
/* do nothing */
Dashboard::disable();
- $furniture = $this->getFurniture();
+ $config = Database::queryFirst('SELECT roomplan, managerip FROM location_roomplan WHERE locationid = :locationid', ['locationid' => $this->locationid]);
+ if ($config !== false) {
+ $managerIp = $config['managerip'];
+ } else {
+ $managerIp = '';
+ }
+ $furniture = $this->getFurniture($config);
$subnetMachines = $this->getPotentialMachines();
$machinesOnPlan = $this->getMachinesOnPlan();
$roomConfig = array_merge($furniture, $machinesOnPlan);
Render::addTemplate('page', [
'location' => $this->location,
+ 'managerip' => $managerIp,
'subnetMachines' => json_encode($subnetMachines),
'locationid' => $this->locationid,
'roomConfiguration' => json_encode($roomConfig)]);
@@ -201,14 +208,18 @@ class Page_Roomplanner extends Page
protected function saveRoomConfig($furniture)
{
$obj = json_encode(['furniture' => $furniture]);
- Database::exec('INSERT INTO location_roomplan (locationid, roomplan) VALUES (:locationid, :roomplan) ON DUPLICATE KEY UPDATE roomplan=:roomplan',
- ['locationid' => $this->locationid,
- 'roomplan' => $obj]);
+ Database::exec('INSERT INTO location_roomplan (locationid, roomplan, managerip, tutoruuid)'
+ . ' VALUES (:locationid, :roomplan, :managerip, :tutoruuid)'
+ . ' ON DUPLICATE KEY UPDATE roomplan=VALUES(roomplan), managerip=VALUES(managerip), tutoruuid=VALUES(tutoruuid)', [
+ 'locationid' => $this->locationid,
+ 'roomplan' => $obj,
+ 'managerip' => Request::post('managerip', '', 'string'),
+ 'tutoruuid' => '' // TODO
+ ]);
}
- protected function getFurniture()
+ protected function getFurniture($config)
{
- $config = Database::queryFirst('SELECT roomplan FROM location_roomplan WHERE locationid = :locationid', ['locationid' => $this->locationid]);
if ($config === false) {
return array();
}
diff --git a/modules-available/roomplanner/templates/page.html b/modules-available/roomplanner/templates/page.html
index f4487ad2..ba720ada 100644
--- a/modules-available/roomplanner/templates/page.html
+++ b/modules-available/roomplanner/templates/page.html
@@ -311,7 +311,10 @@
</div>
<div class="pull-left">
-
+ <div class="input-group" style="width:300px">
+ <div class="input-group-addon">{{lang_managerIp}}</div>
+ <input class="form-control" type="text" id="manager-ip" value="{{managerip}}" placeholder="1.2.3.4">
+ </div>
</div>
<div class="pull-right">
<button class="btn btn-default" onclick="triggerCancel()">{{lang_cancel}}</button>