source: trunk/profile.php @ 6570

Last change on this file since 6570 was 6363, checked in by plg, 15 years ago

remove all svn:mergeinfo properties

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