source: trunk/admin/group_list.php @ 815

Last change on this file since 815 was 815, checked in by plg, 19 years ago
  • modification : admin/group_list screen completely rewrite to present the list of existing groups and a form to add a new group. Here you can delete a group, go to permissions management for a group, go to member list of a group (on admin/user_list with a filter on group).
  • modification : admin/user_perm and admin/group_perm are not directly reachable by the admin menu anymore. Only the user/group list lets you reach user/group permissions management screen.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-08-16 15:19:40 +0000 (Tue, 16 Aug 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 815 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28if( !defined("PHPWG_ROOT_PATH") )
29{
30  die ("Hacking attempt!");
31}
32include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' );
33
34// +-----------------------------------------------------------------------+
35// |                             delete a group                            |
36// +-----------------------------------------------------------------------+
37
38if (isset($_GET['delete']) and is_numeric($_GET['delete']))
39{
40  // destruction of the access linked to the group
41  $query = '
42DELETE
43  FROM '.GROUP_ACCESS_TABLE.'
44  WHERE group_id = '.$_GET['delete'].'
45;';
46  pwg_query($query);
47 
48  // destruction of the users links for this group
49  $query = '
50DELETE
51  FROM '.USER_GROUP_TABLE.'
52  WHERE group_id = '.$_GET['delete'].'
53;';
54  pwg_query($query);
55
56  $query = '
57SELECT name
58  FROM '.GROUPS_TABLE.'
59  WHERE id = '.$_GET['delete'].'
60;';
61  list($groupname) = mysql_fetch_row(pwg_query($query));
62 
63  // destruction of the group
64  $query = '
65DELETE
66  FROM '.GROUPS_TABLE.'
67  WHERE id = '.$_GET['delete'].'
68;';
69  pwg_query($query);
70
71  array_push(
72    $page['infos'],
73    sprintf(l10n('group "%s" deleted'), $groupname)
74    );
75}
76
77// +-----------------------------------------------------------------------+
78// |                              add a group                              |
79// +-----------------------------------------------------------------------+
80
81if (isset($_POST['submit_add']))
82{
83  if (empty($_POST['groupname']))
84  {
85    array_push($page['errors'], $lang['group_add_error1']);
86  }
87  if (count($page['errors']) == 0)
88  {
89    // is the group not already existing ?
90    $query = '
91SELECT COUNT(*)
92  FROM '.GROUPS_TABLE.'
93  WHERE name = \''.$_POST['groupname'].'\'
94;';
95    list($count) = mysql_fetch_row(pwg_query($query));
96    if ($count != 0)
97    {
98      array_push($page['errors'], $lang['group_add_error2']);
99    }
100  }
101  if (count($page['errors']) == 0)
102  {
103    // creating the group
104    $query = '
105INSERT INTO '.GROUPS_TABLE.'
106  (name)
107  VALUES
108  (\''.mysql_escape_string($_POST['groupname']).'\')
109;';
110    pwg_query($query);
111
112    array_push(
113      $page['infos'],
114      sprintf(l10n('group "%s" added'), $_POST['groupname'])
115      );
116  }
117}
118
119// +-----------------------------------------------------------------------+
120// |                             template init                             |
121// +-----------------------------------------------------------------------+
122
123$template->set_filenames(array('group_list' => 'admin/group_list.tpl'));
124
125$template->assign_vars(
126  array(
127    'F_ADD_ACTION' =>
128      add_session_id(PHPWG_ROOT_PATH.'admin.php?page=group_list')
129    )
130  );
131
132// +-----------------------------------------------------------------------+
133// |                              group list                               |
134// +-----------------------------------------------------------------------+
135
136$query = '
137SELECT id, name
138  FROM '.GROUPS_TABLE.'
139  ORDER BY id ASC
140;';
141$result = pwg_query($query);
142
143$admin_url = PHPWG_ROOT_PATH.'admin.php?page=';
144$perm_url    = $admin_url.'group_perm&amp;group_id=';
145$del_url     = $admin_url.'group_list&amp;delete=';
146$members_url = $admin_url.'user_list&amp;group=';
147
148$num = 0;
149while ($row = mysql_fetch_array($result))
150{
151  $query = '
152SELECT COUNT(*)
153  FROM '.USER_GROUP_TABLE.'
154  WHERE group_id = '.$row['id'].'
155;';
156  list($counter) = mysql_fetch_row(pwg_query($query));
157 
158  $template->assign_block_vars(
159    'group',
160    array(
161      'CLASS' => ($num++ % 2 == 1) ? 'row2' : 'row1',
162      'NAME' => $row['name'],
163      'MEMBERS' => sprintf(l10n('%d members'), $counter),
164      'U_MEMBERS' => $members_url.$row['id'],
165      'U_DELETE' => $del_url.$row['id'],
166      'U_PERM' => $perm_url.$row['id']
167      )
168    );
169}
170
171// +-----------------------------------------------------------------------+
172// |                           sending html code                           |
173// +-----------------------------------------------------------------------+
174
175$template->assign_var_from_handle('ADMIN_CONTENT', 'group_list');
176
177?>
Note: See TracBrowser for help on using the repository browser.