[2] | 1 | <?php |
---|
[351] | 2 | // +-----------------------------------------------------------------------+ |
---|
[593] | 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[1719] | 5 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[351] | 6 | // +-----------------------------------------------------------------------+ |
---|
[1719] | 7 | // | file : $Id: profile.php 2015 2007-05-15 20:26:56Z rub $ |
---|
[351] | 8 | // | last update : $Date: 2007-05-15 20:26:56 +0000 (Tue, 15 May 2007) $ |
---|
| 9 | // | last modifier : $Author: rub $ |
---|
| 10 | // | revision : $Revision: 2015 $ |
---|
| 11 | // +-----------------------------------------------------------------------+ |
---|
| 12 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 13 | // | it under the terms of the GNU General Public License as published by | |
---|
[354] | 14 | // | the Free Software Foundation | |
---|
| 15 | // | | |
---|
| 16 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 17 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 18 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 19 | // | General Public License for more details. | |
---|
| 20 | // | | |
---|
| 21 | // | You should have received a copy of the GNU General Public License | |
---|
| 22 | // | along with this program; if not, write to the Free Software | |
---|
| 23 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 24 | // | USA. | |
---|
[351] | 25 | // +-----------------------------------------------------------------------+ |
---|
[2] | 26 | |
---|
| 27 | // customize appearance of the site for a user |
---|
[631] | 28 | // +-----------------------------------------------------------------------+ |
---|
| 29 | // | initialization | |
---|
| 30 | // +-----------------------------------------------------------------------+ |
---|
[808] | 31 | |
---|
[1753] | 32 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 33 | {//direct script access |
---|
| 34 | define('PHPWG_ROOT_PATH','./'); |
---|
| 35 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
[1036] | 36 | |
---|
[1753] | 37 | // +-----------------------------------------------------------------------+ |
---|
| 38 | // | Check Access and exit when user status is not ok | |
---|
| 39 | // +-----------------------------------------------------------------------+ |
---|
| 40 | check_status(ACCESS_CLASSIC); |
---|
[1072] | 41 | |
---|
[1753] | 42 | $userdata = $user; |
---|
[808] | 43 | |
---|
[1753] | 44 | save_profile_from_post($userdata, $errors); |
---|
| 45 | |
---|
[2015] | 46 | $title= l10n('customize_page_title'); |
---|
[1753] | 47 | $page['body_id'] = 'theProfilePage'; |
---|
| 48 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
| 49 | |
---|
| 50 | load_profile_in_template( |
---|
| 51 | get_root_url().'profile.php', // action |
---|
| 52 | make_index_url(), // for redirect |
---|
| 53 | $userdata ); |
---|
| 54 | |
---|
[1788] | 55 | $template->assign_var('U_HOME', make_index_url() ); |
---|
[1753] | 56 | |
---|
| 57 | // +-----------------------------------------------------------------------+ |
---|
| 58 | // | errors display | |
---|
| 59 | // +-----------------------------------------------------------------------+ |
---|
| 60 | if (count($errors) != 0) |
---|
| 61 | { |
---|
| 62 | $template->assign_block_vars('errors',array()); |
---|
| 63 | foreach ($errors as $error) |
---|
| 64 | { |
---|
| 65 | $template->assign_block_vars('errors.error', array('ERROR'=>$error)); |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | $template->set_filename('profile', 'profile.tpl'); |
---|
| 69 | $template->parse('profile'); |
---|
| 70 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
| 71 | } |
---|
| 72 | |
---|
[2] | 73 | //------------------------------------------------------ update & customization |
---|
[1753] | 74 | function save_profile_from_post(&$userdata, &$errors) |
---|
[2] | 75 | { |
---|
[1753] | 76 | global $conf; |
---|
| 77 | $errors = array(); |
---|
| 78 | |
---|
| 79 | if (!isset($_POST['validate'])) |
---|
| 80 | { |
---|
[1926] | 81 | return false; |
---|
[1753] | 82 | } |
---|
| 83 | |
---|
[26] | 84 | $int_pattern = '/^\d+$/'; |
---|
[1043] | 85 | if (empty($_POST['nb_image_line']) |
---|
| 86 | or (!preg_match($int_pattern, $_POST['nb_image_line']))) |
---|
| 87 | { |
---|
[1753] | 88 | $errors[] = l10n('nb_image_line_error'); |
---|
[1043] | 89 | } |
---|
| 90 | |
---|
| 91 | if (empty($_POST['nb_line_page']) |
---|
| 92 | or (!preg_match($int_pattern, $_POST['nb_line_page']))) |
---|
| 93 | { |
---|
[1753] | 94 | $errors[] = l10n('nb_line_page_error'); |
---|
[1043] | 95 | } |
---|
[1620] | 96 | |
---|
[662] | 97 | if ($_POST['maxwidth'] != '' |
---|
| 98 | and (!preg_match($int_pattern, $_POST['maxwidth']) |
---|
| 99 | or $_POST['maxwidth'] < 50)) |
---|
[2] | 100 | { |
---|
[1753] | 101 | $errors[] = l10n('maxwidth_error'); |
---|
[2] | 102 | } |
---|
[662] | 103 | if ($_POST['maxheight'] |
---|
| 104 | and (!preg_match($int_pattern, $_POST['maxheight']) |
---|
| 105 | or $_POST['maxheight'] < 50)) |
---|
[2] | 106 | { |
---|
[1753] | 107 | $errors[] = l10n('maxheight_error'); |
---|
[2] | 108 | } |
---|
[26] | 109 | // periods must be integer values, they represents number of days |
---|
[452] | 110 | if (!preg_match($int_pattern, $_POST['recent_period']) |
---|
| 111 | or $_POST['recent_period'] <= 0) |
---|
[2] | 112 | { |
---|
[1753] | 113 | $errors[] = l10n('periods_error') ; |
---|
[2] | 114 | } |
---|
[662] | 115 | |
---|
[1926] | 116 | if (isset($_POST['mail_address'])) |
---|
[662] | 117 | { |
---|
[1926] | 118 | $mail_error = validate_mail_address($_POST['mail_address']); |
---|
| 119 | if (!empty($mail_error)) |
---|
| 120 | { |
---|
| 121 | $errors[] = $mail_error; |
---|
| 122 | } |
---|
[662] | 123 | } |
---|
[1620] | 124 | |
---|
[808] | 125 | if (!empty($_POST['use_new_pwd'])) |
---|
[630] | 126 | { |
---|
[808] | 127 | // password must be the same as its confirmation |
---|
| 128 | if ($_POST['use_new_pwd'] != $_POST['passwordConf']) |
---|
[631] | 129 | { |
---|
[1753] | 130 | $errors[] = l10n('New password confirmation does not correspond'); |
---|
[662] | 131 | } |
---|
[1620] | 132 | |
---|
[1753] | 133 | if ( !defined('IN_ADMIN') ) |
---|
| 134 | {// changing password requires old password |
---|
| 135 | $query = ' |
---|
| 136 | SELECT '.$conf['user_fields']['password'].' AS password |
---|
| 137 | FROM '.USERS_TABLE.' |
---|
| 138 | WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\' |
---|
| 139 | ;'; |
---|
| 140 | list($current_password) = mysql_fetch_row(pwg_query($query)); |
---|
| 141 | |
---|
| 142 | if ($conf['pass_convert']($_POST['password']) != $current_password) |
---|
| 143 | { |
---|
| 144 | $errors[] = l10n('Current password is wrong'); |
---|
| 145 | } |
---|
[631] | 146 | } |
---|
| 147 | } |
---|
[1620] | 148 | |
---|
[662] | 149 | if (count($errors) == 0) |
---|
[2] | 150 | { |
---|
[808] | 151 | // mass_updates function |
---|
| 152 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
[1620] | 153 | |
---|
[1926] | 154 | if (isset($_POST['mail_address'])) |
---|
| 155 | { |
---|
| 156 | // update common user informations |
---|
| 157 | $fields = array($conf['user_fields']['email']); |
---|
[2] | 158 | |
---|
[1926] | 159 | $data = array(); |
---|
| 160 | $data{$conf['user_fields']['id']} = $_POST['userid']; |
---|
| 161 | $data{$conf['user_fields']['email']} = $_POST['mail_address']; |
---|
[808] | 162 | |
---|
[1926] | 163 | // password is updated only if filled |
---|
| 164 | if (!empty($_POST['use_new_pwd'])) |
---|
| 165 | { |
---|
| 166 | array_push($fields, $conf['user_fields']['password']); |
---|
| 167 | // password is encrpyted with function $conf['pass_convert'] |
---|
| 168 | $data{$conf['user_fields']['password']} = |
---|
| 169 | $conf['pass_convert']($_POST['use_new_pwd']); |
---|
| 170 | } |
---|
| 171 | mass_updates(USERS_TABLE, |
---|
| 172 | array('primary' => array($conf['user_fields']['id']), |
---|
| 173 | 'update' => $fields), |
---|
| 174 | array($data)); |
---|
[2] | 175 | } |
---|
[1620] | 176 | |
---|
[808] | 177 | // update user "additional" informations (specific to PhpWebGallery) |
---|
| 178 | $fields = array( |
---|
| 179 | 'nb_image_line', 'nb_line_page', 'language', 'maxwidth', 'maxheight', |
---|
[1763] | 180 | 'expand', 'show_nb_comments', 'show_nb_hits', 'recent_period', 'template' |
---|
[808] | 181 | ); |
---|
[1620] | 182 | |
---|
[808] | 183 | $data = array(); |
---|
[1043] | 184 | $data['user_id'] = $_POST['userid']; |
---|
[1620] | 185 | |
---|
[808] | 186 | foreach ($fields as $field) |
---|
[631] | 187 | { |
---|
[808] | 188 | if (isset($_POST[$field])) |
---|
[772] | 189 | { |
---|
[1043] | 190 | $data[$field] = $_POST[$field]; |
---|
[772] | 191 | } |
---|
[631] | 192 | } |
---|
[808] | 193 | mass_updates(USER_INFOS_TABLE, |
---|
| 194 | array('primary' => array('user_id'), 'update' => $fields), |
---|
| 195 | array($data)); |
---|
[1620] | 196 | |
---|
[808] | 197 | // redirection |
---|
[1926] | 198 | if (!empty($_POST['redirect'])) |
---|
| 199 | { |
---|
| 200 | redirect($_POST['redirect']); |
---|
| 201 | } |
---|
[2] | 202 | } |
---|
[1926] | 203 | return true; |
---|
[2] | 204 | } |
---|
[850] | 205 | |
---|
[808] | 206 | |
---|
[1753] | 207 | function load_profile_in_template($url_action, $url_redirect, $userdata) |
---|
| 208 | { |
---|
| 209 | global $template; |
---|
[850] | 210 | |
---|
[1753] | 211 | $template->set_filename('profile_content', 'profile_content.tpl'); |
---|
[393] | 212 | |
---|
[1763] | 213 | $expand = ($userdata['expand'] == 'true') ? |
---|
| 214 | 'EXPAND_TREE_YES':'EXPAND_TREE_NO'; |
---|
[1620] | 215 | |
---|
[1753] | 216 | $nb_comments = |
---|
[1763] | 217 | ($userdata['show_nb_comments'] == 'true') ? |
---|
| 218 | 'NB_COMMENTS_YES':'NB_COMMENTS_NO'; |
---|
[1620] | 219 | |
---|
[1763] | 220 | $nb_hits = |
---|
| 221 | ($userdata['show_nb_hits'] == 'true') ? |
---|
| 222 | 'NB_HITS_YES':'NB_HITS_NO'; |
---|
| 223 | |
---|
[1753] | 224 | $template->assign_vars( |
---|
| 225 | array( |
---|
| 226 | 'USERNAME'=>$userdata['username'], |
---|
| 227 | 'USERID'=>$userdata['id'], |
---|
| 228 | 'EMAIL'=>@$userdata['email'], |
---|
| 229 | 'NB_IMAGE_LINE'=>$userdata['nb_image_line'], |
---|
| 230 | 'NB_ROW_PAGE'=>$userdata['nb_line_page'], |
---|
| 231 | 'RECENT_PERIOD'=>$userdata['recent_period'], |
---|
| 232 | 'MAXWIDTH'=>@$userdata['maxwidth'], |
---|
| 233 | 'MAXHEIGHT'=>@$userdata['maxheight'], |
---|
| 234 | |
---|
| 235 | $expand=>'checked="checked"', |
---|
| 236 | $nb_comments=>'checked="checked"', |
---|
[1763] | 237 | $nb_hits=>'checked="checked"', |
---|
[1753] | 238 | |
---|
| 239 | 'REDIRECT' => $url_redirect, |
---|
| 240 | |
---|
| 241 | 'F_ACTION'=>$url_action, |
---|
| 242 | )); |
---|
[1620] | 243 | |
---|
[1753] | 244 | $blockname = 'template_option'; |
---|
[808] | 245 | |
---|
[1753] | 246 | foreach (get_pwg_themes() as $pwg_template) |
---|
[854] | 247 | { |
---|
[1753] | 248 | if (isset($_POST['submit'])) |
---|
| 249 | { |
---|
| 250 | $selected = $_POST['template']==$pwg_template ? 'selected="selected"' : ''; |
---|
| 251 | } |
---|
| 252 | else if ($userdata['template'].'/'.$userdata['theme'] == $pwg_template) |
---|
| 253 | { |
---|
| 254 | $selected = 'selected="selected"'; |
---|
| 255 | } |
---|
| 256 | else |
---|
| 257 | { |
---|
| 258 | $selected = ''; |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | $template->assign_block_vars( |
---|
| 262 | $blockname, |
---|
| 263 | array( |
---|
| 264 | 'VALUE'=> $pwg_template, |
---|
| 265 | 'CONTENT' => $pwg_template, |
---|
| 266 | 'SELECTED' => $selected |
---|
| 267 | )); |
---|
[854] | 268 | } |
---|
[1620] | 269 | |
---|
[1753] | 270 | $blockname = 'language_option'; |
---|
[854] | 271 | |
---|
[1753] | 272 | foreach (get_languages() as $language_code => $language_name) |
---|
[854] | 273 | { |
---|
[1753] | 274 | if (isset($_POST['submit'])) |
---|
| 275 | { |
---|
| 276 | $selected = $_POST['language']==$language_code ? 'selected="selected"':''; |
---|
| 277 | } |
---|
| 278 | else if ($userdata['language'] == $language_code) |
---|
| 279 | { |
---|
| 280 | $selected = 'selected="selected"'; |
---|
| 281 | } |
---|
| 282 | else |
---|
| 283 | { |
---|
| 284 | $selected = ''; |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | $template->assign_block_vars( |
---|
| 288 | $blockname, |
---|
| 289 | array( |
---|
| 290 | 'VALUE'=> $language_code, |
---|
| 291 | 'CONTENT' => $language_name, |
---|
| 292 | 'SELECTED' => $selected |
---|
| 293 | )); |
---|
[854] | 294 | } |
---|
[1926] | 295 | |
---|
| 296 | if (!($userdata['is_the_guest'] or $userdata['is_the_default'])) |
---|
[854] | 297 | { |
---|
[1926] | 298 | $template->assign_block_vars('not_special_user', array()); |
---|
| 299 | if ( !defined('IN_ADMIN') ) |
---|
| 300 | { |
---|
| 301 | $template->assign_block_vars( 'not_special_user.not_admin', array() ); |
---|
| 302 | } |
---|
[854] | 303 | } |
---|
[1926] | 304 | |
---|
[1753] | 305 | $template->assign_var_from_handle('PROFILE_CONTENT', 'profile_content'); |
---|
[854] | 306 | } |
---|
[362] | 307 | ?> |
---|