function settings($action) { global $_out, $_struct; if (($xml = $this->getDataXML()) && ($e = $xml->getElementById('settings'))) { $form = new form($e); $form->replaceURI(array('MODULE' => $this->getId(), 'SECTION' => $this->getSection()->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')); if ($ff = $form->getField('section')) { apSectionEdit::seclist(ap::getClientstructure()->de(), $ff, $ar = array()); } switch ($action) { case 'update': case 'apply_update': $form->save($_REQUEST); break; case 'edit': if (($id = param('section')) && ($sec = $_struct->getSection($id)) && ($modules = $sec->getModules())) { $xml = new xml(null, 'modules', false); foreach ($modules as $m) { $xml->de()->appendChild($xml->importNode($m->getRootElement(), false)); } ap::ajaxResponse($xml); } break; } $form->load(); $_out->addSectionContent($form->getRootElement()); $this->addTemplate('tpl.xsl'); } }
function getForm($id, $isSettingsForm = false) { if (($xml = $this->getDataXML()) && ($e = $xml->query('//form[@id="' . $id . '"]')->item(0))) { $xml = new xml(null, null, false); $form = new form($xml->appendChild($xml->importNode($e))); $mysql = new mysql(); $sec = $this->getSection(); $form->replaceURI(array('TABLE' => $mysql->getTableName($this->table), 'MODULE' => $this->getId(), 'CONFIG_MODULE' => $this->getConf('module'), 'SECTION' => $sec->getId(), 'ROW' => $isSettingsForm ? null : $this->getRow(), 'PATH_DATA_FILE_CLIENT' => ABS_PATH_DATA_CLIENT . ap::id($sec->getId()) . '.xml', 'PATH_DATA_FILE_AP' => ABS_PATH_DATA_AP . ap::id($sec->getId()) . '.xml', 'PATH_SITE' => ABS_PATH_SITE)); return $form; } }
function getIdSection() { return ap::id($this->getSection()->getId()); }
static function removeSection($id) { global $_struct; if ($sec = $_struct->getSection(ap::id($id))) { $modules = $sec->getModules(); foreach ($modules as $m) { apModuleManager::removeModule($sec->getId(), $m->getId()); } ap::getClientstructure()->removeSection($sec->getId(), true); ap::getClientstructure()->save(); $sec->remove(true); } }
function run() { global $_out, $_struct, $_sec; if (ap::isCurrentModule($this)) { ap::addMessage($this->getMessage()); $action = param('action'); $nowId = $this->getSection()->getId(); $form = $this->getForm(); //если это корневой раздел то показываем форму по добавлению нового раздела switch ($action) { case 'ajax': if ($parent = param('parent')) { if (($sec_parent = ap::getClientSection($parent)) || $parent == 'apStruct') { header('Content-type: text/xml'); $xml = new xml(null, 'seclist', false); $res = ap::getClientstructure()->query($parent == 'apStruct' ? '/structure/sec' : '//sec[@id="' . $sec_parent->getId() . '"]/sec'); foreach ($res as $sec) { $xml->de()->appendChild($xml->createElement('sec', array('id' => $sec->getAttribute('id'), 'title' => $sec->getAttribute('title')))); } echo $xml; } die; } if ($issetid = param('isset')) { echo ap::getClientSection($issetid) ? '0' : '1'; die; } break; case 'add': case 'apply': if (is_array($sec = param('sec')) && $sec['id']) { $form->replaceURI(array('PATH' => $this->getQueryPath(param('parent')), 'PATH_STRUCT_CLIENT' => ABS_PATH_STRUCT_CLIENT)); $form->save($_REQUEST); $_struct->addSection($sec['id'], $sec['title']); /* позиция */ if (($id_pos = param('position')) && ($struct = ap::getClientstructure(false))) { if (($sec_new = $struct->getSection($sec['id'])) && ($sec_pos = $struct->getSection($id_pos))) { $sec_pos->getElement()->parentNode->insertBefore($sec_new->getElement(), $sec_pos->getElement()); $struct->save(); } } /* установить выбранный шаблон раздела */ if ($tpl_id = param('template')) { apSectionTemplate::applyTemplate(ap::id($sec['id']), $tpl_id); } $this->redirect($action, $sec["id"]); } else { $this->redirect('fail'); } break; default: $form->replaceURI(array('PATH' => '', 'PATH_STRUCT_CLIENT' => ABS_PATH_STRUCT_CLIENT)); //список разделов if ($ff = $form->getField('parent')) { $s = ap::getClientstructure()->getSection(ap::id($nowId)); $ff->addOption('apStruct', 'Root'); $ar = array(); if ($s) { $p = $s->getParent(); } $this->seclist(ap::getClientstructure()->de(), $ff, $ar); $ff->setValue($p ? $p->getId() : 'apStruct'); } // список разделов шаблонов if (($ff = $form->getField('template')) && ($tl = apSectionTemplate::getPackages())) { if ($tl->getNum()) { foreach ($tl as $e) { $ff->addOption($e->getAttribute('id'), $e->getAttribute('title')); } } else { $ff->remove(); } } $_sec->getTemplate()->addTemplate('../../modules/' . $this->getName() . '/template/sectionadd.xsl'); $_out->elementIncludeTo($form->getRootElement(), '/page/section'); break; } } }
static function getClientSection($id) { $struct = ap::getClientstructure(); return $struct->getSection(ap::id($id)); }