diff options
author | Simon Rettberg | 2017-08-10 15:56:58 +0200 |
---|---|---|
committer | Simon Rettberg | 2017-08-10 15:56:58 +0200 |
commit | 9abacc2da789048a83953da5622a6e588bb432a4 (patch) | |
tree | ee3b98760bc5b23b64a722fb92d7cbbce3fb7beb /modules-available/runmode/page.inc.php | |
parent | [baseconfig] PHP 7 compat (diff) | |
download | slx-admin-9abacc2da789048a83953da5622a6e588bb432a4.tar.gz slx-admin-9abacc2da789048a83953da5622a6e588bb432a4.tar.xz slx-admin-9abacc2da789048a83953da5622a6e588bb432a4.zip |
[runmode] Add isclient property per client, implement overview page
Diffstat (limited to 'modules-available/runmode/page.inc.php')
-rw-r--r-- | modules-available/runmode/page.inc.php | 79 |
1 files changed, 70 insertions, 9 deletions
diff --git a/modules-available/runmode/page.inc.php b/modules-available/runmode/page.inc.php index f3e7d024..05f32f81 100644 --- a/modules-available/runmode/page.inc.php +++ b/modules-available/runmode/page.inc.php @@ -27,14 +27,29 @@ class Page_RunMode extends Page $module = Request::post('module', false, 'string'); $modeId = Request::post('modeid', false, 'string'); // TODO Validate + $active = 0; foreach ($machines as $machine) { - Database::exec("INSERT IGNORE INTO runmode (machineuuid, module, modeid) - VALUES (:machine, :module, :modeId)", compact('machine', 'module', 'modeId')); + $ret = RunMode::setRunMode($machine, $module, $modeId, null, null); + if ($ret) { + $active++; + } else { + Message::addError('invalid-module-or-machine', $module, $machine); + } } - Database::exec('DELETE FROM runmode + $deleted = Database::exec('DELETE FROM runmode WHERE module = :module AND modeid = :modeId AND machineuuid NOT IN (:machines)', compact('module', 'modeId', 'machines')); + Message::addError('enabled-removed-save', $active, $deleted); + $redirect = Request::post('redirect', false, 'string'); + if ($redirect !== false) { + Util::redirect($redirect); + } Util::redirect('?do=runmode&module=' . $module . '&modeid=' . $modeId); + } elseif ($action === 'delete-machine') { + $machineuuid = Request::post('machineuuid', false, 'string'); + if ($machineuuid === false) { + + } } } @@ -45,8 +60,7 @@ class Page_RunMode extends Page $this->renderModule($moduleId); return; } - // TODO - Message::addInfo('OMGhai2U'); + $this->renderClientList(false); } private function renderModule($moduleId) @@ -56,14 +70,60 @@ class Page_RunMode extends Page Message::addError('main.no-such-module', $moduleId); Util::redirect('?do=runmode'); } + $module->activate(); + $config = RunMode::getModuleConfig($moduleId); + if ($config === false) { + Message::addError('module-hasnt-runmode', $moduleId); + Util::redirect('?do=runmode'); + } + // Given modeId? $modeId = Request::get('modeid', false, 'string'); if ($modeId !== false) { + // Show edit page for specific module-mode combo $this->renderModuleMode($module, $modeId); return; } - // TODO - Message::addError('main.parameter-missing', 'modeid'); - Util::redirect('?do=runmode'); + // Show list of machines with assigned mode for this module + $this->renderClientList($moduleId); + Render::setTitle(Page::getModule()->getDisplayName() . ' – ' . $module->getDisplayName()); + } + + private function renderClientList($onlyModule) + { + if ($onlyModule === false) { + $where = ''; + } else { + $where = ' AND r.module = :moduleId '; + } + $res = Database::simpleQuery("SELECT m.machineuuid, m.hostname, m.clientip, r.module, r.modeid, r.isclient" + . " FROM runmode r" + . " INNER JOIN machine m ON (m.machineuuid = r.machineuuid $where )" + . " ORDER BY m.hostname ASC, m.clientip ASC", array('moduleId' => $onlyModule)); + $modules = array(); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + if (!isset($modules[$row['module']])) { + if (!Module::isAvailable($row['module'])) + continue; + $modules[$row['module']] = array('config' => RunMode::getModuleConfig($row['module']), 'list' => array()); + } + if (empty($row['hostname'])) { + $row['hostname'] = $row['clientip']; + } + if ($modules[$row['module']]['config']->getModeName !== false) { + $row['mode_name'] = call_user_func($modules[$row['module']]['config']->getModeName, $row['modeid']); + } + $modules[$row['module']]['list'][] = $row; + } + foreach ($modules as $moduleId => $rows) { + $module = Module::get($moduleId); + if ($module === false) + continue; + Render::addTemplate('module-machine-list', array( + 'list' => $rows['list'], + 'modulename' => $module->getDisplayName(), + 'module' => $moduleId, + )); + } } /** @@ -83,7 +143,8 @@ class Page_RunMode extends Page 'modeid' => $modeId, 'moduleName' => $module->getDisplayName(), 'modeName' => $modeName, - 'machines' => json_encode(RunMode::getForMode($module, $modeId, true)) + 'machines' => json_encode(RunMode::getForMode($module, $modeId, true)), + 'redirect' => Request::get('redirect', '', 'string'), ]); } |