source: trunk/admin/user_modify.php @ 57

Last change on this file since 57 was 57, checked in by z0rglub, 21 years ago

improve the header of each file

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1<?php
2/***************************************************************************
3 *                              user_modify.php                            *
4 *                            -------------------                          *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: user_modify.php 57 2003-08-24 07:40:56Z z0rglub $
9 *                                                                         *
10 ***************************************************************************/
11
12/***************************************************************************
13 *                                                                         *
14 *   This program is free software; you can redistribute it and/or modify  *
15 *   it under the terms of the GNU General Public License as published by  *
16 *   the Free Software Foundation;                                         *
17 *                                                                         *
18 ***************************************************************************/
19include_once( './include/isadmin.inc.php' );
20//----------------------------------------------------- template initialization
21$sub = $vtp->Open( '../template/'.$user['template'].'/admin/user_modify.vtp' );
22$error = array();
23$tpl = array( 'adduser_info_message', 'adduser_info_back', 'adduser_fill_form',
24              'login', 'new', 'password', 'mail_address', 'adduser_status',
25              'submit', 'adduser_info_password_updated','menu_groups',
26              'dissociate','adduser_associate' );
27templatize_array( $tpl, 'lang', $sub );
28//--------------------------------------------------------- form criteria check
29$error = array();
30$display_form = true;
31
32// retrieving information in the database about the user identified by its
33// id in $_GET['user_id']
34$query = 'select';
35$query.= ' username,status,mail_address';
36$query.= ' from '.PREFIX_TABLE.'users';
37$query.= ' where id = '.$_GET['user_id'];
38$query.= ';';
39$row = mysql_fetch_array( mysql_query( $query ) );
40$page['username'] = $row['username'];
41$page['status'] = $row['status'];
42$page['mail_address'] = $row['mail_address'];
43// user is not modifiable if :
44//   1. the selected user is the user "guest"
45//   2. the selected user is the webmaster and the user making the modification
46//      is not the webmaster
47if ( $row['username'] == 'guest'
48     or ( $row['username'] == $conf['webmaster']
49          and $user['username'] != $conf['webmaster'] ) )
50{
51  array_push( $error, $lang['user_err_modify'] );
52  $display_form = false;
53}
54// if the user was not found in the database, no modification possible
55if ( $row['username'] == '' )
56{
57  array_push( $error, $lang['user_err_unknown'] );
58  $display_form = false;
59}
60
61if ( sizeof( $error ) == 0 and isset( $_POST['submit'] ) )
62{
63  // shall we use a new password and overwrite the old one ?
64  $use_new_password = false;
65  if ( $_POST['use_new_pwd'] == 1)
66  {
67    $use_new_password = true;
68  }
69  $error = array_merge( $error, update_user(
70                          $_GET['user_id'], $_POST['mail_address'],
71                          $_POST['status'], $use_new_password,
72                          $_POST['password'] ) );
73}
74// association with groups management
75if ( isset( $_POST['submit'] ) )
76{
77  // deletion of checked groups
78  $query = 'SELECT id,name';
79  $query.= ' FROM '.PREFIX_TABLE.'groups';
80  $query.= ' ORDER BY id ASC';
81  $query.= ';';
82  $result = mysql_query( $query );
83  while ( $row = mysql_fetch_array( $result ) )
84  {
85    $dissociate = 'dissociate-'.$row['id'];
86    if ( $_POST[$dissociate] == 1 )
87    {
88      $query = 'DELETE FROM '.PREFIX_TABLE.'user_group';
89      $query.= ' WHERE user_id = '.$_GET['user_id'];
90      $query.= ' AND group_id ='.$row['id'];
91      $query.= ';';
92      mysql_query( $query );
93    }
94  }
95  // create a new association between the user and a group
96  $query = 'INSERT INTO '.PREFIX_TABLE.'user_group';
97  $query.= ' (user_id,group_id) VALUES';
98  $query.= ' ('.$_GET['user_id'].','.$_POST['associate'].')';
99  $query.= ';';
100  mysql_query( $query );
101}
102//-------------------------------------------------------------- errors display
103if ( sizeof( $error ) != 0 )
104{
105  $vtp->addSession( $sub, 'errors' );
106  for ( $i = 0; $i < sizeof( $error ); $i++ )
107  {
108    $vtp->addSession( $sub, 'li' );
109    $vtp->setVar( $sub, 'li.li', $error[$i] );
110    $vtp->closeSession( $sub, 'li' );
111  }
112  $vtp->closeSession( $sub, 'errors' );
113}
114//---------------------------------------------------------------- confirmation
115if ( sizeof( $error ) == 0 and isset( $_POST['submit'] ) )
116{
117  $vtp->addSession( $sub, 'confirmation' );
118  $vtp->setVar( $sub, 'confirmation.username', $page['username'] );
119  $url = add_session_id( './admin.php?page=user_list' );
120  $vtp->setVar( $sub, 'confirmation.url', $url );
121  $vtp->closeSession( $sub, 'confirmation' );
122  if ( $use_new_pwd )
123  {
124    $vtp->addSession( $sub, 'password_updated' );
125    $vtp->closeSession( $sub, 'password_updated' );
126  }
127}
128//------------------------------------------------------------------------ form
129if ( $display_form )
130{
131  $vtp->addSession( $sub, 'form' );
132  $action = './admin.php?page=user_modify&amp;user_id='.$_GET['user_id'];
133  $vtp->setVar( $sub, 'form.form_action', add_session_id( $action ) );
134  $vtp->setVar( $sub, 'form.user:username',     $page['username'] );
135  if ( isset( $_POST['mail_address'] ) )
136  {
137    $page['mail_address'] = $_POST['mail_address'];
138  }
139  $vtp->setVar( $sub, 'form.user:mail_address', $page['mail_address'] );
140  if ( isset( $_POST['status'] ) )
141  {
142    $page['status'] = $_POST['status'];
143  }
144  $option = get_enums( PREFIX_TABLE.'users', 'status' );
145  for ( $i = 0; $i < sizeof( $option ); $i++ )
146  {
147    $vtp->addSession( $sub, 'status_option' );
148    $vtp->setVar( $sub, 'status_option.value', $option[$i] );
149    $vtp->setVar( $sub, 'status_option.option',
150                  $lang['adduser_status_'.$option[$i]] );
151    if( $option[$i] == $page['status'] )
152    {
153      $vtp->setVar( $sub, 'status_option.selected', ' selected="selected"' );
154    }
155    $vtp->closeSession( $sub, 'status_option' );
156  }
157  // groups linked with this user
158  $query = 'SELECT id,name';
159  $query.= ' FROM '.PREFIX_TABLE.'user_group, '.PREFIX_TABLE.'groups';
160  $query.= ' WHERE group_id = id';
161  $query.= ' AND user_id = '.$_GET['user_id'];
162  $query.= ';';
163  $result = mysql_query( $query );
164  $user_groups = array();
165  if ( mysql_num_rows( $result ) > 0 )
166  {
167    $vtp->addSession( $sub, 'groups' );
168    while ( $row = mysql_fetch_array( $result ) )
169    {
170      $vtp->addSession( $sub, 'group' );
171      $vtp->setVar( $sub, 'group.name', $row['name'] );
172      $vtp->setVar( $sub, 'group.dissociate_id', $row['id'] );
173      $vtp->closeSession( $sub, 'group' );
174      array_push( $user_groups, $row['id'] );
175    }
176    $vtp->closeSession( $sub, 'groups' );
177  }
178  // empty group not to take into account
179  $vtp->addSession( $sub, 'associate_group' );
180  $vtp->setVar( $sub, 'associate_group.value', 'undef' );
181  $vtp->setVar( $sub, 'associate_group.option', '' );
182  $vtp->closeSession( $sub, 'associate_group' );
183  // groups not linked yet to the user
184  $query = 'SELECT id,name';
185  $query.= ' FROM '.PREFIX_TABLE.'groups';
186  $query.= ' ORDER BY id ASC';
187  $query.= ';';
188  $result = mysql_query( $query );
189  while ( $row = mysql_fetch_array( $result ) )
190  {
191    if ( !in_array( $row['id'], $user_groups ) )
192    {
193      $vtp->addSession( $sub, 'associate_group' );
194      $vtp->setVar( $sub, 'associate_group.value', $row['id'] );
195      $vtp->setVar( $sub, 'associate_group.option', $row['name'] );
196      $vtp->closeSession( $sub, 'associate_group' );
197    }
198  }
199
200  $url = add_session_id( './admin.php?page=user_list' );
201  $vtp->setVar( $sub, 'form.url_back', $url );
202  $vtp->closeSession( $sub, 'form' );
203}
204//----------------------------------------------------------- sending html code
205$vtp->Parse( $handle , 'sub', $sub );
206?>
Note: See TracBrowser for help on using the repository browser.