source: trunk/profile.php @ 1050

Last change on this file since 1050 was 1050, checked in by rvelices, 18 years ago

calendar redesign: monthly and weekly styles + list/calendar views for monthly

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.8 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: 2006-02-22 01:00:39 +0000 (Wed, 22 Feb 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1050 $
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');
35
36if ($user['is_the_guest'] and !$guest_allowed)
37{
38  echo '<div style="text-align:center;">'.$lang['only_members'].'<br />';
39  echo '<a href="./identification.php">'.$lang['ident_title'].'</a></div>';
40  exit();
41}
42
43$userdata = $user;
44
45//------------------------------------------------------ update & customization
46$errors = array();
47if (isset($_POST['validate']))
48{
49  $int_pattern = '/^\d+$/';
50  if (empty($_POST['nb_image_line'])
51      or (!preg_match($int_pattern, $_POST['nb_image_line'])))
52  {
53    array_push($errors, $lang['nb_image_line_error']);
54  }
55
56  if (empty($_POST['nb_line_page'])
57      or (!preg_match($int_pattern, $_POST['nb_line_page'])))
58  {
59    array_push($errors, $lang['nb_line_page_error']);
60  }
61 
62  if ($_POST['maxwidth'] != ''
63      and (!preg_match($int_pattern, $_POST['maxwidth'])
64           or $_POST['maxwidth'] < 50))
65  {
66    array_push($errors, $lang['maxwidth_error']);
67  }
68  if ($_POST['maxheight']
69       and (!preg_match($int_pattern, $_POST['maxheight'])
70             or $_POST['maxheight'] < 50))
71  {
72    array_push($errors, $lang['maxheight_error']);
73  }
74  // periods must be integer values, they represents number of days
75  if (!preg_match($int_pattern, $_POST['recent_period'])
76      or $_POST['recent_period'] <= 0)
77  {
78    array_push($errors, $lang['periods_error']);
79  }
80
81  $mail_error = validate_mail_address($_POST['mail_address']);
82  if (!empty($mail_error))
83  {
84    array_push($errors, $mail_error);
85  }
86   
87  if (!empty($_POST['use_new_pwd']))
88  {
89    // password must be the same as its confirmation
90    if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
91    {
92      array_push($errors,
93                 l10n('New password confirmation does not correspond'));
94    }
95   
96    // changing password requires old password
97    $query = '
98SELECT '.$conf['user_fields']['password'].' AS password
99  FROM '.USERS_TABLE.'
100  WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\'
101;';
102    list($current_password) = mysql_fetch_row(pwg_query($query));
103   
104    if ($conf['pass_convert']($_POST['password']) != $current_password)
105    {
106      array_push($errors, l10n('Current password is wrong'));
107    }
108  }
109 
110  if (count($errors) == 0)
111  {
112    // mass_updates function
113    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
114   
115    // update common user informations
116    $fields = array($conf['user_fields']['email']);
117
118    $data = array();
119    $data{$conf['user_fields']['id']} = $_POST['userid'];
120    $data{$conf['user_fields']['email']} = $_POST['mail_address'];
121
122    // password is updated only if filled
123    if (!empty($_POST['use_new_pwd']))
124    {
125      array_push($fields, $conf['user_fields']['password']);
126      // password is encrpyted with function $conf['pass_convert']
127      $data{$conf['user_fields']['password']} =
128        $conf['pass_convert']($_POST['use_new_pwd']);
129    }
130    mass_updates(USERS_TABLE,
131                 array('primary' => array($conf['user_fields']['id']),
132                       'update' => $fields),
133                 array($data));
134   
135    // update user "additional" informations (specific to PhpWebGallery)
136    $fields = array(
137      'nb_image_line', 'nb_line_page', 'language', 'maxwidth', 'maxheight',
138      'expand', 'show_nb_comments', 'recent_period', 'template'
139      );
140   
141    $data = array();
142    $data['user_id'] = $_POST['userid'];
143   
144    foreach ($fields as $field)
145    {
146      if (isset($_POST[$field]))
147      {
148        $data[$field] = $_POST[$field];
149      }
150    }
151    mass_updates(USER_INFOS_TABLE,
152                 array('primary' => array('user_id'), 'update' => $fields),
153                 array($data));
154   
155    // redirection
156    $url = PHPWG_ROOT_PATH.'category.php?'.$_SERVER['QUERY_STRING'];
157    redirect($url);
158  }
159}
160// +-----------------------------------------------------------------------+
161// |                       page header and options                         |
162// +-----------------------------------------------------------------------+
163
164$title= $lang['customize_page_title'];
165$page['body_id'] = 'theProfilePage';
166include(PHPWG_ROOT_PATH.'include/page_header.php');
167
168$url_action = PHPWG_ROOT_PATH.'profile.php';
169
170//----------------------------------------------------- template initialization
171$template->set_filenames(array('profile_body'=>'profile.tpl'));
172
173$expand = ($userdata['expand'] == 'true') ? 'EXPAND_TREE_YES':'EXPAND_TREE_NO';
174 
175$nb_comments =
176($userdata['show_nb_comments'] == 'true') ? 'NB_COMMENTS_YES':'NB_COMMENTS_NO';
177 
178$template->assign_vars(
179  array(
180    'USERNAME'=>$userdata['username'],
181    'USERID'=>$userdata['id'],
182    'EMAIL'=>@$userdata['email'],
183    'NB_IMAGE_LINE'=>$userdata['nb_image_line'],
184    'NB_ROW_PAGE'=>$userdata['nb_line_page'],
185    'RECENT_PERIOD'=>$userdata['recent_period'],
186    'MAXWIDTH'=>@$userdata['maxwidth'],
187    'MAXHEIGHT'=>@$userdata['maxheight'],
188   
189    $expand=>'checked="checked"',
190    $nb_comments=>'checked="checked"',
191   
192    'L_TITLE' => $lang['customize_title'],
193    'L_REGISTRATION_INFO' => $lang['register_title'],
194    'L_PREFERENCES' => $lang['preferences'],
195    'L_USERNAME' => $lang['login'],
196    'L_EMAIL' => $lang['mail_address'],
197    'L_CURRENT_PASSWORD' => $lang['password'],
198    'L_CURRENT_PASSWORD_HINT' => $lang['password_hint'],
199    'L_NEW_PASSWORD' =>  $lang['new_password'],
200    'L_NEW_PASSWORD_HINT' => $lang['new_password_hint'],
201    'L_CONFIRM_PASSWORD' =>  $lang['reg_confirm'],
202    'L_CONFIRM_PASSWORD_HINT' => $lang['confirm_password_hint'],
203    'L_LANG_SELECT'=>$lang['language'],
204    'L_NB_IMAGE_LINE'=>$lang['nb_image_per_row'],
205    'L_NB_ROW_PAGE'=>$lang['nb_row_per_page'],
206    'L_STYLE_SELECT'=>$lang['theme'],
207    'L_RECENT_PERIOD'=>$lang['recent_period'],
208    'L_EXPAND_TREE'=>$lang['auto_expand'],
209    'L_NB_COMMENTS'=>$lang['show_nb_comments'],
210    'L_MAXWIDTH'=>$lang['maxwidth'],
211    'L_MAXHEIGHT'=>$lang['maxheight'],
212    'L_YES'=>$lang['yes'],
213    'L_NO'=>$lang['no'],
214    'L_SUBMIT'=>$lang['submit'],
215    'L_RESET'=>$lang['reset'],
216    'L_RETURN' =>  $lang['home'],
217    'L_RETURN_HINT' =>  $lang['home_hint'],
218
219    'U_RETURN' => PHPWG_ROOT_PATH.'category.php',
220   
221    'F_ACTION'=>$url_action,
222    ));
223
224$blockname = 'template_option';
225
226foreach (get_pwg_themes() as $pwg_template)
227{
228  if (isset($_POST['submit']))
229  {
230    $selected = $_POST['template']==$pwg_template ? 'selected="selected"' : '';
231  }
232  else if ($userdata['template'].'/'.$userdata['theme'] == $pwg_template)
233  {
234    $selected = 'selected="selected"';
235  }
236  else
237  {
238    $selected = '';
239  }
240 
241  $template->assign_block_vars(
242    $blockname,
243    array(
244      'VALUE'=> $pwg_template,
245      'CONTENT' => $pwg_template,
246      'SELECTED' => $selected
247      ));
248}
249
250$blockname = 'language_option';
251
252foreach (get_languages() as $language_code => $language_name)
253{
254  if (isset($_POST['submit']))
255  {
256    $selected = $_POST['language']==$language_code ? 'selected="selected"':'';
257  }
258  else if ($userdata['language'] == $language_code)
259  {
260    $selected = 'selected="selected"';
261  }
262  else
263  {
264    $selected = '';
265  }
266 
267  $template->assign_block_vars(
268    $blockname,
269    array(
270      'VALUE'=> $language_code,
271      'CONTENT' => $language_name,
272      'SELECTED' => $selected
273      ));
274}
275
276// +-----------------------------------------------------------------------+
277// |                             errors display                            |
278// +-----------------------------------------------------------------------+
279if (count($errors) != 0)
280{
281  $template->assign_block_vars('errors',array());
282  foreach ($errors as $error)
283  {
284    $template->assign_block_vars('errors.error', array('ERROR'=>$error));
285  }
286}
287// +-----------------------------------------------------------------------+
288// |                           html code display                           |
289// +-----------------------------------------------------------------------+
290$template->assign_block_vars('profile',array());
291$template->parse('profile_body');
292include(PHPWG_ROOT_PATH.'include/page_tail.php');
293?>
Note: See TracBrowser for help on using the repository browser.