source: trunk/profile.php @ 2297

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 10.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      Piwigo Team                  http://piwigo.org |
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// +-----------------------------------------------------------------------+
23// +-----------------------------------------------------------------------+
24// | PhpWebGallery - a PHP based picture gallery                           |
25// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
26// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
27// +-----------------------------------------------------------------------+
28// | file          : $Id: profile.php 2297 2008-04-04 22:57:23Z plg $
29// | last update   : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $
30// | last modifier : $Author: plg $
31// | revision      : $Revision: 2297 $
32// +-----------------------------------------------------------------------+
33// | This program is free software; you can redistribute it and/or modify  |
34// | it under the terms of the GNU General Public License as published by  |
35// | the Free Software Foundation                                          |
36// |                                                                       |
37// | This program is distributed in the hope that it will be useful, but   |
38// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
39// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
40// | General Public License for more details.                              |
41// |                                                                       |
42// | You should have received a copy of the GNU General Public License     |
43// | along with this program; if not, write to the Free Software           |
44// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
45// | USA.                                                                  |
46// +-----------------------------------------------------------------------+
47
48// customize appearance of the site for a user
49// +-----------------------------------------------------------------------+
50// |                           initialization                              |
51// +-----------------------------------------------------------------------+
52
53if (!defined('PHPWG_ROOT_PATH'))
54{//direct script access
55  define('PHPWG_ROOT_PATH','./');
56  include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
57
58  // +-----------------------------------------------------------------------+
59  // | Check Access and exit when user status is not ok                      |
60  // +-----------------------------------------------------------------------+
61  check_status(ACCESS_CLASSIC);
62
63  $userdata = $user;
64
65  trigger_action('loc_begin_profile');
66
67  save_profile_from_post($userdata, $errors);
68
69  $title= l10n('customize_page_title');
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  {
83    $template->assign('errors', $errors);
84  }
85  $template->set_filename('profile', 'profile.tpl');
86  trigger_action('loc_end_profile');
87  $template->parse('profile');
88  include(PHPWG_ROOT_PATH.'include/page_tail.php');
89}
90
91//------------------------------------------------------ update & customization
92function save_profile_from_post($userdata, &$errors)
93{
94  global $conf;
95  $errors = array();
96
97  if (!isset($_POST['validate']))
98  {
99    return false;
100  }
101
102  $special_user = in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id']));
103  if ($special_user)
104  {
105    unset($_POST['mail_address'],
106          $_POST['password'],
107          $_POST['use_new_pwd'],
108          $_POST['passwordConf']
109          );
110  }
111
112  $int_pattern = '/^\d+$/';
113  if (empty($_POST['nb_image_line'])
114      or (!preg_match($int_pattern, $_POST['nb_image_line'])))
115  {
116    $errors[] = l10n('nb_image_line_error');
117  }
118
119  if (empty($_POST['nb_line_page'])
120      or (!preg_match($int_pattern, $_POST['nb_line_page'])))
121  {
122    $errors[] = l10n('nb_line_page_error');
123  }
124
125  if ($_POST['maxwidth'] != ''
126      and (!preg_match($int_pattern, $_POST['maxwidth'])
127           or $_POST['maxwidth'] < 50))
128  {
129    $errors[] = l10n('maxwidth_error');
130  }
131  if ($_POST['maxheight']
132       and (!preg_match($int_pattern, $_POST['maxheight'])
133             or $_POST['maxheight'] < 50))
134  {
135    $errors[] = l10n('maxheight_error');
136  }
137  // periods must be integer values, they represents number of days
138  if (!preg_match($int_pattern, $_POST['recent_period'])
139      or $_POST['recent_period'] <= 0)
140  {
141    $errors[] = l10n('periods_error') ;
142  }
143
144  if (isset($_POST['mail_address']))
145  {
146    // if $_POST and $userdata have are same email
147    // validate_mail_address allows, however, to check email
148    $mail_error = validate_mail_address($userdata['id'], $_POST['mail_address']);
149    if (!empty($mail_error))
150    {
151      $errors[] = $mail_error;
152    }
153  }
154
155  if (!empty($_POST['use_new_pwd']))
156  {
157    // password must be the same as its confirmation
158    if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
159    {
160      $errors[] = l10n('New password confirmation does not correspond');
161    }
162
163    if ( !defined('IN_ADMIN') )
164    {// changing password requires old password
165      $query = '
166  SELECT '.$conf['user_fields']['password'].' AS password
167    FROM '.USERS_TABLE.'
168    WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\'
169  ;';
170      list($current_password) = mysql_fetch_row(pwg_query($query));
171 
172      if ($conf['pass_convert']($_POST['password']) != $current_password)
173      {
174        $errors[] = l10n('Current password is wrong');
175      }
176    }
177  }
178
179  if (count($errors) == 0)
180  {
181    // mass_updates function
182    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
183
184    if (isset($_POST['mail_address']))
185    {
186      // update common user informations
187      $fields = array($conf['user_fields']['email']);
188
189      $data = array();
190      $data{$conf['user_fields']['id']} = $userdata['id'];
191      $data{$conf['user_fields']['email']} = $_POST['mail_address'];
192
193      // password is updated only if filled
194      if (!empty($_POST['use_new_pwd']))
195      {
196        array_push($fields, $conf['user_fields']['password']);
197        // password is encrpyted with function $conf['pass_convert']
198        $data{$conf['user_fields']['password']} =
199          $conf['pass_convert']($_POST['use_new_pwd']);
200      }
201      mass_updates(USERS_TABLE,
202                   array('primary' => array($conf['user_fields']['id']),
203                         'update' => $fields),
204                   array($data));
205    }
206
207    // update user "additional" informations (specific to PhpWebGallery)
208    $fields = array(
209      'nb_image_line', 'nb_line_page', 'language', 'maxwidth', 'maxheight',
210      'expand', 'show_nb_comments', 'show_nb_hits', 'recent_period', 'template'
211      );
212
213    $data = array();
214    $data['user_id'] = $userdata['id'];
215
216    foreach ($fields as $field)
217    {
218      if (isset($_POST[$field]))
219      {
220        $data[$field] = $_POST[$field];
221      }
222    }
223    mass_updates(USER_INFOS_TABLE,
224                 array('primary' => array('user_id'), 'update' => $fields),
225                 array($data));
226
227    trigger_action( 'save_profile_from_post', $userdata['id'] );
228   
229    if (!empty($_POST['redirect']))
230    {
231      redirect($_POST['redirect']);
232    }
233  }
234  return true;
235}
236
237
238function load_profile_in_template($url_action, $url_redirect, $userdata)
239{
240  global $template, $conf;
241
242  $template->set_filename('profile_content', 'profile_content.tpl');
243
244  $template->assign('radio_options',
245    array(
246      'true' => l10n('Yes'),
247      'false' => l10n('No')));
248
249  $template->assign(
250    array(
251      'USERNAME'=>$userdata['username'],
252      'EMAIL'=>get_email_address_as_display_text(@$userdata['email']),
253      'NB_IMAGE_LINE'=>$userdata['nb_image_line'],
254      'NB_ROW_PAGE'=>$userdata['nb_line_page'],
255      'RECENT_PERIOD'=>$userdata['recent_period'],
256      'MAXWIDTH'=>@$userdata['maxwidth'],
257      'MAXHEIGHT'=>@$userdata['maxheight'],
258      'EXPAND' =>$userdata['expand'] ? 'true' : 'false',
259      'NB_COMMENTS'=>$userdata['show_nb_comments'] ? 'true' : 'false',
260      'NB_HITS'=>$userdata['show_nb_hits'] ? 'true' : 'false',
261      'REDIRECT' => $url_redirect,
262      'F_ACTION'=>$url_action,
263      ));
264
265  foreach (get_pwg_themes() as $pwg_template)
266  {
267    if (isset($_POST['submit'])
268      or $userdata['template'].'/'.$userdata['theme'] == $pwg_template)
269    {
270      $template->assign('template_selection', $pwg_template);
271    }
272    $template_options[$pwg_template] = $pwg_template;
273  }
274  $template->assign('template_options', $template_options);
275
276  foreach (get_languages() as $language_code => $language_name)
277  {
278    if (isset($_POST['submit']) or $userdata['language'] == $language_code)
279    {
280      $template->assign('language_selection', $language_code);
281    }
282    $language_options[$language_code] = $language_name;
283  }
284  $template->assign('language_options', $language_options);
285
286  $special_user = in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id']));
287  $template->assign('SPECIAL_USER', $special_user);
288  $template->assign('IN_ADMIN', defined('IN_ADMIN'));
289
290  // allow plugins to add their own form data to content
291  trigger_action( 'load_profile_in_template', $userdata );
292 
293  $template->assign_var_from_handle('PROFILE_CONTENT', 'profile_content');
294}
295?>
Note: See TracBrowser for help on using the repository browser.