source: trunk/profile.php @ 8611

Last change on this file since 8611 was 7995, checked in by rvelices, 14 years ago

trunk admin theme goes with combine_script instead of old style known_script

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