source: branches/2.0/profile.php @ 3123

Last change on this file since 3123 was 3046, checked in by plg, 15 years ago

Administration: happy new year 2009, all PHP headers updated.

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