source: trunk/admin/group_list.php @ 792

Last change on this file since 792 was 792, checked in by plg, 19 years ago
  • errors and informations boxes : management centralized in admin.php, $errors and $infos arrays replaced by $pageerrors and $pageinfos, special management for admin/update.php (more complex management)
  • Property svn:eol-style set to native
  • 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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-06-11 14:10:04 +0000 (Sat, 11 Jun 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 792 $
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// +-----------------------------------------------------------------------+
27if( !defined("PHPWG_ROOT_PATH") )
28{
29        die ("Hacking attempt!");
30}
31include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' );
32
33//-------------------------------------------------------------- delete a group
34if ( isset( $_POST['delete'] ) && isset( $_POST['confirm_delete'] )  )
35{
36  // destruction of the access linked to the group
37  $query = 'DELETE FROM '.GROUP_ACCESS_TABLE;
38  $query.= ' WHERE group_id = '.$_POST['group_id'];
39  $query.= ';';
40  pwg_query( $query );
41       
42        // destruction of the users links for this group
43  $query = 'DELETE FROM ' . USER_GROUP_TABLE; 
44  $query.= ' WHERE group_id = '.$_POST['group_id'];
45        pwg_query( $query );
46       
47        // destruction of the group
48        $query = 'DELETE FROM ' . GROUPS_TABLE; 
49  $query.= ' WHERE id = '.$_POST['group_id'];
50        $query.= ';';
51        pwg_query( $query );
52}
53//----------------------------------------------------------------- add a group
54elseif ( isset( $_POST['new'] ) )
55{
56  if ( empty($_POST['newgroup']) || preg_match( "/'/", $_POST['newgroup'] )
57       or preg_match( '/"/', $_POST['newgroup'] ) )
58  {
59    array_push( $page['errors'], $lang['group_add_error1'] );
60  }
61  if ( count( $page['errors'] ) == 0 )
62  {
63    // is the group not already existing ?
64    $query = 'SELECT id FROM '.GROUPS_TABLE;
65    $query.= " WHERE name = '".$_POST['newgroup']."'";
66    $query.= ';';
67    $result = pwg_query( $query );
68    if ( mysql_num_rows( $result ) > 0 )
69    {
70      array_push( $page['errors'], $lang['group_add_error2'] );
71    }
72  }
73  if ( count( $page['errors'] ) == 0 )
74  {
75    // creating the group
76    $query = ' INSERT INTO '.GROUPS_TABLE;
77    $query.= " (name) VALUES ('".$_POST['newgroup']."')";
78    $query.= ';';
79    pwg_query( $query );
80  }
81}
82//------------------------------------------------------------- user management
83elseif ( isset( $_POST['add'] ) )
84{
85  $userdata = getuserdata($_POST['username']);
86  if (!$userdata)
87  {
88    array_push($page['errors'], $lang['user_err_unknown']);
89  }
90  else
91  {
92    // create a new association between the user and a group
93    $query = '
94INSERT INTO '.USER_GROUP_TABLE.'
95  (user_id,group_id)
96  VALUES
97  ('.$userdata['id'].','.$_POST['edit_group_id'].')
98;';
99    pwg_query($query);
100  }
101}
102elseif (isset( $_POST['deny_user'] ))
103{
104  $sql_in = '';
105        $members = $_POST['members'];
106        for($i = 0; $i < count($members); $i++)
107  {
108    $sql_in .= ( ( $sql_in != '' ) ? ', ' : '' ) . intval($members[$i]);
109  }
110  $query = 'DELETE FROM ' . USER_GROUP_TABLE; 
111  $query.= ' WHERE user_id IN ('.$sql_in;
112        $query.= ') AND group_id = '.$_POST['edit_group_id'];
113        pwg_query( $query );
114}
115//----------------------------------------------------------------- groups list
116
117$query = 'SELECT id,name FROM '.GROUPS_TABLE;
118$query.= ' ORDER BY id ASC;';
119$result = pwg_query( $query );
120$groups_display = '<select name="group_id">';
121$groups_nb=0;
122while ( $row = mysql_fetch_array( $result ) )
123{
124  $groups_nb++;
125        $selected = '';
126        if (isset($_POST['group_id']) && $_POST['group_id']==$row['id'])
127                $selected = 'selected';
128  $groups_display .= '<option value="' . $row['id'] . '" '.$selected.'>' . $row['name']  . '</option>';
129}
130$groups_display .= '</select>';
131
132$action = PHPWG_ROOT_PATH.'admin.php?page=group_list';
133//----------------------------------------------------- template initialization
134$template->set_filenames( array('groups'=>'admin/group_list.tpl') );
135$template->assign_vars(array(
136  'S_GROUP_SELECT'=>$groups_display,
137       
138  'L_GROUP_SELECT'=>$lang['group_list_title'],
139  'L_GROUP_CONFIRM'=>$lang['group_confirm_delete'],
140  'L_LOOK_UP'=>$lang['edit'],
141  'L_GROUP_DELETE'=>$lang['delete'],
142  'L_CREATE_NEW_GROUP'=>$lang['group_add'],
143  'L_GROUP_EDIT'=>$lang['group_edit'],
144  'L_USER_NAME'=>$lang['login'],
145  'L_USER_EMAIL'=>$lang['mail_address'],
146  'L_USER_SELECT'=>$lang['Select'],
147  'L_DENY_SELECTED'=>$lang['group_deny_user'],
148  'L_ADD_MEMBER'=>$lang['group_add_user'],
149  'L_FIND_USERNAME'=>$lang['Find_username'],
150       
151  'S_GROUP_ACTION'=>add_session_id($action),
152  'U_SEARCH_USER' => add_session_id(PHPWG_ROOT_PATH.'admin/search.php')
153  ));
154
155if ($groups_nb) 
156{
157  $template->assign_block_vars('select_box',array());
158}
159
160//----------------------------------------------------------------- add a group
161if ( isset( $_POST['edit']) || isset( $_POST['add']) || isset( $_POST['deny_user'] ))
162{
163  // Retrieving the group name
164  $query = 'SELECT id, name FROM '.GROUPS_TABLE;
165  $query.= " WHERE id = '".$_POST['group_id']."'";
166  $query.= ';';
167  $result = mysql_fetch_array(pwg_query( $query ));
168  $template->assign_block_vars('edit_group',array(
169          'GROUP_NAME'=>$result['name'],
170          'GROUP_ID'=>$result['id']
171                ));
172               
173  // Retrieving all the users
174  $query = 'SELECT id, username, mail_address';
175  $query.= ' FROM ('.USERS_TABLE.' as u';
176  $query.= ' LEFT JOIN '.USER_GROUP_TABLE.' as ug ON ug.user_id=u.id)';
177  $query.= " WHERE ug.group_id = '".$_POST['group_id']."';";
178  $result = pwg_query( $query );
179  $i=0;
180  while ( $row = mysql_fetch_array( $result ) )
181  {
182    $class = ($i % 2)? 'row1':'row2'; $i++;
183        $template->assign_block_vars('edit_group.user',array(
184                'ID'=>$row['id'],
185                'NAME'=>$row['username'],
186                'EMAIL'=>$row['mail_address'],
187                'T_CLASS'=>$class
188        ));
189  }
190}
191
192//----------------------------------------------------------- sending html code
193$template->assign_var_from_handle('ADMIN_CONTENT', 'groups');
194?>
Note: See TracBrowser for help on using the repository browser.