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
RevLine 
[2]1<?php
[351]2// +-----------------------------------------------------------------------+
[593]3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
[675]5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
[351]6// +-----------------------------------------------------------------------+
[593]7// | branch        : BSF (Best So Far)
[351]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  |
[354]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.                                                                  |
[351]26// +-----------------------------------------------------------------------+
[2]27
28// customize appearance of the site for a user
[631]29// +-----------------------------------------------------------------------+
30// |                           initialization                              |
31// +-----------------------------------------------------------------------+
[808]32
33define('PHPWG_ROOT_PATH','./');
34include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
[1036]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
[808]43$userdata = $user;
44
[2]45//------------------------------------------------------ update & customization
[26]46$errors = array();
[808]47if (isset($_POST['validate']))
[2]48{
[26]49  $int_pattern = '/^\d+$/';
[1043]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  }
[662]61 
62  if ($_POST['maxwidth'] != ''
63      and (!preg_match($int_pattern, $_POST['maxwidth'])
64           or $_POST['maxwidth'] < 50))
[2]65  {
[662]66    array_push($errors, $lang['maxwidth_error']);
[2]67  }
[662]68  if ($_POST['maxheight']
69       and (!preg_match($int_pattern, $_POST['maxheight'])
70             or $_POST['maxheight'] < 50))
[2]71  {
[662]72    array_push($errors, $lang['maxheight_error']);
[2]73  }
[26]74  // periods must be integer values, they represents number of days
[452]75  if (!preg_match($int_pattern, $_POST['recent_period'])
76      or $_POST['recent_period'] <= 0)
[2]77  {
[662]78    array_push($errors, $lang['periods_error']);
[2]79  }
[662]80
[808]81  $mail_error = validate_mail_address($_POST['mail_address']);
82  if (!empty($mail_error))
[662]83  {
[808]84    array_push($errors, $mail_error);
[662]85  }
[808]86   
87  if (!empty($_POST['use_new_pwd']))
[630]88  {
[808]89    // password must be the same as its confirmation
90    if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
[631]91    {
[808]92      array_push($errors,
93                 l10n('New password confirmation does not correspond'));
[662]94    }
[808]95   
96    // changing password requires old password
97    $query = '
[902]98SELECT '.$conf['user_fields']['password'].' AS password
[662]99  FROM '.USERS_TABLE.'
[808]100  WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\'
[662]101;';
[808]102    list($current_password) = mysql_fetch_row(pwg_query($query));
103   
104    if ($conf['pass_convert']($_POST['password']) != $current_password)
[631]105    {
[808]106      array_push($errors, l10n('Current password is wrong'));
[631]107    }
108  }
[662]109 
110  if (count($errors) == 0)
[2]111  {
[808]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']);
[2]117
[808]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
[662]123    if (!empty($_POST['use_new_pwd']))
[2]124    {
[808]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']);
[2]129    }
[808]130    mass_updates(USERS_TABLE,
131                 array('primary' => array($conf['user_fields']['id']),
132                       'update' => $fields),
133                 array($data));
[631]134   
[808]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();
[1043]142    $data['user_id'] = $_POST['userid'];
[808]143   
144    foreach ($fields as $field)
[631]145    {
[808]146      if (isset($_POST[$field]))
[772]147      {
[1043]148        $data[$field] = $_POST[$field];
[772]149      }
[631]150    }
[808]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'];
[1004]157    redirect($url);
[2]158  }
159}
[631]160// +-----------------------------------------------------------------------+
161// |                       page header and options                         |
162// +-----------------------------------------------------------------------+
[850]163
[808]164$title= $lang['customize_page_title'];
[850]165$page['body_id'] = 'theProfilePage';
[808]166include(PHPWG_ROOT_PATH.'include/page_header.php');
167
168$url_action = PHPWG_ROOT_PATH.'profile.php';
[850]169
[2]170//----------------------------------------------------- template initialization
[662]171$template->set_filenames(array('profile_body'=>'profile.tpl'));
[393]172
[768]173$expand = ($userdata['expand'] == 'true') ? 'EXPAND_TREE_YES':'EXPAND_TREE_NO';
[741]174 
[768]175$nb_comments =
176($userdata['show_nb_comments'] == 'true') ? 'NB_COMMENTS_YES':'NB_COMMENTS_NO';
[662]177 
[768]178$template->assign_vars(
179  array(
180    'USERNAME'=>$userdata['username'],
181    'USERID'=>$userdata['id'],
[808]182    'EMAIL'=>@$userdata['email'],
[768]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'],
[808]217    'L_RETURN_HINT' =>  $lang['home_hint'],
218
[1004]219    'U_RETURN' => PHPWG_ROOT_PATH.'category.php',
[768]220   
[1004]221    'F_ACTION'=>$url_action,
[768]222    ));
[854]223
224$blockname = 'template_option';
225
[1050]226foreach (get_pwg_themes() as $pwg_template)
[854]227{
228  if (isset($_POST['submit']))
229  {
230    $selected = $_POST['template']==$pwg_template ? 'selected="selected"' : '';
231  }
[1020]232  else if ($userdata['template'].'/'.$userdata['theme'] == $pwg_template)
[854]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
[631]276// +-----------------------------------------------------------------------+
[741]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// +-----------------------------------------------------------------------+
[631]288// |                           html code display                           |
289// +-----------------------------------------------------------------------+
[808]290$template->assign_block_vars('profile',array());
291$template->parse('profile_body');
292include(PHPWG_ROOT_PATH.'include/page_tail.php');
[362]293?>
Note: See TracBrowser for help on using the repository browser.