[2] | 1 | <?php |
---|
[351] | 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[26461] | 5 | // | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org | |
---|
[2297] | 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
[2] | 23 | |
---|
| 24 | // customize appearance of the site for a user |
---|
[631] | 25 | // +-----------------------------------------------------------------------+ |
---|
| 26 | // | initialization | |
---|
| 27 | // +-----------------------------------------------------------------------+ |
---|
[808] | 28 | |
---|
[1753] | 29 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 30 | {//direct script access |
---|
| 31 | define('PHPWG_ROOT_PATH','./'); |
---|
| 32 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
[1036] | 33 | |
---|
[1753] | 34 | // +-----------------------------------------------------------------------+ |
---|
| 35 | // | Check Access and exit when user status is not ok | |
---|
| 36 | // +-----------------------------------------------------------------------+ |
---|
| 37 | check_status(ACCESS_CLASSIC); |
---|
[1072] | 38 | |
---|
[6897] | 39 | if (!empty($_POST)) |
---|
| 40 | { |
---|
| 41 | check_pwg_token(); |
---|
| 42 | } |
---|
| 43 | |
---|
[1753] | 44 | $userdata = $user; |
---|
[808] | 45 | |
---|
[28587] | 46 | trigger_notify('loc_begin_profile'); |
---|
[2237] | 47 | |
---|
[4003] | 48 | // Reset to default (Guest) custom settings |
---|
[3995] | 49 | if (isset($_POST['reset_to_default'])) |
---|
| 50 | { |
---|
[4003] | 51 | $fields = array( |
---|
[12877] | 52 | 'nb_image_page', 'expand', |
---|
[4003] | 53 | 'show_nb_comments', 'show_nb_hits', 'recent_period', 'show_nb_hits' |
---|
| 54 | ); |
---|
| 55 | |
---|
[3995] | 56 | // Get the Guest custom settings |
---|
[4001] | 57 | $query = ' |
---|
[4003] | 58 | SELECT '.implode(',', $fields).' |
---|
| 59 | FROM '.USER_INFOS_TABLE.' |
---|
| 60 | WHERE user_id = '.$conf['default_user_id'].' |
---|
| 61 | ;'; |
---|
| 62 | $result = pwg_query($query); |
---|
[4325] | 63 | $default_user = pwg_db_fetch_assoc($result); |
---|
[4003] | 64 | $userdata = array_merge($userdata, $default_user); |
---|
| 65 | } |
---|
| 66 | |
---|
[12764] | 67 | save_profile_from_post($userdata, $page['errors']); |
---|
[1753] | 68 | |
---|
[5206] | 69 | $title= l10n('Your Gallery Customization'); |
---|
[1753] | 70 | $page['body_id'] = 'theProfilePage'; |
---|
[10812] | 71 | $template->set_filename('profile', 'profile.tpl'); |
---|
[29221] | 72 | $template->set_filename('profile_content', 'profile_content.tpl'); |
---|
[1753] | 73 | |
---|
| 74 | load_profile_in_template( |
---|
| 75 | get_root_url().'profile.php', // action |
---|
| 76 | make_index_url(), // for redirect |
---|
| 77 | $userdata ); |
---|
[29221] | 78 | $template->assign_var_from_handle('PROFILE_CONTENT', 'profile_content'); |
---|
[1753] | 79 | |
---|
[29221] | 80 | |
---|
[10812] | 81 | |
---|
| 82 | // include menubar |
---|
| 83 | $themeconf = $template->get_template_vars('themeconf'); |
---|
[10824] | 84 | if (!isset($themeconf['hide_menu_on']) OR !in_array('theProfilePage', $themeconf['hide_menu_on'])) |
---|
[10812] | 85 | { |
---|
| 86 | include( PHPWG_ROOT_PATH.'include/menubar.inc.php'); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
[28587] | 90 | trigger_notify('loc_end_profile'); |
---|
[20609] | 91 | flush_page_messages(); |
---|
[7995] | 92 | $template->pparse('profile'); |
---|
[1753] | 93 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
| 94 | } |
---|
| 95 | |
---|
[2] | 96 | //------------------------------------------------------ update & customization |
---|
[2268] | 97 | function save_profile_from_post($userdata, &$errors) |
---|
[2] | 98 | { |
---|
[12884] | 99 | global $conf, $page; |
---|
[1753] | 100 | $errors = array(); |
---|
[2268] | 101 | |
---|
[1753] | 102 | if (!isset($_POST['validate'])) |
---|
| 103 | { |
---|
[1926] | 104 | return false; |
---|
[1753] | 105 | } |
---|
| 106 | |
---|
[2268] | 107 | $special_user = in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id'])); |
---|
| 108 | if ($special_user) |
---|
| 109 | { |
---|
[5996] | 110 | unset( |
---|
[12882] | 111 | $_POST['username'], |
---|
[5996] | 112 | $_POST['mail_address'], |
---|
| 113 | $_POST['password'], |
---|
| 114 | $_POST['use_new_pwd'], |
---|
| 115 | $_POST['passwordConf'], |
---|
| 116 | $_POST['theme'], |
---|
| 117 | $_POST['language'] |
---|
| 118 | ); |
---|
[6314] | 119 | $_POST['theme'] = get_default_theme(); |
---|
| 120 | $_POST['language'] = get_default_language(); |
---|
[2268] | 121 | } |
---|
[12882] | 122 | |
---|
| 123 | if (!defined('IN_ADMIN')) |
---|
| 124 | { |
---|
| 125 | unset($_POST['username']); |
---|
| 126 | } |
---|
[2268] | 127 | |
---|
[5328] | 128 | if ($conf['allow_user_customization'] or defined('IN_ADMIN')) |
---|
[1043] | 129 | { |
---|
[5328] | 130 | $int_pattern = '/^\d+$/'; |
---|
[10198] | 131 | if (empty($_POST['nb_image_page']) |
---|
| 132 | or (!preg_match($int_pattern, $_POST['nb_image_page']))) |
---|
[5328] | 133 | { |
---|
[10198] | 134 | $errors[] = l10n('The number of photos per page must be a not null scalar'); |
---|
[5328] | 135 | } |
---|
[1043] | 136 | |
---|
[5328] | 137 | // periods must be integer values, they represents number of days |
---|
| 138 | if (!preg_match($int_pattern, $_POST['recent_period']) |
---|
[25120] | 139 | or $_POST['recent_period'] < 0) |
---|
[5328] | 140 | { |
---|
| 141 | $errors[] = l10n('Recent period must be a positive integer value') ; |
---|
| 142 | } |
---|
[11159] | 143 | |
---|
| 144 | if (!in_array($_POST['language'], array_keys(get_languages()))) |
---|
| 145 | { |
---|
| 146 | die('Hacking attempt, incorrect language value'); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | if (!in_array($_POST['theme'], array_keys(get_pwg_themes()))) |
---|
| 150 | { |
---|
| 151 | die('Hacking attempt, incorrect theme value'); |
---|
| 152 | } |
---|
[2] | 153 | } |
---|
[662] | 154 | |
---|
[1926] | 155 | if (isset($_POST['mail_address'])) |
---|
[662] | 156 | { |
---|
[2124] | 157 | // if $_POST and $userdata have are same email |
---|
| 158 | // validate_mail_address allows, however, to check email |
---|
| 159 | $mail_error = validate_mail_address($userdata['id'], $_POST['mail_address']); |
---|
[1926] | 160 | if (!empty($mail_error)) |
---|
| 161 | { |
---|
| 162 | $errors[] = $mail_error; |
---|
| 163 | } |
---|
[662] | 164 | } |
---|
[1620] | 165 | |
---|
[808] | 166 | if (!empty($_POST['use_new_pwd'])) |
---|
[630] | 167 | { |
---|
[808] | 168 | // password must be the same as its confirmation |
---|
| 169 | if ($_POST['use_new_pwd'] != $_POST['passwordConf']) |
---|
[631] | 170 | { |
---|
[12672] | 171 | $errors[] = l10n('The passwords do not match'); |
---|
[662] | 172 | } |
---|
[1620] | 173 | |
---|
[1753] | 174 | if ( !defined('IN_ADMIN') ) |
---|
| 175 | {// changing password requires old password |
---|
| 176 | $query = ' |
---|
| 177 | SELECT '.$conf['user_fields']['password'].' AS password |
---|
| 178 | FROM '.USERS_TABLE.' |
---|
| 179 | WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\' |
---|
| 180 | ;'; |
---|
[4325] | 181 | list($current_password) = pwg_db_fetch_row(pwg_query($query)); |
---|
[5206] | 182 | |
---|
[18889] | 183 | if (!$conf['password_verify']($_POST['password'], $current_password)) |
---|
[1753] | 184 | { |
---|
| 185 | $errors[] = l10n('Current password is wrong'); |
---|
| 186 | } |
---|
[631] | 187 | } |
---|
| 188 | } |
---|
[1620] | 189 | |
---|
[662] | 190 | if (count($errors) == 0) |
---|
[2] | 191 | { |
---|
[808] | 192 | // mass_updates function |
---|
| 193 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
[1620] | 194 | |
---|
[1926] | 195 | if (isset($_POST['mail_address'])) |
---|
| 196 | { |
---|
| 197 | // update common user informations |
---|
| 198 | $fields = array($conf['user_fields']['email']); |
---|
[2] | 199 | |
---|
[1926] | 200 | $data = array(); |
---|
[2268] | 201 | $data{$conf['user_fields']['id']} = $userdata['id']; |
---|
[1926] | 202 | $data{$conf['user_fields']['email']} = $_POST['mail_address']; |
---|
[808] | 203 | |
---|
[1926] | 204 | // password is updated only if filled |
---|
| 205 | if (!empty($_POST['use_new_pwd'])) |
---|
| 206 | { |
---|
[25018] | 207 | $fields[] = $conf['user_fields']['password']; |
---|
[18889] | 208 | // password is hashed with function $conf['password_hash'] |
---|
| 209 | $data{$conf['user_fields']['password']} = $conf['password_hash']($_POST['use_new_pwd']); |
---|
[1926] | 210 | } |
---|
[12882] | 211 | |
---|
| 212 | // username is updated only if allowed |
---|
| 213 | if (!empty($_POST['username'])) |
---|
| 214 | { |
---|
[12884] | 215 | if ($_POST['username'] != $userdata['username'] and get_userid($_POST['username'])) |
---|
[12882] | 216 | { |
---|
[25018] | 217 | $page['errors'][] = l10n('this login is already used'); |
---|
[12884] | 218 | unset($_POST['redirect']); |
---|
| 219 | } |
---|
| 220 | else |
---|
| 221 | { |
---|
[25018] | 222 | $fields[] = $conf['user_fields']['username']; |
---|
[12884] | 223 | $data{$conf['user_fields']['username']} = $_POST['username']; |
---|
[12882] | 224 | |
---|
[12884] | 225 | // send email to the user |
---|
| 226 | if ($_POST['username'] != $userdata['username']) |
---|
| 227 | { |
---|
| 228 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
| 229 | switch_lang_to($userdata['language']); |
---|
[12882] | 230 | |
---|
[12884] | 231 | $keyargs_content = array( |
---|
| 232 | get_l10n_args('Hello', ''), |
---|
| 233 | get_l10n_args('Your username has been successfully changed to : %s', $_POST['username']), |
---|
| 234 | ); |
---|
| 235 | |
---|
| 236 | pwg_mail( |
---|
| 237 | $_POST['mail_address'], |
---|
| 238 | array( |
---|
| 239 | 'subject' => '['.$conf['gallery_title'].'] '.l10n('Username modification'), |
---|
| 240 | 'content' => l10n_args($keyargs_content), |
---|
| 241 | 'content_format' => 'text/plain', |
---|
| 242 | ) |
---|
| 243 | ); |
---|
| 244 | |
---|
| 245 | switch_lang_back(); |
---|
| 246 | } |
---|
[12882] | 247 | } |
---|
| 248 | } |
---|
| 249 | |
---|
[1926] | 250 | mass_updates(USERS_TABLE, |
---|
[12882] | 251 | array( |
---|
| 252 | 'primary' => array($conf['user_fields']['id']), |
---|
| 253 | 'update' => $fields |
---|
| 254 | ), |
---|
[1926] | 255 | array($data)); |
---|
[2] | 256 | } |
---|
[1620] | 257 | |
---|
[5328] | 258 | if ($conf['allow_user_customization'] or defined('IN_ADMIN')) |
---|
| 259 | { |
---|
| 260 | // update user "additional" informations (specific to Piwigo) |
---|
| 261 | $fields = array( |
---|
[12877] | 262 | 'nb_image_page', 'language', |
---|
[12887] | 263 | 'expand', 'show_nb_hits', 'recent_period', 'theme' |
---|
[5328] | 264 | ); |
---|
[12887] | 265 | |
---|
| 266 | if ($conf['activate_comments']) |
---|
| 267 | { |
---|
[25018] | 268 | $fields[] = 'show_nb_comments'; |
---|
[12887] | 269 | } |
---|
[1620] | 270 | |
---|
[5328] | 271 | $data = array(); |
---|
| 272 | $data['user_id'] = $userdata['id']; |
---|
[1620] | 273 | |
---|
[5328] | 274 | foreach ($fields as $field) |
---|
[772] | 275 | { |
---|
[5328] | 276 | if (isset($_POST[$field])) |
---|
| 277 | { |
---|
| 278 | $data[$field] = $_POST[$field]; |
---|
| 279 | } |
---|
[772] | 280 | } |
---|
[5328] | 281 | mass_updates(USER_INFOS_TABLE, |
---|
| 282 | array('primary' => array('user_id'), 'update' => $fields), |
---|
| 283 | array($data)); |
---|
[631] | 284 | } |
---|
[28587] | 285 | trigger_notify( 'save_profile_from_post', $userdata['id'] ); |
---|
[5206] | 286 | |
---|
[1926] | 287 | if (!empty($_POST['redirect'])) |
---|
| 288 | { |
---|
| 289 | redirect($_POST['redirect']); |
---|
| 290 | } |
---|
[2] | 291 | } |
---|
[1926] | 292 | return true; |
---|
[2] | 293 | } |
---|
[850] | 294 | |
---|
[29221] | 295 | /** |
---|
| 296 | * Assign template variables, from arguments |
---|
| 297 | * Used to build profile edition pages |
---|
| 298 | * |
---|
| 299 | * @param string $url_action |
---|
| 300 | * @param string $url_redirect |
---|
| 301 | * @param array $userdata |
---|
| 302 | */ |
---|
| 303 | function load_profile_in_template($url_action, $url_redirect, $userdata, $template_prefixe=null) |
---|
[1753] | 304 | { |
---|
[2029] | 305 | global $template, $conf; |
---|
[850] | 306 | |
---|
[2246] | 307 | $template->assign('radio_options', |
---|
| 308 | array( |
---|
[2268] | 309 | 'true' => l10n('Yes'), |
---|
| 310 | 'false' => l10n('No'))); |
---|
[1620] | 311 | |
---|
[2246] | 312 | $template->assign( |
---|
[1753] | 313 | array( |
---|
[29221] | 314 | $template_prefixe.'USERNAME'=>stripslashes($userdata['username']), |
---|
| 315 | $template_prefixe.'EMAIL'=>@$userdata['email'], |
---|
| 316 | $template_prefixe.'ALLOW_USER_CUSTOMIZATION'=>$conf['allow_user_customization'], |
---|
| 317 | $template_prefixe.'ACTIVATE_COMMENTS'=>$conf['activate_comments'], |
---|
| 318 | $template_prefixe.'NB_IMAGE_PAGE'=>$userdata['nb_image_page'], |
---|
| 319 | $template_prefixe.'RECENT_PERIOD'=>$userdata['recent_period'], |
---|
| 320 | $template_prefixe.'EXPAND' =>$userdata['expand'] ? 'true' : 'false', |
---|
| 321 | $template_prefixe.'NB_COMMENTS'=>$userdata['show_nb_comments'] ? 'true' : 'false', |
---|
| 322 | $template_prefixe.'NB_HITS'=>$userdata['show_nb_hits'] ? 'true' : 'false', |
---|
| 323 | $template_prefixe.'REDIRECT' => $url_redirect, |
---|
| 324 | $template_prefixe.'F_ACTION'=>$url_action, |
---|
[1753] | 325 | )); |
---|
[1620] | 326 | |
---|
[5153] | 327 | $template->assign('template_selection', $userdata['theme']); |
---|
| 328 | $template->assign('template_options', get_pwg_themes()); |
---|
[1620] | 329 | |
---|
[1753] | 330 | foreach (get_languages() as $language_code => $language_name) |
---|
[854] | 331 | { |
---|
[2246] | 332 | if (isset($_POST['submit']) or $userdata['language'] == $language_code) |
---|
[1753] | 333 | { |
---|
[2246] | 334 | $template->assign('language_selection', $language_code); |
---|
[1753] | 335 | } |
---|
[2246] | 336 | $language_options[$language_code] = $language_name; |
---|
[854] | 337 | } |
---|
[3995] | 338 | |
---|
[2246] | 339 | $template->assign('language_options', $language_options); |
---|
[1926] | 340 | |
---|
[2268] | 341 | $special_user = in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id'])); |
---|
| 342 | $template->assign('SPECIAL_USER', $special_user); |
---|
| 343 | $template->assign('IN_ADMIN', defined('IN_ADMIN')); |
---|
[1926] | 344 | |
---|
[2268] | 345 | // allow plugins to add their own form data to content |
---|
[28587] | 346 | trigger_notify( 'load_profile_in_template', $userdata ); |
---|
[5206] | 347 | |
---|
[6897] | 348 | $template->assign('PWG_TOKEN', get_pwg_token()); |
---|
[854] | 349 | } |
---|
[362] | 350 | ?> |
---|