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