[2] | 1 | <?php |
---|
| 2 | /*************************************************************************** |
---|
[14] | 3 | * profile.php * |
---|
[2] | 4 | * ------------------- * |
---|
[14] | 5 | * application : PhpWebGallery 1.3 * |
---|
| 6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
[2] | 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 | // customize appearance of the site for a user |
---|
| 18 | //----------------------------------------------------------- personnal include |
---|
| 19 | include_once( './include/init.inc.php' ); |
---|
| 20 | //-------------------------------------------------- access authorization check |
---|
| 21 | check_login_authorization(); |
---|
| 22 | if ( $user['is_the_guest'] ) |
---|
| 23 | { |
---|
| 24 | echo '<div style="text-align:center;">'.$lang['only_members'].'<br />'; |
---|
| 25 | echo '<a href="./identification.php">'.$lang['ident_title'].'</a></div>'; |
---|
| 26 | exit(); |
---|
| 27 | } |
---|
| 28 | //-------------------------------------------------------------- initialization |
---|
| 29 | check_cat_id( $_GET['cat'] ); |
---|
| 30 | //------------------------------------------------------ update & customization |
---|
[26] | 31 | $infos = array( 'nb_image_line', 'nb_line_page', 'language', |
---|
[2] | 32 | 'maxwidth', 'maxheight', 'expand', 'show_nb_comments', |
---|
| 33 | 'short_period', 'long_period', 'template', 'mail_address' ); |
---|
| 34 | // mise à jour dans la base de données des valeurs |
---|
| 35 | // des paramètres pour l'utilisateur courant |
---|
| 36 | // - on teste si chacune des variables est passée en argument à la page |
---|
| 37 | // - ce qui signifie que l'on doit venir de la page de personnalisation |
---|
[26] | 38 | $errors = array(); |
---|
[2] | 39 | if ( isset( $_POST['submit'] ) ) |
---|
| 40 | { |
---|
[26] | 41 | $int_pattern = '/^\d+$/'; |
---|
| 42 | if ( $_POST['maxwidth'] != '' |
---|
| 43 | and ( !preg_match( $int_pattern, $_POST['maxwidth'] ) |
---|
| 44 | or $_POST['maxwidth'] < 50 ) ) |
---|
[2] | 45 | { |
---|
[26] | 46 | array_push( $errors, $lang['err_maxwidth'] ); |
---|
[2] | 47 | } |
---|
[26] | 48 | if ( $_POST['maxheight'] |
---|
| 49 | and ( !preg_match( $int_pattern, $_POST['maxheight'] ) |
---|
| 50 | or $_POST['maxheight'] < 50 ) ) |
---|
[2] | 51 | { |
---|
[26] | 52 | array_push( $errors, $lang['err_maxheight'] ); |
---|
[2] | 53 | } |
---|
[26] | 54 | // periods must be integer values, they represents number of days |
---|
| 55 | if ( !preg_match( $int_pattern, $_POST['short_period'] ) |
---|
| 56 | or !preg_match( $int_pattern, $_POST['long_period'] ) ) |
---|
[2] | 57 | { |
---|
[26] | 58 | array_push( $errors, $lang['err_periods'] ); |
---|
[2] | 59 | } |
---|
| 60 | else |
---|
| 61 | { |
---|
[26] | 62 | // long period must be longer than short period |
---|
[2] | 63 | if ( $_POST['long_period'] <= $_POST['short_period'] |
---|
[26] | 64 | or $_POST['short_period'] <= 0 ) |
---|
[2] | 65 | { |
---|
[26] | 66 | array_push( $errors, $lang['err_periods_2'] ); |
---|
[2] | 67 | } |
---|
| 68 | } |
---|
[26] | 69 | $mail_error = validate_mail_address( $_POST['mail_address'] ); |
---|
| 70 | if ( $mail_error != '' ) |
---|
[2] | 71 | { |
---|
[26] | 72 | array_push( $errors, $mail_error ); |
---|
[2] | 73 | } |
---|
| 74 | if ( $_POST['use_new_pwd'] == 1 ) |
---|
| 75 | { |
---|
[26] | 76 | // password must be the same as its confirmation |
---|
[2] | 77 | if ( $_POST['password'] != $_POST['passwordConf'] ) |
---|
| 78 | { |
---|
[26] | 79 | array_push( $errors, $lang['reg_err_pass'] ); |
---|
[2] | 80 | } |
---|
| 81 | } |
---|
| 82 | |
---|
[26] | 83 | if ( count( $errors ) == 0 ) |
---|
[2] | 84 | { |
---|
[26] | 85 | $query = 'UPDATE '.PREFIX_TABLE.'users'; |
---|
| 86 | $query.= ' SET '; |
---|
| 87 | foreach ( $infos as $i => $info ) { |
---|
| 88 | if ( $i > 0 ) $query.= ','; |
---|
| 89 | $query.= $info; |
---|
[2] | 90 | $query.= ' = '; |
---|
[26] | 91 | if ( $_POST[$info] == '' ) $query.= 'NULL'; |
---|
| 92 | else $query.= "'".$_POST[$info]."'"; |
---|
[2] | 93 | } |
---|
[26] | 94 | $query.= ' WHERE id = '.$user['id']; |
---|
[2] | 95 | $query.= ';'; |
---|
| 96 | mysql_query( $query ); |
---|
| 97 | |
---|
| 98 | if ( $_POST['use_new_pwd'] == 1 ) |
---|
| 99 | { |
---|
[26] | 100 | $query = 'UPDATE '.PREFIX_TABLE.'users'; |
---|
| 101 | $query.= " SET password = '".md5( $_POST['password'] )."'"; |
---|
| 102 | $query.= ' WHERE id = '.$user['id']; |
---|
[2] | 103 | $query.= ';'; |
---|
| 104 | mysql_query( $query ); |
---|
| 105 | } |
---|
| 106 | // redirection |
---|
| 107 | $url = 'category.php?cat='.$page['cat'].'&expand='.$_GET['expand']; |
---|
| 108 | if ( $page['cat'] == 'search' ) |
---|
| 109 | { |
---|
[26] | 110 | $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; |
---|
[2] | 111 | } |
---|
| 112 | $url = add_session_id( $url, true ); |
---|
| 113 | header( 'Request-URI: '.$url ); |
---|
| 114 | header( 'Content-Location: '.$url ); |
---|
| 115 | header( 'Location: '.$url ); |
---|
| 116 | exit(); |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | //----------------------------------------------------- template initialization |
---|
| 120 | $vtp = new VTemplate; |
---|
| 121 | $handle = $vtp->Open( './template/'.$user['template'].'/profile.vtp' ); |
---|
[9] | 122 | initialize_template(); |
---|
[14] | 123 | $tpl = array( 'customize_page_title','customize_title','password','new', |
---|
| 124 | 'reg_confirm','submit' ); |
---|
| 125 | templatize_array( $tpl, 'lang', $handle ); |
---|
[2] | 126 | //----------------------------------------------------------------- form action |
---|
| 127 | $url = './profile.php?cat='.$page['cat'].'&expand='.$page['expand']; |
---|
| 128 | if ( $page['cat'] == 'search' ) |
---|
| 129 | { |
---|
[17] | 130 | $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; |
---|
[2] | 131 | } |
---|
| 132 | $vtp->setGlobalVar( $handle, 'form_action', add_session_id( $url ) ); |
---|
| 133 | //-------------------------------------------------------------- errors display |
---|
[26] | 134 | if ( count( $errors ) != 0 ) |
---|
[2] | 135 | { |
---|
| 136 | $vtp->addSession( $handle, 'errors' ); |
---|
[26] | 137 | foreach ( $errors as $error ) { |
---|
[2] | 138 | $vtp->addSession( $handle, 'li' ); |
---|
[26] | 139 | $vtp->setVar( $handle, 'li.li', $error ); |
---|
[2] | 140 | $vtp->closeSession( $handle, 'li' ); |
---|
| 141 | } |
---|
| 142 | $vtp->closeSession( $handle, 'errors' ); |
---|
| 143 | } |
---|
| 144 | //---------------------------------------------------- number of images per row |
---|
| 145 | if ( in_array( 'nb_image_line', $infos ) ) |
---|
| 146 | { |
---|
| 147 | $vtp->addSession( $handle, 'line' ); |
---|
| 148 | $vtp->setVar( $handle, 'line.name', $lang['customize_nb_image_per_row'] ); |
---|
| 149 | $vtp->addSession( $handle, 'select' ); |
---|
| 150 | $vtp->setVar( $handle, 'select.name', 'nb_image_line' ); |
---|
| 151 | for ( $i = 0; $i < sizeof( $conf['nb_image_row'] ); $i++ ) |
---|
| 152 | { |
---|
| 153 | $vtp->addSession( $handle, 'option' ); |
---|
| 154 | $vtp->setVar( $handle, 'option.option', $conf['nb_image_row'][$i] ); |
---|
| 155 | if ( $conf['nb_image_row'][$i] == $user['nb_image_line'] ) |
---|
| 156 | { |
---|
| 157 | $vtp->setVar( $handle, 'option.selected', ' selected="selected"' ); |
---|
| 158 | } |
---|
| 159 | $vtp->closeSession( $handle, 'option' ); |
---|
| 160 | } |
---|
| 161 | $vtp->closeSession( $handle, 'select' ); |
---|
| 162 | $vtp->closeSession( $handle, 'line' ); |
---|
| 163 | } |
---|
| 164 | //------------------------------------------------------ number of row per page |
---|
| 165 | if ( in_array( 'nb_line_page', $infos ) ) |
---|
| 166 | { |
---|
| 167 | $vtp->addSession( $handle, 'line' ); |
---|
| 168 | $vtp->setVar( $handle, 'line.name', $lang['customize_nb_row_per_page'] ); |
---|
| 169 | $vtp->addSession( $handle, 'select' ); |
---|
| 170 | $vtp->setVar( $handle, 'select.name', 'nb_line_page' ); |
---|
| 171 | for ( $i = 0; $i < sizeof( $conf['nb_row_page'] ); $i++ ) |
---|
| 172 | { |
---|
| 173 | $vtp->addSession( $handle, 'option' ); |
---|
| 174 | $vtp->setVar( $handle, 'option.option', $conf['nb_row_page'][$i] ); |
---|
| 175 | if ( $conf['nb_row_page'][$i] == $user['nb_line_page'] ) |
---|
| 176 | { |
---|
| 177 | $vtp->setVar( $handle, 'option.selected', ' selected="selected"' ); |
---|
| 178 | } |
---|
| 179 | $vtp->closeSession( $handle, 'option' ); |
---|
| 180 | } |
---|
| 181 | $vtp->closeSession( $handle, 'select' ); |
---|
| 182 | $vtp->closeSession( $handle, 'line' ); |
---|
| 183 | } |
---|
| 184 | //-------------------------------------------------------------------- template |
---|
| 185 | if ( in_array( 'template', $infos ) ) |
---|
| 186 | { |
---|
| 187 | $vtp->addSession( $handle, 'line' ); |
---|
| 188 | $vtp->setVar( $handle, 'line.name', $lang['customize_template'] ); |
---|
| 189 | $vtp->addSession( $handle, 'select' ); |
---|
| 190 | $vtp->setVar( $handle, 'select.name', 'template' ); |
---|
| 191 | $option = get_dirs( './template/' ); |
---|
| 192 | for ( $i = 0; $i < sizeof( $option ); $i++ ) |
---|
| 193 | { |
---|
| 194 | $vtp->addSession( $handle, 'option' ); |
---|
| 195 | $vtp->setVar( $handle, 'option.option', $option[$i] ); |
---|
| 196 | if ( $option[$i] == $user['template'] ) |
---|
| 197 | { |
---|
| 198 | $vtp->setVar( $handle, 'option.selected', ' selected="selected"' ); |
---|
| 199 | } |
---|
| 200 | $vtp->closeSession( $handle, 'option' ); |
---|
| 201 | } |
---|
| 202 | $vtp->closeSession( $handle, 'select' ); |
---|
| 203 | $vtp->closeSession( $handle, 'line' ); |
---|
| 204 | } |
---|
| 205 | //-------------------------------------------------------------------- language |
---|
| 206 | if ( in_array( 'language', $infos ) ) |
---|
| 207 | { |
---|
| 208 | $vtp->addSession( $handle, 'line' ); |
---|
| 209 | $vtp->setVar( $handle, 'line.name', $lang['customize_language'] ); |
---|
| 210 | $vtp->addSession( $handle, 'select' ); |
---|
| 211 | $vtp->setVar( $handle, 'select.name', 'language' ); |
---|
| 212 | $option = get_languages( './language/' ); |
---|
| 213 | for ( $i = 0; $i < sizeof( $option ); $i++ ) |
---|
| 214 | { |
---|
| 215 | $vtp->addSession( $handle, 'option' ); |
---|
| 216 | $vtp->setVar( $handle, 'option.option', $option[$i] ); |
---|
| 217 | if( $option[$i] == $user['language'] ) |
---|
| 218 | { |
---|
| 219 | $vtp->setVar( $handle, 'option.selected', ' selected="selected"' ); |
---|
| 220 | } |
---|
| 221 | $vtp->closeSession( $handle, 'option' ); |
---|
| 222 | } |
---|
| 223 | $vtp->closeSession( $handle, 'select' ); |
---|
| 224 | $vtp->closeSession( $handle, 'line' ); |
---|
| 225 | } |
---|
| 226 | //---------------------------------------------------------------- short period |
---|
| 227 | if ( in_array( 'short_period', $infos ) ) |
---|
| 228 | { |
---|
| 229 | $vtp->addSession( $handle, 'line' ); |
---|
| 230 | $vtp->setVar( $handle, 'line.name', $lang['customize_short_period'] ); |
---|
| 231 | $vtp->addSession( $handle, 'text' ); |
---|
| 232 | $vtp->setVar( $handle, 'text.name', 'short_period' ); |
---|
| 233 | $vtp->setVar( $handle, 'text.value', $user['short_period'] ); |
---|
| 234 | $vtp->closeSession( $handle, 'text' ); |
---|
| 235 | $vtp->closeSession( $handle, 'line' ); |
---|
| 236 | } |
---|
| 237 | //----------------------------------------------------------------- long period |
---|
| 238 | if ( in_array( 'long_period', $infos ) ) |
---|
| 239 | { |
---|
| 240 | $vtp->addSession( $handle, 'line' ); |
---|
| 241 | $vtp->setVar( $handle, 'line.name', $lang['customize_long_period'] ); |
---|
| 242 | $vtp->addSession( $handle, 'text' ); |
---|
| 243 | $vtp->setVar( $handle, 'text.name', 'long_period' ); |
---|
| 244 | $vtp->setVar( $handle, 'text.value', $user['long_period'] ); |
---|
| 245 | $vtp->closeSession( $handle, 'text' ); |
---|
| 246 | $vtp->closeSession( $handle, 'line' ); |
---|
| 247 | } |
---|
| 248 | //--------------------------------------------------------- max displayed width |
---|
| 249 | if ( in_array( 'maxwidth', $infos ) ) |
---|
| 250 | { |
---|
| 251 | $vtp->addSession( $handle, 'line' ); |
---|
| 252 | $vtp->setVar( $handle, 'line.name', $lang['maxwidth'] ); |
---|
| 253 | $vtp->addSession( $handle, 'text' ); |
---|
| 254 | $vtp->setVar( $handle, 'text.name', 'maxwidth' ); |
---|
| 255 | $vtp->setVar( $handle, 'text.value', $user['maxwidth'] ); |
---|
| 256 | $vtp->closeSession( $handle, 'text' ); |
---|
| 257 | $vtp->closeSession( $handle, 'line' ); |
---|
| 258 | } |
---|
| 259 | //-------------------------------------------------------- max displayed height |
---|
| 260 | if ( in_array( 'maxheight', $infos ) ) |
---|
| 261 | { |
---|
| 262 | $vtp->addSession( $handle, 'line' ); |
---|
| 263 | $vtp->setVar( $handle, 'line.name', $lang['maxheight'] ); |
---|
| 264 | $vtp->addSession( $handle, 'text' ); |
---|
| 265 | $vtp->setVar( $handle, 'text.name', 'maxheight' ); |
---|
| 266 | $vtp->setVar( $handle, 'text.value', $user['maxheight'] ); |
---|
| 267 | $vtp->closeSession( $handle, 'text' ); |
---|
| 268 | $vtp->closeSession( $handle, 'line' ); |
---|
| 269 | } |
---|
| 270 | //---------------------------------------------------------------- mail address |
---|
| 271 | if ( in_array( 'mail_address', $infos ) ) |
---|
| 272 | { |
---|
| 273 | $vtp->addSession( $handle, 'line' ); |
---|
[9] | 274 | $vtp->setVar( $handle, 'line.name', $lang['mail_address'] ); |
---|
[2] | 275 | $vtp->addSession( $handle, 'text' ); |
---|
| 276 | $vtp->setVar( $handle, 'text.name', 'mail_address' ); |
---|
| 277 | $vtp->setVar( $handle, 'text.value', $user['mail_address'] ); |
---|
| 278 | $vtp->closeSession( $handle, 'text' ); |
---|
| 279 | $vtp->closeSession( $handle, 'line' ); |
---|
| 280 | } |
---|
| 281 | //----------------------------------------------------- expand all categories ? |
---|
| 282 | if ( in_array( 'expand', $infos ) ) |
---|
| 283 | { |
---|
| 284 | $vtp->addSession( $handle, 'line' ); |
---|
| 285 | $vtp->setVar( $handle, 'line.name', $lang['customize_expand'] ); |
---|
| 286 | $vtp->addSession( $handle, 'group' ); |
---|
| 287 | $vtp->addSession( $handle, 'radio' ); |
---|
| 288 | $vtp->setVar( $handle, 'radio.name', 'expand' ); |
---|
| 289 | $vtp->setVar( $handle, 'radio.value', 'true' ); |
---|
| 290 | $checked = ''; |
---|
| 291 | if ( $user['expand'] ) |
---|
| 292 | { |
---|
| 293 | $checked = ' checked="checked"'; |
---|
| 294 | } |
---|
| 295 | $vtp->setVar( $handle, 'radio.checked', $checked ); |
---|
| 296 | $vtp->setVar( $handle, 'radio.option', $lang['yes'] ); |
---|
| 297 | $vtp->closeSession( $handle, 'radio' ); |
---|
| 298 | $vtp->addSession( $handle, 'radio' ); |
---|
| 299 | $vtp->setVar( $handle, 'radio.name', 'expand' ); |
---|
| 300 | $vtp->setVar( $handle, 'radio.value', 'false' ); |
---|
| 301 | $checked = ''; |
---|
| 302 | if ( !$user['expand'] ) |
---|
| 303 | { |
---|
| 304 | $checked = ' checked="checked"'; |
---|
| 305 | } |
---|
| 306 | $vtp->setVar( $handle, 'radio.checked', $checked ); |
---|
| 307 | $vtp->setVar( $handle, 'radio.option', $lang['no'] ); |
---|
| 308 | $vtp->closeSession( $handle, 'radio' ); |
---|
| 309 | $vtp->closeSession( $handle, 'group' ); |
---|
| 310 | $vtp->closeSession( $handle, 'line' ); |
---|
| 311 | } |
---|
| 312 | //---------------------------------- show number of comments on thumbnails page |
---|
| 313 | if ( in_array( 'show_nb_comments', $infos ) ) |
---|
| 314 | { |
---|
| 315 | $vtp->addSession( $handle, 'line' ); |
---|
| 316 | $vtp->setVar( $handle, 'line.name', $lang['customize_show_nb_comments'] ); |
---|
| 317 | $vtp->addSession( $handle, 'group' ); |
---|
| 318 | $vtp->addSession( $handle, 'radio' ); |
---|
| 319 | $vtp->setVar( $handle, 'radio.name', 'show_nb_comments' ); |
---|
| 320 | $vtp->setVar( $handle, 'radio.value', 'true' ); |
---|
| 321 | $checked = ''; |
---|
| 322 | if ( $user['show_nb_comments'] ) |
---|
| 323 | { |
---|
| 324 | $checked = ' checked="checked"'; |
---|
| 325 | } |
---|
| 326 | $vtp->setVar( $handle, 'radio.checked', $checked ); |
---|
| 327 | $vtp->setVar( $handle, 'radio.option', $lang['yes'] ); |
---|
| 328 | $vtp->closeSession( $handle, 'radio' ); |
---|
| 329 | $vtp->addSession( $handle, 'radio' ); |
---|
| 330 | $vtp->setVar( $handle, 'radio.name', 'show_nb_comments' ); |
---|
| 331 | $vtp->setVar( $handle, 'radio.value', 'false' ); |
---|
| 332 | $checked = ''; |
---|
| 333 | if ( !$user['show_nb_comments'] ) |
---|
| 334 | { |
---|
| 335 | $checked = ' checked="checked"'; |
---|
| 336 | } |
---|
| 337 | $vtp->setVar( $handle, 'radio.checked', $checked ); |
---|
| 338 | $vtp->setVar( $handle, 'radio.option', $lang['no'] ); |
---|
| 339 | $vtp->closeSession( $handle, 'radio' ); |
---|
| 340 | $vtp->closeSession( $handle, 'group' ); |
---|
| 341 | $vtp->closeSession( $handle, 'line' ); |
---|
| 342 | } |
---|
| 343 | //----------------------------------------------------------- html code display |
---|
| 344 | $code = $vtp->Display( $handle, 0 ); |
---|
| 345 | echo $code; |
---|
| 346 | ?> |
---|