[2] | 1 | <?php |
---|
| 2 | /*************************************************************************** |
---|
[9] | 3 | * user_list.php * |
---|
[2] | 4 | * ------------------- * |
---|
[57] | 5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
| 6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
[2] | 7 | * * |
---|
[57] | 8 | * $Id: user_list.php 226 2003-11-03 20:59:40Z z0rglub $ |
---|
| 9 | * * |
---|
[2] | 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 | ***************************************************************************/ |
---|
[226] | 19 | include_once( './admin/include/isadmin.inc.php' ); |
---|
[2] | 20 | //----------------------------------------------------- template initialization |
---|
[225] | 21 | $sub = $vtp->Open( './template/'.$user['template'].'/admin/user_list.vtp' ); |
---|
[21] | 22 | $tpl = array( 'listuser_confirm','listuser_modify_hint','listuser_modify', |
---|
| 23 | 'listuser_permission','listuser_permission_hint', |
---|
| 24 | 'listuser_delete_hint','listuser_delete','yes','no', |
---|
| 25 | 'listuser_button_all','listuser_button_invert', |
---|
[98] | 26 | 'listuser_button_create_address','title_add','login','password', |
---|
| 27 | 'add','errors_title' ); |
---|
[21] | 28 | templatize_array( $tpl, 'lang', $sub ); |
---|
[47] | 29 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
[98] | 30 | //------------------------------------------------------------------ add a user |
---|
| 31 | $errors = array(); |
---|
[164] | 32 | if ( isset( $_POST['submit_add_user'] ) ) |
---|
[98] | 33 | { |
---|
| 34 | $errors = register_user( |
---|
| 35 | $_POST['username'], $_POST['password'], $_POST['password'], '', 'guest' ); |
---|
| 36 | } |
---|
| 37 | //-------------------------------------------------------------- errors display |
---|
| 38 | if ( sizeof( $errors ) != 0 ) |
---|
| 39 | { |
---|
| 40 | $vtp->addSession( $sub, 'errors' ); |
---|
| 41 | foreach ( $errors as $error ) { |
---|
| 42 | $vtp->addSession( $sub, 'li' ); |
---|
| 43 | $vtp->setVar( $sub, 'li.li', $error ); |
---|
| 44 | $vtp->closeSession( $sub, 'li' ); |
---|
| 45 | } |
---|
| 46 | $vtp->closeSession( $sub, 'errors' ); |
---|
| 47 | } |
---|
[164] | 48 | else if ( isset( $_POST['submit_add_user'] ) ) |
---|
[98] | 49 | { |
---|
| 50 | $_POST = array(); |
---|
| 51 | } |
---|
[2] | 52 | //--------------------------------------------------------------- delete a user |
---|
[9] | 53 | if ( isset ( $_GET['delete'] ) and is_numeric( $_GET['delete'] ) ) |
---|
[2] | 54 | { |
---|
[21] | 55 | $query = 'SELECT username'; |
---|
| 56 | $query.= ' FROM '.PREFIX_TABLE.'users'; |
---|
| 57 | $query.= ' WHERE id = '.$_GET['delete']; |
---|
[2] | 58 | $query.= ';'; |
---|
| 59 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
| 60 | // confirm user deletion ? |
---|
| 61 | if ( $_GET['confirm'] != 1 ) |
---|
| 62 | { |
---|
| 63 | $vtp->addSession( $sub, 'deletion' ); |
---|
[9] | 64 | $vtp->setVar( $sub, 'deletion.login', $row['username'] ); |
---|
[2] | 65 | $yes_url = './admin.php?page=user_list&delete='.$_GET['delete']; |
---|
| 66 | $yes_url.= '&confirm=1'; |
---|
| 67 | $vtp->setVar( $sub, 'deletion.yes_url', add_session_id( $yes_url ) ); |
---|
| 68 | $no_url = './admin.php?page=user_list'; |
---|
| 69 | $vtp->setVar( $sub, 'deletion.no_url', add_session_id( $no_url ) ); |
---|
| 70 | $vtp->closeSession( $sub, 'deletion' ); |
---|
| 71 | } |
---|
| 72 | // user deletion confirmed |
---|
| 73 | else |
---|
| 74 | { |
---|
| 75 | $vtp->addSession( $sub, 'confirmation' ); |
---|
[9] | 76 | if ( $row['username'] != 'guest' |
---|
| 77 | and $row['username'] != $conf['webmaster'] ) |
---|
[2] | 78 | { |
---|
[21] | 79 | $query = 'SELECT COUNT(*) AS nb_result'; |
---|
| 80 | $query.= ' FROM '.PREFIX_TABLE.'users'; |
---|
| 81 | $query.= ' WHERE id = '.$_GET['delete']; |
---|
[2] | 82 | $query.= ';'; |
---|
| 83 | $row2 = mysql_fetch_array( mysql_query( $query ) ); |
---|
| 84 | if ( $row2['nb_result'] > 0 ) |
---|
| 85 | { |
---|
| 86 | delete_user( $_GET['delete'] ); |
---|
| 87 | $vtp->setVar( $sub, 'confirmation.class', 'info' ); |
---|
[9] | 88 | $info = '"'.$row['username'].'" '.$lang['listuser_info_deletion']; |
---|
[2] | 89 | $vtp->setVar( $sub, 'confirmation.info', $info ); |
---|
| 90 | } |
---|
| 91 | else |
---|
| 92 | { |
---|
| 93 | $vtp->setVar( $sub, 'confirmation.class', 'erreur' ); |
---|
| 94 | $vtp->setVar( $sub, 'confirmation.info', $lang['user_err_unknown'] ); |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | else |
---|
| 98 | { |
---|
| 99 | $vtp->setVar( $sub, 'confirmation.class', 'erreur' ); |
---|
| 100 | $vtp->setVar( $sub, 'confirmation.info', $lang['user_err_modify'] ); |
---|
| 101 | } |
---|
| 102 | $vtp->closeSession( $sub, 'confirmation' ); |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | //------------------------------------------------------------------ users list |
---|
| 106 | else |
---|
| 107 | { |
---|
[98] | 108 | // add a user |
---|
| 109 | $vtp->addSession( $sub, 'add_user' ); |
---|
| 110 | $action = './admin.php?'.$_SERVER['QUERY_STRING']; |
---|
| 111 | $vtp->setVar( $sub, 'add_user.form_action', $action ); |
---|
| 112 | $vtp->setVar( $sub, 'add_user.f_username', $_POST['username'] ); |
---|
| 113 | $vtp->closeSession( $sub, 'add_user' ); |
---|
| 114 | |
---|
[2] | 115 | $vtp->addSession( $sub, 'users' ); |
---|
| 116 | |
---|
| 117 | $action = './admin.php?'.$_SERVER['QUERY_STRING']; |
---|
| 118 | if ( !isset( $_GET['mail'] ) ) |
---|
| 119 | { |
---|
| 120 | $action.= '&mail=true'; |
---|
| 121 | } |
---|
| 122 | $vtp->setVar( $sub, 'users.form_action', $action ); |
---|
| 123 | |
---|
[21] | 124 | $query = 'SELECT id,username,status,mail_address'; |
---|
| 125 | $query.= ' FROM '.PREFIX_TABLE.'users'; |
---|
| 126 | $query.= ' ORDER BY status ASC, username ASC'; |
---|
[2] | 127 | $query.= ';'; |
---|
| 128 | $result = mysql_query( $query ); |
---|
| 129 | |
---|
| 130 | $current_status = ''; |
---|
| 131 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 132 | { |
---|
| 133 | // display the line indicating the status of the next users |
---|
| 134 | if ( $row['status'] != $current_status ) |
---|
| 135 | { |
---|
| 136 | if ( $current_status != '' ) |
---|
| 137 | { |
---|
| 138 | $vtp->closeSession( $sub, 'category' ); |
---|
| 139 | } |
---|
| 140 | $vtp->addSession( $sub, 'category' ); |
---|
| 141 | $title = $lang['listuser_user_group'].' '; |
---|
| 142 | switch ( $row['status'] ) |
---|
| 143 | { |
---|
[21] | 144 | case 'admin' : $title.= $lang['adduser_status_admin']; break; |
---|
| 145 | case 'guest' : $title.= $lang['adduser_status_guest']; break; |
---|
[2] | 146 | } |
---|
| 147 | $vtp->setVar( $sub, 'category.title', $title ); |
---|
| 148 | $current_status = $row['status']; |
---|
| 149 | } |
---|
| 150 | $vtp->addSession( $sub, 'user' ); |
---|
| 151 | // checkbox for mail management if the user has a mail address |
---|
[9] | 152 | if ( $row['mail_address'] != '' and $row['username'] != 'guest' ) |
---|
[2] | 153 | { |
---|
| 154 | $vtp->addSession( $sub, 'checkbox' ); |
---|
| 155 | $vtp->setVar( $sub, 'checkbox.name', 'mail-'.$row['id'] ); |
---|
| 156 | $vtp->closeSession( $sub, 'checkbox' ); |
---|
| 157 | } |
---|
| 158 | // use a special color for the login of the user ? |
---|
[9] | 159 | if ( $row['username'] == $conf['webmaster'] ) |
---|
[2] | 160 | { |
---|
| 161 | $vtp->setVar( $sub, 'user.color', 'red' ); |
---|
| 162 | } |
---|
[9] | 163 | if ( $row['username'] == 'guest' ) |
---|
[2] | 164 | { |
---|
| 165 | $vtp->setVar( $sub, 'user.color', 'green' ); |
---|
[9] | 166 | $vtp->setVar( $sub, 'user.login', $lang['guest'] ); |
---|
| 167 | } |
---|
| 168 | else |
---|
| 169 | { |
---|
| 170 | $vtp->setVar( $sub, 'user.login', $row['username'] ); |
---|
| 171 | } |
---|
[2] | 172 | // modify or not modify ? |
---|
[9] | 173 | if ( $row['username'] == 'guest' |
---|
| 174 | or ( $row['username'] == $conf['webmaster'] |
---|
| 175 | and $user['username'] != $conf['webmaster'] ) ) |
---|
[2] | 176 | { |
---|
| 177 | $vtp->addSession( $sub, 'not_modify' ); |
---|
| 178 | $vtp->closeSession( $sub, 'not_modify' ); |
---|
| 179 | } |
---|
| 180 | else |
---|
| 181 | { |
---|
| 182 | $vtp->addSession( $sub, 'modify' ); |
---|
[9] | 183 | $url = './admin.php?page=user_modify&user_id='; |
---|
[2] | 184 | $url.= $row['id']; |
---|
| 185 | $vtp->setVar( $sub, 'modify.url', add_session_id( $url ) ); |
---|
[9] | 186 | $vtp->setVar( $sub, 'modify.login', $row['username'] ); |
---|
[2] | 187 | $vtp->closeSession( $sub, 'modify' ); |
---|
| 188 | } |
---|
| 189 | // manage permission or not ? |
---|
[21] | 190 | if ( $row['username'] == $conf['webmaster'] |
---|
| 191 | and $user['username'] != $conf['webmaster'] ) |
---|
[2] | 192 | { |
---|
| 193 | $vtp->addSession( $sub, 'not_permission' ); |
---|
| 194 | $vtp->closeSession( $sub, 'not_permission' ); |
---|
| 195 | } |
---|
| 196 | else |
---|
| 197 | { |
---|
| 198 | $vtp->addSession( $sub, 'permission' ); |
---|
[21] | 199 | $url = './admin.php?page=user_perm&user_id='.$row['id']; |
---|
[2] | 200 | $vtp->setVar( $sub, 'permission.url', add_session_id( $url ) ); |
---|
[9] | 201 | $vtp->setVar( $sub, 'permission.login', $row['username'] ); |
---|
[2] | 202 | $vtp->closeSession( $sub, 'permission' ); |
---|
| 203 | } |
---|
| 204 | // is the user deletable or not ? |
---|
[9] | 205 | if ( $row['username'] == 'guest' |
---|
| 206 | or $row['username'] == $conf['webmaster'] ) |
---|
[2] | 207 | { |
---|
| 208 | $vtp->addSession( $sub, 'not_delete' ); |
---|
| 209 | $vtp->closeSession( $sub, 'not_delete' ); |
---|
| 210 | } |
---|
| 211 | else |
---|
| 212 | { |
---|
| 213 | $vtp->addSession( $sub, 'delete' ); |
---|
| 214 | $url = './admin.php?page=user_list&delete='.$row['id']; |
---|
| 215 | $vtp->setVar( $sub, 'delete.url', add_session_id( $url ) ); |
---|
[9] | 216 | $vtp->setVar( $sub, 'delete.login', $row['username'] ); |
---|
[2] | 217 | $vtp->closeSession( $sub, 'delete' ); |
---|
| 218 | } |
---|
| 219 | $vtp->closeSession( $sub, 'user' ); |
---|
| 220 | } |
---|
| 221 | $vtp->closeSession( $sub, 'category' ); |
---|
| 222 | // mail management : creation of the mail address if asked by administrator |
---|
[164] | 223 | if ( isset( $_POST['submit_generate_mail'] ) and isset( $_GET['mail'] ) ) |
---|
[2] | 224 | { |
---|
[164] | 225 | $mails = array(); |
---|
[21] | 226 | $query = 'SELECT id,mail_address'; |
---|
| 227 | $query.= ' FROM '.PREFIX_TABLE.'users'; |
---|
[2] | 228 | $query.= ';'; |
---|
| 229 | $result = mysql_query( $query ); |
---|
| 230 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 231 | { |
---|
[164] | 232 | if ( $_POST['mail-'.$row['id']] == 1 ) |
---|
| 233 | array_push( $mails, $row['mail_address'] ); |
---|
[2] | 234 | } |
---|
| 235 | $mail_destination = ''; |
---|
[164] | 236 | foreach ( $mails as $i => $mail_address ) { |
---|
| 237 | if ( $i > 0 ) $mail_destination.= ','; |
---|
| 238 | $mail_destination.= $mail_address; |
---|
[2] | 239 | } |
---|
[164] | 240 | if ( sizeof( $mails ) > 0 ) |
---|
[2] | 241 | { |
---|
| 242 | $vtp->addSession( $sub, 'mail_link' ); |
---|
| 243 | $vtp->setVar( $sub, 'mail_link.mailto', $mail_destination ); |
---|
| 244 | $vtp->setVar( $sub, 'mail_link.mail_address_start', |
---|
| 245 | substr( $mail_destination, 0, 50 ) ); |
---|
| 246 | $vtp->closeSession( $sub, 'mail_link' ); |
---|
| 247 | } |
---|
| 248 | } |
---|
| 249 | $vtp->closeSession( $sub, 'users' ); |
---|
| 250 | } |
---|
| 251 | //----------------------------------------------------------- sending html code |
---|
| 252 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
| 253 | ?> |
---|