XOOPS  2.6.0
admin_menu.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  */
11 
13 
23 include_once __DIR__ . '/header.php';
24 
27 
28 // Call Header & ...
29 $xoops->header('admin:menus/menus_admin_menu.tpl');
30 $admin_page = new \Xoops\Module\Admin();
31 $admin_page->renderNavigation('admin_menu.php');
32 $xoops->theme()->addStylesheet('modules/system/css/admin.css');
33 
34 // Get $_GET, $_POST, ...
35 $op = Request::getCmd('op', 'list');
36 $id = Request::getInt('id', 0);
37 $pid = Request::getInt('pid', 0);
38 $weight = Request::getInt('weight', 0);
39 $visible = Request::getInt('visible', 0);
40 
41 
42 $menus_handler = $helper->getHandlerMenus();
44 $criteria->setSort('title');
45 $criteria->setOrder('ASC');
47 
48 $indexAdmin = new \Xoops\Module\Admin();
49 
50 if (empty($menus_list)) {
51  $xoops->redirect('admin_menus.php', 1, _AM_MENUS_MSG_NOMENUS);
52 }
53 
54 if (isset($_REQUEST['menu_id']) && in_array($_REQUEST['menu_id'], array_keys($menus_list))) {
55  $menu_id = $_REQUEST['menu_id'];
57 } else {
58  $keys = array_keys($menus_list);
61 }
62 
63 $xoops->tpl()->assign('menu_id', $menu_id);
64 $xoops->tpl()->assign('menu_title', $menu_title);
65 $xoops->tpl()->assign('menus_list', $menus_list);
66 
67 switch ($op) {
68  case 'add':
69  $admin_page->addItemButton(_AM_MENUS_LIST_MENUS, 'admin_menu.php', 'application-view-detail');
70  $admin_page->renderButton();
71  // Create form
72  $obj = $helper->getHandlerMenu()->create();
73  $obj->setVar('pid', $pid);
74  $obj->setVar('mid', $menu_id);
75  $form = $helper->getForm($obj, 'menus_menu');
76  $xoops->tpl()->assign('form', $form->render());
77  break;
78 
79  case 'edit':
80  $admin_page->addItemButton(_AM_MENUS_LIST_MENUS, 'admin_menu.php', 'application-view-detail');
81  $admin_page->renderButton();
82  // Create form
83  $id = Request::getInt('id', 0);
84  $obj = $helper->getHandlerMenu()->get($id);
85  $form = $helper->getForm($obj, 'menus_menu');
86  $xoops->tpl()->assign('form', $form->render());
87  break;
88 
89  case 'save':
90  if (!$xoops->security()->check()) {
91  $xoops->redirect('admin_menu.php', 3, implode('<br />', $xoops->security()->getErrors()));
92  }
93 
94  $msg[] = _AM_MENUS_SAVE;
95 
96  $id = Request::getInt('id', 0);
97  if (isset($id) && $id !=0) {
98  $obj = $helper->getHandlerMenu()->get($id);
99  } else {
100  $obj = $helper->getHandlerMenu()->create();
101  }
102 
103  $this_handler = $helper->getHandlerMenu();
104  $criteria = new CriteriaCompo(new Criteria('mid', $_POST['mid']));
105  $criteria->setSort('weight');
106  $criteria->setOrder('DESC');
107  $criteria->setLimit(1);
108  $menus = $this_handler->getObjects($criteria);
109  $weight = 1;
110  if (isset($menus[0]) && is_object($menus[0])) {
111  $weight = $menus[0]->getVar('weight') + 1;
112  }
113 
114  if (!isset($_POST['hooks'])) {
115  $_POST['hooks'] = array();
116  }
117  $obj->setVars($_POST);
118  $obj->setVar('weight', $weight);
119 
120  if ($helper->getHandlerMenu()->insert($obj)) {
121  $this_handler->update_weights($obj);
122  $xoops->redirect('admin_menu.php?op=list&amp;menu_id=' . $obj->getVar('mid'), 2, implode('<br />', $msg));
123  }
124  echo $xoops->alert('error', $obj->getHtmlErrors());
125  $form = $helper->getForm($obj, 'menus_menu');
126  $xoops->tpl()->assign('form', $form->render());
127  break;
128 
129  case 'del':
130  $ok = Request::getInt('ok', 0);
131  $obj = $helper->getHandlerMenu()->get($id);
132 
133  if ($ok == 1) {
134  if (!$xoops->security()->check()) {
135  $xoops->redirect('admin_menu.php', 3, implode(',', $xoops->security()->getErrors()));
136  }
137  if ($helper->getHandlerMenu()->delete($obj)) {
138  $xoops->redirect('admin_menu.php?menu_id=' . $menu_id, 2, _AM_MENUS_MSG_SUCCESS);
139  } else {
140  echo $xoops->alert('error', $obj->getHtmlErrors());
141  }
142  } else {
143  echo $xoops->confirm(
144  array('ok' => 1, 'id' => $id, 'op' => 'del', 'menu_id' => $menu_id),
145  $helper->url('admin/admin_menu.php'),
146  _AM_MENUS_MSG_SUREDEL . '<br /><strong>' . $obj->getVar('title') . '</strong>'
147  );
148  }
149  break;
150 
151  case 'move':
152  $this_handler = Menus::getInstance()->getHandlerMenu();
153  $obj = $this_handler->get($id);
154  $obj->setVar('weight', $weight);
155  $this_handler->insert($obj);
156  $this_handler->update_weights($obj);
157  $xoops->redirect('admin_menu.php?op=list&amp;menu_id=' . $obj->getVar('mid'), 2, _AM_MENUS_SAVE);
158  break;
159 
160  case 'toggle':
161  $visible = ($visible == 1) ? 0 : 1;
162  $this_handler = Menus::getInstance()->getHandlerMenu();
163  $obj = $this_handler->get($id);
164  $obj->setVar('visible', $visible);
165  $this_handler->insert($obj);
166  $xoops->redirect('admin_menu.php?op=list&amp;menu_id=' . $obj->getVar('mid'), 2, _AM_MENUS_SAVE);
167  break;
168 
169  case 'list':
170  default:
171  $admin_page->addItemButton(_AM_MENUS_ADD_MENUS, 'admin_menu.php?op=add&amp;menu_id=' . $menu_id, 'add');
172  $admin_page->renderButton();
173 
174  $this_handler = $helper->getHandlerMenu();
175 
176  $criteria = new CriteriaCompo(new Criteria('mid', $menu_id));
177  $count = $this_handler->getCount($criteria);
178  $xoops->tpl()->assign('count', $count);
179  $xoops->tpl()->assign('select', true);
180  $criteria->setSort('weight');
181  $criteria->setOrder('ASC');
182 
183  if ($count > 0) {
184  $array = array();
185  $menus = $this_handler->getObjects($criteria);
186  /* @var $menu MenusMenu */
187  foreach ($menus as $menu) {
188  $array[] = $menu->getValues();
189  }
190  $builder = new MenusBuilder($array);
191  $menusArray = $builder->render();
192  $xoops->tpl()->assign('menus', $menusArray);
193  } else {
194  $xoops->tpl()->assign('error_message', _AM_MENUS_MSG_NOTFOUND);
195  }
196  break;
197 }
198 $xoops->footer();
$criteria
Definition: admin_menu.php:43
const _AM_MENUS_SAVE
Definition: admin.php:23
$helper
Definition: admin_menu.php:26
$indexAdmin
Definition: admin_menu.php:48
static getInstance()
Definition: Xoops.php:160
$weight
Definition: admin_menu.php:38
$pid
Definition: admin_menu.php:37
$menu_title
Definition: admin_menu.php:60
const _AM_MENUS_LIST_MENUS
Definition: admin.php:21
static getInstance()
Definition: helper.php:34
const _AM_MENUS_ADD_MENUS
Definition: admin.php:20
$form
Definition: xoops_code.php:21
$visible
Definition: admin_menu.php:39
$id
Definition: admin_menu.php:36
$admin_page
Definition: admin_menu.php:30
const _AM_MENUS_MSG_NOTFOUND
Definition: admin.php:37
$menu
$menus_handler
Definition: admin_menu.php:42
$xoops
Definition: admin_menu.php:25
$op
Definition: admin_menu.php:35
const _AM_MENUS_MSG_SUREDEL
Definition: admin.php:36
$keys
Definition: install_tpl.php:37
const _AM_MENUS_MSG_SUCCESS
Definition: admin.php:35
if(!is_object($module)||!$module->getVar('isactive')) $msg
Definition: groupperm.php:38
const _AM_MENUS_MSG_NOMENUS
Definition: admin.php:38
$menus_list
Definition: admin_menu.php:46
$menu_id
Definition: admin_menu.php:59