source: trunk/profile.php @ 1719

Last change on this file since 1719 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
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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $Id: profile.php 1719 2007-01-13 03:13:40Z rvelices $
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  |
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
36// +-----------------------------------------------------------------------+
37// | Check Access and exit when user status is not ok                      |
38// +-----------------------------------------------------------------------+
39check_status(ACCESS_CLASSIC);
40
41$userdata = $user;
42
43//------------------------------------------------------ update & customization
44$errors = array();
45if (isset($_POST['validate']))
46{
47  $int_pattern = '/^\d+$/';
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  }
59
60  if ($_POST['maxwidth'] != ''
61      and (!preg_match($int_pattern, $_POST['maxwidth'])
62           or $_POST['maxwidth'] < 50))
63  {
64    array_push($errors, $lang['maxwidth_error']);
65  }
66  if ($_POST['maxheight']
67       and (!preg_match($int_pattern, $_POST['maxheight'])
68             or $_POST['maxheight'] < 50))
69  {
70    array_push($errors, $lang['maxheight_error']);
71  }
72  // periods must be integer values, they represents number of days
73  if (!preg_match($int_pattern, $_POST['recent_period'])
74      or $_POST['recent_period'] <= 0)
75  {
76    array_push($errors, $lang['periods_error']);
77  }
78
79  $mail_error = validate_mail_address($_POST['mail_address']);
80  if (!empty($mail_error))
81  {
82    array_push($errors, $mail_error);
83  }
84
85  if (!empty($_POST['use_new_pwd']))
86  {
87    // password must be the same as its confirmation
88    if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
89    {
90      array_push($errors,
91                 l10n('New password confirmation does not correspond'));
92    }
93
94    // changing password requires old password
95    $query = '
96SELECT '.$conf['user_fields']['password'].' AS password
97  FROM '.USERS_TABLE.'
98  WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\'
99;';
100    list($current_password) = mysql_fetch_row(pwg_query($query));
101
102    if ($conf['pass_convert']($_POST['password']) != $current_password)
103    {
104      array_push($errors, l10n('Current password is wrong'));
105    }
106  }
107
108  if (count($errors) == 0)
109  {
110    // mass_updates function
111    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
112
113    // update common user informations
114    $fields = array($conf['user_fields']['email']);
115
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
121    if (!empty($_POST['use_new_pwd']))
122    {
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']);
127    }
128    mass_updates(USERS_TABLE,
129                 array('primary' => array($conf['user_fields']['id']),
130                       'update' => $fields),
131                 array($data));
132
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      );
138
139    $data = array();
140    $data['user_id'] = $_POST['userid'];
141
142    foreach ($fields as $field)
143    {
144      if (isset($_POST[$field]))
145      {
146        $data[$field] = $_POST[$field];
147      }
148    }
149    mass_updates(USER_INFOS_TABLE,
150                 array('primary' => array('user_id'), 'update' => $fields),
151                 array($data));
152
153    // redirection
154    redirect(make_index_url());
155  }
156}
157// +-----------------------------------------------------------------------+
158// |                       page header and options                         |
159// +-----------------------------------------------------------------------+
160
161$title= $lang['customize_page_title'];
162$page['body_id'] = 'theProfilePage';
163include(PHPWG_ROOT_PATH.'include/page_header.php');
164
165$url_action = PHPWG_ROOT_PATH.'profile.php';
166
167//----------------------------------------------------- template initialization
168$template->set_filenames(array('profile_body'=>'profile.tpl'));
169
170$expand = ($userdata['expand'] == 'true') ? 'EXPAND_TREE_YES':'EXPAND_TREE_NO';
171
172$nb_comments =
173($userdata['show_nb_comments'] == 'true') ? 'NB_COMMENTS_YES':'NB_COMMENTS_NO';
174
175$template->assign_vars(
176  array(
177    'USERNAME'=>$userdata['username'],
178    'USERID'=>$userdata['id'],
179    'EMAIL'=>@$userdata['email'],
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'],
185
186    $expand=>'checked="checked"',
187    $nb_comments=>'checked="checked"',
188
189    'U_RETURN' => make_index_url(),
190
191    'F_ACTION'=>$url_action,
192    ));
193
194$blockname = 'template_option';
195
196foreach (get_pwg_themes() as $pwg_template)
197{
198  if (isset($_POST['submit']))
199  {
200    $selected = $_POST['template']==$pwg_template ? 'selected="selected"' : '';
201  }
202  else if ($userdata['template'].'/'.$userdata['theme'] == $pwg_template)
203  {
204    $selected = 'selected="selected"';
205  }
206  else
207  {
208    $selected = '';
209  }
210
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  }
236
237  $template->assign_block_vars(
238    $blockname,
239    array(
240      'VALUE'=> $language_code,
241      'CONTENT' => $language_name,
242      'SELECTED' => $selected
243      ));
244}
245
246// +-----------------------------------------------------------------------+
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// +-----------------------------------------------------------------------+
258// |                           html code display                           |
259// +-----------------------------------------------------------------------+
260$template->assign_block_vars('profile',array());
261$template->parse('profile_body');
262include(PHPWG_ROOT_PATH.'include/page_tail.php');
263?>
Note: See TracBrowser for help on using the repository browser.