source: trunk/profile.php @ 808

Last change on this file since 808 was 808, checked in by plg, 19 years ago
  • new : external authentication in another users table. Previous users table is divided between users (common properties with any web application) and user_infos (phpwebgallery specific informations). External table and fields can be configured.
  • modification : profile.php is not reachable through administration anymore (not useful).
  • modification : in profile.php, current password is mandatory only if user tries to change his password. Username can't be changed.
  • deletion : of obsolete functions get_user_restrictions, update_user_restrictions, get_user_all_restrictions, is_user_allowed, update_user
  • modification : user_forbidden table becomes user_cache so that not only restriction informations can be stored in this table.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-08-08 20:52:19 +0000 (Mon, 08 Aug 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 808 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28// customize appearance of the site for a user
29// +-----------------------------------------------------------------------+
30// |                           initialization                              |
31// +-----------------------------------------------------------------------+
32
33define('PHPWG_ROOT_PATH','./');
34include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
35check_login_authorization(false);
36$userdata = $user;
37
38//------------------------------------------------------ update & customization
39$errors = array();
40if (isset($_POST['validate']))
41{
42  $int_pattern = '/^\d+$/';
43 
44  if ($_POST['maxwidth'] != ''
45      and (!preg_match($int_pattern, $_POST['maxwidth'])
46           or $_POST['maxwidth'] < 50))
47  {
48    array_push($errors, $lang['maxwidth_error']);
49  }
50  if ($_POST['maxheight']
51       and (!preg_match($int_pattern, $_POST['maxheight'])
52             or $_POST['maxheight'] < 50))
53  {
54    array_push($errors, $lang['maxheight_error']);
55  }
56  // periods must be integer values, they represents number of days
57  if (!preg_match($int_pattern, $_POST['recent_period'])
58      or $_POST['recent_period'] <= 0)
59  {
60    array_push($errors, $lang['periods_error']);
61  }
62
63  $mail_error = validate_mail_address($_POST['mail_address']);
64  if (!empty($mail_error))
65  {
66    array_push($errors, $mail_error);
67  }
68   
69  if (!empty($_POST['use_new_pwd']))
70  {
71    // password must be the same as its confirmation
72    if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
73    {
74      array_push($errors,
75                 l10n('New password confirmation does not correspond'));
76    }
77   
78    // changing password requires old password
79    $query = '
80SELECT password
81  FROM '.USERS_TABLE.'
82  WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\'
83;';
84    list($current_password) = mysql_fetch_row(pwg_query($query));
85   
86    if ($conf['pass_convert']($_POST['password']) != $current_password)
87    {
88      array_push($errors, l10n('Current password is wrong'));
89    }
90  }
91 
92  if (count($errors) == 0)
93  {
94    // mass_updates function
95    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
96   
97    // update common user informations
98    $fields = array($conf['user_fields']['email']);
99
100    $data = array();
101    $data{$conf['user_fields']['id']} = $_POST['userid'];
102    $data{$conf['user_fields']['email']} = $_POST['mail_address'];
103
104    // password is updated only if filled
105    if (!empty($_POST['use_new_pwd']))
106    {
107      array_push($fields, $conf['user_fields']['password']);
108      // password is encrpyted with function $conf['pass_convert']
109      $data{$conf['user_fields']['password']} =
110        $conf['pass_convert']($_POST['use_new_pwd']);
111    }
112    mass_updates(USERS_TABLE,
113                 array('primary' => array($conf['user_fields']['id']),
114                       'update' => $fields),
115                 array($data));
116   
117    // update user "additional" informations (specific to PhpWebGallery)
118    $fields = array(
119      'nb_image_line', 'nb_line_page', 'language', 'maxwidth', 'maxheight',
120      'expand', 'show_nb_comments', 'recent_period', 'template'
121      );
122   
123    $data = array();
124    $data{'user_id'} = $_POST['userid'];
125   
126    foreach ($fields as $field)
127    {
128      if (isset($_POST[$field]))
129      {
130        $data{$field} = $_POST[$field];
131      }
132    }
133    mass_updates(USER_INFOS_TABLE,
134                 array('primary' => array('user_id'), 'update' => $fields),
135                 array($data));
136   
137    // redirection
138    $url = PHPWG_ROOT_PATH.'category.php?'.$_SERVER['QUERY_STRING'];
139    redirect(add_session_id($url));
140  }
141}
142// +-----------------------------------------------------------------------+
143// |                       page header and options                         |
144// +-----------------------------------------------------------------------+
145$title= $lang['customize_page_title'];
146include(PHPWG_ROOT_PATH.'include/page_header.php');
147
148$url_action = PHPWG_ROOT_PATH.'profile.php';
149//----------------------------------------------------- template initialization
150$template->set_filenames(array('profile_body'=>'profile.tpl'));
151
152$expand = ($userdata['expand'] == 'true') ? 'EXPAND_TREE_YES':'EXPAND_TREE_NO';
153 
154$nb_comments =
155($userdata['show_nb_comments'] == 'true') ? 'NB_COMMENTS_YES':'NB_COMMENTS_NO';
156 
157$template->assign_vars(
158  array(
159    'USERNAME'=>$userdata['username'],
160    'USERID'=>$userdata['id'],
161    'EMAIL'=>@$userdata['email'],
162    'LANG_SELECT'=>language_select($userdata['language'], 'language'),
163    'NB_IMAGE_LINE'=>$userdata['nb_image_line'],
164    'NB_ROW_PAGE'=>$userdata['nb_line_page'],
165    'STYLE_SELECT'=>style_select($userdata['template'], 'template'),
166    'RECENT_PERIOD'=>$userdata['recent_period'],
167    'MAXWIDTH'=>@$userdata['maxwidth'],
168    'MAXHEIGHT'=>@$userdata['maxheight'],
169   
170    $expand=>'checked="checked"',
171    $nb_comments=>'checked="checked"',
172   
173    'L_TITLE' => $lang['customize_title'],
174    'L_REGISTRATION_INFO' => $lang['register_title'],
175    'L_PREFERENCES' => $lang['preferences'],
176    'L_USERNAME' => $lang['login'],
177    'L_EMAIL' => $lang['mail_address'],
178    'L_CURRENT_PASSWORD' => $lang['password'],
179    'L_CURRENT_PASSWORD_HINT' => $lang['password_hint'],
180    'L_NEW_PASSWORD' =>  $lang['new_password'],
181    'L_NEW_PASSWORD_HINT' => $lang['new_password_hint'],
182    'L_CONFIRM_PASSWORD' =>  $lang['reg_confirm'],
183    'L_CONFIRM_PASSWORD_HINT' => $lang['confirm_password_hint'],
184    'L_LANG_SELECT'=>$lang['language'],
185    'L_NB_IMAGE_LINE'=>$lang['nb_image_per_row'],
186    'L_NB_ROW_PAGE'=>$lang['nb_row_per_page'],
187    'L_STYLE_SELECT'=>$lang['theme'],
188    'L_RECENT_PERIOD'=>$lang['recent_period'],
189    'L_EXPAND_TREE'=>$lang['auto_expand'],
190    'L_NB_COMMENTS'=>$lang['show_nb_comments'],
191    'L_MAXWIDTH'=>$lang['maxwidth'],
192    'L_MAXHEIGHT'=>$lang['maxheight'],
193    'L_YES'=>$lang['yes'],
194    'L_NO'=>$lang['no'],
195    'L_SUBMIT'=>$lang['submit'],
196    'L_RESET'=>$lang['reset'],
197    'L_RETURN' =>  $lang['home'],
198    'L_RETURN_HINT' =>  $lang['home_hint'],
199
200    'U_RETURN' => add_session_id(PHPWG_ROOT_PATH.'category.php'),
201   
202    'F_ACTION'=>add_session_id($url_action),
203    ));
204// +-----------------------------------------------------------------------+
205// |                             errors display                            |
206// +-----------------------------------------------------------------------+
207if (count($errors) != 0)
208{
209  $template->assign_block_vars('errors',array());
210  foreach ($errors as $error)
211  {
212    $template->assign_block_vars('errors.error', array('ERROR'=>$error));
213  }
214}
215// +-----------------------------------------------------------------------+
216// |                           html code display                           |
217// +-----------------------------------------------------------------------+
218$template->assign_block_vars('profile',array());
219$template->parse('profile_body');
220include(PHPWG_ROOT_PATH.'include/page_tail.php');
221?>
Note: See TracBrowser for help on using the repository browser.