source: trunk/profile.php @ 2247

Revision 2247, 8.9 KB checked in by patdenice, 11 years ago (diff)

Register goes smarty.
Correction in profile.php (forgotten assign_var)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
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// | file          : $Id$
8// | last update   : $Date$
9// | last modifier : $Author$
10// | revision      : $Revision$
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27// customize appearance of the site for a user
28// +-----------------------------------------------------------------------+
29// |                           initialization                              |
30// +-----------------------------------------------------------------------+
31
32if (!defined('PHPWG_ROOT_PATH'))
33{//direct script access
34  define('PHPWG_ROOT_PATH','./');
35  include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
36
37  // +-----------------------------------------------------------------------+
38  // | Check Access and exit when user status is not ok                      |
39  // +-----------------------------------------------------------------------+
40  check_status(ACCESS_CLASSIC);
41
42  $userdata = $user;
43
44  trigger_action('loc_begin_profile');
45
46  save_profile_from_post($userdata, $errors);
47
48  $title= l10n('customize_page_title');
49  $page['body_id'] = 'theProfilePage';
50  include(PHPWG_ROOT_PATH.'include/page_header.php');
51
52  load_profile_in_template(
53    get_root_url().'profile.php', // action
54    make_index_url(), // for redirect
55    $userdata );
56
57  $template->assign('U_HOME', make_index_url());
58
59  // +-----------------------------------------------------------------------+
60  // |                             errors display                            |
61  // +-----------------------------------------------------------------------+
62  if (count($errors) != 0)
63  {
64    $template->assign('errors', $errors);
65  }
66  $template->set_filename('profile', 'profile.tpl');
67  trigger_action('loc_end_profile');
68  $template->parse('profile');
69  include(PHPWG_ROOT_PATH.'include/page_tail.php');
70}
71
72//------------------------------------------------------ update & customization
73function save_profile_from_post(&$userdata, &$errors)
74{
75  global $conf;
76  $errors = array();
77 
78  if (!isset($_POST['validate']))
79  {
80    return false;
81  }
82
83  $int_pattern = '/^\d+$/';
84  if (empty($_POST['nb_image_line'])
85      or (!preg_match($int_pattern, $_POST['nb_image_line'])))
86  {
87    $errors[] = l10n('nb_image_line_error');
88  }
89
90  if (empty($_POST['nb_line_page'])
91      or (!preg_match($int_pattern, $_POST['nb_line_page'])))
92  {
93    $errors[] = l10n('nb_line_page_error');
94  }
95
96  if ($_POST['maxwidth'] != ''
97      and (!preg_match($int_pattern, $_POST['maxwidth'])
98           or $_POST['maxwidth'] < 50))
99  {
100    $errors[] = l10n('maxwidth_error');
101  }
102  if ($_POST['maxheight']
103       and (!preg_match($int_pattern, $_POST['maxheight'])
104             or $_POST['maxheight'] < 50))
105  {
106    $errors[] = l10n('maxheight_error');
107  }
108  // periods must be integer values, they represents number of days
109  if (!preg_match($int_pattern, $_POST['recent_period'])
110      or $_POST['recent_period'] <= 0)
111  {
112    $errors[] = l10n('periods_error') ;
113  }
114
115  if (isset($_POST['mail_address']))
116  {
117    // if $_POST and $userdata have are same email
118    // validate_mail_address allows, however, to check email
119    $mail_error = validate_mail_address($userdata['id'], $_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    trigger_action( 'loc_user_profile_updated', $_POST['userid'] );
199   
200    if (!empty($_POST['redirect']))
201    {
202      redirect($_POST['redirect']);
203    }
204  }
205  return true;
206}
207
208
209function load_profile_in_template($url_action, $url_redirect, $userdata)
210{
211  global $template, $conf;
212
213  $template->set_filename('profile_content', 'profile_content.tpl');
214
215  $template->assign('radio_options',
216    array(
217      'true' => l10n('yes'),
218      'false' => l10n('no')));
219
220  $template->assign(
221    array(
222      'USERNAME'=>$userdata['username'],
223      'USERID'=>$userdata['id'],
224      'EMAIL'=>get_email_address_as_display_text(@$userdata['email']),
225      'NB_IMAGE_LINE'=>$userdata['nb_image_line'],
226      'NB_ROW_PAGE'=>$userdata['nb_line_page'],
227      'RECENT_PERIOD'=>$userdata['recent_period'],
228      'MAXWIDTH'=>@$userdata['maxwidth'],
229      'MAXHEIGHT'=>@$userdata['maxheight'],
230      'EXPAND' =>$userdata['expand'] ? 'true' : 'false',
231      'NB_COMMENTS'=>$userdata['show_nb_comments'] ? 'true' : 'false',
232      'NB_HITS'=>$userdata['show_nb_hits'] ? 'true' : 'false',
233      'REDIRECT' => $url_redirect,
234      'F_ACTION'=>$url_action,
235      ));
236
237  foreach (get_pwg_themes() as $pwg_template)
238  {
239    if (isset($_POST['submit'])
240      or $userdata['template'].'/'.$userdata['theme'] == $pwg_template)
241    {
242      $template->assign('template_selection', $pwg_template);
243    }
244    $template_options[$pwg_template] = $pwg_template;
245  }
246  $template->assign('template_options', $template_options);
247
248  foreach (get_languages() as $language_code => $language_name)
249  {
250    if (isset($_POST['submit']) or $userdata['language'] == $language_code)
251    {
252      $template->assign('language_selection', $language_code);
253    }
254    $language_options[$language_code] = $language_name;
255  }
256  $template->assign('language_options', $language_options);
257
258  if (!(in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id']))))
259  {
260    $template->assign('not_special_user', true);
261    $template->assign('in_admin', defined('IN_ADMIN'));
262  }
263
264  $template->assign_var_from_handle('PROFILE_CONTENT', 'profile_content');
265}
266?>
Note: See TracBrowser for help on using the repository browser.