edit = ConfigModule::get($editId); if (self::$instance->edit === false) Util::traceError('Invalid module id for editing'); if ($step !== 'AddModule_Assign' && !preg_match('/^' . self::$instance->edit->moduleType() . '_/', $step)) Util::traceError('Module to edit is of different type!'); Util::addRedirectParam('edit', self::$instance->edit->id()); } } protected function tmError() { Message::addError('main.taskmanager-error'); Util::redirect('?do=SysConfig'); } protected function taskError($status) { if (isset($status['data']['error'])) { $error = $status['data']['error']; } elseif (isset($status['statusCode'])) { $error = $status['statusCode']; } else { $error = Dictionary::translate('lang_unknwonTaskManager'); } Message::addError('main.task-error', $error); Util::redirect('?do=SysConfig'); } /** * Called before any HTML rendering happens, so you can * prepare stuff, validate input, and optionally redirect * early if something is wrong, or you received post * data etc. */ protected function preprocessInternal() { // void } /** * Do page rendering. */ protected function renderInternal() { // void } /** * Handle ajax stuff */ protected function ajaxInternal() { // void } public static function preprocess() { if (self::$instance === false) { Util::traceError('No step instance yet'); } self::$instance->preprocessInternal(); } public static function render() { if (self::$instance === false) { Util::traceError('No step instance yet'); } if (get_class(self::$instance) !== 'AddModule_Assign' && self::$instance->edit !== false) { Message::addInfo('replacing-module', self::$instance->edit->title()); } self::$instance->renderInternal(); } public static function ajax() { if (self::$instance === false) { Util::traceError('No step instance yet'); } self::$instance->ajaxInternal(); } } /** * Start dialog for adding module. Here the user * selects which kind of module they want to add. */ class AddModule_Start extends AddModule_Base { protected function renderInternal() { $title = $order = array(); $mods = ConfigModule::getList(); foreach ($mods as $module) { $title[] = $module['title']; $order[] = $module['sortOrder']; } array_multisort($order, SORT_ASC, $title, SORT_ASC, $mods); Render::addDialog(Dictionary::translate('lang_moduleAdd'), false, 'start', array('modules' => array_values($mods))); } } /** * End dialog for adding module. Here the user * can assign the module to configs. */ class AddModule_Assign extends AddModule_Base { protected function preprocessInternal() { $assign = Request::any('assign', false, 'boolean'); if ($assign) { $configIds = Request::any('configs', [], 'array'); $moduleId = $this->edit->id(); $moduleType = $this->edit->moduleType(); if (ConfigModule::getList()[$moduleType]['unique']) { $moduleIds = []; foreach (ConfigModule::getAll($moduleType) as $module) { $moduleIds[] = $module->id(); } Database::exec("DELETE FROM configtgz_x_module WHERE configid IN (:configids) AND moduleid IN (:moduleids)", array('configids' => $configIds, 'moduleids' => $moduleIds)); } foreach ($configIds as $configId) { Database::exec("INSERT INTO configtgz_x_module (configid, moduleid) VALUES (:configid, :moduleid)", array( 'configid' => $configId, 'moduleid' => $moduleId )); ConfigTgz::get($configId)->generate(); } Util::redirect('?do=SysConfig'); } } protected function renderInternal() { $data = ['edit' => $this->edit->id(), 'configs' => SysConfig::getAll()]; if (count($data['configs']) === 0) Util::redirect('?do=SysConfig'); Render::addDialog(Dictionary::translate('lang_moduleAssign'), false, 'assign', $data); } } /* * Helper functions to set/get a batch of vars from/to post variables or a module */ /** * * @param \ConfigModule $module * @param array $array * @param array $keys */ function moduleToArray($module, &$array, $keys) { foreach ($keys as $key) { $array[$key] = $module->getData($key); } } /** * * @param \ConfigModule $module * @param array $array * @param array $keys */ function arrayToModule($module, $array, $keys) { foreach ($keys as $key) { $module->setData($key, $array[$key]); } } /** * * @param array $array * @param array $keys */ function postToArray(&$array, $keys, $ignoreMissing = false) { foreach ($keys as $key) { $val = Request::post($key, '--not-in-post'); if ($ignoreMissing && $val === '--not-in-post') continue; $array[$key] = $val; } }