diff options
author | Simon Rettberg | 2017-12-01 13:42:04 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-12-01 13:42:04 +0100 |
commit | 5393703f6e1485ddff94a50f63bcdd216ab629f4 (patch) | |
tree | ce2db7130302bd4fb78b170e1fbd75496a1b4510 /modules-available/runmode/page.inc.php | |
parent | Merge remote-tracking branch 'origin/permission-manager' into permission-manager (diff) | |
parent | [roomplanner] Sort already placed machines to the bottom (diff) | |
download | slx-admin-5393703f6e1485ddff94a50f63bcdd216ab629f4.tar.gz slx-admin-5393703f6e1485ddff94a50f63bcdd216ab629f4.tar.xz slx-admin-5393703f6e1485ddff94a50f63bcdd216ab629f4.zip |
Merge branch 'master' into permission-manager
Diffstat (limited to 'modules-available/runmode/page.inc.php')
-rw-r--r-- | modules-available/runmode/page.inc.php | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/modules-available/runmode/page.inc.php b/modules-available/runmode/page.inc.php index 05f32f81..ef42e7be 100644 --- a/modules-available/runmode/page.inc.php +++ b/modules-available/runmode/page.inc.php @@ -26,20 +26,33 @@ class Page_RunMode extends Page $machines = array_filter(Request::post('machines', [], 'array'), 'is_string'); $module = Request::post('module', false, 'string'); $modeId = Request::post('modeid', false, 'string'); - // TODO Validate + $modConfig = RunMode::getModuleConfig($module); + if ($modConfig === false) { + Message::addError('module-hasnt-runmode', $module); + return; + } + if (!$modConfig->allowGenericEditor) { + Message::addError('cannot-edit-module', $module); + return; + } + $test = RunMode::getModeName($module, $modeId); + if ($test === false) { + Message::addError('invalid-modeid', $module, $modeId); + return; + } $active = 0; foreach ($machines as $machine) { $ret = RunMode::setRunMode($machine, $module, $modeId, null, null); if ($ret) { $active++; } else { - Message::addError('invalid-module-or-machine', $module, $machine); + Message::addError('runmode.machine-not-found', $machine); } } $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); + Message::addSuccess('runmode.enabled-removed-save', $active, $deleted); $redirect = Request::post('redirect', false, 'string'); if ($redirect !== false) { Util::redirect($redirect); @@ -48,7 +61,13 @@ class Page_RunMode extends Page } elseif ($action === 'delete-machine') { $machineuuid = Request::post('machineuuid', false, 'string'); if ($machineuuid === false) { - + Message::addError('machine-not-found', $machineuuid); + } else { + if (RunMode::setRunMode($machineuuid, null, null)) { + Message::addSuccess('machine-removed', $machineuuid); + } else { + Message::addWarning('machine-not-runmode', $machineuuid); + } } } } @@ -135,7 +154,7 @@ class Page_RunMode extends Page $moduleId = $module->getIdentifier(); $modeName = RunMode::getModeName($moduleId, $modeId); if ($modeName === false) { - Message::addError('invalid-modeid', $modeId); + Message::addError('invalid-modeid', $moduleId, $modeId); Util::redirect('?do=runmode'); } Render::addTemplate('machine-selector', [ |