1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * user_modify.php * |
---|
4 | * ------------------- * |
---|
5 | * application : PhpWebGallery 1.3 * |
---|
6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
7 | * * |
---|
8 | ***************************************************************************/ |
---|
9 | |
---|
10 | /*************************************************************************** |
---|
11 | * * |
---|
12 | * This program is free software; you can redistribute it and/or modify * |
---|
13 | * it under the terms of the GNU General Public License as published by * |
---|
14 | * the Free Software Foundation; * |
---|
15 | * * |
---|
16 | ***************************************************************************/ |
---|
17 | include_once( './include/isadmin.inc.php' ); |
---|
18 | //----------------------------------------------------- template initialization |
---|
19 | $sub = $vtp->Open( '../template/'.$user['template'].'/admin/user_modify.vtp' ); |
---|
20 | $error = array(); |
---|
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' ); |
---|
24 | templatize_array( $tpl, 'lang', $sub ); |
---|
25 | //--------------------------------------------------------- form criteria check |
---|
26 | $error = array(); |
---|
27 | $display_form = true; |
---|
28 | |
---|
29 | // retrieving information in the database about the user identified by its |
---|
30 | // id in $_GET['user_id'] |
---|
31 | $query = 'select'; |
---|
32 | $query.= ' username,status,mail_address'; |
---|
33 | $query.= ' from '.PREFIX_TABLE.'users'; |
---|
34 | $query.= ' where id = '.$_GET['user_id']; |
---|
35 | $query.= ';'; |
---|
36 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
37 | |
---|
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 |
---|
42 | if ( $row['username'] == 'guest' |
---|
43 | or ( $row['username'] == $conf['webmaster'] |
---|
44 | and $user['username'] != $conf['webmaster'] ) ) |
---|
45 | { |
---|
46 | array_push( $error, $lang['user_err_modify'] ); |
---|
47 | $display_form = false; |
---|
48 | } |
---|
49 | // if the user was not found in the database, no modification possible |
---|
50 | if ( $row['username'] == '' ) |
---|
51 | { |
---|
52 | array_push( $error, $lang['user_err_unknown'] ); |
---|
53 | $display_form = false; |
---|
54 | } |
---|
55 | |
---|
56 | if ( sizeof( $error ) == 0 and isset( $_POST['submit'] ) ) |
---|
57 | { |
---|
58 | // shall we use a new password and overwrite the old one ? |
---|
59 | $use_new_password = false; |
---|
60 | if ( $_POST['use_new_pwd'] == 1) |
---|
61 | { |
---|
62 | $use_new_password = true; |
---|
63 | } |
---|
64 | $error = array_merge( $error, update_user( |
---|
65 | $_GET['user_id'], $_POST['mail_address'], |
---|
66 | $_POST['status'], $use_new_password, |
---|
67 | $_POST['password'] ) ); |
---|
68 | } |
---|
69 | //-------------------------------------------------------------- errors display |
---|
70 | if ( 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 |
---|
82 | if ( 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 |
---|
97 | if ( $display_form ) |
---|
98 | { |
---|
99 | $vtp->addSession( $sub, 'form' ); |
---|
100 | $action = './admin.php?page=user_modify&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( PREFIX_TABLE.'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 ); |
---|
129 | ?> |
---|