2003-05-09 14:42:42 +02:00
|
|
|
<?php
|
|
|
|
/***************************************************************************
|
2003-05-13 12:02:06 +02:00
|
|
|
* user_list.php *
|
2003-05-09 14:42:42 +02:00
|
|
|
* ------------------- *
|
2003-08-24 09:40:56 +02:00
|
|
|
* application : PhpWebGallery 1.3 <http://phpwebgallery.net> *
|
|
|
|
* author : Pierrick LE GALL <pierrick@z0rglub.com> *
|
|
|
|
* *
|
|
|
|
* $Id$
|
2003-05-09 14:42:42 +02:00
|
|
|
* *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* *
|
|
|
|
* 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; *
|
|
|
|
* *
|
|
|
|
***************************************************************************/
|
|
|
|
include_once( './include/isadmin.inc.php' );
|
|
|
|
//----------------------------------------------------- template initialization
|
|
|
|
$sub = $vtp->Open( '../template/'.$user['template'].'/admin/user_list.vtp' );
|
2003-07-01 11:27:20 +02:00
|
|
|
$tpl = array( 'listuser_confirm','listuser_modify_hint','listuser_modify',
|
|
|
|
'listuser_permission','listuser_permission_hint',
|
|
|
|
'listuser_delete_hint','listuser_delete','yes','no',
|
|
|
|
'listuser_button_all','listuser_button_invert',
|
2003-09-14 17:02:52 +02:00
|
|
|
'listuser_button_create_address','title_add','login','password',
|
|
|
|
'add','errors_title' );
|
2003-07-01 11:27:20 +02:00
|
|
|
templatize_array( $tpl, 'lang', $sub );
|
2003-07-28 22:18:05 +02:00
|
|
|
$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
|
2003-09-14 17:02:52 +02:00
|
|
|
//------------------------------------------------------------------ add a user
|
|
|
|
$errors = array();
|
2003-09-24 21:30:24 +02:00
|
|
|
if ( isset( $_POST['submit_add_user'] ) )
|
2003-09-14 17:02:52 +02:00
|
|
|
{
|
|
|
|
$errors = register_user(
|
|
|
|
$_POST['username'], $_POST['password'], $_POST['password'], '', 'guest' );
|
|
|
|
}
|
|
|
|
//-------------------------------------------------------------- errors display
|
|
|
|
if ( sizeof( $errors ) != 0 )
|
|
|
|
{
|
|
|
|
$vtp->addSession( $sub, 'errors' );
|
|
|
|
foreach ( $errors as $error ) {
|
|
|
|
$vtp->addSession( $sub, 'li' );
|
|
|
|
$vtp->setVar( $sub, 'li.li', $error );
|
|
|
|
$vtp->closeSession( $sub, 'li' );
|
|
|
|
}
|
|
|
|
$vtp->closeSession( $sub, 'errors' );
|
|
|
|
}
|
2003-09-24 21:30:24 +02:00
|
|
|
else if ( isset( $_POST['submit_add_user'] ) )
|
2003-09-14 17:02:52 +02:00
|
|
|
{
|
|
|
|
$_POST = array();
|
|
|
|
}
|
2003-05-09 14:42:42 +02:00
|
|
|
//--------------------------------------------------------------- delete a user
|
2003-05-13 12:02:06 +02:00
|
|
|
if ( isset ( $_GET['delete'] ) and is_numeric( $_GET['delete'] ) )
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2003-07-01 11:27:20 +02:00
|
|
|
$query = 'SELECT username';
|
|
|
|
$query.= ' FROM '.PREFIX_TABLE.'users';
|
|
|
|
$query.= ' WHERE id = '.$_GET['delete'];
|
2003-05-09 14:42:42 +02:00
|
|
|
$query.= ';';
|
|
|
|
$row = mysql_fetch_array( mysql_query( $query ) );
|
|
|
|
// confirm user deletion ?
|
2004-01-22 00:33:56 +01:00
|
|
|
if ( !isset( $_GET['confirm'] ) )
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
|
|
|
$vtp->addSession( $sub, 'deletion' );
|
2003-05-13 12:02:06 +02:00
|
|
|
$vtp->setVar( $sub, 'deletion.login', $row['username'] );
|
2003-05-09 14:42:42 +02:00
|
|
|
$yes_url = './admin.php?page=user_list&delete='.$_GET['delete'];
|
|
|
|
$yes_url.= '&confirm=1';
|
|
|
|
$vtp->setVar( $sub, 'deletion.yes_url', add_session_id( $yes_url ) );
|
|
|
|
$no_url = './admin.php?page=user_list';
|
|
|
|
$vtp->setVar( $sub, 'deletion.no_url', add_session_id( $no_url ) );
|
|
|
|
$vtp->closeSession( $sub, 'deletion' );
|
|
|
|
}
|
|
|
|
// user deletion confirmed
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$vtp->addSession( $sub, 'confirmation' );
|
2003-05-13 12:02:06 +02:00
|
|
|
if ( $row['username'] != 'guest'
|
|
|
|
and $row['username'] != $conf['webmaster'] )
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2003-07-01 11:27:20 +02:00
|
|
|
$query = 'SELECT COUNT(*) AS nb_result';
|
|
|
|
$query.= ' FROM '.PREFIX_TABLE.'users';
|
|
|
|
$query.= ' WHERE id = '.$_GET['delete'];
|
2003-05-09 14:42:42 +02:00
|
|
|
$query.= ';';
|
|
|
|
$row2 = mysql_fetch_array( mysql_query( $query ) );
|
|
|
|
if ( $row2['nb_result'] > 0 )
|
|
|
|
{
|
|
|
|
delete_user( $_GET['delete'] );
|
|
|
|
$vtp->setVar( $sub, 'confirmation.class', 'info' );
|
2003-05-13 12:02:06 +02:00
|
|
|
$info = '"'.$row['username'].'" '.$lang['listuser_info_deletion'];
|
2003-05-09 14:42:42 +02:00
|
|
|
$vtp->setVar( $sub, 'confirmation.info', $info );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$vtp->setVar( $sub, 'confirmation.class', 'erreur' );
|
|
|
|
$vtp->setVar( $sub, 'confirmation.info', $lang['user_err_unknown'] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$vtp->setVar( $sub, 'confirmation.class', 'erreur' );
|
|
|
|
$vtp->setVar( $sub, 'confirmation.info', $lang['user_err_modify'] );
|
|
|
|
}
|
|
|
|
$vtp->closeSession( $sub, 'confirmation' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------ users list
|
|
|
|
else
|
|
|
|
{
|
2003-09-14 17:02:52 +02:00
|
|
|
// add a user
|
|
|
|
$vtp->addSession( $sub, 'add_user' );
|
|
|
|
$action = './admin.php?'.$_SERVER['QUERY_STRING'];
|
|
|
|
$vtp->setVar( $sub, 'add_user.form_action', $action );
|
2004-01-15 18:06:45 +01:00
|
|
|
if (isset( $_POST['username']))
|
|
|
|
$vtp->setVar( $sub, 'add_user.f_username', $_POST['username'] );
|
2003-09-14 17:02:52 +02:00
|
|
|
$vtp->closeSession( $sub, 'add_user' );
|
|
|
|
|
2003-05-09 14:42:42 +02:00
|
|
|
$vtp->addSession( $sub, 'users' );
|
|
|
|
|
|
|
|
$action = './admin.php?'.$_SERVER['QUERY_STRING'];
|
|
|
|
if ( !isset( $_GET['mail'] ) )
|
|
|
|
{
|
|
|
|
$action.= '&mail=true';
|
|
|
|
}
|
|
|
|
$vtp->setVar( $sub, 'users.form_action', $action );
|
|
|
|
|
2003-07-01 11:27:20 +02:00
|
|
|
$query = 'SELECT id,username,status,mail_address';
|
|
|
|
$query.= ' FROM '.PREFIX_TABLE.'users';
|
|
|
|
$query.= ' ORDER BY status ASC, username ASC';
|
2003-05-09 14:42:42 +02:00
|
|
|
$query.= ';';
|
|
|
|
$result = mysql_query( $query );
|
|
|
|
|
|
|
|
$current_status = '';
|
|
|
|
while ( $row = mysql_fetch_array( $result ) )
|
|
|
|
{
|
|
|
|
// display the line indicating the status of the next users
|
|
|
|
if ( $row['status'] != $current_status )
|
|
|
|
{
|
|
|
|
if ( $current_status != '' )
|
|
|
|
{
|
|
|
|
$vtp->closeSession( $sub, 'category' );
|
|
|
|
}
|
|
|
|
$vtp->addSession( $sub, 'category' );
|
|
|
|
$title = $lang['listuser_user_group'].' ';
|
|
|
|
switch ( $row['status'] )
|
|
|
|
{
|
2003-07-01 11:27:20 +02:00
|
|
|
case 'admin' : $title.= $lang['adduser_status_admin']; break;
|
|
|
|
case 'guest' : $title.= $lang['adduser_status_guest']; break;
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
|
|
|
$vtp->setVar( $sub, 'category.title', $title );
|
|
|
|
$current_status = $row['status'];
|
|
|
|
}
|
|
|
|
$vtp->addSession( $sub, 'user' );
|
|
|
|
// checkbox for mail management if the user has a mail address
|
2004-01-19 23:33:26 +01:00
|
|
|
if ( isset( $row['mail_address'] ) and $row['username'] != 'guest' )
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
|
|
|
$vtp->addSession( $sub, 'checkbox' );
|
|
|
|
$vtp->setVar( $sub, 'checkbox.name', 'mail-'.$row['id'] );
|
|
|
|
$vtp->closeSession( $sub, 'checkbox' );
|
|
|
|
}
|
|
|
|
// use a special color for the login of the user ?
|
2003-05-13 12:02:06 +02:00
|
|
|
if ( $row['username'] == $conf['webmaster'] )
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
|
|
|
$vtp->setVar( $sub, 'user.color', 'red' );
|
|
|
|
}
|
2003-05-13 12:02:06 +02:00
|
|
|
if ( $row['username'] == 'guest' )
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
|
|
|
$vtp->setVar( $sub, 'user.color', 'green' );
|
2003-05-13 12:02:06 +02:00
|
|
|
$vtp->setVar( $sub, 'user.login', $lang['guest'] );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$vtp->setVar( $sub, 'user.login', $row['username'] );
|
|
|
|
}
|
2003-05-09 14:42:42 +02:00
|
|
|
// modify or not modify ?
|
2003-05-13 12:02:06 +02:00
|
|
|
if ( $row['username'] == 'guest'
|
|
|
|
or ( $row['username'] == $conf['webmaster']
|
|
|
|
and $user['username'] != $conf['webmaster'] ) )
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
|
|
|
$vtp->addSession( $sub, 'not_modify' );
|
|
|
|
$vtp->closeSession( $sub, 'not_modify' );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$vtp->addSession( $sub, 'modify' );
|
2003-05-13 12:02:06 +02:00
|
|
|
$url = './admin.php?page=user_modify&user_id=';
|
2003-05-09 14:42:42 +02:00
|
|
|
$url.= $row['id'];
|
|
|
|
$vtp->setVar( $sub, 'modify.url', add_session_id( $url ) );
|
2003-05-13 12:02:06 +02:00
|
|
|
$vtp->setVar( $sub, 'modify.login', $row['username'] );
|
2003-05-09 14:42:42 +02:00
|
|
|
$vtp->closeSession( $sub, 'modify' );
|
|
|
|
}
|
|
|
|
// manage permission or not ?
|
2003-07-01 11:27:20 +02:00
|
|
|
if ( $row['username'] == $conf['webmaster']
|
|
|
|
and $user['username'] != $conf['webmaster'] )
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
|
|
|
$vtp->addSession( $sub, 'not_permission' );
|
|
|
|
$vtp->closeSession( $sub, 'not_permission' );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$vtp->addSession( $sub, 'permission' );
|
2003-07-01 11:27:20 +02:00
|
|
|
$url = './admin.php?page=user_perm&user_id='.$row['id'];
|
2003-05-09 14:42:42 +02:00
|
|
|
$vtp->setVar( $sub, 'permission.url', add_session_id( $url ) );
|
2003-05-13 12:02:06 +02:00
|
|
|
$vtp->setVar( $sub, 'permission.login', $row['username'] );
|
2003-05-09 14:42:42 +02:00
|
|
|
$vtp->closeSession( $sub, 'permission' );
|
|
|
|
}
|
|
|
|
// is the user deletable or not ?
|
2003-05-13 12:02:06 +02:00
|
|
|
if ( $row['username'] == 'guest'
|
|
|
|
or $row['username'] == $conf['webmaster'] )
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
|
|
|
$vtp->addSession( $sub, 'not_delete' );
|
|
|
|
$vtp->closeSession( $sub, 'not_delete' );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$vtp->addSession( $sub, 'delete' );
|
|
|
|
$url = './admin.php?page=user_list&delete='.$row['id'];
|
|
|
|
$vtp->setVar( $sub, 'delete.url', add_session_id( $url ) );
|
2003-05-13 12:02:06 +02:00
|
|
|
$vtp->setVar( $sub, 'delete.login', $row['username'] );
|
2003-05-09 14:42:42 +02:00
|
|
|
$vtp->closeSession( $sub, 'delete' );
|
|
|
|
}
|
|
|
|
$vtp->closeSession( $sub, 'user' );
|
|
|
|
}
|
|
|
|
$vtp->closeSession( $sub, 'category' );
|
|
|
|
// mail management : creation of the mail address if asked by administrator
|
2003-09-24 21:30:24 +02:00
|
|
|
if ( isset( $_POST['submit_generate_mail'] ) and isset( $_GET['mail'] ) )
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2003-09-24 21:30:24 +02:00
|
|
|
$mails = array();
|
2003-07-01 11:27:20 +02:00
|
|
|
$query = 'SELECT id,mail_address';
|
|
|
|
$query.= ' FROM '.PREFIX_TABLE.'users';
|
2003-05-09 14:42:42 +02:00
|
|
|
$query.= ';';
|
|
|
|
$result = mysql_query( $query );
|
|
|
|
while ( $row = mysql_fetch_array( $result ) )
|
|
|
|
{
|
2004-01-29 22:18:53 +01:00
|
|
|
if ( isset( $_POST['mail-'.$row['id']] ) )
|
2003-09-24 21:30:24 +02:00
|
|
|
array_push( $mails, $row['mail_address'] );
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
|
|
|
$mail_destination = '';
|
2003-09-24 21:30:24 +02:00
|
|
|
foreach ( $mails as $i => $mail_address ) {
|
|
|
|
if ( $i > 0 ) $mail_destination.= ',';
|
|
|
|
$mail_destination.= $mail_address;
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2003-09-24 21:30:24 +02:00
|
|
|
if ( sizeof( $mails ) > 0 )
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
|
|
|
$vtp->addSession( $sub, 'mail_link' );
|
|
|
|
$vtp->setVar( $sub, 'mail_link.mailto', $mail_destination );
|
|
|
|
$vtp->setVar( $sub, 'mail_link.mail_address_start',
|
|
|
|
substr( $mail_destination, 0, 50 ) );
|
|
|
|
$vtp->closeSession( $sub, 'mail_link' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$vtp->closeSession( $sub, 'users' );
|
|
|
|
}
|
|
|
|
//----------------------------------------------------------- sending html code
|
|
|
|
$vtp->Parse( $handle , 'sub', $sub );
|
|
|
|
?>
|