function run() { global $_out, $_sec; if (ap::isCurrentModule($this)) { ap::addMessage($this->getMessage()); $action = param('action'); $nowId = $this->getSection()->getId(); $path = "//sec[@id='" . substr($nowId, 3) . "']"; $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; } break; case 'remove': $struct = ap::getClientstructure(); $id = $this->getSection()->getParent()->getId(); apSectionEdit::removeSection($nowId); $this->redirect($action, $id); break; case 'save': $form->replaceURI(array('PATH' => $this->getQueryPath(), 'PATH_STRUCT_CLIENT' => ABS_PATH_STRUCT_CLIENT)); // сохранение атрибутов $form->save($_REQUEST); // перенос элемента со сменой родителя и порядка $struct = ap::getClientstructure(false); if ($id = ap::getClientSection(param('id_sec'))->getId()) { if (!($parent = $struct->query('/structure//sec[@id="' . param('parent') . '"]')->item(0))) { $parent = $struct->query('/structure')->item(0); } if ($parent) { $sec = $struct->query('/structure//sec[@id="' . $id . '"]')->item(0); $sec = $sec->parentNode->removeChild($sec); if (($pos = param('position')) && ($before = $struct->query('/structure//sec[@id="' . $pos . '"]')->item(0))) { $parent->insertBefore($sec, $before); } else { $parent->appendChild($sec); } $struct->save(); } } $this->redirect($action, param('id_sec')); break; case 'newtpl': if (apSectionTemplate::createPackage(ap::id($this->getSection()->getId()), param('title'))) { $this->redirect('newtpl_ok'); } else { $this->redirect('newtpl_fail'); } break; default: $form->replaceURI(array('PATH' => $path, 'PATH_STRUCT_CLIENT' => ABS_PATH_STRUCT_CLIENT)); $form->getRootElement()->setAttribute('title', str_replace("%TITLE%", $_sec->getTitle(), $form->getRootElement()->getAttribute('title'))); //список разделов if (($ff = $form->getField('parent')) && ($s = ap::getClientstructure()->getSection(ap::id($nowId)))) { $ff->addOption('apStruct', 'Root'); $ar = array($s->getId()); $p = $s->getParent(); $this->seclist(ap::getClientstructure()->de(), $ff, $ar); $ff->setValue($p ? $p->getId() : 'apStruct'); } if ($ff = $form->getField('position')) { $ff->setValue(ap::id($nowId)); } if (!($nowId == 'apStruct')) { $form->load(); } $_sec->getTemplate()->addTemplate('../../modules/' . $this->getName() . '/template/sectionedit.xsl'); $_out->elementIncludeTo($form->getRootElement(), '/page/section'); break; } } }
function onDelete() { if ($row = $this->getRow()) { if (!is_array($row)) { $row = array($row); } foreach ($row as $id) { if ($id) { apSectionEdit::removeSection($id); } } return true; } }