function run() { global $_out; if (ap::isCurrentModule($this)) { $action = param('action'); // управление текущими модулями $modules = $this->getModules(); // все модули доступные для подключения $all_modules = $this->getModuleList(); $form = $this->getForm($action); switch ($action) { case 'active': if (($row = param('row')) && ($sec = $this->getDataSection()) && ($modules = $sec->getModules()) && ($module = $modules->getById($row)) && ($e = $module->getRootElement())) { if (param('active') == 'on') { $e->setAttribute('readonly', 'readonly'); } elseif ($e->hasAttribute('readonly')) { $e->removeAttribute('readonly'); } $modules->getXML()->save(); $state = !(param('active') == 'on'); if (param('ajax')) { ap::ajaxResponse($state ? 'on' : 'off'); } } break; case 'move': if (($row = param('row')) && ($pos = param('pos'))) { $modules->move($row, $pos); $modules->getXML()->save(); } $this->redirect($action); break; case 'delete': if ($row = param('row')) { apModuleManager::removeModule($this->getIdSection(), $row); } $this->redirect($action); break; case 'add': case 'apply_add': if ($m = apModuleManager::addModule($this->getIdSection(), param('name'), param('title'), param('readonly'))) { $this->redirect($action, $m->getId()); } else { throw new Exception('Error add module "' . $_REQUEST['name'] . '"'); } break; case 'update': case 'apply_update': case 'edit': if (($row = param('row')) && ($sec = $this->getDataSection()) && ($modules = $sec->getModules()) && ($module = $modules->getById($row)) && method_exists($module, 'settings')) { $module->settings($action); } $this->redirect($action, $row); break; case 'new': $m = $modules->add('tests_module'); $form->replaceURI(array('ID' => $this->getIdSection(), 'MODULEID' => $m->getId(), 'PATH_DATA_FILE_CLIENT' => ABS_PATH_DATA_CLIENT . ap::id($this->getSection()->getId()) . '.xml', 'PATH_DATA_FILE_AP' => ABS_PATH_DATA_AP . ap::id($this->getSection()->getId()) . '.xml')); $select = $form->getField('name'); foreach ($all_modules as $key => $module) { $select->addOption($key, $module['name']); } $_out->elementIncludeTo($form->getRootElement(), '/page/section'); break; default: if ($res = $this->getList()) { $_out->addSectionContent($res); } } } }
function onSectionReady($params = null) { global $_sec, $_out; $modules = $_sec->getModules(); if (!$modules->getNum() && $_sec->isChildOf('apData')) { if (apModuleManager::addModule($_sec->getId(), 'apContent', $_sec->getTitle())) { header('Location: ' . $_SERVER['REQUEST_URI']); die; } else { throw new Exception('apContent install error', EXCEPTION_XML); } } if ($_sec->getId() == 'apStruct') { if (!$modules->hasModule('apSectionAdd')) { $modules->add('apSectionAdd', t('Add section')); } } if ($_sec->isChildOf('apStruct')) { if (!$modules->hasModule('apSectionEdit')) { $modules->add('apSectionEdit', t('Properties')); } if (!$modules->hasModule('apModuleManager')) { $modules->add('apModuleManager', t('Modules')); } if (!$modules->hasModule('apTemplateManager')) { $modules->add('apTemplateManager', t('Templates')); } if (!$modules->hasModule('apSectionAdd')) { $modules->add('apSectionAdd', t('Add section')); } } foreach ($modules as $id => $m) { $title = $m->getTitle(); if (!$title) { continue; } ap::addTab($m->getId(), $title, ap::isCurrentModule($m->getId())); } if ($e = $_out->query('/page/section')->item(0)) { $e->setAttribute('module', ap::getCurrentModule()->getId()); } }