source: trunk/admin/group_list.php @ 623

Last change on this file since 623 was 623, checked in by gweltas, 19 years ago

New template for group management
French translation for synchronization
Minor update of the css file

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