source: trunk/profile.php @ 2291

Last change on this file since 2291 was 2268, checked in by rvelices, 16 years ago
  • security fix (profile)
  • les langues a la hache
  • fix some copy/paste errors
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
RevLine 
[2]1<?php
[351]2// +-----------------------------------------------------------------------+
[593]3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
[2268]5// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
[351]6// +-----------------------------------------------------------------------+
[1719]7// | file          : $Id: profile.php 2268 2008-03-08 12:38:09Z rvelices $
[351]8// | last update   : $Date: 2008-03-08 12:38:09 +0000 (Sat, 08 Mar 2008) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 2268 $
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]32if (!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
[2237]44  trigger_action('loc_begin_profile');
45
[1753]46  save_profile_from_post($userdata, $errors);
47
[2014]48  $title= l10n('customize_page_title');
[1753]49  $page['body_id'] = 'theProfilePage';
50  include(PHPWG_ROOT_PATH.'include/page_header.php');
51
52  load_profile_in_template(
53    get_root_url().'profile.php', // action
54    make_index_url(), // for redirect
55    $userdata );
56
57  // +-----------------------------------------------------------------------+
58  // |                             errors display                            |
59  // +-----------------------------------------------------------------------+
60  if (count($errors) != 0)
61  {
[2246]62    $template->assign('errors', $errors);
[1753]63  }
64  $template->set_filename('profile', 'profile.tpl');
[2237]65  trigger_action('loc_end_profile');
[1753]66  $template->parse('profile');
67  include(PHPWG_ROOT_PATH.'include/page_tail.php');
68}
69
[2]70//------------------------------------------------------ update & customization
[2268]71function save_profile_from_post($userdata, &$errors)
[2]72{
[1753]73  global $conf;
74  $errors = array();
[2268]75
[1753]76  if (!isset($_POST['validate']))
77  {
[1926]78    return false;
[1753]79  }
80
[2268]81  $special_user = in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id']));
82  if ($special_user)
83  {
84    unset($_POST['mail_address'],
85          $_POST['password'],
86          $_POST['use_new_pwd'],
87          $_POST['passwordConf']
88          );
89  }
90
[26]91  $int_pattern = '/^\d+$/';
[1043]92  if (empty($_POST['nb_image_line'])
93      or (!preg_match($int_pattern, $_POST['nb_image_line'])))
94  {
[1753]95    $errors[] = l10n('nb_image_line_error');
[1043]96  }
97
98  if (empty($_POST['nb_line_page'])
99      or (!preg_match($int_pattern, $_POST['nb_line_page'])))
100  {
[1753]101    $errors[] = l10n('nb_line_page_error');
[1043]102  }
[1620]103
[662]104  if ($_POST['maxwidth'] != ''
105      and (!preg_match($int_pattern, $_POST['maxwidth'])
106           or $_POST['maxwidth'] < 50))
[2]107  {
[1753]108    $errors[] = l10n('maxwidth_error');
[2]109  }
[662]110  if ($_POST['maxheight']
111       and (!preg_match($int_pattern, $_POST['maxheight'])
112             or $_POST['maxheight'] < 50))
[2]113  {
[1753]114    $errors[] = l10n('maxheight_error');
[2]115  }
[26]116  // periods must be integer values, they represents number of days
[452]117  if (!preg_match($int_pattern, $_POST['recent_period'])
118      or $_POST['recent_period'] <= 0)
[2]119  {
[1753]120    $errors[] = l10n('periods_error') ;
[2]121  }
[662]122
[1926]123  if (isset($_POST['mail_address']))
[662]124  {
[2124]125    // if $_POST and $userdata have are same email
126    // validate_mail_address allows, however, to check email
127    $mail_error = validate_mail_address($userdata['id'], $_POST['mail_address']);
[1926]128    if (!empty($mail_error))
129    {
130      $errors[] = $mail_error;
131    }
[662]132  }
[1620]133
[808]134  if (!empty($_POST['use_new_pwd']))
[630]135  {
[808]136    // password must be the same as its confirmation
137    if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
[631]138    {
[1753]139      $errors[] = l10n('New password confirmation does not correspond');
[662]140    }
[1620]141
[1753]142    if ( !defined('IN_ADMIN') )
143    {// changing password requires old password
144      $query = '
145  SELECT '.$conf['user_fields']['password'].' AS password
146    FROM '.USERS_TABLE.'
147    WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\'
148  ;';
149      list($current_password) = mysql_fetch_row(pwg_query($query));
150 
151      if ($conf['pass_convert']($_POST['password']) != $current_password)
152      {
153        $errors[] = l10n('Current password is wrong');
154      }
[631]155    }
156  }
[1620]157
[662]158  if (count($errors) == 0)
[2]159  {
[808]160    // mass_updates function
161    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
[1620]162
[1926]163    if (isset($_POST['mail_address']))
164    {
165      // update common user informations
166      $fields = array($conf['user_fields']['email']);
[2]167
[1926]168      $data = array();
[2268]169      $data{$conf['user_fields']['id']} = $userdata['id'];
[1926]170      $data{$conf['user_fields']['email']} = $_POST['mail_address'];
[808]171
[1926]172      // password is updated only if filled
173      if (!empty($_POST['use_new_pwd']))
174      {
175        array_push($fields, $conf['user_fields']['password']);
176        // password is encrpyted with function $conf['pass_convert']
177        $data{$conf['user_fields']['password']} =
178          $conf['pass_convert']($_POST['use_new_pwd']);
179      }
180      mass_updates(USERS_TABLE,
181                   array('primary' => array($conf['user_fields']['id']),
182                         'update' => $fields),
183                   array($data));
[2]184    }
[1620]185
[808]186    // update user "additional" informations (specific to PhpWebGallery)
187    $fields = array(
188      'nb_image_line', 'nb_line_page', 'language', 'maxwidth', 'maxheight',
[1763]189      'expand', 'show_nb_comments', 'show_nb_hits', 'recent_period', 'template'
[808]190      );
[1620]191
[808]192    $data = array();
[2268]193    $data['user_id'] = $userdata['id'];
[1620]194
[808]195    foreach ($fields as $field)
[631]196    {
[808]197      if (isset($_POST[$field]))
[772]198      {
[1043]199        $data[$field] = $_POST[$field];
[772]200      }
[631]201    }
[808]202    mass_updates(USER_INFOS_TABLE,
203                 array('primary' => array('user_id'), 'update' => $fields),
204                 array($data));
[1620]205
[2268]206    trigger_action( 'save_profile_from_post', $userdata['id'] );
[2048]207   
[1926]208    if (!empty($_POST['redirect']))
209    {
210      redirect($_POST['redirect']);
211    }
[2]212  }
[1926]213  return true;
[2]214}
[850]215
[808]216
[1753]217function load_profile_in_template($url_action, $url_redirect, $userdata)
218{
[2029]219  global $template, $conf;
[850]220
[1753]221  $template->set_filename('profile_content', 'profile_content.tpl');
[393]222
[2246]223  $template->assign('radio_options',
224    array(
[2268]225      'true' => l10n('Yes'),
226      'false' => l10n('No')));
[1620]227
[2246]228  $template->assign(
[1753]229    array(
230      'USERNAME'=>$userdata['username'],
[2229]231      'EMAIL'=>get_email_address_as_display_text(@$userdata['email']),
[1753]232      'NB_IMAGE_LINE'=>$userdata['nb_image_line'],
233      'NB_ROW_PAGE'=>$userdata['nb_line_page'],
234      'RECENT_PERIOD'=>$userdata['recent_period'],
235      'MAXWIDTH'=>@$userdata['maxwidth'],
236      'MAXHEIGHT'=>@$userdata['maxheight'],
[2246]237      'EXPAND' =>$userdata['expand'] ? 'true' : 'false',
238      'NB_COMMENTS'=>$userdata['show_nb_comments'] ? 'true' : 'false',
239      'NB_HITS'=>$userdata['show_nb_hits'] ? 'true' : 'false',
[1753]240      'REDIRECT' => $url_redirect,
241      'F_ACTION'=>$url_action,
242      ));
[1620]243
[1753]244  foreach (get_pwg_themes() as $pwg_template)
[854]245  {
[2246]246    if (isset($_POST['submit'])
247      or $userdata['template'].'/'.$userdata['theme'] == $pwg_template)
[1753]248    {
[2246]249      $template->assign('template_selection', $pwg_template);
[1753]250    }
[2246]251    $template_options[$pwg_template] = $pwg_template;
[854]252  }
[2246]253  $template->assign('template_options', $template_options);
[1620]254
[1753]255  foreach (get_languages() as $language_code => $language_name)
[854]256  {
[2246]257    if (isset($_POST['submit']) or $userdata['language'] == $language_code)
[1753]258    {
[2246]259      $template->assign('language_selection', $language_code);
[1753]260    }
[2246]261    $language_options[$language_code] = $language_name;
[854]262  }
[2246]263  $template->assign('language_options', $language_options);
[1926]264
[2268]265  $special_user = in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id']));
266  $template->assign('SPECIAL_USER', $special_user);
267  $template->assign('IN_ADMIN', defined('IN_ADMIN'));
[1926]268
[2268]269  // allow plugins to add their own form data to content
270  trigger_action( 'load_profile_in_template', $userdata );
271 
[1753]272  $template->assign_var_from_handle('PROFILE_CONTENT', 'profile_content');
[854]273}
[362]274?>
Note: See TracBrowser for help on using the repository browser.