source: trunk/admin/user_modify.php @ 364

Last change on this file since 364 was 364, checked in by gweltas, 20 years ago

Split of langage files

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