source: trunk/profile.php @ 768

Last change on this file since 768 was 768, checked in by plg, 19 years ago
  • profile.php is no longer used for listing users : admin/user_list.php comes back (as in 1.3 branch)
  • user list updated : ability to filter list on username
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.5 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-25 21:35:10 +0000 (Mon, 25 Apr 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 768 $
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['submit']))
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['submit']))
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 (!defined('IN_ADMIN') or !IN_ADMIN)
197    {
198      $url = PHPWG_ROOT_PATH.'category.php?'.$_SERVER['QUERY_STRING'];
199      redirect(add_session_id($url));
200    }
201    else
202    {
203      redirect(add_session_id(PHPWG_ROOT_PATH.'admin.php?page=profile'));
204    }
205  }
206}
207// +-----------------------------------------------------------------------+
208// |                       page header and options                         |
209// +-----------------------------------------------------------------------+
210$url_action = PHPWG_ROOT_PATH;
211if (!defined('IN_ADMIN'))
212{
213  $title= $lang['customize_page_title'];
214  include(PHPWG_ROOT_PATH.'include/page_header.php');
215  $url_action .='profile.php';
216}
217else
218{
219  $url_action .='admin.php?page=profile';
220}
221//----------------------------------------------------- template initialization
222$template->set_filenames(array('profile_body'=>'profile.tpl'));
223
224$expand = ($userdata['expand'] == 'true') ? 'EXPAND_TREE_YES':'EXPAND_TREE_NO';
225 
226$nb_comments =
227($userdata['show_nb_comments'] == 'true') ? 'NB_COMMENTS_YES':'NB_COMMENTS_NO';
228 
229$template->assign_vars(
230  array(
231    'USERNAME'=>$userdata['username'],
232    'USERID'=>$userdata['id'],
233    'EMAIL'=>@$userdata['mail_address'],
234    'LANG_SELECT'=>language_select($userdata['language'], 'language'),
235    'NB_IMAGE_LINE'=>$userdata['nb_image_line'],
236    'NB_ROW_PAGE'=>$userdata['nb_line_page'],
237    'STYLE_SELECT'=>style_select($userdata['template'], 'template'),
238    'RECENT_PERIOD'=>$userdata['recent_period'],
239    'MAXWIDTH'=>@$userdata['maxwidth'],
240    'MAXHEIGHT'=>@$userdata['maxheight'],
241   
242    $expand=>'checked="checked"',
243    $nb_comments=>'checked="checked"',
244   
245    'L_TITLE' => $lang['customize_title'],
246    'L_REGISTRATION_INFO' => $lang['register_title'],
247    'L_PREFERENCES' => $lang['preferences'],
248    'L_USERNAME' => $lang['login'],
249    'L_EMAIL' => $lang['mail_address'],
250    'L_CURRENT_PASSWORD' => $lang['password'],
251    'L_CURRENT_PASSWORD_HINT' => $lang['password_hint'],
252    'L_NEW_PASSWORD' =>  $lang['new_password'],
253    'L_NEW_PASSWORD_HINT' => $lang['new_password_hint'],
254    'L_CONFIRM_PASSWORD' =>  $lang['reg_confirm'],
255    'L_CONFIRM_PASSWORD_HINT' => $lang['confirm_password_hint'],
256    'L_LANG_SELECT'=>$lang['language'],
257    'L_NB_IMAGE_LINE'=>$lang['nb_image_per_row'],
258    'L_NB_ROW_PAGE'=>$lang['nb_row_per_page'],
259    'L_STYLE_SELECT'=>$lang['theme'],
260    'L_RECENT_PERIOD'=>$lang['recent_period'],
261    'L_EXPAND_TREE'=>$lang['auto_expand'],
262    'L_NB_COMMENTS'=>$lang['show_nb_comments'],
263    'L_MAXWIDTH'=>$lang['maxwidth'],
264    'L_MAXHEIGHT'=>$lang['maxheight'],
265    'L_YES'=>$lang['yes'],
266    'L_NO'=>$lang['no'],
267    'L_SUBMIT'=>$lang['submit'],
268    'L_RESET'=>$lang['reset'],
269    'L_RETURN' =>  $lang['home'],
270    'L_RETURN_HINT' =>  $lang['home_hint'], 
271   
272    'F_ACTION'=>add_session_id($url_action),
273    ));
274
275if (!defined('IN_ADMIN') or !IN_ADMIN)
276{
277  $url_return = PHPWG_ROOT_PATH.'category.php?'.$_SERVER['QUERY_STRING'];
278  $template->assign_vars(array('U_RETURN' => add_session_id($url_return)));
279}
280//------------------------------------------------------------- user management
281if (defined('IN_ADMIN') and IN_ADMIN)
282{
283  $status_select = '<select name="status">';
284  $status_select .='<option value = "guest" ';
285  if ($userdata['status'] == 'guest')
286  {
287    $status_select .= 'selected="selected"';
288  }
289  $status_select .='>'.$lang['user_status_guest'] .'</option>';
290  $status_select .='<option value = "admin" ';
291  if ($userdata['status'] == 'admin')
292  {
293    $status_select .= 'selected="selected"';
294  }
295  $status_select .='>'.$lang['user_status_admin'] .'</option>';
296  $status_select .='</select>';
297  $template->assign_block_vars(
298    'admin',
299    array(
300      'L_ADMIN_USER'=>$lang['user_management'],
301      'L_STATUS'=>$lang['user_status'],
302      'L_DELETE'=>$lang['user_delete'],
303      'L_DELETE_HINT'=>$lang['user_delete_hint'],
304      'STATUS'=>$status_select
305      ));
306}
307// +-----------------------------------------------------------------------+
308// |                             errors display                            |
309// +-----------------------------------------------------------------------+
310if (count($errors) != 0)
311{
312  $template->assign_block_vars('errors',array());
313  foreach ($errors as $error)
314  {
315    $template->assign_block_vars('errors.error', array('ERROR'=>$error));
316  }
317}
318// +-----------------------------------------------------------------------+
319// |                           html code display                           |
320// +-----------------------------------------------------------------------+
321if (defined('IN_ADMIN') and IN_ADMIN)
322{
323  $template->assign_var_from_handle('ADMIN_CONTENT', 'profile_body');
324}
325else
326{
327  $template->assign_block_vars('profile',array());
328  $template->parse('profile_body');
329  include(PHPWG_ROOT_PATH.'include/page_tail.php');
330}
331?>
Note: See TracBrowser for help on using the repository browser.