source: trunk/profile.php @ 1734

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

very small improvements:

  • mass_inserts does not requires keys to start at 0
  • recent_cats categories are sorted by global_rank (consistency)
  • removed warning from page_header.php (when included from redirect)
  • added 2 template functions for plugins (get_var and concat_var)
  • removed unused code from profile.php
  • changed css width for tag selection (search page) from 55em to almost 100%
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 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 |
[1719]5// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
[351]6// +-----------------------------------------------------------------------+
[593]7// | branch        : BSF (Best So Far)
[1719]8// | file          : $Id: profile.php 1719 2007-01-13 03:13:40Z rvelices $
[351]9// | last update   : $Date: 2007-01-13 03:13:40 +0000 (Sat, 13 Jan 2007) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1719 $
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
[1072]36// +-----------------------------------------------------------------------+
37// | Check Access and exit when user status is not ok                      |
38// +-----------------------------------------------------------------------+
39check_status(ACCESS_CLASSIC);
40
[808]41$userdata = $user;
42
[2]43//------------------------------------------------------ update & customization
[26]44$errors = array();
[808]45if (isset($_POST['validate']))
[2]46{
[26]47  $int_pattern = '/^\d+$/';
[1043]48  if (empty($_POST['nb_image_line'])
49      or (!preg_match($int_pattern, $_POST['nb_image_line'])))
50  {
51    array_push($errors, $lang['nb_image_line_error']);
52  }
53
54  if (empty($_POST['nb_line_page'])
55      or (!preg_match($int_pattern, $_POST['nb_line_page'])))
56  {
57    array_push($errors, $lang['nb_line_page_error']);
58  }
[1620]59
[662]60  if ($_POST['maxwidth'] != ''
61      and (!preg_match($int_pattern, $_POST['maxwidth'])
62           or $_POST['maxwidth'] < 50))
[2]63  {
[662]64    array_push($errors, $lang['maxwidth_error']);
[2]65  }
[662]66  if ($_POST['maxheight']
67       and (!preg_match($int_pattern, $_POST['maxheight'])
68             or $_POST['maxheight'] < 50))
[2]69  {
[662]70    array_push($errors, $lang['maxheight_error']);
[2]71  }
[26]72  // periods must be integer values, they represents number of days
[452]73  if (!preg_match($int_pattern, $_POST['recent_period'])
74      or $_POST['recent_period'] <= 0)
[2]75  {
[662]76    array_push($errors, $lang['periods_error']);
[2]77  }
[662]78
[808]79  $mail_error = validate_mail_address($_POST['mail_address']);
80  if (!empty($mail_error))
[662]81  {
[808]82    array_push($errors, $mail_error);
[662]83  }
[1620]84
[808]85  if (!empty($_POST['use_new_pwd']))
[630]86  {
[808]87    // password must be the same as its confirmation
88    if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
[631]89    {
[808]90      array_push($errors,
91                 l10n('New password confirmation does not correspond'));
[662]92    }
[1620]93
[808]94    // changing password requires old password
95    $query = '
[902]96SELECT '.$conf['user_fields']['password'].' AS password
[662]97  FROM '.USERS_TABLE.'
[808]98  WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\'
[662]99;';
[808]100    list($current_password) = mysql_fetch_row(pwg_query($query));
[1620]101
[808]102    if ($conf['pass_convert']($_POST['password']) != $current_password)
[631]103    {
[808]104      array_push($errors, l10n('Current password is wrong'));
[631]105    }
106  }
[1620]107
[662]108  if (count($errors) == 0)
[2]109  {
[808]110    // mass_updates function
111    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
[1620]112
[808]113    // update common user informations
114    $fields = array($conf['user_fields']['email']);
[2]115
[808]116    $data = array();
117    $data{$conf['user_fields']['id']} = $_POST['userid'];
118    $data{$conf['user_fields']['email']} = $_POST['mail_address'];
119
120    // password is updated only if filled
[662]121    if (!empty($_POST['use_new_pwd']))
[2]122    {
[808]123      array_push($fields, $conf['user_fields']['password']);
124      // password is encrpyted with function $conf['pass_convert']
125      $data{$conf['user_fields']['password']} =
126        $conf['pass_convert']($_POST['use_new_pwd']);
[2]127    }
[808]128    mass_updates(USERS_TABLE,
129                 array('primary' => array($conf['user_fields']['id']),
130                       'update' => $fields),
131                 array($data));
[1620]132
[808]133    // update user "additional" informations (specific to PhpWebGallery)
134    $fields = array(
135      'nb_image_line', 'nb_line_page', 'language', 'maxwidth', 'maxheight',
136      'expand', 'show_nb_comments', 'recent_period', 'template'
137      );
[1620]138
[808]139    $data = array();
[1043]140    $data['user_id'] = $_POST['userid'];
[1620]141
[808]142    foreach ($fields as $field)
[631]143    {
[808]144      if (isset($_POST[$field]))
[772]145      {
[1043]146        $data[$field] = $_POST[$field];
[772]147      }
[631]148    }
[808]149    mass_updates(USER_INFOS_TABLE,
150                 array('primary' => array('user_id'), 'update' => $fields),
151                 array($data));
[1620]152
[808]153    // redirection
[1082]154    redirect(make_index_url());
[2]155  }
156}
[631]157// +-----------------------------------------------------------------------+
158// |                       page header and options                         |
159// +-----------------------------------------------------------------------+
[850]160
[808]161$title= $lang['customize_page_title'];
[850]162$page['body_id'] = 'theProfilePage';
[808]163include(PHPWG_ROOT_PATH.'include/page_header.php');
164
165$url_action = PHPWG_ROOT_PATH.'profile.php';
[850]166
[2]167//----------------------------------------------------- template initialization
[662]168$template->set_filenames(array('profile_body'=>'profile.tpl'));
[393]169
[768]170$expand = ($userdata['expand'] == 'true') ? 'EXPAND_TREE_YES':'EXPAND_TREE_NO';
[1620]171
[768]172$nb_comments =
173($userdata['show_nb_comments'] == 'true') ? 'NB_COMMENTS_YES':'NB_COMMENTS_NO';
[1620]174
[768]175$template->assign_vars(
176  array(
177    'USERNAME'=>$userdata['username'],
178    'USERID'=>$userdata['id'],
[808]179    'EMAIL'=>@$userdata['email'],
[768]180    'NB_IMAGE_LINE'=>$userdata['nb_image_line'],
181    'NB_ROW_PAGE'=>$userdata['nb_line_page'],
182    'RECENT_PERIOD'=>$userdata['recent_period'],
183    'MAXWIDTH'=>@$userdata['maxwidth'],
184    'MAXHEIGHT'=>@$userdata['maxheight'],
[1620]185
[768]186    $expand=>'checked="checked"',
187    $nb_comments=>'checked="checked"',
[808]188
[1082]189    'U_RETURN' => make_index_url(),
[1620]190
[1004]191    'F_ACTION'=>$url_action,
[768]192    ));
[854]193
194$blockname = 'template_option';
195
[1050]196foreach (get_pwg_themes() as $pwg_template)
[854]197{
198  if (isset($_POST['submit']))
199  {
200    $selected = $_POST['template']==$pwg_template ? 'selected="selected"' : '';
201  }
[1020]202  else if ($userdata['template'].'/'.$userdata['theme'] == $pwg_template)
[854]203  {
204    $selected = 'selected="selected"';
205  }
206  else
207  {
208    $selected = '';
209  }
[1620]210
[854]211  $template->assign_block_vars(
212    $blockname,
213    array(
214      'VALUE'=> $pwg_template,
215      'CONTENT' => $pwg_template,
216      'SELECTED' => $selected
217      ));
218}
219
220$blockname = 'language_option';
221
222foreach (get_languages() as $language_code => $language_name)
223{
224  if (isset($_POST['submit']))
225  {
226    $selected = $_POST['language']==$language_code ? 'selected="selected"':'';
227  }
228  else if ($userdata['language'] == $language_code)
229  {
230    $selected = 'selected="selected"';
231  }
232  else
233  {
234    $selected = '';
235  }
[1620]236
[854]237  $template->assign_block_vars(
238    $blockname,
239    array(
240      'VALUE'=> $language_code,
241      'CONTENT' => $language_name,
242      'SELECTED' => $selected
243      ));
244}
245
[631]246// +-----------------------------------------------------------------------+
[741]247// |                             errors display                            |
248// +-----------------------------------------------------------------------+
249if (count($errors) != 0)
250{
251  $template->assign_block_vars('errors',array());
252  foreach ($errors as $error)
253  {
254    $template->assign_block_vars('errors.error', array('ERROR'=>$error));
255  }
256}
257// +-----------------------------------------------------------------------+
[631]258// |                           html code display                           |
259// +-----------------------------------------------------------------------+
[808]260$template->assign_block_vars('profile',array());
261$template->parse('profile_body');
262include(PHPWG_ROOT_PATH.'include/page_tail.php');
[362]263?>
Note: See TracBrowser for help on using the repository browser.