source: trunk/admin/group_list.php @ 703

Last change on this file since 703 was 675, checked in by plg, 20 years ago

all headers adapted to new year 2005, happy new year

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