XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
main.php
Go to the documentation of this file.
1 <?php
2 // $Id: main.php 8066 2011-11-06 05:09:33Z beckmi $
3 // ------------------------------------------------------------------------ //
4 // XOOPS - PHP Content Management System //
5 // Copyright (c) 2000 XOOPS.org //
6 // <http://www.xoops.org/> //
7 // ------------------------------------------------------------------------ //
8 // This program is free software; you can redistribute it and/or modify //
9 // it under the terms of the GNU General Public License as published by //
10 // the Free Software Foundation; either version 2 of the License, or //
11 // (at your option) any later version. //
12 // //
13 // You may not change or alter any portion of this comment or credits //
14 // of supporting developers from this source code or any supporting //
15 // source code which is considered copyrighted (c) material of the //
16 // original comment or credit authors. //
17 // //
18 // This program is distributed in the hope that it will be useful, //
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21 // GNU General Public License for more details. //
22 // //
23 // You should have received a copy of the GNU General Public License //
24 // along with this program; if not, write to the Free Software //
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
26 // ------------------------------------------------------------------------ //
27 // Author: Kazumi Ono (AKA onokazu) //
28 // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
29 // Project: The XOOPS Project //
30 // ------------------------------------------------------------------------- //
31 
32 // Check users rights
33 if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) exit( _NOPERM );
34 // Parameters
35 $nb_group = xoops_getModuleOption('groups_pager', 'system');
36 // Get Action type
37 $op = system_CleanVars ( $_REQUEST, 'op', 'list', 'string' );
38 // Get groups handler
39 $groups_Handler =& xoops_getModuleHandler("group", "system");
41 // Define main template
42 $xoopsOption['template_main'] = 'system_groups.html';
43 // Call Header
45 $xoBreadCrumb->addLink(_AM_SYSTEM_GROUPS_NAV_MANAGER, system_adminVersion('groups', 'adminpath'));
46 
47 switch ($op) {
48 
49  case 'list': default:
50  // Define Stylesheet
51  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
52  $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
53  $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.tablesorter.js');
54  $xoTheme->addScript('modules/system/js/admin.js');
55  // Define Breadcrumb and tips
56  $xoBreadCrumb->addHelp( system_adminVersion('groups', 'help') );
58  $xoBreadCrumb->render();
59  // Get start pager
60  $start = system_CleanVars ( $_REQUEST, 'start', 0, 'int' );
61  // Criteria
62  $criteria = new CriteriaCompo();
63  $criteria->setSort("groupid");
64  $criteria->setOrder("ASC");
65  $criteria->setStart($start);
66  $criteria->setLimit($nb_group);
67  // Count group
68  $groups_count = $groups_Handler->getCount($criteria);
69  $groups_arr = $groups_Handler->getall($criteria);
70  // Assign Template variables
71  $xoopsTpl->assign( 'groups_count', $groups_count );
72  if ( $groups_count > 0 ){
73  foreach (array_keys($groups_arr) as $i){
74  $groups_id = $groups_arr[$i]->getVar("groupid");
75  $groups['groups_id'] = $groups_id;
76  $groups['name'] = $groups_arr[$i]->getVar("name");
77  $groups['description'] = $groups_arr[$i]->getVar("description");
78  $member_handler =& xoops_gethandler('member', 'system');
79  if ( $groups_id != 3 ) {
80  $group_id_arr[0] = $groups_id;
81  $nb_users_by_groups = $member_handler->getUserCountByGroupLink($group_id_arr);
82  $groups['nb_users_by_groups'] = sprintf(_AM_SYSTEM_GROUPS_NB_USERS_BY_GROUPS_USERS, $nb_users_by_groups);
83  } else {
84  $groups['nb_users_by_groups'] = '';
85  }
86  $edit_delete = '<a href="admin.php?fct=groups&amp;op=groups_edit&amp;groups_id=' . $groups_id . '">
87  <img src="./images/icons/edit.png" border="0" alt="' . _AM_SYSTEM_GROUPS_EDIT . '" title="' . _AM_SYSTEM_GROUPS_EDIT . '"></a>';
88  if (!in_array($groups_arr[$i]->getVar("groupid"), array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS))) {
89  $groups['delete'] = 1;
90  $edit_delete .= '<a href="admin.php?fct=groups&amp;op=groups_delete&amp;groups_id=' . $groups_id . '">
91  <img src="./images/icons/delete.png" border="0" alt="' . _AM_SYSTEM_GROUPS_DELETE . '" title="' . _AM_SYSTEM_GROUPS_DELETE . '"></a>';
92  }
93  $groups['edit_delete'] = $edit_delete;
94  $xoopsTpl->append_by_ref( 'groups', $groups );
95  unset( $groups );
96  }
97  }
98  // Display Page Navigation
99  if ($groups_count > $nb_group) {
100  $nav = new XoopsPageNav($groups_count, $nb_group, $start, 'start', 'fct=groups&amp;op=list');
101  $xoopsTpl->assign('nav_menu', $nav->renderNav(4));
102  }
103  break;
104 
105  //Add a group
106  case 'groups_add':
107  // Define Stylesheet
108  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
109  // Define Breadcrumb and tips
111  $xoBreadCrumb->addHelp( system_adminVersion('groups', 'help') . '#add' );
113  $xoBreadCrumb->render();
114  // Create form
115  $obj =& $groups_Handler->create();
116  $form = $obj->getForm();
117  // Assign form
118  $xoopsTpl->assign('form', $form->render());
119  break;
120 
121  //Edit a group
122  case 'groups_edit':
123  // Define Stylesheet
124  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
125  // Define Breadcrumb and tips
127  $xoBreadCrumb->addHelp( system_adminVersion('groups', 'help') . '#edit' );
129  $xoBreadCrumb->render();
130  // Create form
131  $groups_id = system_CleanVars($_REQUEST, 'groups_id', 0, 'int');
132  if ( $groups_id > 0 ) {
133  $obj = $groups_Handler->get($groups_id);
134  $form = $obj->getForm();
135  // Assign form
136  $xoopsTpl->assign('form', $form->render());
137  } else {
138  redirect_header('admin.php?fct=groups', 1, _AM_SYSTEM_DBERROR);
139  }
140  break;
141 
142  //Save a new group
143  case 'groups_save_add':
144  if (!$GLOBALS['xoopsSecurity']->check()) {
145  redirect_header('admin.php?fct=groups', 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
146  }
147  $system_catids = system_CleanVars($_POST, 'system_catids', array(), 'array');
148  $admin_mids = system_CleanVars($_POST, 'admin_mids', array(), 'array');
149  $read_mids = system_CleanVars($_POST, 'read_mids', array(), 'array');
150  $read_bids = system_CleanVars($_POST, 'read_bids', array(), 'array');
151 
152  $member_handler = &xoops_gethandler('member');
153  $group = &$member_handler->createGroup();
154  $group->setVar('name', $_POST["name"]);
155  $group->setVar('description', $_POST["desc"]);
156  if (count($system_catids) > 0) {
157  $group->setVar('group_type', 'Admin');
158  }
159  if (!$member_handler->insertGroup($group)) {
160  xoops_cp_header();
161  xoops_error( $group->getHtmlErrors() );
162  xoops_cp_footer();
163  } else {
164  $groupid = $group->getVar('groupid');
165  $gperm_handler = &xoops_gethandler('groupperm');
166  if (count($system_catids) > 0) {
167  array_push($admin_mids, 1);
168  foreach ($system_catids as $s_cid) {
169  $sysperm = &$gperm_handler->create();
170  $sysperm->setVar('gperm_groupid', $groupid);
171  $sysperm->setVar('gperm_itemid', $s_cid);
172  $sysperm->setVar('gperm_name', 'system_admin');
173  $sysperm->setVar('gperm_modid', 1);
174  $gperm_handler->insert($sysperm);
175  }
176  }
177  foreach ($admin_mids as $a_mid) {
178  $modperm = &$gperm_handler->create();
179  $modperm->setVar('gperm_groupid', $groupid);
180  $modperm->setVar('gperm_itemid', $a_mid);
181  $modperm->setVar('gperm_name', 'module_admin');
182  $modperm->setVar('gperm_modid', 1);
183  $gperm_handler->insert($modperm);
184  }
185  array_push($read_mids, 1);
186  foreach ($read_mids as $r_mid) {
187  $modperm = &$gperm_handler->create();
188  $modperm->setVar('gperm_groupid', $groupid);
189  $modperm->setVar('gperm_itemid', $r_mid);
190  $modperm->setVar('gperm_name', 'module_read');
191  $modperm->setVar('gperm_modid', 1);
192  $gperm_handler->insert($modperm);
193  }
194  foreach ($read_bids as $r_bid) {
195  $blockperm = &$gperm_handler->create();
196  $blockperm->setVar('gperm_groupid', $groupid);
197  $blockperm->setVar('gperm_itemid', $r_bid);
198  $blockperm->setVar('gperm_name', 'block_read');
199  $blockperm->setVar('gperm_modid', 1);
200  $gperm_handler->insert($blockperm);
201  }
202  redirect_header('admin.php?fct=groups', 1, _AM_SYSTEM_GROUPS_DBUPDATED);
203  }
204  break;
205 
206  //Save a edit group
207  case 'groups_save_update':
208  if (!$GLOBALS['xoopsSecurity']->check()) {
209  redirect_header('admin.php?fct=groups', 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
210  }
211  $system_catids = system_CleanVars($_POST, 'system_catids', array(), 'array');
212  $admin_mids = system_CleanVars($_POST, 'admin_mids', array(), 'array');
213  $read_mids = system_CleanVars($_POST, 'read_mids', array(), 'array');
214  $read_bids = system_CleanVars($_POST, 'read_bids', array(), 'array');
215 
216  $member_handler = &xoops_gethandler('member');
217  $gid = system_CleanVars($_POST, 'g_id', 0, 'int');
218  if ( $gid > 0 ) {
219  $group = $member_handler->getGroup( $gid );
220  $group->setVar('name', $_POST["name"]);
221  $group->setVar('description', $_POST["desc"]);
222  // if this group is not one of the default groups
223  if (!in_array($group->getVar('groupid'), array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS))) {
224  if (count($system_catids) > 0) {
225  $group->setVar('group_type', 'Admin');
226  } else {
227  $group->setVar('group_type', '');
228  }
229  }
230  if (!$member_handler->insertGroup($group)) {
231  xoops_cp_header();
232  echo $group->getHtmlErrors();
233  xoops_cp_footer();
234  } else {
235  $groupid = $group->getVar('groupid');
236  $gperm_handler = &xoops_gethandler('groupperm');
237  $criteria = new CriteriaCompo(new Criteria('gperm_groupid', $groupid));
238  $criteria->add(new Criteria('gperm_modid', 1));
239  $criteria2 = new CriteriaCompo(new Criteria('gperm_name', 'system_admin'));
240  $criteria2->add(new Criteria('gperm_name', 'module_admin'), 'OR');
241  $criteria2->add(new Criteria('gperm_name', 'module_read'), 'OR');
242  $criteria2->add(new Criteria('gperm_name', 'block_read'), 'OR');
243  $criteria->add($criteria2);
244  $gperm_handler->deleteAll($criteria);
245  if (count($system_catids) > 0) {
246  array_push($admin_mids, 1);
247  foreach ($system_catids as $s_cid) {
248  $sysperm = &$gperm_handler->create();
249  $sysperm->setVar('gperm_groupid', $groupid);
250  $sysperm->setVar('gperm_itemid', $s_cid);
251  $sysperm->setVar('gperm_name', 'system_admin');
252  $sysperm->setVar('gperm_modid', 1);
253  $gperm_handler->insert($sysperm);
254  }
255  }
256  foreach ($admin_mids as $a_mid) {
257  $modperm = &$gperm_handler->create();
258  $modperm->setVar('gperm_groupid', $groupid);
259  $modperm->setVar('gperm_itemid', $a_mid);
260  $modperm->setVar('gperm_name', 'module_admin');
261  $modperm->setVar('gperm_modid', 1);
262  $gperm_handler->insert($modperm);
263  }
264  array_push($read_mids, 1);
265  foreach ($read_mids as $r_mid) {
266  $modperm = &$gperm_handler->create();
267  $modperm->setVar('gperm_groupid', $groupid);
268  $modperm->setVar('gperm_itemid', $r_mid);
269  $modperm->setVar('gperm_name', 'module_read');
270  $modperm->setVar('gperm_modid', 1);
271  $gperm_handler->insert($modperm);
272  }
273  foreach ($read_bids as $r_bid) {
274  $blockperm = &$gperm_handler->create();
275  $blockperm->setVar('gperm_groupid', $groupid);
276  $blockperm->setVar('gperm_itemid', $r_bid);
277  $blockperm->setVar('gperm_name', 'block_read');
278  $blockperm->setVar('gperm_modid', 1);
279  $gperm_handler->insert($blockperm);
280  }
281  redirect_header("admin.php?fct=groups", 1, _AM_SYSTEM_GROUPS_DBUPDATED);
282  }
283  } else {
284  redirect_header('admin.php?fct=groups', 1, _AM_SYSTEM_DBERROR);
285  }
286  break;
287 
288  //Del a group
289  case 'groups_delete':
290  $groups_id = system_CleanVars($_REQUEST, 'groups_id', 0, 'int');
291  if ( $groups_id > 0 ) {
292  $obj =& $groups_Handler->get( $groups_id );
293  if (isset($_POST["ok"]) && $_POST["ok"] == 1) {
294  if ( !$GLOBALS["xoopsSecurity"]->check() ) {
295  redirect_header("admin.php?fct=groups", 3, implode(",", $GLOBALS["xoopsSecurity"]->getErrors()));
296  }
297  if ( $groups_id > 0 && !in_array($groups_id, array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS))) {
298  $member_handler = &xoops_gethandler('member');
299  $group = $member_handler->getGroup( $groups_id );
300  $member_handler->deleteGroup($group);
301  $gperm_handler = &xoops_gethandler('groupperm');
302  $gperm_handler->deleteByGroup( $groups_id );
303  redirect_header('admin.php?fct=groups', 1, _AM_SYSTEM_GROUPS_DBUPDATED);
304  }else{
305  redirect_header('admin.php?fct=groups', 2, _AM_SYSTEM_GROUPS_ERROR_DELETE);
306  }
307 
308  } else {
309  // Define Stylesheet
310  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
311  // Define Breadcrumb and tips
313  $xoBreadCrumb->addHelp( system_adminVersion('groups', 'help') . '#edit' );
314  $xoBreadCrumb->render();
315  // Display message
316  xoops_confirm(array("ok" => 1, "groups_id" => $_REQUEST["groups_id"], "op" => "groups_delete"), 'admin.php?fct=groups', sprintf(_AM_SYSTEM_GROUPS_SUREDEL) . '<br >' . $obj->getVar("name") . '<br >');
317  }
318  } else {
319  redirect_header('admin.php?fct=groups', 1, _AM_SYSTEM_DBERROR);
320  }
321  break;
322 
323  //Add users group
324  case 'action_group':
325  $error = true;
326  if ( isset($_REQUEST['edit_group']))
327  {
328  if ( isset($_REQUEST['edit_group']) && $_REQUEST['edit_group'] == 'add_group' && isset($_REQUEST['selgroups']) )
329  {
330  foreach ($_REQUEST['memberslist_id'] as $uid)
331  {
332  $member_handler->addUserToGroup($_REQUEST['selgroups'], $uid);
333  $error = false;
334  }
335  } else if (isset($_REQUEST['edit_group']) && $_REQUEST['edit_group'] == 'delete_group' && isset($_REQUEST['selgroups']) )
336  {
337  $member_handler->removeUsersFromGroup($_REQUEST['selgroups'], $_REQUEST['memberslist_id']);
338  $error = false;
339  }
340  //if ($error == true)
341  redirect_header("admin.php?fct=users",1,_AM_SYSTEM_GROUPS_DBUPDATED);
342  }
343  break;
344 }
345 // Call Footer
347 
348 ?>