2003-07-01 09:27:20 +00:00
|
|
|
<?php
|
2004-02-11 23:20:38 +00:00
|
|
|
// +-----------------------------------------------------------------------+
|
2004-11-06 21:12:59 +00:00
|
|
|
// | PhpWebGallery - a PHP based picture gallery |
|
|
|
|
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
|
2005-01-07 23:10:51 +00:00
|
|
|
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
|
2004-02-11 23:20:38 +00:00
|
|
|
// +-----------------------------------------------------------------------+
|
2004-11-06 21:12:59 +00:00
|
|
|
// | branch : BSF (Best So Far)
|
2004-02-11 23:20:38 +00:00
|
|
|
// | file : $RCSfile$
|
|
|
|
// | last update : $Date$
|
|
|
|
// | last modifier : $Author$
|
|
|
|
// | revision : $Revision$
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | This program is free software; you can redistribute it and/or modify |
|
|
|
|
// | it under the terms of the GNU General Public License as published by |
|
|
|
|
// | the Free Software Foundation |
|
|
|
|
// | |
|
|
|
|
// | This program is distributed in the hope that it will be useful, but |
|
|
|
|
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
|
|
// | General Public License for more details. |
|
|
|
|
// | |
|
|
|
|
// | You should have received a copy of the GNU General Public License |
|
|
|
|
// | along with this program; if not, write to the Free Software |
|
|
|
|
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|
|
|
|
// | USA. |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2004-11-26 16:10:17 +00:00
|
|
|
if( !defined("PHPWG_ROOT_PATH") )
|
|
|
|
{
|
|
|
|
die ("Hacking attempt!");
|
|
|
|
}
|
|
|
|
include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' );
|
|
|
|
|
2003-07-01 09:27:20 +00:00
|
|
|
//-------------------------------------------------------------- delete a group
|
|
|
|
$error = array();
|
2004-11-26 16:10:17 +00:00
|
|
|
if ( isset( $_POST['delete'] ) && isset( $_POST['confirm_delete'] ) )
|
2003-07-01 09:27:20 +00:00
|
|
|
{
|
2004-12-03 16:30:12 +00:00
|
|
|
// destruction of the access linked to the group
|
|
|
|
$query = 'DELETE FROM '.GROUP_ACCESS_TABLE;
|
|
|
|
$query.= ' WHERE group_id = '.$_POST['group_id'];
|
|
|
|
$query.= ';';
|
|
|
|
pwg_query( $query );
|
|
|
|
|
|
|
|
// destruction of the users links for this group
|
2004-11-26 16:10:17 +00:00
|
|
|
$query = 'DELETE FROM ' . USER_GROUP_TABLE;
|
|
|
|
$query.= ' WHERE group_id = '.$_POST['group_id'];
|
|
|
|
pwg_query( $query );
|
|
|
|
|
2004-12-03 16:30:12 +00:00
|
|
|
// destruction of the group
|
2004-11-26 16:10:17 +00:00
|
|
|
$query = 'DELETE FROM ' . GROUPS_TABLE;
|
|
|
|
$query.= ' WHERE id = '.$_POST['group_id'];
|
|
|
|
$query.= ';';
|
|
|
|
pwg_query( $query );
|
2003-07-01 09:27:20 +00:00
|
|
|
}
|
|
|
|
//----------------------------------------------------------------- add a group
|
2004-11-26 16:10:17 +00:00
|
|
|
elseif ( isset( $_POST['new'] ) )
|
2003-07-01 09:27:20 +00:00
|
|
|
{
|
2004-11-26 16:10:17 +00:00
|
|
|
if ( empty($_POST['newgroup']) || preg_match( "/'/", $_POST['newgroup'] )
|
|
|
|
or preg_match( '/"/', $_POST['newgroup'] ) )
|
2003-07-01 09:27:20 +00:00
|
|
|
{
|
|
|
|
array_push( $error, $lang['group_add_error1'] );
|
|
|
|
}
|
|
|
|
if ( count( $error ) == 0 )
|
|
|
|
{
|
|
|
|
// is the group not already existing ?
|
2004-11-26 16:10:17 +00:00
|
|
|
$query = 'SELECT id FROM '.GROUPS_TABLE;
|
|
|
|
$query.= " WHERE name = '".$_POST['newgroup']."'";
|
2003-07-01 09:27:20 +00:00
|
|
|
$query.= ';';
|
2004-10-30 15:42:29 +00:00
|
|
|
$result = pwg_query( $query );
|
2003-07-01 09:27:20 +00:00
|
|
|
if ( mysql_num_rows( $result ) > 0 )
|
|
|
|
{
|
|
|
|
array_push( $error, $lang['group_add_error2'] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( count( $error ) == 0 )
|
|
|
|
{
|
|
|
|
// creating the group
|
2004-11-26 16:10:17 +00:00
|
|
|
$query = ' INSERT INTO '.GROUPS_TABLE;
|
|
|
|
$query.= " (name) VALUES ('".$_POST['newgroup']."')";
|
2003-07-01 09:27:20 +00:00
|
|
|
$query.= ';';
|
2004-10-30 15:42:29 +00:00
|
|
|
pwg_query( $query );
|
2003-07-01 09:27:20 +00:00
|
|
|
}
|
|
|
|
}
|
2004-11-26 16:10:17 +00:00
|
|
|
//--------------------------------------------------------------- user management
|
|
|
|
elseif ( isset( $_POST['add'] ) )
|
|
|
|
{
|
|
|
|
$userdata = getuserdata($_POST['username']);
|
|
|
|
if (!$userdata) echo "Utilisateur inexistant";
|
|
|
|
|
|
|
|
// create a new association between the user and a group
|
|
|
|
$query = 'INSERT INTO '.USER_GROUP_TABLE;
|
|
|
|
$query.= ' (user_id,group_id) VALUES';
|
|
|
|
$query.= ' ('.$userdata['id'].','.$_POST['edit_group_id'].')';
|
|
|
|
$query.= ';';
|
|
|
|
pwg_query( $query );
|
|
|
|
}
|
|
|
|
elseif (isset( $_POST['deny_user'] ))
|
|
|
|
{
|
|
|
|
$sql_in = '';
|
|
|
|
$members = $_POST['members'];
|
|
|
|
for($i = 0; $i < count($members); $i++)
|
|
|
|
{
|
|
|
|
$sql_in .= ( ( $sql_in != '' ) ? ', ' : '' ) . intval($members[$i]);
|
|
|
|
}
|
|
|
|
$query = 'DELETE FROM ' . USER_GROUP_TABLE;
|
|
|
|
$query.= ' WHERE user_id IN ('.$sql_in;
|
|
|
|
$query.= ') AND group_id = '.$_POST['edit_group_id'];
|
|
|
|
pwg_query( $query );
|
|
|
|
}
|
2003-07-01 09:27:20 +00:00
|
|
|
//-------------------------------------------------------------- errors display
|
|
|
|
if ( sizeof( $error ) != 0 )
|
|
|
|
{
|
2004-11-26 16:10:17 +00:00
|
|
|
$template->assign_block_vars('errors',array());
|
2003-07-01 09:27:20 +00:00
|
|
|
for ( $i = 0; $i < sizeof( $error ); $i++ )
|
|
|
|
{
|
2004-11-26 16:10:17 +00:00
|
|
|
$template->assign_block_vars('errors.error',array('ERROR'=>$error[$i]));
|
2003-07-01 09:27:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//----------------------------------------------------------------- groups list
|
|
|
|
|
2004-11-26 16:10:17 +00:00
|
|
|
$query = 'SELECT id,name FROM '.GROUPS_TABLE;
|
|
|
|
$query.= ' ORDER BY id ASC;';
|
2004-10-30 15:42:29 +00:00
|
|
|
$result = pwg_query( $query );
|
2004-11-26 16:10:17 +00:00
|
|
|
$groups_display = '<select name="group_id">';
|
|
|
|
$groups_nb=0;
|
2003-07-01 09:27:20 +00:00
|
|
|
while ( $row = mysql_fetch_array( $result ) )
|
|
|
|
{
|
2004-11-26 16:10:17 +00:00
|
|
|
$groups_nb++;
|
|
|
|
$selected = '';
|
|
|
|
if (isset($_POST['group_id']) && $_POST['group_id']==$row['id'])
|
|
|
|
$selected = 'selected';
|
|
|
|
$groups_display .= '<option value="' . $row['id'] . '" '.$selected.'>' . $row['name'] . '</option>';
|
|
|
|
}
|
|
|
|
$groups_display .= '</select>';
|
|
|
|
|
|
|
|
$action = PHPWG_ROOT_PATH.'admin.php?page=group_list';
|
|
|
|
//----------------------------------------------------- template initialization
|
|
|
|
$template->set_filenames( array('groups'=>'admin/group_list.tpl') );
|
|
|
|
$template->assign_vars(array(
|
|
|
|
'S_GROUP_SELECT'=>$groups_display,
|
|
|
|
|
|
|
|
'L_GROUP_SELECT'=>$lang['group_list_title'],
|
2005-01-06 16:33:04 +00:00
|
|
|
'L_GROUP_CONFIRM'=>$lang['group_confirm_delete'],
|
|
|
|
'L_LOOK_UP'=>$lang['edit'],
|
|
|
|
'L_GROUP_DELETE'=>$lang['delete'],
|
2004-11-26 16:10:17 +00:00
|
|
|
'L_CREATE_NEW_GROUP'=>$lang['group_add'],
|
|
|
|
'L_GROUP_EDIT'=>$lang['group_edit'],
|
2005-01-06 16:33:04 +00:00
|
|
|
'L_USER_NAME'=>$lang['login'],
|
|
|
|
'L_USER_EMAIL'=>$lang['mail_address'],
|
|
|
|
'L_USER_SELECT'=>$lang['Select'],
|
|
|
|
'L_DENY_SELECTED'=>$lang['group_deny_user'],
|
|
|
|
'L_ADD_MEMBER'=>$lang['group_add_user'],
|
2004-11-26 16:10:17 +00:00
|
|
|
'L_FIND_USERNAME'=>$lang['Find_username'],
|
|
|
|
|
2005-01-06 16:33:04 +00:00
|
|
|
'S_GROUP_ACTION'=>add_session_id($action),
|
|
|
|
'U_SEARCH_USER' => add_session_id(PHPWG_ROOT_PATH.'admin/search.php')
|
|
|
|
));
|
2004-11-26 16:10:17 +00:00
|
|
|
|
|
|
|
if ($groups_nb)
|
|
|
|
{
|
|
|
|
$template->assign_block_vars('select_box',array());
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------- add a group
|
|
|
|
if ( isset( $_POST['edit']) || isset( $_POST['add']) || isset( $_POST['deny_user'] ))
|
|
|
|
{
|
|
|
|
// Retrieving the group name
|
2005-01-06 16:33:04 +00:00
|
|
|
$query = 'SELECT id, name FROM '.GROUPS_TABLE;
|
2004-11-26 16:10:17 +00:00
|
|
|
$query.= " WHERE id = '".$_POST['group_id']."'";
|
|
|
|
$query.= ';';
|
|
|
|
$result = mysql_fetch_array(pwg_query( $query ));
|
|
|
|
$template->assign_block_vars('edit_group',array(
|
|
|
|
'GROUP_NAME'=>$result['name'],
|
2005-01-06 16:33:04 +00:00
|
|
|
'GROUP_ID'=>$result['id']
|
2004-11-26 16:10:17 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
// Retrieving all the users
|
2005-01-06 16:33:04 +00:00
|
|
|
$query = 'SELECT id, username, mail_address';
|
|
|
|
$query.= ' FROM ('.USERS_TABLE.' as u';
|
|
|
|
$query.= ' LEFT JOIN '.USER_GROUP_TABLE.' as ug ON ug.user_id=u.id)';
|
2004-11-26 16:10:17 +00:00
|
|
|
$query.= " WHERE ug.group_id = '".$_POST['group_id']."';";
|
2005-01-06 16:33:04 +00:00
|
|
|
$result = pwg_query( $query );
|
|
|
|
$i=0;
|
|
|
|
while ( $row = mysql_fetch_array( $result ) )
|
|
|
|
{
|
|
|
|
$class = ($i % 2)? 'row1':'row2'; $i++;
|
|
|
|
$template->assign_block_vars('edit_group.user',array(
|
|
|
|
'ID'=>$row['id'],
|
|
|
|
'NAME'=>$row['username'],
|
|
|
|
'EMAIL'=>$row['mail_address'],
|
|
|
|
'T_CLASS'=>$class
|
|
|
|
));
|
|
|
|
}
|
2003-07-01 09:27:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------- sending html code
|
2004-11-26 16:10:17 +00:00
|
|
|
$template->assign_var_from_handle('ADMIN_CONTENT', 'groups');
|
2004-02-11 23:20:38 +00:00
|
|
|
?>
|