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