XOOPS  2.6.0
admin_menus.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_menus.tpl');
30 $admin_page = new \Xoops\Module\Admin();
31 $admin_page->renderNavigation('admin_menus.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 $limit = Request::getInt('limit', 15);
38 $start = Request::getInt('start', 0);
39 
40 
41 switch ($op) {
42  case 'add':
43  $admin_page->addItemButton(_AM_MENUS_LIST_MENUS, 'admin_menus.php', 'application-view-detail');
44  $admin_page->renderButton();
45  // Create form
46  $obj = $helper->getHandlerMenus()->create();
47  $form = $helper->getForm($obj, 'menus_menus');
48  $xoops->tpl()->assign('form', $form->render());
49  break;
50 
51  case 'edit':
52  $admin_page->addItemButton(_AM_MENUS_LIST_MENUS, 'admin_menus.php', 'application-view-detail');
53  $admin_page->renderButton();
54  // Create form
55  $id = Request::getInt('id', 0);
56  $obj = $helper->getHandlerMenus()->get($id);
57  $form = $helper->getForm($obj, 'menus_menus');
58  $xoops->tpl()->assign('form', $form->render());
59  break;
60 
61  case 'save':
62  if (!$xoops->security()->check()) {
63  $xoops->redirect('admin_menus.php', 3, implode('<br />', $xoops->security()->getErrors()));
64  }
65 
66  $msg[] = _AM_MENUS_SAVE;
67 
68  $id = Request::getInt('id', 0);
69  if (isset($id) && $id !=0) {
70  $obj = $helper->getHandlerMenus()->get($id);
71  } else {
72  $obj = $helper->getHandlerMenus()->create();
73  }
74 
75  $obj->setVar('title', Request::getString('title', ''));
76 
77  if ($helper->getHandlerMenus()->insert($obj)) {
78  $xoops->redirect('admin_menus.php', 2, implode('<br />', $msg));
79  }
80  echo $xoops->alert('error', $obj->getHtmlErrors());
81  $form = $helper->getForm($obj, 'menus_menus');
82  $xoops->tpl()->assign('form', $form->render());
83  break;
84 
85  case 'del':
86  $ok = Request::getInt('ok', 0);
87  $obj = $helper->getHandlerMenus()->get($id);
88 
89  if ($ok == 1) {
90  if (!$xoops->security()->check()) {
91  $xoops->redirect('admin_menus.php', 3, implode(',', $xoops->security()->getErrors()));
92  }
93  if ($helper->getHandlerMenus()->delete($obj)) {
94  $this_handler = $helper->getHandlerMenu();
95  $criteria = new Criteria('mid', $id);
96  $this_handler->deleteAll($criteria);
97  $xoops->redirect('admin_menus.php', 2, _AM_MENUS_MSG_SUCCESS);
98  } else {
99  echo $xoops->alert('error', $obj->getHtmlErrors());
100  }
101  } else {
102  echo $xoops->confirm(
103  array('ok' => 1, 'id' => $id, 'op' => 'del'),
104  $helper->url('admin/admin_menus.php'),
105  _AM_MENUS_MSG_SUREDEL . '<br /><strong>' . $obj->getVar('title') . '</strong>'
106  );
107  }
108  break;
109 
110  case 'list':
111  default:
113  $admin_page->addItemButton(_AM_MENUS_ADD_MENUS, 'admin_menus.php?op=add', 'add');
114  $admin_page->renderButton();
115 
116  $this_handler = $helper->getHandlerMenus();
117 
118  $query = Request::getString('query', '');
119 
120  $xoops->tpl()->assign('query', $query);
121 
122  $criteria = new CriteriaCompo();
123  if ($query != '') {
124  $crit = new CriteriaCompo(new Criteria('title', $myts->addSlashes($query) . '%', 'LIKE'));
125  $criteria->add($crit);
126  }
127 
128  $count = $this_handler->getCount($criteria);
129  $xoops->tpl()->assign('count', $count);
130 
131  $criteria->setStart($start);
132  $criteria->setLimit($limit);
133  $criteria->setSort('id');
134  $criteria->setOrder('ASC');
135 
136  if ($count > 0) {
137  // Display Page Navigation
138  if ($count > $limit) {
139  $nav = new XoopsPageNav($count, $limit, $start, 'start', 'op=list');
140  $xoops->tpl()->assign('nav_menu', $nav->renderNav(2));
141  }
142 
143  $objs = $this_handler->getObjects($criteria);
144  /* @var $obj MenusMenus */
145  foreach ($objs as $obj) {
146  $xoops->tpl()->append('objs', $obj->getValues());
147  }
148  } else {
149  $xoops->tpl()->assign('error_message', _AM_MENUS_MSG_NOTFOUND);
150  }
151  break;
152 }
153 $xoops->footer();
$admin_page
Definition: admin_menus.php:30
$start
Definition: admin_menus.php:38
const _AM_MENUS_SAVE
Definition: admin.php:23
$xoops
Definition: admin_menus.php:25
static getInstance()
Definition: Xoops.php:160
$query
Definition: index.php:37
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
$limit
Definition: admin_menus.php:37
$op
Definition: admin_menus.php:35
$helper
Definition: admin_menus.php:26
$id
Definition: admin_menus.php:36
const _AM_MENUS_MSG_NOTFOUND
Definition: admin.php:37
const _AM_MENUS_MSG_SUREDEL
Definition: admin.php:36
const _AM_MENUS_MSG_SUCCESS
Definition: admin.php:35
$criteria
if(!is_object($module)||!$module->getVar('isactive')) $msg
Definition: groupperm.php:38
$myts
Definition: edituser.php:38