Ignore:
Timestamp:
May 13, 2003, 12:02:06 PM (21 years ago)
Author:
z0rglub
Message:

2003.05.13 user_add and user_modify added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/user_modify.php

    r8 r9  
    1919$sub = $vtp->Open( '../template/'.$user['template'].'/admin/user_modify.vtp' );
    2020$error = array();
    21 $tpl = array( 'user_err_modify', 'user_err_unknown' );
    22 templatize_array( $tpl, 'lang' );
     21$tpl = array( 'adduser_info_message', 'adduser_info_back', 'adduser_fill_form',
     22              'login', 'new', 'password', 'mail_address', 'adduser_status',
     23              'submit', 'adduser_info_password_updated' );
     24templatize_array( $tpl, 'lang', $sub );
    2325//--------------------------------------------------------- form criteria check
     26$error = array();
    2427$display_form = true;
    2528
     29// retrieving information in the database about the user identified by its
     30// id in $_GET['user_id']
    2631$query = 'select';
    2732$query.= ' username,status,mail_address';
     
    3136$row = mysql_fetch_array( mysql_query( $query ) );
    3237
    33 $username     = $row['username'];
    34 $status       = $row['status'];
    35 $mail_address = $row['mail_address'];
    36 
    37 if ( $username == 'guest'
    38      or ( $username == $conf['webmaster']
     38// user is not modifiable if :
     39//   1. the selected user is the user "guest"
     40//   2. the selected user is the webmaster and the user making the modification
     41//      is not the webmaster
     42if ( $row['username'] == 'guest'
     43     or ( $row['username'] == $conf['webmaster']
    3944          and $user['username'] != $conf['webmaster'] ) )
    4045{
    41   $vtp->addSession( $sub, 'err_modify' );
    42   $vtp->closeSession( $sub, 'err_modify' );
     46  array_push( $error, $lang['user_err_modify'] );
    4347  $display_form = false;
    4448}
    45 if ( $username == '' )
     49// if the user was not found in the database, no modification possible
     50if ( $row['username'] == '' )
    4651{
    47   $vtp->addSession( $sub, 'err_unknown' );
    48   $vtp->closeSession( $sub, 'err_unknown' );
     52  array_push( $error, $lang['user_err_unknown'] );
    4953  $display_form = false;
    5054}
    5155
    52 if ( $display_form and isset( $_POST['submit'] ) )
     56if ( sizeof( $error ) == 0 and isset( $_POST['submit'] ) )
    5357{
     58  // shall we use a new password and overwrite the old one ?
    5459  $use_new_password = false;
    5560  if ( $_POST['use_new_pwd'] == 1)
     
    5762    $use_new_password = true;
    5863  }
    59   $error = update_user(
    60     $_GET['user_id'], $_POST['mail_address'], $_POST['status'],
    61     $use_new_password, $POST['password'] );
     64  $error = array_merge( $error, update_user(
     65                          $_GET['user_id'], $_POST['mail_address'],
     66                          $_POST['status'], $use_new_password,
     67                          $_POST['password'] ) );
    6268}
     69//-------------------------------------------------------------- errors display
     70if ( sizeof( $error ) != 0 )
     71{
     72  $vtp->addSession( $sub, 'errors' );
     73  for ( $i = 0; $i < sizeof( $error ); $i++ )
     74  {
     75    $vtp->addSession( $sub, 'li' );
     76    $vtp->setVar( $sub, 'li.li', $error[$i] );
     77    $vtp->closeSession( $sub, 'li' );
     78  }
     79  $vtp->closeSession( $sub, 'errors' );
     80}
     81//---------------------------------------------------------------- confirmation
     82if ( sizeof( $error ) == 0 and isset( $_POST['submit'] ) )
     83{
     84  $vtp->addSession( $sub, 'confirmation' );
     85  $vtp->setVar( $sub, 'confirmation.username', $row['username'] );
     86  $url = add_session_id( './admin.php?page=user_list' );
     87  $vtp->setVar( $sub, 'confirmation.url', $url );
     88  $vtp->closeSession( $sub, 'confirmation' );
     89  if ( $use_new_pwd )
     90  {
     91    $vtp->addSession( $sub, 'password_updated' );
     92    $vtp->closeSession( $sub, 'password_updated' );
     93  }
     94  $display_form = false;
     95}
     96//------------------------------------------------------------------------ form
     97if ( $display_form )
     98{
     99  $vtp->addSession( $sub, 'form' );
     100  $action = './admin.php?page=user_modify&amp;user_id='.$_GET['user_id'];
     101  $vtp->setVar( $sub, 'form.form_action', add_session_id( $action ) );
     102  $vtp->setVar( $sub, 'form.user:username',     $row['username'] );
     103  $vtp->setVar( $sub, 'form.user:password',     $_POST['password'] );
     104  $vtp->setVar( $sub, 'form.user:mail_address', $_POST['mail_address'] );
     105
     106  if ( !isset( $_POST['status'] ) )
     107  {
     108    $_POST['status'] = 'guest';
     109  }
     110  $option = get_enums( $prefixeTable.'users', 'status' );
     111  for ( $i = 0; $i < sizeof( $option ); $i++ )
     112  {
     113    $vtp->addSession( $sub, 'status_option' );
     114    $vtp->setVar( $sub, 'status_option.value', $option[$i] );
     115    $vtp->setVar( $sub, 'status_option.option',
     116                  $lang['adduser_status_'.$option[$i]] );
     117    if( $option[$i] == $_POST['status'] )
     118    {
     119      $vtp->setVar( $sub, 'status_option.selected', ' selected="selected"' );
     120    }
     121    $vtp->closeSession( $sub, 'status_option' );
     122  }
     123  $url = add_session_id( './admin.php?page=user_list' );
     124  $vtp->setVar( $sub, 'form.url_back', $url );
     125  $vtp->closeSession( $sub, 'form' );
     126}
     127//----------------------------------------------------------- sending html code
     128$vtp->Parse( $handle , 'sub', $sub );
    63129?>
Note: See TracChangeset for help on using the changeset viewer.