summaryrefslogtreecommitdiffstats
path: root/modules-available/runmode/page.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/runmode/page.inc.php')
-rw-r--r--modules-available/runmode/page.inc.php56
1 files changed, 46 insertions, 10 deletions
diff --git a/modules-available/runmode/page.inc.php b/modules-available/runmode/page.inc.php
index 05f32f81..e26950d0 100644
--- a/modules-available/runmode/page.inc.php
+++ b/modules-available/runmode/page.inc.php
@@ -26,29 +26,58 @@ 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('runmode.module-hasnt-runmode', $module);
+ return;
+ }
+ if (!$modConfig->allowGenericEditor) {
+ Message::addError('runmode.cannot-edit-module', $module);
+ return;
+ }
+ $test = RunMode::getModeName($module, $modeId);
+ if ($test === false) {
+ Message::addError('runmode.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);
- $redirect = Request::post('redirect', false, 'string');
- if ($redirect !== false) {
- Util::redirect($redirect);
- }
- Util::redirect('?do=runmode&module=' . $module . '&modeid=' . $modeId);
+ Message::addSuccess('runmode.enabled-removed-save', $active, $deleted);
+ Util::redirect('?do=runmode&module=' . $module . '&modeid=' . $modeId, true);
} elseif ($action === 'delete-machine') {
$machineuuid = Request::post('machineuuid', false, 'string');
if ($machineuuid === false) {
-
+ Message::addError('main.parameter-missing', 'machineuuid');
+ return;
+ }
+ $mode = RunMode::getRunMode($machineuuid);
+ if ($mode === false) {
+ Message::addError('runmode.machine-not-found', $machineuuid);
+ return;
+ }
+ $modConfig = RunMode::getModuleConfig($mode['module']);
+ if ($modConfig === false) {
+ Message::addError('module-hasnt-runmode', $mode['moduleName']);
+ return;
+ }
+ if (!$modConfig->allowGenericEditor) {
+ Message::addError('runmode.cannot-edit-module', $mode['moduleName']);
+ return;
+ }
+ if (RunMode::setRunMode($machineuuid, null, null)) {
+ Message::addSuccess('machine-removed', $machineuuid);
+ } else {
+ Message::addWarning('machine-not-runmode', $machineuuid);
}
}
}
@@ -76,6 +105,10 @@ class Page_RunMode extends Page
Message::addError('module-hasnt-runmode', $moduleId);
Util::redirect('?do=runmode');
}
+ if (!$config->allowGenericEditor) {
+ Message::addError('runmode.cannot-edit-module', $moduleId);
+ return;
+ }
// Given modeId?
$modeId = Request::get('modeid', false, 'string');
if ($modeId !== false) {
@@ -118,10 +151,13 @@ class Page_RunMode extends Page
$module = Module::get($moduleId);
if ($module === false)
continue;
+ $config = RunMode::getModuleConfig($moduleId);
Render::addTemplate('module-machine-list', array(
'list' => $rows['list'],
'modulename' => $module->getDisplayName(),
'module' => $moduleId,
+ 'canedit' => $config !== false && $config->allowGenericEditor && $config->deleteUrlSnippet === false,
+ 'deleteUrl' => $config->deleteUrlSnippet
));
}
}
@@ -135,7 +171,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', [