source: trunk/profile.php @ 1926

Last change on this file since 1926 was 1926, checked in by rub, 17 years ago

Issue 578
User guest must be real user

Step 1: guest is a real user

On next commit, I finish installation and use of guest of user list and group

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $Id: profile.php 1926 2007-03-28 19:57:00Z rub $
9// | last update   : $Date: 2007-03-28 19:57:00 +0000 (Wed, 28 Mar 2007) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1926 $
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
33if (!defined('PHPWG_ROOT_PATH'))
34{//direct script access
35  define('PHPWG_ROOT_PATH','./');
36  include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
37
38  // +-----------------------------------------------------------------------+
39  // | Check Access and exit when user status is not ok                      |
40  // +-----------------------------------------------------------------------+
41  check_status(ACCESS_CLASSIC);
42
43  $userdata = $user;
44
45  save_profile_from_post($userdata, $errors);
46
47  $title= $lang['customize_page_title'];
48  $page['body_id'] = 'theProfilePage';
49  include(PHPWG_ROOT_PATH.'include/page_header.php');
50
51  load_profile_in_template(
52    get_root_url().'profile.php', // action
53    make_index_url(), // for redirect
54    $userdata );
55
56  $template->assign_var('U_HOME', make_index_url() );
57
58  // +-----------------------------------------------------------------------+
59  // |                             errors display                            |
60  // +-----------------------------------------------------------------------+
61  if (count($errors) != 0)
62  {
63    $template->assign_block_vars('errors',array());
64    foreach ($errors as $error)
65    {
66      $template->assign_block_vars('errors.error', array('ERROR'=>$error));
67    }
68  }
69  $template->set_filename('profile', 'profile.tpl');
70  $template->parse('profile');
71  include(PHPWG_ROOT_PATH.'include/page_tail.php');
72}
73
74//------------------------------------------------------ update & customization
75function save_profile_from_post(&$userdata, &$errors)
76{
77  global $conf;
78  $errors = array();
79 
80  if (!isset($_POST['validate']))
81  {
82    return false;
83  }
84
85  $int_pattern = '/^\d+$/';
86  if (empty($_POST['nb_image_line'])
87      or (!preg_match($int_pattern, $_POST['nb_image_line'])))
88  {
89    $errors[] = l10n('nb_image_line_error');
90  }
91
92  if (empty($_POST['nb_line_page'])
93      or (!preg_match($int_pattern, $_POST['nb_line_page'])))
94  {
95    $errors[] = l10n('nb_line_page_error');
96  }
97
98  if ($_POST['maxwidth'] != ''
99      and (!preg_match($int_pattern, $_POST['maxwidth'])
100           or $_POST['maxwidth'] < 50))
101  {
102    $errors[] = l10n('maxwidth_error');
103  }
104  if ($_POST['maxheight']
105       and (!preg_match($int_pattern, $_POST['maxheight'])
106             or $_POST['maxheight'] < 50))
107  {
108    $errors[] = l10n('maxheight_error');
109  }
110  // periods must be integer values, they represents number of days
111  if (!preg_match($int_pattern, $_POST['recent_period'])
112      or $_POST['recent_period'] <= 0)
113  {
114    $errors[] = l10n('periods_error') ;
115  }
116
117  if (isset($_POST['mail_address']))
118  {
119    $mail_error = validate_mail_address($_POST['mail_address']);
120    if (!empty($mail_error))
121    {
122      $errors[] = $mail_error;
123    }
124  }
125
126  if (!empty($_POST['use_new_pwd']))
127  {
128    // password must be the same as its confirmation
129    if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
130    {
131      $errors[] = l10n('New password confirmation does not correspond');
132    }
133
134    if ( !defined('IN_ADMIN') )
135    {// changing password requires old password
136      $query = '
137  SELECT '.$conf['user_fields']['password'].' AS password
138    FROM '.USERS_TABLE.'
139    WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\'
140  ;';
141      list($current_password) = mysql_fetch_row(pwg_query($query));
142 
143      if ($conf['pass_convert']($_POST['password']) != $current_password)
144      {
145        $errors[] = l10n('Current password is wrong');
146      }
147    }
148  }
149
150  if (count($errors) == 0)
151  {
152    // mass_updates function
153    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
154
155    if (isset($_POST['mail_address']))
156    {
157      // update common user informations
158      $fields = array($conf['user_fields']['email']);
159
160      $data = array();
161      $data{$conf['user_fields']['id']} = $_POST['userid'];
162      $data{$conf['user_fields']['email']} = $_POST['mail_address'];
163
164      // password is updated only if filled
165      if (!empty($_POST['use_new_pwd']))
166      {
167        array_push($fields, $conf['user_fields']['password']);
168        // password is encrpyted with function $conf['pass_convert']
169        $data{$conf['user_fields']['password']} =
170          $conf['pass_convert']($_POST['use_new_pwd']);
171      }
172      mass_updates(USERS_TABLE,
173                   array('primary' => array($conf['user_fields']['id']),
174                         'update' => $fields),
175                   array($data));
176    }
177
178    // update user "additional" informations (specific to PhpWebGallery)
179    $fields = array(
180      'nb_image_line', 'nb_line_page', 'language', 'maxwidth', 'maxheight',
181      'expand', 'show_nb_comments', 'show_nb_hits', 'recent_period', 'template'
182      );
183
184    $data = array();
185    $data['user_id'] = $_POST['userid'];
186
187    foreach ($fields as $field)
188    {
189      if (isset($_POST[$field]))
190      {
191        $data[$field] = $_POST[$field];
192      }
193    }
194    mass_updates(USER_INFOS_TABLE,
195                 array('primary' => array('user_id'), 'update' => $fields),
196                 array($data));
197
198    // redirection
199    if (!empty($_POST['redirect']))
200    {
201      redirect($_POST['redirect']);
202    }
203  }
204  return true;
205}
206
207
208function load_profile_in_template($url_action, $url_redirect, $userdata)
209{
210  global $template;
211
212  $template->set_filename('profile_content', 'profile_content.tpl');
213
214  $expand = ($userdata['expand'] == 'true') ? 
215            'EXPAND_TREE_YES':'EXPAND_TREE_NO';
216
217  $nb_comments =
218    ($userdata['show_nb_comments'] == 'true') ? 
219               'NB_COMMENTS_YES':'NB_COMMENTS_NO';
220
221  $nb_hits =
222    ($userdata['show_nb_hits'] == 'true') ? 
223               'NB_HITS_YES':'NB_HITS_NO';
224
225  $template->assign_vars(
226    array(
227      'USERNAME'=>$userdata['username'],
228      'USERID'=>$userdata['id'],
229      'EMAIL'=>@$userdata['email'],
230      'NB_IMAGE_LINE'=>$userdata['nb_image_line'],
231      'NB_ROW_PAGE'=>$userdata['nb_line_page'],
232      'RECENT_PERIOD'=>$userdata['recent_period'],
233      'MAXWIDTH'=>@$userdata['maxwidth'],
234      'MAXHEIGHT'=>@$userdata['maxheight'],
235 
236      $expand=>'checked="checked"',
237      $nb_comments=>'checked="checked"',
238      $nb_hits=>'checked="checked"',
239 
240      'REDIRECT' => $url_redirect,
241 
242      'F_ACTION'=>$url_action,
243      ));
244
245  $blockname = 'template_option';
246
247  foreach (get_pwg_themes() as $pwg_template)
248  {
249    if (isset($_POST['submit']))
250    {
251      $selected = $_POST['template']==$pwg_template ? 'selected="selected"' : '';
252    }
253    else if ($userdata['template'].'/'.$userdata['theme'] == $pwg_template)
254    {
255      $selected = 'selected="selected"';
256    }
257    else
258    {
259      $selected = '';
260    }
261 
262    $template->assign_block_vars(
263      $blockname,
264      array(
265        'VALUE'=> $pwg_template,
266        'CONTENT' => $pwg_template,
267        'SELECTED' => $selected
268        ));
269  }
270
271  $blockname = 'language_option';
272
273  foreach (get_languages() as $language_code => $language_name)
274  {
275    if (isset($_POST['submit']))
276    {
277      $selected = $_POST['language']==$language_code ? 'selected="selected"':'';
278    }
279    else if ($userdata['language'] == $language_code)
280    {
281      $selected = 'selected="selected"';
282    }
283    else
284    {
285      $selected = '';
286    }
287 
288    $template->assign_block_vars(
289      $blockname,
290      array(
291        'VALUE'=> $language_code,
292        'CONTENT' => $language_name,
293        'SELECTED' => $selected
294        ));
295  }
296
297  if (!($userdata['is_the_guest'] or $userdata['is_the_default']))
298  {
299    $template->assign_block_vars('not_special_user', array());
300    if ( !defined('IN_ADMIN') )
301    {
302      $template->assign_block_vars( 'not_special_user.not_admin', array() );
303    }
304  }
305
306  $template->assign_var_from_handle('PROFILE_CONTENT', 'profile_content');
307}
308?>
Note: See TracBrowser for help on using the repository browser.