[2] | 1 | <?php |
---|
[351] | 2 | // +-----------------------------------------------------------------------+ |
---|
[593] | 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[675] | 5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[351] | 6 | // +-----------------------------------------------------------------------+ |
---|
[593] | 7 | // | branch : BSF (Best So Far) |
---|
[351] | 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2006-02-12 21:52:16 +0000 (Sun, 12 Feb 2006) $ |
---|
| 10 | // | last modifier : $Author: plg $ |
---|
| 11 | // | revision : $Revision: 1036 $ |
---|
| 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 |
---|
[631] | 29 | // +-----------------------------------------------------------------------+ |
---|
| 30 | // | initialization | |
---|
| 31 | // +-----------------------------------------------------------------------+ |
---|
[808] | 32 | |
---|
| 33 | define('PHPWG_ROOT_PATH','./'); |
---|
| 34 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
[1036] | 35 | |
---|
| 36 | if ($user['is_the_guest'] and !$guest_allowed) |
---|
| 37 | { |
---|
| 38 | echo '<div style="text-align:center;">'.$lang['only_members'].'<br />'; |
---|
| 39 | echo '<a href="./identification.php">'.$lang['ident_title'].'</a></div>'; |
---|
| 40 | exit(); |
---|
| 41 | } |
---|
| 42 | |
---|
[808] | 43 | $userdata = $user; |
---|
| 44 | |
---|
[2] | 45 | //------------------------------------------------------ update & customization |
---|
[26] | 46 | $errors = array(); |
---|
[808] | 47 | if (isset($_POST['validate'])) |
---|
[2] | 48 | { |
---|
[26] | 49 | $int_pattern = '/^\d+$/'; |
---|
[662] | 50 | |
---|
| 51 | if ($_POST['maxwidth'] != '' |
---|
| 52 | and (!preg_match($int_pattern, $_POST['maxwidth']) |
---|
| 53 | or $_POST['maxwidth'] < 50)) |
---|
[2] | 54 | { |
---|
[662] | 55 | array_push($errors, $lang['maxwidth_error']); |
---|
[2] | 56 | } |
---|
[662] | 57 | if ($_POST['maxheight'] |
---|
| 58 | and (!preg_match($int_pattern, $_POST['maxheight']) |
---|
| 59 | or $_POST['maxheight'] < 50)) |
---|
[2] | 60 | { |
---|
[662] | 61 | array_push($errors, $lang['maxheight_error']); |
---|
[2] | 62 | } |
---|
[26] | 63 | // periods must be integer values, they represents number of days |
---|
[452] | 64 | if (!preg_match($int_pattern, $_POST['recent_period']) |
---|
| 65 | or $_POST['recent_period'] <= 0) |
---|
[2] | 66 | { |
---|
[662] | 67 | array_push($errors, $lang['periods_error']); |
---|
[2] | 68 | } |
---|
[662] | 69 | |
---|
[808] | 70 | $mail_error = validate_mail_address($_POST['mail_address']); |
---|
| 71 | if (!empty($mail_error)) |
---|
[662] | 72 | { |
---|
[808] | 73 | array_push($errors, $mail_error); |
---|
[662] | 74 | } |
---|
[808] | 75 | |
---|
| 76 | if (!empty($_POST['use_new_pwd'])) |
---|
[630] | 77 | { |
---|
[808] | 78 | // password must be the same as its confirmation |
---|
| 79 | if ($_POST['use_new_pwd'] != $_POST['passwordConf']) |
---|
[631] | 80 | { |
---|
[808] | 81 | array_push($errors, |
---|
| 82 | l10n('New password confirmation does not correspond')); |
---|
[662] | 83 | } |
---|
[808] | 84 | |
---|
| 85 | // changing password requires old password |
---|
| 86 | $query = ' |
---|
[902] | 87 | SELECT '.$conf['user_fields']['password'].' AS password |
---|
[662] | 88 | FROM '.USERS_TABLE.' |
---|
[808] | 89 | WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\' |
---|
[662] | 90 | ;'; |
---|
[808] | 91 | list($current_password) = mysql_fetch_row(pwg_query($query)); |
---|
| 92 | |
---|
| 93 | if ($conf['pass_convert']($_POST['password']) != $current_password) |
---|
[631] | 94 | { |
---|
[808] | 95 | array_push($errors, l10n('Current password is wrong')); |
---|
[631] | 96 | } |
---|
| 97 | } |
---|
[662] | 98 | |
---|
| 99 | if (count($errors) == 0) |
---|
[2] | 100 | { |
---|
[808] | 101 | // mass_updates function |
---|
| 102 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 103 | |
---|
| 104 | // update common user informations |
---|
| 105 | $fields = array($conf['user_fields']['email']); |
---|
[2] | 106 | |
---|
[808] | 107 | $data = array(); |
---|
| 108 | $data{$conf['user_fields']['id']} = $_POST['userid']; |
---|
| 109 | $data{$conf['user_fields']['email']} = $_POST['mail_address']; |
---|
| 110 | |
---|
| 111 | // password is updated only if filled |
---|
[662] | 112 | if (!empty($_POST['use_new_pwd'])) |
---|
[2] | 113 | { |
---|
[808] | 114 | array_push($fields, $conf['user_fields']['password']); |
---|
| 115 | // password is encrpyted with function $conf['pass_convert'] |
---|
| 116 | $data{$conf['user_fields']['password']} = |
---|
| 117 | $conf['pass_convert']($_POST['use_new_pwd']); |
---|
[2] | 118 | } |
---|
[808] | 119 | mass_updates(USERS_TABLE, |
---|
| 120 | array('primary' => array($conf['user_fields']['id']), |
---|
| 121 | 'update' => $fields), |
---|
| 122 | array($data)); |
---|
[631] | 123 | |
---|
[808] | 124 | // update user "additional" informations (specific to PhpWebGallery) |
---|
| 125 | $fields = array( |
---|
| 126 | 'nb_image_line', 'nb_line_page', 'language', 'maxwidth', 'maxheight', |
---|
| 127 | 'expand', 'show_nb_comments', 'recent_period', 'template' |
---|
| 128 | ); |
---|
| 129 | |
---|
| 130 | $data = array(); |
---|
| 131 | $data{'user_id'} = $_POST['userid']; |
---|
| 132 | |
---|
| 133 | foreach ($fields as $field) |
---|
[631] | 134 | { |
---|
[808] | 135 | if (isset($_POST[$field])) |
---|
[772] | 136 | { |
---|
[808] | 137 | $data{$field} = $_POST[$field]; |
---|
[772] | 138 | } |
---|
[631] | 139 | } |
---|
[808] | 140 | mass_updates(USER_INFOS_TABLE, |
---|
| 141 | array('primary' => array('user_id'), 'update' => $fields), |
---|
| 142 | array($data)); |
---|
| 143 | |
---|
| 144 | // redirection |
---|
| 145 | $url = PHPWG_ROOT_PATH.'category.php?'.$_SERVER['QUERY_STRING']; |
---|
[1004] | 146 | redirect($url); |
---|
[2] | 147 | } |
---|
| 148 | } |
---|
[631] | 149 | // +-----------------------------------------------------------------------+ |
---|
| 150 | // | page header and options | |
---|
| 151 | // +-----------------------------------------------------------------------+ |
---|
[850] | 152 | |
---|
[808] | 153 | $title= $lang['customize_page_title']; |
---|
[850] | 154 | $page['body_id'] = 'theProfilePage'; |
---|
[808] | 155 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
| 156 | |
---|
| 157 | $url_action = PHPWG_ROOT_PATH.'profile.php'; |
---|
[850] | 158 | |
---|
[2] | 159 | //----------------------------------------------------- template initialization |
---|
[662] | 160 | $template->set_filenames(array('profile_body'=>'profile.tpl')); |
---|
[393] | 161 | |
---|
[768] | 162 | $expand = ($userdata['expand'] == 'true') ? 'EXPAND_TREE_YES':'EXPAND_TREE_NO'; |
---|
[741] | 163 | |
---|
[768] | 164 | $nb_comments = |
---|
| 165 | ($userdata['show_nb_comments'] == 'true') ? 'NB_COMMENTS_YES':'NB_COMMENTS_NO'; |
---|
[662] | 166 | |
---|
[768] | 167 | $template->assign_vars( |
---|
| 168 | array( |
---|
| 169 | 'USERNAME'=>$userdata['username'], |
---|
| 170 | 'USERID'=>$userdata['id'], |
---|
[808] | 171 | 'EMAIL'=>@$userdata['email'], |
---|
[768] | 172 | 'NB_IMAGE_LINE'=>$userdata['nb_image_line'], |
---|
| 173 | 'NB_ROW_PAGE'=>$userdata['nb_line_page'], |
---|
| 174 | 'RECENT_PERIOD'=>$userdata['recent_period'], |
---|
| 175 | 'MAXWIDTH'=>@$userdata['maxwidth'], |
---|
| 176 | 'MAXHEIGHT'=>@$userdata['maxheight'], |
---|
| 177 | |
---|
| 178 | $expand=>'checked="checked"', |
---|
| 179 | $nb_comments=>'checked="checked"', |
---|
| 180 | |
---|
| 181 | 'L_TITLE' => $lang['customize_title'], |
---|
| 182 | 'L_REGISTRATION_INFO' => $lang['register_title'], |
---|
| 183 | 'L_PREFERENCES' => $lang['preferences'], |
---|
| 184 | 'L_USERNAME' => $lang['login'], |
---|
| 185 | 'L_EMAIL' => $lang['mail_address'], |
---|
| 186 | 'L_CURRENT_PASSWORD' => $lang['password'], |
---|
| 187 | 'L_CURRENT_PASSWORD_HINT' => $lang['password_hint'], |
---|
| 188 | 'L_NEW_PASSWORD' => $lang['new_password'], |
---|
| 189 | 'L_NEW_PASSWORD_HINT' => $lang['new_password_hint'], |
---|
| 190 | 'L_CONFIRM_PASSWORD' => $lang['reg_confirm'], |
---|
| 191 | 'L_CONFIRM_PASSWORD_HINT' => $lang['confirm_password_hint'], |
---|
| 192 | 'L_LANG_SELECT'=>$lang['language'], |
---|
| 193 | 'L_NB_IMAGE_LINE'=>$lang['nb_image_per_row'], |
---|
| 194 | 'L_NB_ROW_PAGE'=>$lang['nb_row_per_page'], |
---|
| 195 | 'L_STYLE_SELECT'=>$lang['theme'], |
---|
| 196 | 'L_RECENT_PERIOD'=>$lang['recent_period'], |
---|
| 197 | 'L_EXPAND_TREE'=>$lang['auto_expand'], |
---|
| 198 | 'L_NB_COMMENTS'=>$lang['show_nb_comments'], |
---|
| 199 | 'L_MAXWIDTH'=>$lang['maxwidth'], |
---|
| 200 | 'L_MAXHEIGHT'=>$lang['maxheight'], |
---|
| 201 | 'L_YES'=>$lang['yes'], |
---|
| 202 | 'L_NO'=>$lang['no'], |
---|
| 203 | 'L_SUBMIT'=>$lang['submit'], |
---|
| 204 | 'L_RESET'=>$lang['reset'], |
---|
| 205 | 'L_RETURN' => $lang['home'], |
---|
[808] | 206 | 'L_RETURN_HINT' => $lang['home_hint'], |
---|
| 207 | |
---|
[1004] | 208 | 'U_RETURN' => PHPWG_ROOT_PATH.'category.php', |
---|
[768] | 209 | |
---|
[1004] | 210 | 'F_ACTION'=>$url_action, |
---|
[768] | 211 | )); |
---|
[854] | 212 | |
---|
| 213 | $blockname = 'template_option'; |
---|
| 214 | |
---|
[960] | 215 | foreach (get_themes() as $pwg_template) |
---|
[854] | 216 | { |
---|
| 217 | if (isset($_POST['submit'])) |
---|
| 218 | { |
---|
| 219 | $selected = $_POST['template']==$pwg_template ? 'selected="selected"' : ''; |
---|
| 220 | } |
---|
[1020] | 221 | else if ($userdata['template'].'/'.$userdata['theme'] == $pwg_template) |
---|
[854] | 222 | { |
---|
| 223 | $selected = 'selected="selected"'; |
---|
| 224 | } |
---|
| 225 | else |
---|
| 226 | { |
---|
| 227 | $selected = ''; |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | $template->assign_block_vars( |
---|
| 231 | $blockname, |
---|
| 232 | array( |
---|
| 233 | 'VALUE'=> $pwg_template, |
---|
| 234 | 'CONTENT' => $pwg_template, |
---|
| 235 | 'SELECTED' => $selected |
---|
| 236 | )); |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | $blockname = 'language_option'; |
---|
| 240 | |
---|
| 241 | foreach (get_languages() as $language_code => $language_name) |
---|
| 242 | { |
---|
| 243 | if (isset($_POST['submit'])) |
---|
| 244 | { |
---|
| 245 | $selected = $_POST['language']==$language_code ? 'selected="selected"':''; |
---|
| 246 | } |
---|
| 247 | else if ($userdata['language'] == $language_code) |
---|
| 248 | { |
---|
| 249 | $selected = 'selected="selected"'; |
---|
| 250 | } |
---|
| 251 | else |
---|
| 252 | { |
---|
| 253 | $selected = ''; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | $template->assign_block_vars( |
---|
| 257 | $blockname, |
---|
| 258 | array( |
---|
| 259 | 'VALUE'=> $language_code, |
---|
| 260 | 'CONTENT' => $language_name, |
---|
| 261 | 'SELECTED' => $selected |
---|
| 262 | )); |
---|
| 263 | } |
---|
| 264 | |
---|
[631] | 265 | // +-----------------------------------------------------------------------+ |
---|
[741] | 266 | // | errors display | |
---|
| 267 | // +-----------------------------------------------------------------------+ |
---|
| 268 | if (count($errors) != 0) |
---|
| 269 | { |
---|
| 270 | $template->assign_block_vars('errors',array()); |
---|
| 271 | foreach ($errors as $error) |
---|
| 272 | { |
---|
| 273 | $template->assign_block_vars('errors.error', array('ERROR'=>$error)); |
---|
| 274 | } |
---|
| 275 | } |
---|
| 276 | // +-----------------------------------------------------------------------+ |
---|
[631] | 277 | // | html code display | |
---|
| 278 | // +-----------------------------------------------------------------------+ |
---|
[808] | 279 | $template->assign_block_vars('profile',array()); |
---|
| 280 | $template->parse('profile_body'); |
---|
| 281 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
[362] | 282 | ?> |
---|