示例#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);
         }
     }
 }
示例#2
0
 function run()
 {
     global $_out;
     if (ap::isCurrentModule($this)) {
         /* локализация */
         ap::translate($this->getSection()->getXML(), array('//@title', '//field[@label]/@label', '//button[@value]/@value', '//rowlist/col[@header]/@header'), PATH_MODULE . __CLASS__ . '/translate.php');
         ap::addMessage($this->getMessage());
         $row = $this->getRow();
         switch ($action = param('action')) {
             case 'delete':
                 if ($row && ($tl = $this->getPackages())) {
                     if (!is_array($row)) {
                         $row = array($row);
                     }
                     foreach ($row as $v) {
                         if ($e = $tl->getById($v)) {
                             $tl->remove($e);
                         }
                     }
                     $tl->getXML()->save();
                     $this->redirect('delete_ok');
                 } else {
                     $this->redirect('delete_fail');
                 }
                 break;
             default:
                 if ($rl = $this->getRowList()) {
                     $_out->elementIncludeTo($rl->getRootElement(), '/page/section');
                 }
         }
     }
 }
示例#3
0
 function run()
 {
     if (ap::isCurrentModule($this)) {
         ap::addMessage($this->getMessage());
         switch (param('action')) {
             case 'update':
                 if ($this->onUpdate()) {
                     $this->redirect('save_ok');
                 } else {
                     $this->redirect('save_fail');
                 }
                 break;
             default:
                 $this->onDefault();
         }
     }
 }
示例#4
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()));
             switch ($action = param('action')) {
                 case 'save':
                     $form->save($_REQUEST);
                     $this->redirect('save_ok');
                     break;
             }
             $form->load();
             $_out->elementIncludeTo($form->getRootElement(), '/page/section');
         } else {
             throw new Exception('Form not found', EXCEPTION_XML);
         }
     }
 }
示例#5
0
 function run()
 {
     global $_out;
     if (ap::isCurrentModule($this)) {
         ap::addMessage($this->getMessage());
         switch ($action = param('action')) {
             case 'active':
                 if ($row = $this->getRow()) {
                     $mysql = new mysql();
                     $state = !(param('active') == 'on');
                     $res = $mysql->update($this->table, array('active' => $state ? '1' : '0'), '`id`=' . $row);
                     if (!$res) {
                         $state = !$state;
                     }
                     if (param('ajax')) {
                         ap::ajaxResponse($state ? 'on' : 'off');
                     } else {
                         $this->redirect('active_' . ($res ? 'ok' : 'fail'));
                     }
                 }
                 break;
             case 'move':
                 if (($row = $this->getRow()) && ($pos = param('pos')) && ($rl = $this->getList()) && $rl->moveRow($row, $pos)) {
                     $this->redirect('move_ok');
                 } else {
                     $this->redirect('move_fail');
                 }
                 break;
             case 'delete':
                 if ($this->onDelete($action)) {
                     $this->redirect('delete_ok');
                 } else {
                     $this->redirect('delete_fail');
                 }
                 break;
             case 'update':
             case 'apply_update':
                 if ($this->onUpdate($action)) {
                     $this->redirect('update_ok');
                 } else {
                     $this->redirect('update_fail');
                 }
                 break;
             case 'add':
             case 'apply_add':
                 if ($this->onAdd($action)) {
                     $this->redirect('add_ok');
                 } else {
                     $this->redirect('add_fail');
                 }
                 break;
             case 'edit':
                 if ($this->onEdit($action)) {
                     $_out->addSectionContent($this->getForm($action)->getRootElement());
                 }
                 break;
             case 'new':
                 if ($this->onNew($action)) {
                     $_out->addSectionContent($this->getForm($action)->getRootElement());
                 }
                 break;
             default:
                 if ($rl = $this->getList()) {
                     $rl->build();
                     $_out->addSectionContent($rl->getRootElement());
                 }
         }
     }
 }
示例#6
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;
         }
     }
 }
示例#7
0
 function run()
 {
     if (ap::isCurrentModule($this)) {
         ap::addMessage($this->getMessage());
         switch ($this->getAction()) {
             case 'active':
                 if ($this->onActive()) {
                     $this->redirect('active_ok');
                 } else {
                     $this->redirect('active_fail');
                 }
                 break;
             case 'move':
                 if ($this->onMove()) {
                     $this->redirect('move_ok');
                 } else {
                     $this->redirect('move_fail');
                 }
                 break;
             case 'delete':
                 if ($this->onDelete()) {
                     $this->redirect('delete_ok');
                 } else {
                     $this->redirect('delete_fail');
                 }
                 break;
             case 'update':
             case 'apply_update':
                 if ($this->onUpdate()) {
                     $this->redirect('update_ok');
                 } else {
                     $this->redirect('update_fail');
                 }
                 break;
             case 'add':
             case 'apply_add':
                 if ($this->onAdd()) {
                     $this->redirect('add_ok');
                 } else {
                     $this->redirect('add_fail');
                 }
                 break;
             case 'edit':
                 $this->onEdit();
                 break;
             case 'new':
                 $this->onNew();
                 break;
             default:
                 $this->onDefault();
         }
     }
 }
示例#8
0
 function run()
 {
     global $_out, $_sec;
     if (ap::isCurrentModule($this)) {
         ap::addMessage($this->getMessage());
         $this->xml = $this->getSection()->getXML();
         $this->sec = ap::getClientSection($_sec->getId())->getModules()->getXML();
         $action = param('action');
         $this->forms = $this->getForm($action);
         $this->tl = $this->getTagList();
         $this->tl->setKeyAttribute('name');
         $this->checks = array('text' => 'empty', 'email' => 'empty email', 'password' => 'empty', 'textarea' => 'empty');
         switch ($action) {
             case 'delete':
                 if ($this->onDelete($action)) {
                     $this->redirect('delete_ok');
                 } else {
                     $this->redirect('delete_fail');
                 }
                 break;
             case "move":
                 if (($row = $this->getRow()) && ($pos = param('pos')) > 0 && ($e = $this->tl->getById($row))) {
                     $this->tl->move($e, $pos);
                     $this->tl->getXML()->save();
                     $this->redirect('move_ok');
                 } else {
                     $this->redirect('move_fail');
                 }
                 break;
             case 'update':
             case 'apply_update':
                 if ($this->onUpdate($action)) {
                     $this->redirect('update_ok');
                 } else {
                     $this->redirect('update_fail');
                 }
                 break;
             case 'edit':
                 $this->onEdit($action);
                 break;
             case 'add':
             case 'apply_add':
                 if ($this->onAdd()) {
                     $this->redirect('add_ok');
                 } else {
                     $this->redirect('add_fail');
                 }
                 break;
             case 'new':
                 $this->onNew($action);
                 break;
             default:
                 if ($rl = $this->getList()) {
                     $_out->addSectionContent($rl->getRootElement());
                 }
                 break;
         }
     }
 }
示例#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;
         }
     }
 }
示例#10
0
 function run()
 {
     global $_out;
     if (ap::isCurrentModule($this)) {
         ap::addMessage($this->getMessage());
         $action = param('action');
         $users = new users();
         $form = $this->getForm($action);
         $row = $this->getRow();
         switch ($action) {
             case 'active':
                 if ($row && $users->userExists($row)) {
                     $usr = $users->getUser($row);
                     $usr->disable(param('active') == 'on');
                     if (param('ajax')) {
                         ap::ajaxResponse($usr->getDisabled() ? 'off' : 'on');
                     } else {
                         $this->redirect('active_ok');
                     }
                 }
                 break;
             case 'move':
                 if ($row && $users->userExists($row) && ($pos = param('pos')) > 0) {
                     $users->moveUser($users->getUser($row), $pos);
                     $this->redirect('move_ok');
                 } else {
                     $this->redirect('move_fail');
                 }
                 break;
             case 'delete':
                 if ($row && $users->userExists($row)) {
                     $users->removeUser(param('row'));
                     $this->redirect('delete_ok');
                 } else {
                     $this->redirect('delete_fail');
                 }
                 break;
             case 'update':
             case 'apply_update':
                 if ($row && $users->userExists($row)) {
                     $pos = $users->getPos($users->getUser($row)) + 1;
                     $form->replaceURI(array('POSITION' => $pos));
                     $form->save($_REQUEST);
                     $this->redirect('update_ok');
                 } else {
                     $this->redirect('update_fail');
                 }
                 break;
             case 'add':
             case 'apply_add':
                 if ($row && !$users->userExists($row)) {
                     $form->save($_REQUEST);
                     $this->redirect('add_ok');
                 } else {
                     $this->redirect('add_fail');
                 }
                 break;
             case 'edit':
                 $pos = $users->getPos($users->getUser($row)) + 1;
                 $form->replaceURI(array('POSITION' => $pos));
                 $form->load();
             case 'new':
                 $_out->elementIncludeTo($form->getRootElement(), '/page/section');
                 break;
             default:
                 if ($rl = $this->getList($users)) {
                     $_out->elementIncludeTo($rl->getRootElement(), '/page/section');
                 }
         }
     }
 }
示例#11
0
 function run()
 {
     global $_out, $_struct;
     if (ap::isCurrentModule($this)) {
         ap::addMessage($this->getMessage());
         // управление текущими шаблонами
         $templates = $this->getTemplate();
         if (is_object($templates)) {
             $num_templates = $templates->getNum() + 1;
         } else {
             $num_templates = 1;
         }
         // все шаблоны доступные для подключения
         $attay_all_template = $this->getAllTemplates(false);
         // объект в массив
         $array_all_template_by_sec = array();
         if ($templates) {
             foreach ($templates as $template) {
                 $array_all_template_by_sec[] = $template->getAttribute('id');
             }
         }
         // разность
         $array_diff = array_diff($attay_all_template, $array_all_template_by_sec);
         $action = param('action');
         $form = $this->getForm($action);
         $form_def_tpl = $this->getForm('edit_def_tpl');
         $form_def_tpl->replaceURI(array('ID' => $this->getIdSection()));
         switch ($action) {
             case 'delete':
                 if ($row = param('row')) {
                     if (!is_array($row)) {
                         $row = array($row);
                     }
                     $row = array_reverse($row);
                     $count = 0;
                     foreach ($row as $v) {
                         if ($templates->getById($v)) {
                             $templates->remove($templates->getById($v));
                             $count++;
                         }
                     }
                     if ($count) {
                         $templates->getXML()->save();
                     }
                     $this->setMessage($action . '_' . $count);
                 }
                 $this->redirect($action);
                 break;
             case 'update':
             case 'apply_update':
                 $form->replaceURI(array('ID' => $this->getIdSection(), 'TEMLATEID' => param('row')));
                 $form->save($_REQUEST);
                 $this->setMessage($action);
                 $this->redirect($action, param('row'));
                 break;
             case 'add':
             case 'apply_add':
                 if ($id = ap::getClientSection($this->getIdSection())->getTemplate()->getId()) {
                     $form->replaceURI(array('ID' => $this->getIdSection(), 'TEMLATEID' => $id));
                     $form->save($_REQUEST);
                     $tpl = param('tpl');
                     $this->setMessage($action);
                     $this->redirect($action, $tpl['id']);
                 }
                 break;
             case 'edit':
                 if ($id = ap::getClientSection($this->getIdSection())->getTemplate()->getId()) {
                     $form->replaceURI(array('ID' => $this->getIdSection(), 'TEMLATEID' => param('row')));
                     $select = $form->getField('id_template');
                     if ($template = $templates->getById(param('row'))) {
                         $array_diff[] = $template->getAttribute('id');
                     }
                     foreach ($array_diff as $item) {
                         $select->addOption($item, $item);
                     }
                     $form->load();
                     $_out->elementIncludeTo($form->getRootElement(), '/page/section');
                 } else {
                     $this->redirect();
                 }
                 break;
             case 'new':
                 if ($id = ap::getClientSection($this->getIdSection())->getTemplate()->getId()) {
                     $select = $form->getField('tpl[id]');
                     foreach ($array_diff as $item) {
                         $select->addOption($item, $item);
                     }
                     $_out->elementIncludeTo($form->getRootElement(), '/page/section');
                 } else {
                     $this->redirect();
                 }
                 break;
             case 'apply_def_tpl':
                 $form_def_tpl->save($_REQUEST);
                 $this->setMessage($action);
                 $this->redirect($action);
                 break;
             default:
                 if ($res = $this->getList(array('count' => count($array_diff)))) {
                     $select_def_tpl = $form_def_tpl->getField('id_template');
                     foreach ($attay_all_template as $item) {
                         $select_def_tpl->addOption($item, $item);
                     }
                     // форма редактирования по умолчнию
                     $form_def_tpl->load();
                     if (!$select_def_tpl->getValue()) {
                         $select_def_tpl->setValue('default');
                     }
                     $_out->elementIncludeTo($form_def_tpl->getRootElement(), '/page/section');
                     // подключаем rowlist
                     $_out->elementIncludeTo($res, '/page/section');
                 }
         }
     }
 }