Ignore:
Timestamp:
Jul 1, 2003, 11:27:20 AM (21 years ago)
Author:
z0rglub
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/user_modify.php

    r10 r21  
    2121$tpl = array( 'adduser_info_message', 'adduser_info_back', 'adduser_fill_form',
    2222              'login', 'new', 'password', 'mail_address', 'adduser_status',
    23               'submit', 'adduser_info_password_updated' );
     23              'submit', 'adduser_info_password_updated','menu_groups',
     24              'dissociate','adduser_associate' );
    2425templatize_array( $tpl, 'lang', $sub );
    2526//--------------------------------------------------------- form criteria check
     
    3536$query.= ';';
    3637$row = mysql_fetch_array( mysql_query( $query ) );
    37 
     38$page['username'] = $row['username'];
     39$page['status'] = $row['status'];
     40$page['mail_address'] = $row['mail_address'];
    3841// user is not modifiable if :
    3942//   1. the selected user is the user "guest"
     
    6770                          $_POST['password'] ) );
    6871}
     72// association with groups management
     73if ( isset( $_POST['submit'] ) )
     74{
     75  // deletion of checked groups
     76  $query = 'SELECT id,name';
     77  $query.= ' FROM '.PREFIX_TABLE.'groups';
     78  $query.= ' ORDER BY id ASC';
     79  $query.= ';';
     80  $result = mysql_query( $query );
     81  while ( $row = mysql_fetch_array( $result ) )
     82  {
     83    $dissociate = 'dissociate-'.$row['id'];
     84    if ( $_POST[$dissociate] == 1 )
     85    {
     86      $query = 'DELETE FROM '.PREFIX_TABLE.'user_group';
     87      $query.= ' WHERE user_id = '.$_GET['user_id'];
     88      $query.= ' AND group_id ='.$row['id'];
     89      $query.= ';';
     90      mysql_query( $query );
     91    }
     92  }
     93  // create a new association between the user and a group
     94  $query = 'INSERT INTO '.PREFIX_TABLE.'user_group';
     95  $query.= ' (user_id,group_id) VALUES';
     96  $query.= ' ('.$_GET['user_id'].','.$_POST['associate'].')';
     97  $query.= ';';
     98  mysql_query( $query );
     99}
    69100//-------------------------------------------------------------- errors display
    70101if ( sizeof( $error ) != 0 )
     
    83114{
    84115  $vtp->addSession( $sub, 'confirmation' );
    85   $vtp->setVar( $sub, 'confirmation.username', $row['username'] );
     116  $vtp->setVar( $sub, 'confirmation.username', $page['username'] );
    86117  $url = add_session_id( './admin.php?page=user_list' );
    87118  $vtp->setVar( $sub, 'confirmation.url', $url );
     
    92123    $vtp->closeSession( $sub, 'password_updated' );
    93124  }
    94   $display_form = false;
    95125}
    96126//------------------------------------------------------------------------ form
     
    100130  $action = './admin.php?page=user_modify&user_id='.$_GET['user_id'];
    101131  $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';
     132  $vtp->setVar( $sub, 'form.user:username',     $page['username'] );
     133  if ( isset( $_POST['mail_address'] ) )
     134  {
     135    $page['mail_address'] = $_POST['mail_address'];
     136  }
     137  $vtp->setVar( $sub, 'form.user:mail_address', $page['mail_address'] );
     138  if ( isset( $_POST['status'] ) )
     139  {
     140    $page['status'] = $_POST['status'];
    109141  }
    110142  $option = get_enums( PREFIX_TABLE.'users', 'status' );
     
    115147    $vtp->setVar( $sub, 'status_option.option',
    116148                  $lang['adduser_status_'.$option[$i]] );
    117     if( $option[$i] == $_POST['status'] )
     149    if( $option[$i] == $page['status'] )
    118150    {
    119151      $vtp->setVar( $sub, 'status_option.selected', ' selected="selected"' );
     
    121153    $vtp->closeSession( $sub, 'status_option' );
    122154  }
     155  // groups linked with this user
     156  $query = 'SELECT id,name';
     157  $query.= ' FROM '.PREFIX_TABLE.'user_group, '.PREFIX_TABLE.'groups';
     158  $query.= ' WHERE group_id = id';
     159  $query.= ' AND user_id = '.$_GET['user_id'];
     160  $query.= ';';
     161  $result = mysql_query( $query );
     162  $user_groups = array();
     163  if ( mysql_num_rows( $result ) > 0 )
     164  {
     165    $vtp->addSession( $sub, 'groups' );
     166    while ( $row = mysql_fetch_array( $result ) )
     167    {
     168      $vtp->addSession( $sub, 'group' );
     169      $vtp->setVar( $sub, 'group.name', $row['name'] );
     170      $vtp->setVar( $sub, 'group.dissociate_id', $row['id'] );
     171      $vtp->closeSession( $sub, 'group' );
     172      array_push( $user_groups, $row['id'] );
     173    }
     174    $vtp->closeSession( $sub, 'groups' );
     175  }
     176  // empty group not to take into account
     177  $vtp->addSession( $sub, 'associate_group' );
     178  $vtp->setVar( $sub, 'associate_group.value', 'undef' );
     179  $vtp->setVar( $sub, 'associate_group.option', '' );
     180  $vtp->closeSession( $sub, 'associate_group' );
     181  // groups not linked yet to the user
     182  $query = 'SELECT id,name';
     183  $query.= ' FROM '.PREFIX_TABLE.'groups';
     184  $query.= ' ORDER BY id ASC';
     185  $query.= ';';
     186  $result = mysql_query( $query );
     187  while ( $row = mysql_fetch_array( $result ) )
     188  {
     189    if ( !in_array( $row['id'], $user_groups ) )
     190    {
     191      $vtp->addSession( $sub, 'associate_group' );
     192      $vtp->setVar( $sub, 'associate_group.value', $row['id'] );
     193      $vtp->setVar( $sub, 'associate_group.option', $row['name'] );
     194      $vtp->closeSession( $sub, 'associate_group' );
     195    }
     196  }
     197
    123198  $url = add_session_id( './admin.php?page=user_list' );
    124199  $vtp->setVar( $sub, 'form.url_back', $url );
Note: See TracChangeset for help on using the changeset viewer.