source: trunk/profile.php @ 772

Last change on this file since 772 was 772, checked in by gweltas, 19 years ago

Bug 99 : javascript error in profile.php
Enhancement of the radio class under IE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-04-26 09:46:33 +0000 (Tue, 26 Apr 2005) $
10// | last modifier : $Author: gweltas $
11// | revision      : $Revision: 772 $
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$userdata = array();
33if (defined('IN_ADMIN') and IN_ADMIN and isset($_GET['user_id']))
34{
35  $userdata = getuserdata(intval($_GET['user_id']));
36}
37elseif (defined('IN_ADMIN') and (isset($_POST['validate'])) )
38{
39  $userdata = getuserdata(intval($_POST['userid']));
40}
41elseif (!defined('IN_ADMIN') or !IN_ADMIN)
42{
43  define('PHPWG_ROOT_PATH','./');
44  include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
45  check_login_authorization(false);
46  $userdata = $user;
47}
48//------------------------------------------------------ update & customization
49$infos = array('nb_image_line', 'nb_line_page', 'language',
50               'maxwidth', 'maxheight', 'expand', 'show_nb_comments',
51               'recent_period', 'template', 'mail_address');
52
53$errors = array();
54if (isset($_POST['username']) && !isset($_POST['reset']))
55{
56  $int_pattern = '/^\d+$/';
57 
58  if ($_POST['maxwidth'] != ''
59      and (!preg_match($int_pattern, $_POST['maxwidth'])
60           or $_POST['maxwidth'] < 50))
61  {
62    array_push($errors, $lang['maxwidth_error']);
63  }
64  if ($_POST['maxheight']
65       and (!preg_match($int_pattern, $_POST['maxheight'])
66             or $_POST['maxheight'] < 50))
67  {
68    array_push($errors, $lang['maxheight_error']);
69  }
70  // periods must be integer values, they represents number of days
71  if (!preg_match($int_pattern, $_POST['recent_period'])
72      or $_POST['recent_period'] <= 0)
73  {
74    array_push($errors, $lang['periods_error']);
75  }
76
77  // if mail_address has changed
78  if (!isset($userdata['mail_address']))
79  {
80    $userdata['mail_address'] = '';
81  }
82 
83  if ($_POST['mail_address'] != @$userdata['mail_address'])
84  {
85    if ($user['status'] == 'admin')
86    {
87      $mail_error = validate_mail_address($_POST['mail_address']);
88      if (!empty($mail_error))
89      {
90        array_push($errors, $mail_error);
91      }
92    }
93    else if (!empty($_POST['password']))
94    {
95      array_push($errors, $lang['reg_err_pass']);
96    }
97    else
98    {
99      // retrieving the encrypted password of the login submitted
100      $query = '
101SELECT password
102  FROM '.USERS_TABLE.'
103  WHERE id = \''.$userdata['id'].'\'
104;';
105      $row = mysql_fetch_array(pwg_query($query));
106      if ($row['password'] == md5($_POST['password']))
107      {
108        $mail_error = validate_mail_address($_POST['mail_address']);
109        if (!empty($mail_error))
110        {
111          array_push($errors, $mail_error);
112        }
113      }
114      else
115      {
116        array_push($errors, $lang['reg_err_pass']);
117      }
118    }
119  }
120 
121  // password must be the same as its confirmation
122  if (!empty($_POST['use_new_pwd'])
123      and $_POST['use_new_pwd'] != $_POST['passwordConf'])
124  {
125    array_push($errors, $lang['reg_err_pass']);
126  }
127 
128  // We check if we are in the admin level
129  if (isset($_POST['user_delete']))
130  {
131    if ($_POST['userid'] > 2) // gallery founder + guest
132    {
133      delete_user($_POST['userid']);
134    }
135    else
136    {
137      array_push($errors, $lang['user_err_modify']);
138    }
139  }
140       
141  // We check if we are in the admin level
142  if (isset($_POST['status']) and $_POST['status'] <> $userdata['status'])
143  {
144    if ($_POST['userid'] > 2) // gallery founder + guest
145    {
146      array_push($infos, 'status');
147    }
148    else
149    {
150      array_push($errors, $lang['user_err_modify']);
151    }
152  }
153 
154  if (count($errors) == 0)
155  {
156    $query = '
157UPDATE '.USERS_TABLE.'
158  SET ';
159    $is_first = true;
160    foreach ($infos as $i => $info)
161    {
162      if (!$is_first)
163      {
164        $query.= '
165    , ';
166      }
167      $is_first = false;
168     
169      $query.= $info;
170      $query.= ' = ';
171      if ($_POST[$info] == '')
172      {
173        $query.= 'NULL';
174      }
175      else
176      {
177        $query.= "'".$_POST[$info]."'";
178      }
179    }
180    $query.= '
181  WHERE id = '.$_POST['userid'].'
182;';
183    pwg_query($query);
184
185    if (!empty($_POST['use_new_pwd']))
186    {
187      $query = '
188UPDATE '.USERS_TABLE.'
189  SET password = \''.md5($_POST['use_new_pwd']).'\'
190  WHERE id = '.$_POST['userid'].'
191;';
192      pwg_query($query);
193    }
194   
195    // redirection
196    if (isset($_POST['validate']))
197    {
198      if (!defined('IN_ADMIN') or !IN_ADMIN)
199      {
200        $url = PHPWG_ROOT_PATH.'category.php?'.$_SERVER['QUERY_STRING'];
201        redirect(add_session_id($url));
202       }
203      else
204      {
205        redirect(add_session_id(PHPWG_ROOT_PATH.'admin.php?page=profile'));
206      }
207    }
208  }
209}
210// +-----------------------------------------------------------------------+
211// |                       page header and options                         |
212// +-----------------------------------------------------------------------+
213$url_action = PHPWG_ROOT_PATH;
214if (!defined('IN_ADMIN'))
215{
216  $title= $lang['customize_page_title'];
217  include(PHPWG_ROOT_PATH.'include/page_header.php');
218  $url_action .='profile.php';
219}
220else
221{
222  $url_action .='admin.php?page=profile';
223}
224//----------------------------------------------------- template initialization
225$template->set_filenames(array('profile_body'=>'profile.tpl'));
226
227$expand = ($userdata['expand'] == 'true') ? 'EXPAND_TREE_YES':'EXPAND_TREE_NO';
228 
229$nb_comments =
230($userdata['show_nb_comments'] == 'true') ? 'NB_COMMENTS_YES':'NB_COMMENTS_NO';
231 
232$template->assign_vars(
233  array(
234    'USERNAME'=>$userdata['username'],
235    'USERID'=>$userdata['id'],
236    'EMAIL'=>@$userdata['mail_address'],
237    'LANG_SELECT'=>language_select($userdata['language'], 'language'),
238    'NB_IMAGE_LINE'=>$userdata['nb_image_line'],
239    'NB_ROW_PAGE'=>$userdata['nb_line_page'],
240    'STYLE_SELECT'=>style_select($userdata['template'], 'template'),
241    'RECENT_PERIOD'=>$userdata['recent_period'],
242    'MAXWIDTH'=>@$userdata['maxwidth'],
243    'MAXHEIGHT'=>@$userdata['maxheight'],
244   
245    $expand=>'checked="checked"',
246    $nb_comments=>'checked="checked"',
247   
248    'L_TITLE' => $lang['customize_title'],
249    'L_REGISTRATION_INFO' => $lang['register_title'],
250    'L_PREFERENCES' => $lang['preferences'],
251    'L_USERNAME' => $lang['login'],
252    'L_EMAIL' => $lang['mail_address'],
253    'L_CURRENT_PASSWORD' => $lang['password'],
254    'L_CURRENT_PASSWORD_HINT' => $lang['password_hint'],
255    'L_NEW_PASSWORD' =>  $lang['new_password'],
256    'L_NEW_PASSWORD_HINT' => $lang['new_password_hint'],
257    'L_CONFIRM_PASSWORD' =>  $lang['reg_confirm'],
258    'L_CONFIRM_PASSWORD_HINT' => $lang['confirm_password_hint'],
259    'L_LANG_SELECT'=>$lang['language'],
260    'L_NB_IMAGE_LINE'=>$lang['nb_image_per_row'],
261    'L_NB_ROW_PAGE'=>$lang['nb_row_per_page'],
262    'L_STYLE_SELECT'=>$lang['theme'],
263    'L_RECENT_PERIOD'=>$lang['recent_period'],
264    'L_EXPAND_TREE'=>$lang['auto_expand'],
265    'L_NB_COMMENTS'=>$lang['show_nb_comments'],
266    'L_MAXWIDTH'=>$lang['maxwidth'],
267    'L_MAXHEIGHT'=>$lang['maxheight'],
268    'L_YES'=>$lang['yes'],
269    'L_NO'=>$lang['no'],
270    'L_SUBMIT'=>$lang['submit'],
271    'L_RESET'=>$lang['reset'],
272    'L_RETURN' =>  $lang['home'],
273    'L_RETURN_HINT' =>  $lang['home_hint'], 
274   
275    'F_ACTION'=>add_session_id($url_action),
276    ));
277
278if (!defined('IN_ADMIN') or !IN_ADMIN)
279{
280  $url_return = PHPWG_ROOT_PATH.'category.php?'.$_SERVER['QUERY_STRING'];
281  $template->assign_vars(array('U_RETURN' => add_session_id($url_return)));
282}
283//------------------------------------------------------------- user management
284if (defined('IN_ADMIN') and IN_ADMIN)
285{
286  $status_select = '<select name="status">';
287  $status_select .='<option value = "guest" ';
288  if ($userdata['status'] == 'guest')
289  {
290    $status_select .= 'selected="selected"';
291  }
292  $status_select .='>'.$lang['user_status_guest'] .'</option>';
293  $status_select .='<option value = "admin" ';
294  if ($userdata['status'] == 'admin')
295  {
296    $status_select .= 'selected="selected"';
297  }
298  $status_select .='>'.$lang['user_status_admin'] .'</option>';
299  $status_select .='</select>';
300  $template->assign_block_vars(
301    'admin',
302    array(
303      'L_ADMIN_USER'=>$lang['user_management'],
304      'L_STATUS'=>$lang['user_status'],
305      'L_DELETE'=>$lang['user_delete'],
306      'L_DELETE_HINT'=>$lang['user_delete_hint'],
307      'STATUS'=>$status_select
308      ));
309}
310// +-----------------------------------------------------------------------+
311// |                             errors display                            |
312// +-----------------------------------------------------------------------+
313if (count($errors) != 0)
314{
315  $template->assign_block_vars('errors',array());
316  foreach ($errors as $error)
317  {
318    $template->assign_block_vars('errors.error', array('ERROR'=>$error));
319  }
320}
321// +-----------------------------------------------------------------------+
322// |                           html code display                           |
323// +-----------------------------------------------------------------------+
324if (defined('IN_ADMIN') and IN_ADMIN)
325{
326  $template->assign_var_from_handle('ADMIN_CONTENT', 'profile_body');
327}
328else
329{
330  $template->assign_block_vars('profile',array());
331  $template->parse('profile_body');
332  include(PHPWG_ROOT_PATH.'include/page_tail.php');
333}
334?>
Note: See TracBrowser for help on using the repository browser.