source: trunk/admin/group_list.php @ 2273

Last change on this file since 2273 was 2273, checked in by rvelices, 16 years ago

group_list, group_perm and site_manager go smarty

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 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-2008 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: group_list.php 2273 2008-03-11 01:51:47Z rvelices $
8// | last update   : $Date: 2008-03-11 01:51:47 +0000 (Tue, 11 Mar 2008) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 2273 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27if( !defined("PHPWG_ROOT_PATH") )
28{
29  die ("Hacking attempt!");
30}
31
32include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
33
34// +-----------------------------------------------------------------------+
35// | Check Access and exit when user status is not ok                      |
36// +-----------------------------------------------------------------------+
37check_status(ACCESS_ADMINISTRATOR);
38
39// +-----------------------------------------------------------------------+
40// |                             delete a group                            |
41// +-----------------------------------------------------------------------+
42
43if (isset($_GET['delete']) and is_numeric($_GET['delete']) and !is_adviser())
44{
45  // destruction of the access linked to the group
46  $query = '
47DELETE
48  FROM '.GROUP_ACCESS_TABLE.'
49  WHERE group_id = '.$_GET['delete'].'
50;';
51  pwg_query($query);
52 
53  // destruction of the users links for this group
54  $query = '
55DELETE
56  FROM '.USER_GROUP_TABLE.'
57  WHERE group_id = '.$_GET['delete'].'
58;';
59  pwg_query($query);
60
61  $query = '
62SELECT name
63  FROM '.GROUPS_TABLE.'
64  WHERE id = '.$_GET['delete'].'
65;';
66  list($groupname) = mysql_fetch_row(pwg_query($query));
67 
68  // destruction of the group
69  $query = '
70DELETE
71  FROM '.GROUPS_TABLE.'
72  WHERE id = '.$_GET['delete'].'
73;';
74  pwg_query($query);
75
76  array_push(
77    $page['infos'],
78    sprintf(l10n('group "%s" deleted'), $groupname)
79    );
80}
81
82// +-----------------------------------------------------------------------+
83// |                              add a group                              |
84// +-----------------------------------------------------------------------+
85
86if (isset($_POST['submit_add']) and !is_adviser())
87{
88  if (empty($_POST['groupname']))
89  {
90    array_push($page['errors'], l10n('group_add_error1'));
91  }
92  if (count($page['errors']) == 0)
93  {
94    // is the group not already existing ?
95    $query = '
96SELECT COUNT(*)
97  FROM '.GROUPS_TABLE.'
98  WHERE name = \''.$_POST['groupname'].'\'
99;';
100    list($count) = mysql_fetch_row(pwg_query($query));
101    if ($count != 0)
102    {
103      array_push($page['errors'], l10n('group_add_error2'));
104    }
105  }
106  if (count($page['errors']) == 0)
107  {
108    // creating the group
109    $query = '
110INSERT INTO '.GROUPS_TABLE.'
111  (name)
112  VALUES
113  (\''.mysql_escape_string($_POST['groupname']).'\')
114;';
115    pwg_query($query);
116
117    array_push(
118      $page['infos'],
119      sprintf(l10n('group "%s" added'), $_POST['groupname'])
120      );
121  }
122}
123
124// +-----------------------------------------------------------------------+
125// | toggle is default group property                                      |
126// +-----------------------------------------------------------------------+
127
128if (isset($_GET['toggle_is_default']) and is_numeric($_GET['toggle_is_default']) and !is_adviser())
129{
130  $query = '
131SELECT name, is_default
132  FROM '.GROUPS_TABLE.'
133  WHERE id = '.$_GET['toggle_is_default'].'
134;';
135  list($groupname, $is_default) = mysql_fetch_row(pwg_query($query));
136 
137  // update of the group
138  $query = '
139UPDATE '.GROUPS_TABLE.'
140  SET is_default = \''.boolean_to_string(!get_boolean($is_default)).'\'
141  WHERE id = '.$_GET['toggle_is_default'].'
142;';
143  pwg_query($query);
144
145  array_push(
146    $page['infos'],
147    sprintf(l10n('group "%s" updated'), $groupname)
148    );
149}
150
151// +-----------------------------------------------------------------------+
152// |                             template init                             |
153// +-----------------------------------------------------------------------+
154
155$template->set_filenames(array('group_list' => 'admin/group_list.tpl'));
156
157$template->assign(
158  array(
159    'F_ADD_ACTION' => get_root_url().'admin.php?page=group_list',
160    'U_HELP' => get_root_url().'popuphelp.php?page=group_list',
161    )
162  );
163
164// +-----------------------------------------------------------------------+
165// |                              group list                               |
166// +-----------------------------------------------------------------------+
167
168$query = '
169SELECT id, name, is_default
170  FROM '.GROUPS_TABLE.'
171  ORDER BY name ASC
172;';
173$result = pwg_query($query);
174
175$admin_url = get_root_url().'admin.php?page=';
176$perm_url    = $admin_url.'group_perm&amp;group_id=';
177$del_url     = $admin_url.'group_list&amp;delete=';
178$members_url = $admin_url.'user_list&amp;group=';
179$toggle_is_default_url     = $admin_url.'group_list&amp;toggle_is_default=';
180
181while ($row = mysql_fetch_array($result))
182{
183  $query = '
184SELECT COUNT(*)
185  FROM '.USER_GROUP_TABLE.'
186  WHERE group_id = '.$row['id'].'
187;';
188  list($counter) = mysql_fetch_row(pwg_query($query));
189 
190  $template->append(
191    'groups',
192    array(
193      'NAME' => $row['name'],
194      'IS_DEFAULT' => (get_boolean($row['is_default']) ? ' ['.l10n('is_default_group').']' : ''),
195      'MEMBERS' => l10n_dec('%d member', '%d members', $counter),
196      'U_MEMBERS' => $members_url.$row['id'],
197      'U_DELETE' => $del_url.$row['id'],
198      'U_PERM' => $perm_url.$row['id'],
199      'U_ISDEFAULT' => $toggle_is_default_url.$row['id']
200      )
201    );
202}
203
204// +-----------------------------------------------------------------------+
205// |                           sending html code                           |
206// +-----------------------------------------------------------------------+
207
208$template->assign_var_from_handle('ADMIN_CONTENT', 'group_list');
209
210?>
Note: See TracBrowser for help on using the repository browser.