diff options
author | Simon Rettberg | 2017-11-30 18:30:01 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-11-30 18:30:01 +0100 |
commit | b90c97b1f096008b5fa9abf8c50a120a85c47a4e (patch) | |
tree | 2e6de58e0de3d044549946b352cb6b2bd61916fd /modules-available/roomplanner/page.inc.php | |
parent | Update translations (diff) | |
download | slx-admin-b90c97b1f096008b5fa9abf8c50a120a85c47a4e.tar.gz slx-admin-b90c97b1f096008b5fa9abf8c50a120a85c47a4e.tar.xz slx-admin-b90c97b1f096008b5fa9abf8c50a120a85c47a4e.zip |
[roomplanner] Refactor to use runmode
Diffstat (limited to 'modules-available/roomplanner/page.inc.php')
-rw-r--r-- | modules-available/roomplanner/page.inc.php | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php index 4e36d3ba..71499caf 100644 --- a/modules-available/roomplanner/page.inc.php +++ b/modules-available/roomplanner/page.inc.php @@ -58,7 +58,17 @@ class Page_Roomplanner extends Page if ($this->action === 'show') { /* do nothing */ Dashboard::disable(); - $config = Database::queryFirst('SELECT roomplan, managerip, dedicatedmgr, tutoruuid FROM location_roomplan WHERE locationid = :locationid', ['locationid' => $this->locationid]); + $config = Database::queryFirst('SELECT roomplan, managerip, tutoruuid FROM location_roomplan WHERE locationid = :locationid', ['locationid' => $this->locationid]); + $runmode = RunMode::getForMode(Page::getModule(), $this->locationid, true); + if (empty($runmode)) { + $config['dedicatedmgr'] = false; + } else { + $runmode = array_pop($runmode); + $config['managerip'] = $runmode['clientip']; + $config['manageruuid'] = $runmode['machineuuid']; + $data = json_decode($runmode['modedata'], true); + $config['dedicatedmgr'] = (isset($data['dedicatedmgr']) && $data['dedicatedmgr']); + } if ($config !== false) { $managerIp = $config['managerip']; $dediMgr = $config['dedicatedmgr'] ? 'checked' : ''; @@ -207,16 +217,30 @@ class Page_Roomplanner extends Page protected function saveRoomConfig($furniture, $tutorUuid) { $obj = json_encode(['furniture' => $furniture]); - Database::exec('INSERT INTO location_roomplan (locationid, roomplan, managerip, tutoruuid, dedicatedmgr)' - . ' VALUES (:locationid, :roomplan, :managerip, :tutoruuid, :dedicatedmgr)' + $managerIp = Request::post('managerip', '', 'string'); + 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), dedicatedmgr=VALUES(dedicatedmgr)', [ + . ' roomplan=VALUES(roomplan), managerip=VALUES(managerip), tutoruuid=VALUES(tutoruuid)', [ 'locationid' => $this->locationid, 'roomplan' => $obj, - 'managerip' => Request::post('managerip', '', 'string'), - 'dedicatedmgr' => (Request::post('dedimgr') === 'on' ? 1 : 0), + 'managerip' => $managerIp, '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); + $pc = Statistics::getMachinesByIp($managerIp, Machine::NO_DATA, 'lastseen DESC'); + if (!empty($pc)) { + $dedicated = (Request::post('dedimgr') === 'on'); + $pc = array_shift($pc); + RunMode::setRunMode($pc->machineuuid, Page::getModule()->getIdentifier(), $this->locationid, json_encode([ + 'dedicatedmgr' => $dedicated + ]), !$dedicated); + } + } } protected function getFurniture($config) |