[2] | 1 | <?php |
---|
[351] | 2 | // +-----------------------------------------------------------------------+ |
---|
[593] | 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
| 5 | // | Copyright (C) 2003-2004 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[351] | 6 | // +-----------------------------------------------------------------------+ |
---|
[593] | 7 | // | branch : BSF (Best So Far) |
---|
[351] | 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2004-11-06 21:12:59 +0000 (Sat, 06 Nov 2004) $ |
---|
| 10 | // | last modifier : $Author: z0rglub $ |
---|
| 11 | // | revision : $Revision: 593 $ |
---|
| 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 | |
---|
[354] | 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. | |
---|
[351] | 26 | // +-----------------------------------------------------------------------+ |
---|
[2] | 27 | |
---|
| 28 | // customize appearance of the site for a user |
---|
[345] | 29 | //----------------------------------------------------------- include |
---|
[364] | 30 | define('PHPWG_ROOT_PATH','./'); |
---|
| 31 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
[2] | 32 | //-------------------------------------------------- access authorization check |
---|
| 33 | check_login_authorization(); |
---|
| 34 | if ( $user['is_the_guest'] ) |
---|
| 35 | { |
---|
| 36 | echo '<div style="text-align:center;">'.$lang['only_members'].'<br />'; |
---|
| 37 | echo '<a href="./identification.php">'.$lang['ident_title'].'</a></div>'; |
---|
| 38 | exit(); |
---|
| 39 | } |
---|
| 40 | //------------------------------------------------------ update & customization |
---|
[26] | 41 | $infos = array( 'nb_image_line', 'nb_line_page', 'language', |
---|
[2] | 42 | 'maxwidth', 'maxheight', 'expand', 'show_nb_comments', |
---|
[452] | 43 | 'recent_period', 'template', 'mail_address' ); |
---|
[2] | 44 | // mise à jour dans la base de données des valeurs |
---|
| 45 | // des paramètres pour l'utilisateur courant |
---|
| 46 | // - on teste si chacune des variables est passée en argument à la page |
---|
| 47 | // - ce qui signifie que l'on doit venir de la page de personnalisation |
---|
[26] | 48 | $errors = array(); |
---|
[2] | 49 | if ( isset( $_POST['submit'] ) ) |
---|
| 50 | { |
---|
[26] | 51 | $int_pattern = '/^\d+$/'; |
---|
| 52 | if ( $_POST['maxwidth'] != '' |
---|
| 53 | and ( !preg_match( $int_pattern, $_POST['maxwidth'] ) |
---|
| 54 | or $_POST['maxwidth'] < 50 ) ) |
---|
[2] | 55 | { |
---|
[527] | 56 | array_push( $errors, $lang['maxwidth_error'] ); |
---|
[2] | 57 | } |
---|
[26] | 58 | if ( $_POST['maxheight'] |
---|
| 59 | and ( !preg_match( $int_pattern, $_POST['maxheight'] ) |
---|
| 60 | or $_POST['maxheight'] < 50 ) ) |
---|
[2] | 61 | { |
---|
[527] | 62 | array_push( $errors, $lang['maxheight_error'] ); |
---|
[2] | 63 | } |
---|
[26] | 64 | // periods must be integer values, they represents number of days |
---|
[452] | 65 | if (!preg_match($int_pattern, $_POST['recent_period']) |
---|
| 66 | or $_POST['recent_period'] <= 0) |
---|
[2] | 67 | { |
---|
[527] | 68 | array_push( $errors, $lang['periods_error'] ); |
---|
[2] | 69 | } |
---|
[26] | 70 | $mail_error = validate_mail_address( $_POST['mail_address'] ); |
---|
[345] | 71 | if ( $mail_error != '' ) array_push( $errors, $mail_error ); |
---|
| 72 | // password must be the same as its confirmation |
---|
| 73 | if ( isset( $_POST['use_new_pwd'] ) |
---|
| 74 | and $_POST['password'] != $_POST['passwordConf'] ) |
---|
| 75 | array_push( $errors, $lang['reg_err_pass'] ); |
---|
| 76 | |
---|
[26] | 77 | if ( count( $errors ) == 0 ) |
---|
[2] | 78 | { |
---|
[364] | 79 | $query = 'UPDATE '.USERS_TABLE; |
---|
[26] | 80 | $query.= ' SET '; |
---|
| 81 | foreach ( $infos as $i => $info ) { |
---|
| 82 | if ( $i > 0 ) $query.= ','; |
---|
| 83 | $query.= $info; |
---|
[2] | 84 | $query.= ' = '; |
---|
[26] | 85 | if ( $_POST[$info] == '' ) $query.= 'NULL'; |
---|
| 86 | else $query.= "'".$_POST[$info]."'"; |
---|
[2] | 87 | } |
---|
[26] | 88 | $query.= ' WHERE id = '.$user['id']; |
---|
[2] | 89 | $query.= ';'; |
---|
[587] | 90 | pwg_query( $query ); |
---|
[2] | 91 | |
---|
[345] | 92 | if ( isset( $_POST['use_new_pwd'] ) ) |
---|
[2] | 93 | { |
---|
[364] | 94 | $query = 'UPDATE '.USERS_TABLE; |
---|
[26] | 95 | $query.= " SET password = '".md5( $_POST['password'] )."'"; |
---|
| 96 | $query.= ' WHERE id = '.$user['id']; |
---|
[2] | 97 | $query.= ';'; |
---|
[587] | 98 | pwg_query( $query ); |
---|
[2] | 99 | } |
---|
[345] | 100 | if ( isset( $_POST['create_cookie'] ) ) |
---|
[45] | 101 | { |
---|
| 102 | setcookie( 'id',$page['session_id'],$_POST['cookie_expiration'], |
---|
| 103 | cookie_path() ); |
---|
[60] | 104 | // update the expiration date of the session |
---|
[364] | 105 | $query = 'UPDATE '.SESSIONS_TABLE; |
---|
[60] | 106 | $query.= ' SET expiration = '.$_POST['cookie_expiration']; |
---|
| 107 | $query.= " WHERE id = '".$page['session_id']."'"; |
---|
| 108 | $query.= ';'; |
---|
[587] | 109 | pwg_query( $query ); |
---|
[45] | 110 | } |
---|
[2] | 111 | // redirection |
---|
[345] | 112 | $url = 'category.php'; |
---|
| 113 | if ( !isset($_POST['create_cookie']) ) $url = add_session_id( $url,true ); |
---|
[405] | 114 | redirect( $url ); |
---|
[2] | 115 | } |
---|
| 116 | } |
---|
| 117 | //----------------------------------------------------- template initialization |
---|
[393] | 118 | $expand = ($user['expand']=='true')?'EXPAND_TREE_YES':'EXPAND_TREE_NO'; |
---|
| 119 | $nb_comments = ($user['show_nb_comments']=='true')?'NB_COMMENTS_YES':'NB_COMMENTS_NO'; |
---|
| 120 | |
---|
[345] | 121 | $title = $lang['customize_page_title']; |
---|
[369] | 122 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
[345] | 123 | |
---|
[364] | 124 | $template->set_filenames(array('profile'=>'profile.tpl')); |
---|
| 125 | |
---|
| 126 | $template->assign_vars(array( |
---|
[393] | 127 | 'LANG_SELECT'=>language_select($user['language'], 'language'), |
---|
| 128 | 'NB_IMAGE_LINE'=>$user['nb_image_line'], |
---|
| 129 | 'NB_ROW_PAGE'=>$user['nb_line_page'], |
---|
| 130 | 'STYLE_SELECT'=>style_select($user['template'], 'template'), |
---|
[452] | 131 | 'RECENT_PERIOD'=>$user['recent_period'], |
---|
[393] | 132 | |
---|
| 133 | $expand=>'checked="checked"', |
---|
| 134 | $nb_comments=>'checked="checked"', |
---|
| 135 | |
---|
[452] | 136 | 'L_TITLE' => $lang['customize_title'], |
---|
[364] | 137 | 'L_PASSWORD' => $lang['password'], |
---|
[452] | 138 | 'L_NEW' => $lang['new'], |
---|
| 139 | 'L_CONFIRM' => $lang['reg_confirm'], |
---|
[364] | 140 | 'L_COOKIE' => $lang['create_cookie'], |
---|
[527] | 141 | 'L_LANG_SELECT'=>$lang['language'], |
---|
| 142 | 'L_NB_IMAGE_LINE'=>$lang['nb_image_per_row'], |
---|
| 143 | 'L_NB_ROW_PAGE'=>$lang['nb_row_per_page'], |
---|
| 144 | 'L_STYLE_SELECT'=>$lang['theme'], |
---|
| 145 | 'L_RECENT_PERIOD'=>$lang['recent_period'], |
---|
| 146 | 'L_EXPAND_TREE'=>$lang['auto_expand'], |
---|
| 147 | 'L_NB_COMMENTS'=>$lang['show_nb_comments'], |
---|
[393] | 148 | 'L_YES'=>$lang['yes'], |
---|
| 149 | 'L_NO'=>$lang['no'], |
---|
| 150 | 'L_SUBMIT'=>$lang['submit'], |
---|
| 151 | |
---|
| 152 | 'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'profile.php'), |
---|
| 153 | |
---|
| 154 | 'U_RETURN' => add_session_id(PHPWG_ROOT_PATH.'category.php?'.$_SERVER['QUERY_STRING']) |
---|
[364] | 155 | )); |
---|
| 156 | |
---|
[2] | 157 | //-------------------------------------------------------------- errors display |
---|
[364] | 158 | if ( sizeof( $errors ) != 0 ) |
---|
[2] | 159 | { |
---|
[364] | 160 | $template->assign_block_vars('errors',array()); |
---|
| 161 | for ( $i = 0; $i < sizeof( $errors ); $i++ ) |
---|
[2] | 162 | { |
---|
[364] | 163 | $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i])); |
---|
[2] | 164 | } |
---|
| 165 | } |
---|
[364] | 166 | |
---|
| 167 | $template->assign_block_vars('text',array( |
---|
| 168 | 'F_LABEL'=>$lang['maxwidth'], |
---|
| 169 | 'F_NAME'=>'maxwidth', |
---|
| 170 | 'F_VALUE'=>$user['maxwidth'] |
---|
| 171 | )); |
---|
| 172 | |
---|
| 173 | $template->assign_block_vars('text',array( |
---|
| 174 | 'F_LABEL'=>$lang['maxheight'], |
---|
| 175 | 'F_NAME'=>'maxheight', |
---|
| 176 | 'F_VALUE'=>$user['maxheight'] |
---|
| 177 | )); |
---|
| 178 | |
---|
| 179 | $template->assign_block_vars('text',array( |
---|
| 180 | 'F_LABEL'=>$lang['mail_address'], |
---|
| 181 | 'F_NAME'=>'mail_address', |
---|
| 182 | 'F_VALUE'=>$user['mail_address'] |
---|
| 183 | )); |
---|
| 184 | |
---|
[2] | 185 | //----------------------------------------------------------- html code display |
---|
[364] | 186 | $template->pparse('profile'); |
---|
[369] | 187 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
[362] | 188 | ?> |
---|