Ejemplo n.º 1
0
 function run()
 {
     global $_out, $_sec;
     if (ap::isCurrentModule($this)) {
         ap::addMessage($this->getMessage());
         if ($form = $this->getForm()) {
             $form->replaceURI(array('ID' => $_sec->getId(), 'MD' => $this->getId(), 'PARENT' => $this->getSection()->GetParent()->getId()));
             switch ($action = param('action')) {
                 case 'save':
                     $values = $this->initImages($form, true);
                     $values = array_merge($_REQUEST, $values);
                     $form->save($values);
                     $this->updateImagesSize($form);
                     $this->redirect('save_ok');
                     break;
                 case 'fileinfo':
                     if (($path = urldecode(param('path'))) && ($f = ap::getFileInfo($_SERVER['DOCUMENT_ROOT'] . $path))) {
                         $f['path'] = $path;
                         $xml = new xml(null, 'file', false);
                         foreach ($f as $tagName => $value) {
                             $xml->de()->appendChild($xml->createElement($tagName, null, $value));
                         }
                         ap::ajaxResponse($xml);
                     }
                     vdump('Error file not found ' . $path);
                     break;
             }
             $this->initImages($form, false);
             $form->load();
             $_out->elementIncludeTo($form->getRootElement(), '/page/section');
         } else {
             throw new Exception('Form not found', EXCEPTION_XML);
         }
     }
 }
Ejemplo n.º 2
0
 function __construct(xml $xml, $tagName = null)
 {
     global $_struct;
     if (!$tagName) {
         $tagName = 'modules';
     }
     if ($modules = $xml->query($query = '/*/' . $tagName)->item(0)) {
     } else {
         $modules = $xml->de()->appendChild($xml->createElement($tagName));
     }
     parent::__construct($modules, 'module');
     $this->keyAttribute = 'id';
     $this->setStructure($_struct);
 }
Ejemplo n.º 3
0
 function run()
 {
     global $_out;
     if (ap::isCurrentModule($this)) {
         switch ($action = param('action')) {
             case 'fileinfo':
                 if (($path = urldecode(param('path'))) && ($f = $this->getFileInfo($_SERVER['DOCUMENT_ROOT'] . $path))) {
                     $f['path'] = $path;
                     $xml = new xml(null, 'file', false);
                     foreach ($f as $tagName => $value) {
                         $xml->de()->appendChild($xml->createElement($tagName, null, $value));
                     }
                     ap::ajaxResponse($xml);
                 }
                 vdump('Error file not found ' . $path);
                 break;
         }
         parent::run();
     }
 }
Ejemplo n.º 4
0
 function rowToXML($outTagname, $condition, &$row)
 {
     $this->getRow($row_set, $condition);
     if ($row = mysql_fetch_assoc($row_set)) {
         $page = 1;
         if ($this->sort_control) {
             $query = 'active=1 and `sort`<=' . $row['sort'];
             if ($this->section_control) {
                 $query .= ' and `' . $this->section_field . '`="' . $this->getCurrentSection() . '"';
             }
             $page = ceil($this->getNumRows($query) / $this->getPageSize());
         } elseif ($this->pageParamName) {
             $page = intval(param($this->pageParamName)) ? intval(param($this->pageParamName)) : 1;
         }
         $out = new xml('new_doc');
         $rec = $out->dd()->appendChild($out->createElement($outTagname, array('page' => $page)));
         $this->addValuesToRecord($rec, $row, $out);
         return $out;
     }
     return null;
 }
Ejemplo n.º 5
0
 function addOption($value, $text)
 {
     $xml = new xml($this->e);
     $this->e->appendChild($xml->createElement('option', array('value' => $value), $text));
 }
Ejemplo n.º 6
0
 function formMessage($str, $form)
 {
     $xml = new xml($form);
     return $form->appendChild($xml->createElement('message', null, $str));
 }
Ejemplo n.º 7
0
 function getButtons()
 {
     $xml = new xml($this->e);
     if ($e = $xml->query('buttons', $this->e)->item(0)) {
     } else {
         $e = $this->e->appendChild($xml->createElement('buttons'));
     }
     if ($e) {
         return new taglist($e, 'b');
     }
 }
Ejemplo n.º 8
0
 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;
         }
     }
 }
Ejemplo n.º 9
0
 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;
         }
     }
 }
Ejemplo n.º 10
0
 static function ajaxResponse($val, $message = null)
 {
     if ($val instanceof xml) {
         $xml = $val;
     } elseif ($val instanceof DOMElement) {
         $xml = new xml();
         $xml->appendChild($xml->importNode($val));
     } else {
         $xml = new xml(null, 'response', false);
         $xml->de()->appendChild($xml->createElement('value', null, $val));
         if ($message) {
             $xml->de()->appendChild($xml->createElement('message', null, $message));
         }
     }
     if ($xml) {
         header('Content-Type: text/xml; charset=utf-8');
         echo $xml;
     }
     die;
 }