XOOPS  2.6.0
main.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 
15 
27 // Get main instance
31 // Check users rights
32 if (!$xoops->isUser() || !$xoops->isModule() || !$xoops->user->isAdmin($xoops->module->mid())) {
34 }
35 // Parameters
36 $nb_group = $xoops->getModuleConfig('groups_pager', 'system');
37 // Get Action type
38 $op = $system->cleanVars($_REQUEST, 'op', 'list', 'string');
39 // Get groups handler
40 $groups_handler = $xoops->getHandler('group');
41 $member_handler = $xoops->getHandlerMember();
42 
43 // Call Header
44 $xoops->header('admin:system/system_groups.tpl');
45 //$system_breadcrumb->addLink(_AM_SYSTEM_GROUPS_NAV_MANAGER, system_adminVersion('groups', 'adminpath'));
46 
47 switch ($op) {
48 
49  case 'list':
50  default:
51  // Define Stylesheet
52  $xoops->theme()->addStylesheet('modules/system/css/admin.css');
53  // Define Scripts
54  $xoops->theme()->addScript('media/jquery/plugins/jquery.tablesorter.js');
55  $xoops->theme()->addScript('modules/system/js/admin.js');
56  // Define Breadcrumb and tips
57  $admin_page = new \Xoops\Module\Admin();
58  $admin_page->addBreadcrumbLink(SystemLocale::CONTROL_PANEL, \XoopsBaseConfig::get('url') . '/admin.php', true);
59  $admin_page->addBreadcrumbLink(SystemLocale::GROUPS_MANAGER, $system->adminVersion('groups', 'adminpath'));
60  $admin_page->addBreadcrumbLink(XoopsLocale::MAIN);
61  $admin_page->addItemButton(SystemLocale::ADD_NEW_GROUP, 'admin.php?fct=groups&amp;op=groups_add', 'add');
63  $admin_page->renderBreadcrumb();
64  $admin_page->renderTips();
65  $admin_page->renderButton();
66  // Get start pager
67  $start = $system->cleanVars($_REQUEST, 'start', 0, 'int');
68  // Criteria
69  $criteria = new CriteriaCompo();
70  $criteria->setSort("groupid");
71  $criteria->setOrder("ASC");
72  $criteria->setStart($start);
73  $criteria->setLimit($nb_group);
74  $groups_arr = $groups_handler->getAll($criteria);
75  // Count group
76  $groups_count = count($groups_arr);
77  // Assign Template variables
78  $xoops->tpl()->assign('groups_count', $groups_count);
79  /* @var $group XoopsGroup */
80  foreach ($groups_arr as $group) {
81  $groups_id = $group->getVar("groupid");
82  $groups['groups_id'] = $groups_id;
83  $groups['name'] = $group->getVar("name");
84  $groups['description'] = $group->getVar("description");
85  $member_handler = $xoops->getHandlerMember();
86  if ($groups_id != 3) {
87  $group_id_arr[0] = $groups_id;
88  $nb_users_by_groups = $member_handler->getUserCountByGroupLink($group_id_arr);
89  $groups['nb_users_by_groups'] = sprintf(SystemLocale::F_USERS, $nb_users_by_groups);
90  } else {
91  $groups['nb_users_by_groups'] = '';
92  }
93  $edit_delete = '<a href="admin.php?fct=groups&amp;op=groups_edit&amp;groups_id=' . $groups_id . '">'
94  . '<img src="./images/icons/edit.png" border="0" alt="' . SystemLocale::EDIT_GROUP
95  . '" title="' . SystemLocale::EDIT_GROUP . '"></a>';
96  if (!in_array($group->getVar("groupid"), array(FixedGroups::ADMIN, FixedGroups::USERS, FixedGroups::ANONYMOUS))
97  ) {
98  $groups['delete'] = 1;
99  $edit_delete .= '<a href="admin.php?fct=groups&amp;op=groups_delete&amp;groups_id=' . $groups_id . '">'
100  . '<img src="./images/icons/delete.png" border="0" alt="' . SystemLocale::DELETE_GROUP
101  . '" title="' . SystemLocale::DELETE_GROUP . '"></a>';
102  }
103  $groups['edit_delete'] = $edit_delete;
104  $xoops->tpl()->appendByRef('groups', $groups);
105  unset($groups, $group);
106  }
107  // Display Page Navigation
108  if ($groups_count > $nb_group) {
109  $nav = new XoopsPageNav($groups_count, $nb_group, $start, 'start', 'fct=groups&amp;op=list');
110  $xoops->tpl()->assign('nav_menu', $nav->renderNav(4));
111  }
112  break;
113 
114  //Add a group
115  case 'groups_add':
116  // Define Stylesheet
117  $xoops->theme()->addStylesheet('modules/system/css/admin.css');
118  // Define Breadcrumb and tips
119  $admin_page = new \Xoops\Module\Admin();
120  $admin_page->addBreadcrumbLink(SystemLocale::CONTROL_PANEL, \XoopsBaseConfig::get('url') . '/admin.php', true);
121  $admin_page->addBreadcrumbLink(SystemLocale::GROUPS_MANAGER, $system->adminVersion('groups', 'adminpath'));
122  $admin_page->addBreadcrumbLink(SystemLocale::ADD_NEW_GROUP);
124  $admin_page->renderBreadcrumb();
125  $admin_page->renderTips();
126  // Create form
127  $obj = $groups_handler->create();
128  $form = $xoops->getModuleForm($obj, 'group');
129  // Assign form
130  $xoops->tpl()->assign('form', $form->render());
131  break;
132 
133  //Edit a group
134  case 'groups_edit':
135  // Define Stylesheet
136  $xoops->theme()->addStylesheet('modules/system/css/admin.css');
137  // Define Breadcrumb and tips
138  $admin_page = new \Xoops\Module\Admin();
139  $admin_page->addBreadcrumbLink(SystemLocale::CONTROL_PANEL, \XoopsBaseConfig::get('url') . '/admin.php', true);
140  $admin_page->addBreadcrumbLink(SystemLocale::GROUPS_MANAGER, $system->adminVersion('groups', 'adminpath'));
141  $admin_page->addBreadcrumbLink(SystemLocale::EDIT_GROUP);
143  $admin_page->renderBreadcrumb();
144  $admin_page->renderTips();
145  // Create form
146  $groups_id = $system->cleanVars($_REQUEST, 'groups_id', 0, 'int');
147  if ($groups_id > 0) {
148  $obj = $groups_handler->get($groups_id);
149  $form = $xoops->getModuleForm($obj, 'group');
150  // Assign form
151  $xoops->tpl()->assign('form', $form->render());
152  } else {
153  $xoops->redirect('admin.php?fct=groups', 1, XoopsLocale::E_DATABASE_NOT_UPDATED);
154  }
155  break;
156 
157  //Save a new group
158  case 'groups_save_add':
159  if (!$xoops->security()->check()) {
160  $xoops->redirect('admin.php?fct=groups', 3, implode('<br />', $xoops->security()->getErrors()));
161  }
162  $system_catids = $system->cleanVars($_POST, 'system_catids', array(), 'array');
163  $admin_mids = $system->cleanVars($_POST, 'admin_mids', array(), 'array');
164  $read_mids = $system->cleanVars($_POST, 'read_mids', array(), 'array');
165  $read_bids = $system->cleanVars($_POST, 'read_bids', array(), 'array');
166 
167  $member_handler = $xoops->getHandlerMember();
168  $group = $member_handler->createGroup();
169  $group->setVar('name', $_POST["name"]);
170  $group->setVar('description', $_POST["desc"]);
171  if (count($system_catids) > 0) {
172  $group->setVar('group_type', 'Admin');
173  }
174  if (!$member_handler->insertGroup($group)) {
175  $xoops->header();
176  echo $xoops->alert('error', $group->getHtmlErrors());
177  $xoops->footer();
178  } else {
179  $xoops->db()->beginTransaction();
180  $groupid = $group->getVar('groupid');
181  $gperm_handler = $xoops->getHandlerGroupperm();
182  if (count($system_catids) > 0) {
183  array_push($admin_mids, 1);
184  foreach ($system_catids as $s_cid) {
185  $sysperm = & $gperm_handler->create();
186  $sysperm->setVar('gperm_groupid', $groupid);
187  $sysperm->setVar('gperm_itemid', $s_cid);
188  $sysperm->setVar('gperm_name', 'system_admin');
189  $sysperm->setVar('gperm_modid', 1);
190  $gperm_handler->insert($sysperm);
191  }
192  }
193  foreach ($admin_mids as $a_mid) {
194  $modperm = & $gperm_handler->create();
195  $modperm->setVar('gperm_groupid', $groupid);
196  $modperm->setVar('gperm_itemid', $a_mid);
197  $modperm->setVar('gperm_name', 'module_admin');
198  $modperm->setVar('gperm_modid', 1);
199  $gperm_handler->insert($modperm);
200  }
201  array_push($read_mids, 1);
202  foreach ($read_mids as $r_mid) {
203  $modperm = & $gperm_handler->create();
204  $modperm->setVar('gperm_groupid', $groupid);
205  $modperm->setVar('gperm_itemid', $r_mid);
206  $modperm->setVar('gperm_name', 'module_read');
207  $modperm->setVar('gperm_modid', 1);
208  $gperm_handler->insert($modperm);
209  }
210  foreach ($read_bids as $r_bid) {
211  $blockperm = & $gperm_handler->create();
212  $blockperm->setVar('gperm_groupid', $groupid);
213  $blockperm->setVar('gperm_itemid', $r_bid);
214  $blockperm->setVar('gperm_name', 'block_read');
215  $blockperm->setVar('gperm_modid', 1);
216  $gperm_handler->insert($blockperm);
217  }
218  $xoops->db()->commit();
219  $xoops->redirect('admin.php?fct=groups', 1, XoopsLocale::S_DATABASE_UPDATED);
220  }
221  break;
222 
223  //Save a edit group
224  case 'groups_save_update':
225  if (!$xoops->security()->check()) {
226  $xoops->redirect('admin.php?fct=groups', 3, implode('<br />', $xoops->security()->getErrors()));
227  }
228  $system_catids = $system->cleanVars($_POST, 'system_catids', array(), 'array');
229  $admin_mids = $system->cleanVars($_POST, 'admin_mids', array(), 'array');
230  $read_mids = $system->cleanVars($_POST, 'read_mids', array(), 'array');
231  $read_bids = $system->cleanVars($_POST, 'read_bids', array(), 'array');
232 
233  $member_handler = $xoops->getHandlerMember();
234  $gid = $system->cleanVars($_POST, 'g_id', 0, 'int');
235  if ($gid > 0) {
236  $group = $member_handler->getGroup($gid);
237  $group->setVar('name', $_POST["name"]);
238  $group->setVar('description', $_POST["desc"]);
239  // if this group is not one of the default groups
240  if (!in_array($group->getVar('groupid'), array(FixedGroups::ADMIN, FixedGroups::USERS, FixedGroups::ANONYMOUS))
241  ) {
242  if (count($system_catids) > 0) {
243  $group->setVar('group_type', 'Admin');
244  } else {
245  $group->setVar('group_type', '');
246  }
247  }
248  if (!$member_handler->insertGroup($group)) {
249  $xoops->header();
250  echo $group->getHtmlErrors();
251  $xoops->footer();
252  } else {
253  $xoops->db()->beginTransaction();
254  $groupid = $group->getVar('groupid');
255  $gperm_handler = $xoops->getHandlerGroupperm();
256  $criteria = new CriteriaCompo(new Criteria('gperm_groupid', $groupid));
257  $criteria->add(new Criteria('gperm_modid', 1));
258  $criteria2 = new CriteriaCompo(new Criteria('gperm_name', 'system_admin'));
259  $criteria2->add(new Criteria('gperm_name', 'module_admin'), 'OR');
260  $criteria2->add(new Criteria('gperm_name', 'module_read'), 'OR');
261  $criteria2->add(new Criteria('gperm_name', 'block_read'), 'OR');
262  $criteria->add($criteria2);
263  $gperm_handler->deleteAll($criteria);
264  if (count($system_catids) > 0) {
265  array_push($admin_mids, 1);
266  foreach ($system_catids as $s_cid) {
267  $sysperm = $gperm_handler->create();
268  $sysperm->setVar('gperm_groupid', $groupid);
269  $sysperm->setVar('gperm_itemid', $s_cid);
270  $sysperm->setVar('gperm_name', 'system_admin');
271  $sysperm->setVar('gperm_modid', 1);
272  $gperm_handler->insert($sysperm);
273  }
274  }
275  foreach ($admin_mids as $a_mid) {
276  $modperm = $gperm_handler->create();
277  $modperm->setVar('gperm_groupid', $groupid);
278  $modperm->setVar('gperm_itemid', $a_mid);
279  $modperm->setVar('gperm_name', 'module_admin');
280  $modperm->setVar('gperm_modid', 1);
281  $gperm_handler->insert($modperm);
282  }
283  array_push($read_mids, 1);
284  foreach ($read_mids as $r_mid) {
285  $modperm = $gperm_handler->create();
286  $modperm->setVar('gperm_groupid', $groupid);
287  $modperm->setVar('gperm_itemid', $r_mid);
288  $modperm->setVar('gperm_name', 'module_read');
289  $modperm->setVar('gperm_modid', 1);
290  $gperm_handler->insert($modperm);
291  }
292  foreach ($read_bids as $r_bid) {
293  $blockperm = $gperm_handler->create();
294  $blockperm->setVar('gperm_groupid', $groupid);
295  $blockperm->setVar('gperm_itemid', $r_bid);
296  $blockperm->setVar('gperm_name', 'block_read');
297  $blockperm->setVar('gperm_modid', 1);
298  $gperm_handler->insert($blockperm);
299  }
300  $xoops->db()->commit();
301  $xoops->redirect("admin.php?fct=groups", 1, XoopsLocale::S_DATABASE_UPDATED);
302  }
303  } else {
304  $xoops->redirect('admin.php?fct=groups', 1, XoopsLocale::E_DATABASE_NOT_UPDATED);
305  }
306  break;
307 
308  //Del a group
309  case 'groups_delete':
310  // Define Breadcrumb and tips
311  $admin_page = new \Xoops\Module\Admin();
312  $admin_page->addBreadcrumbLink(SystemLocale::CONTROL_PANEL, \XoopsBaseConfig::get('url') . '/admin.php', true);
313  $admin_page->addBreadcrumbLink(SystemLocale::GROUPS_MANAGER, $system->adminVersion('groups', 'adminpath'));
314  $admin_page->addBreadcrumbLink(SystemLocale::DELETE_GROUP);
315  $admin_page->renderBreadcrumb();
316  $groups_id = $system->cleanVars($_REQUEST, 'groups_id', 0, 'int');
317  if ($groups_id > 0) {
318  $obj = $groups_handler->get($groups_id);
319  if (isset($_POST["ok"]) && $_POST["ok"] == 1) {
320  if (!$xoops->security()->check()) {
321  $xoops->redirect("admin.php?fct=groups", 3, implode(",", $xoops->security()->getErrors()));
322  }
323  if ($groups_id > 0 && !in_array($groups_id, array(
324  FixedGroups::ADMIN,
325  FixedGroups::USERS,
326  FixedGroups::ANONYMOUS
327  ))
328  ) {
329  $member_handler = $xoops->getHandlerMember();
330  $group = $member_handler->getGroup($groups_id);
331  $member_handler->deleteGroup($group);
332  $gperm_handler = $xoops->getHandlerGroupperm();
333  $gperm_handler->deleteByGroup($groups_id);
334  $xoops->redirect('admin.php?fct=groups', 1, XoopsLocale::S_DATABASE_UPDATED);
335  } else {
336  $xoops->redirect('admin.php?fct=groups', 2, SystemLocale::E_YOU_CANNOT_REMOVE_THIS_GROUP);
337  }
338  } else {
339  // Define Stylesheet
340  $xoops->theme()->addStylesheet('modules/system/css/admin.css');
341  // Define Breadcrumb and tips
343  $system_breadcrumb->addHelp(system_adminVersion('groups', 'help') . '#edit');
344  $system_breadcrumb->render();
345  // Display message
346  echo $xoops->confirm(
347  array(
348  "ok" => 1,
349  "groups_id" => $_REQUEST["groups_id"],
350  "op" => "groups_delete"
351  ),
352  'admin.php?fct=groups',
353  SystemLocale::Q_ARE_YOU_SURE_DELETE_THIS_GROUP . '<br />' . $obj->getVar("name") . '<br />'
354  );
355  }
356  } else {
357  $xoops->redirect('admin.php?fct=groups', 1, XoopsLocale::E_DATABASE_NOT_UPDATED);
358  }
359  break;
360 
361  //Add users group
362  case 'action_group':
363  $error = true;
364  if (isset($_REQUEST['edit_group'])) {
365  if (isset($_REQUEST['edit_group'])
366  && $_REQUEST['edit_group'] == 'add_group'
367  && isset($_REQUEST['selgroups'])
368  ) {
369  foreach ($_REQUEST['memberslist_id'] as $uid) {
370  $member_handler->addUserToGroup($_REQUEST['selgroups'], $uid);
371  $error = false;
372  }
373  } else {
374  if (isset($_REQUEST['edit_group'])
375  && $_REQUEST['edit_group'] == 'delete_group'
376  && isset($_REQUEST['selgroups'])
377  ) {
378  $member_handler->removeUsersFromGroup($_REQUEST['selgroups'], $_REQUEST['memberslist_id']);
379  $error = false;
380  }
381  }
382  //if ($error == true)
383  $xoops->redirect("admin.php?fct=users", 1, XoopsLocale::S_DATABASE_UPDATED);
384  }
385  break;
386 }
387 // Call Footer
388 $xoops->footer();
const Q_ARE_YOU_SURE_DELETE_THIS_GROUP
Definition: en_US.php:365
if(empty($settings['ROOT_PATH'])) elseif(empty($settings['DB_PARAMETERS'])) $error
$member_handler
Definition: main.php:41
$uid
Definition: main.php:60
$system
Definition: main.php:26
static getInstance($fct= '')
static getInstance()
Definition: system.php:46
const DELETE_GROUP
Definition: en_US.php:258
static getInstance()
Definition: Xoops.php:160
const GROUPS_TIPS_2
Definition: en_US.php:320
system_adminVersion($version, $value= '')
Definition: functions.php:95
const ADD_NEW_GROUP
Definition: en_US.php:31
$admin_page
Definition: main.php:34
$form
Definition: xoops_code.php:21
const E_YOU_CANNOT_REMOVE_THIS_GROUP
Definition: en_US.php:299
$gperm_handler
exit
Definition: browse.php:104
const GROUPS_MANAGER
Definition: en_US.php:318
$op
Definition: main.php:30
static get($name)
$start
Definition: main.php:45
const CONTROL_PANEL
Definition: en_US.php:247
$criteria2
const E_NO_ACCESS_PERMISSION
Definition: en_US.php:351
$groups
$criteria
$xoops
Definition: main.php:25
$system_breadcrumb
Definition: main.php:30
const GROUPS_TIPS_1
Definition: en_US.php:319
const S_DATABASE_UPDATED
Definition: en_US.php:1024
if(!$xoops->isUser()||!$xoops->isModule()||!$xoops->user->isAdmin($xoops->module->mid())) $nb_group
Definition: main.php:36
$groups_handler
Definition: main.php:40
const E_DATABASE_NOT_UPDATED
Definition: en_US.php:320
const EDIT_GROUP
Definition: en_US.php:265