[2] | 1 | <?php |
---|
[351] | 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 5 | // | Copyright(C) 2008-2011 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 | |
---|
[2237] | 46 | trigger_action('loc_begin_profile'); |
---|
| 47 | |
---|
[4003] | 48 | // Reset to default (Guest) custom settings |
---|
[3995] | 49 | if (isset($_POST['reset_to_default'])) |
---|
| 50 | { |
---|
[4003] | 51 | $fields = array( |
---|
[10198] | 52 | 'nb_image_page', 'maxwidth', 'maxheight', '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 | |
---|
[1753] | 67 | save_profile_from_post($userdata, $errors); |
---|
| 68 | |
---|
[5206] | 69 | $title= l10n('Your Gallery Customization'); |
---|
[1753] | 70 | $page['body_id'] = 'theProfilePage'; |
---|
[10812] | 71 | $template->set_filename('profile', 'profile.tpl'); |
---|
[1753] | 72 | |
---|
| 73 | load_profile_in_template( |
---|
| 74 | get_root_url().'profile.php', // action |
---|
| 75 | make_index_url(), // for redirect |
---|
| 76 | $userdata ); |
---|
| 77 | |
---|
| 78 | // +-----------------------------------------------------------------------+ |
---|
| 79 | // | errors display | |
---|
| 80 | // +-----------------------------------------------------------------------+ |
---|
| 81 | if (count($errors) != 0) |
---|
| 82 | { |
---|
[2246] | 83 | $template->assign('errors', $errors); |
---|
[1753] | 84 | } |
---|
[10812] | 85 | |
---|
| 86 | // include menubar |
---|
| 87 | $themeconf = $template->get_template_vars('themeconf'); |
---|
[10824] | 88 | if (!isset($themeconf['hide_menu_on']) OR !in_array('theProfilePage', $themeconf['hide_menu_on'])) |
---|
[10812] | 89 | { |
---|
| 90 | include( PHPWG_ROOT_PATH.'include/menubar.inc.php'); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
[2237] | 94 | trigger_action('loc_end_profile'); |
---|
[7995] | 95 | $template->pparse('profile'); |
---|
[1753] | 96 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
| 97 | } |
---|
| 98 | |
---|
[2] | 99 | //------------------------------------------------------ update & customization |
---|
[2268] | 100 | function save_profile_from_post($userdata, &$errors) |
---|
[2] | 101 | { |
---|
[1753] | 102 | global $conf; |
---|
| 103 | $errors = array(); |
---|
[2268] | 104 | |
---|
[1753] | 105 | if (!isset($_POST['validate'])) |
---|
| 106 | { |
---|
[1926] | 107 | return false; |
---|
[1753] | 108 | } |
---|
| 109 | |
---|
[2268] | 110 | $special_user = in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id'])); |
---|
| 111 | if ($special_user) |
---|
| 112 | { |
---|
[5996] | 113 | unset( |
---|
| 114 | $_POST['mail_address'], |
---|
| 115 | $_POST['password'], |
---|
| 116 | $_POST['use_new_pwd'], |
---|
| 117 | $_POST['passwordConf'], |
---|
| 118 | $_POST['theme'], |
---|
| 119 | $_POST['language'] |
---|
| 120 | ); |
---|
[6314] | 121 | $_POST['theme'] = get_default_theme(); |
---|
| 122 | $_POST['language'] = get_default_language(); |
---|
[2268] | 123 | } |
---|
| 124 | |
---|
[5328] | 125 | if ($conf['allow_user_customization'] or defined('IN_ADMIN')) |
---|
[1043] | 126 | { |
---|
[5328] | 127 | $int_pattern = '/^\d+$/'; |
---|
[10198] | 128 | if (empty($_POST['nb_image_page']) |
---|
| 129 | or (!preg_match($int_pattern, $_POST['nb_image_page']))) |
---|
[5328] | 130 | { |
---|
[10198] | 131 | $errors[] = l10n('The number of photos per page must be a not null scalar'); |
---|
[5328] | 132 | } |
---|
[1043] | 133 | |
---|
[5328] | 134 | if ($_POST['maxwidth'] != '' |
---|
| 135 | and (!preg_match($int_pattern, $_POST['maxwidth']) |
---|
| 136 | or $_POST['maxwidth'] < 50)) |
---|
| 137 | { |
---|
| 138 | $errors[] = l10n('Maximum width must be a number superior to 50'); |
---|
| 139 | } |
---|
| 140 | if ($_POST['maxheight'] |
---|
| 141 | and (!preg_match($int_pattern, $_POST['maxheight']) |
---|
| 142 | or $_POST['maxheight'] < 50)) |
---|
| 143 | { |
---|
| 144 | $errors[] = l10n('Maximum height must be a number superior to 50'); |
---|
| 145 | } |
---|
| 146 | // periods must be integer values, they represents number of days |
---|
| 147 | if (!preg_match($int_pattern, $_POST['recent_period']) |
---|
| 148 | or $_POST['recent_period'] <= 0) |
---|
| 149 | { |
---|
| 150 | $errors[] = l10n('Recent period must be a positive integer value') ; |
---|
| 151 | } |
---|
[11159] | 152 | |
---|
| 153 | if (!in_array($_POST['language'], array_keys(get_languages()))) |
---|
| 154 | { |
---|
| 155 | die('Hacking attempt, incorrect language value'); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | if (!in_array($_POST['theme'], array_keys(get_pwg_themes()))) |
---|
| 159 | { |
---|
| 160 | die('Hacking attempt, incorrect theme value'); |
---|
| 161 | } |
---|
[2] | 162 | } |
---|
[662] | 163 | |
---|
[1926] | 164 | if (isset($_POST['mail_address'])) |
---|
[662] | 165 | { |
---|
[2124] | 166 | // if $_POST and $userdata have are same email |
---|
| 167 | // validate_mail_address allows, however, to check email |
---|
| 168 | $mail_error = validate_mail_address($userdata['id'], $_POST['mail_address']); |
---|
[1926] | 169 | if (!empty($mail_error)) |
---|
| 170 | { |
---|
| 171 | $errors[] = $mail_error; |
---|
| 172 | } |
---|
[662] | 173 | } |
---|
[1620] | 174 | |
---|
[808] | 175 | if (!empty($_POST['use_new_pwd'])) |
---|
[630] | 176 | { |
---|
[808] | 177 | // password must be the same as its confirmation |
---|
| 178 | if ($_POST['use_new_pwd'] != $_POST['passwordConf']) |
---|
[631] | 179 | { |
---|
[1753] | 180 | $errors[] = l10n('New password confirmation does not correspond'); |
---|
[662] | 181 | } |
---|
[1620] | 182 | |
---|
[1753] | 183 | if ( !defined('IN_ADMIN') ) |
---|
| 184 | {// changing password requires old password |
---|
| 185 | $query = ' |
---|
| 186 | SELECT '.$conf['user_fields']['password'].' AS password |
---|
| 187 | FROM '.USERS_TABLE.' |
---|
| 188 | WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\' |
---|
| 189 | ;'; |
---|
[4325] | 190 | list($current_password) = pwg_db_fetch_row(pwg_query($query)); |
---|
[5206] | 191 | |
---|
[1753] | 192 | if ($conf['pass_convert']($_POST['password']) != $current_password) |
---|
| 193 | { |
---|
| 194 | $errors[] = l10n('Current password is wrong'); |
---|
| 195 | } |
---|
[631] | 196 | } |
---|
| 197 | } |
---|
[1620] | 198 | |
---|
[662] | 199 | if (count($errors) == 0) |
---|
[2] | 200 | { |
---|
[808] | 201 | // mass_updates function |
---|
| 202 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
[1620] | 203 | |
---|
[1926] | 204 | if (isset($_POST['mail_address'])) |
---|
| 205 | { |
---|
| 206 | // update common user informations |
---|
| 207 | $fields = array($conf['user_fields']['email']); |
---|
[2] | 208 | |
---|
[1926] | 209 | $data = array(); |
---|
[2268] | 210 | $data{$conf['user_fields']['id']} = $userdata['id']; |
---|
[1926] | 211 | $data{$conf['user_fields']['email']} = $_POST['mail_address']; |
---|
[808] | 212 | |
---|
[1926] | 213 | // password is updated only if filled |
---|
| 214 | if (!empty($_POST['use_new_pwd'])) |
---|
| 215 | { |
---|
| 216 | array_push($fields, $conf['user_fields']['password']); |
---|
| 217 | // password is encrpyted with function $conf['pass_convert'] |
---|
| 218 | $data{$conf['user_fields']['password']} = |
---|
| 219 | $conf['pass_convert']($_POST['use_new_pwd']); |
---|
| 220 | } |
---|
| 221 | mass_updates(USERS_TABLE, |
---|
| 222 | array('primary' => array($conf['user_fields']['id']), |
---|
| 223 | 'update' => $fields), |
---|
| 224 | array($data)); |
---|
[2] | 225 | } |
---|
[1620] | 226 | |
---|
[5328] | 227 | if ($conf['allow_user_customization'] or defined('IN_ADMIN')) |
---|
| 228 | { |
---|
| 229 | // update user "additional" informations (specific to Piwigo) |
---|
| 230 | $fields = array( |
---|
[10198] | 231 | 'nb_image_page', 'language', 'maxwidth', 'maxheight', |
---|
[5328] | 232 | 'expand', 'show_nb_comments', 'show_nb_hits', 'recent_period', 'theme' |
---|
| 233 | ); |
---|
[1620] | 234 | |
---|
[5328] | 235 | $data = array(); |
---|
| 236 | $data['user_id'] = $userdata['id']; |
---|
[1620] | 237 | |
---|
[5328] | 238 | foreach ($fields as $field) |
---|
[772] | 239 | { |
---|
[5328] | 240 | if (isset($_POST[$field])) |
---|
| 241 | { |
---|
| 242 | $data[$field] = $_POST[$field]; |
---|
| 243 | } |
---|
[772] | 244 | } |
---|
[5328] | 245 | mass_updates(USER_INFOS_TABLE, |
---|
| 246 | array('primary' => array('user_id'), 'update' => $fields), |
---|
| 247 | array($data)); |
---|
[631] | 248 | } |
---|
[2268] | 249 | trigger_action( 'save_profile_from_post', $userdata['id'] ); |
---|
[5206] | 250 | |
---|
[1926] | 251 | if (!empty($_POST['redirect'])) |
---|
| 252 | { |
---|
| 253 | redirect($_POST['redirect']); |
---|
| 254 | } |
---|
[2] | 255 | } |
---|
[1926] | 256 | return true; |
---|
[2] | 257 | } |
---|
[850] | 258 | |
---|
[808] | 259 | |
---|
[1753] | 260 | function load_profile_in_template($url_action, $url_redirect, $userdata) |
---|
| 261 | { |
---|
[2029] | 262 | global $template, $conf; |
---|
[850] | 263 | |
---|
[1753] | 264 | $template->set_filename('profile_content', 'profile_content.tpl'); |
---|
[393] | 265 | |
---|
[2246] | 266 | $template->assign('radio_options', |
---|
| 267 | array( |
---|
[2268] | 268 | 'true' => l10n('Yes'), |
---|
| 269 | 'false' => l10n('No'))); |
---|
[1620] | 270 | |
---|
[2246] | 271 | $template->assign( |
---|
[1753] | 272 | array( |
---|
[4304] | 273 | 'USERNAME'=>stripslashes($userdata['username']), |
---|
[2229] | 274 | 'EMAIL'=>get_email_address_as_display_text(@$userdata['email']), |
---|
[5328] | 275 | 'ALLOW_USER_CUSTOMIZATION'=>$conf['allow_user_customization'], |
---|
[10198] | 276 | 'NB_IMAGE_PAGE'=>$userdata['nb_image_page'], |
---|
[1753] | 277 | 'RECENT_PERIOD'=>$userdata['recent_period'], |
---|
| 278 | 'MAXWIDTH'=>@$userdata['maxwidth'], |
---|
| 279 | 'MAXHEIGHT'=>@$userdata['maxheight'], |
---|
[2246] | 280 | 'EXPAND' =>$userdata['expand'] ? 'true' : 'false', |
---|
| 281 | 'NB_COMMENTS'=>$userdata['show_nb_comments'] ? 'true' : 'false', |
---|
| 282 | 'NB_HITS'=>$userdata['show_nb_hits'] ? 'true' : 'false', |
---|
[1753] | 283 | 'REDIRECT' => $url_redirect, |
---|
| 284 | 'F_ACTION'=>$url_action, |
---|
| 285 | )); |
---|
[1620] | 286 | |
---|
[5153] | 287 | $template->assign('template_selection', $userdata['theme']); |
---|
| 288 | $template->assign('template_options', get_pwg_themes()); |
---|
[1620] | 289 | |
---|
[1753] | 290 | foreach (get_languages() as $language_code => $language_name) |
---|
[854] | 291 | { |
---|
[2246] | 292 | if (isset($_POST['submit']) or $userdata['language'] == $language_code) |
---|
[1753] | 293 | { |
---|
[2246] | 294 | $template->assign('language_selection', $language_code); |
---|
[1753] | 295 | } |
---|
[2246] | 296 | $language_options[$language_code] = $language_name; |
---|
[854] | 297 | } |
---|
[3995] | 298 | |
---|
[2246] | 299 | $template->assign('language_options', $language_options); |
---|
[1926] | 300 | |
---|
[2268] | 301 | $special_user = in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id'])); |
---|
| 302 | $template->assign('SPECIAL_USER', $special_user); |
---|
| 303 | $template->assign('IN_ADMIN', defined('IN_ADMIN')); |
---|
[1926] | 304 | |
---|
[2268] | 305 | // allow plugins to add their own form data to content |
---|
| 306 | trigger_action( 'load_profile_in_template', $userdata ); |
---|
[5206] | 307 | |
---|
[6897] | 308 | $template->assign('PWG_TOKEN', get_pwg_token()); |
---|
[1753] | 309 | $template->assign_var_from_handle('PROFILE_CONTENT', 'profile_content'); |
---|
[854] | 310 | } |
---|
[362] | 311 | ?> |
---|