source: trunk/admin/group_list.php @ 2297

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

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