source: trunk/profile.php @ 630

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

Update of the user preferences panel.
Deletion of some PREFIX_TABLE occurences

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.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-2004 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-12-02 15:42:57 +0000 (Thu, 02 Dec 2004) $
10// | last modifier : $Author: gweltas $
11// | revision      : $Revision: 630 $
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//----------------------------------------------------------- include
30define('PHPWG_ROOT_PATH','./');
31include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
32//-------------------------------------------------- access authorization check
33check_login_authorization();
34if ( $user['is_the_guest'] )
35{
36  echo '<div style="text-align:center;">'.$lang['only_members'].'<br />';
37  echo '<a href="./identification.php">'.$lang['ident_title'].'</a></div>';
38  exit();
39}
40//------------------------------------------------------ update & customization
41$infos = array( 'nb_image_line', 'nb_line_page', 'language',
42                'maxwidth', 'maxheight', 'expand', 'show_nb_comments',
43                'recent_period', 'template', 'mail_address' );
44// mise à jour dans la base de données des valeurs
45// des paramètres pour l'utilisateur courant
46//    - on teste si chacune des variables est passée en argument à la page
47//    - ce qui signifie que l'on doit venir de la page de personnalisation
48$errors = array();
49if ( isset( $_POST['submit'] ) )
50{
51  $int_pattern = '/^\d+$/';
52  if ( $_POST['maxwidth'] != ''
53       and ( !preg_match( $int_pattern, $_POST['maxwidth'] )
54             or $_POST['maxwidth'] < 50 ) )
55  {
56    array_push( $errors, $lang['maxwidth_error'] );
57  }
58  if ( $_POST['maxheight']
59       and ( !preg_match( $int_pattern, $_POST['maxheight'] )
60             or $_POST['maxheight'] < 50 ) )
61  {
62    array_push( $errors, $lang['maxheight_error'] );
63  }
64  // periods must be integer values, they represents number of days
65  if (!preg_match($int_pattern, $_POST['recent_period'])
66      or $_POST['recent_period'] <= 0)
67  {
68    array_push( $errors, $lang['periods_error'] );
69  }
70       
71  if ( $_POST['mail_address']!= $user['mail_address'])
72  {
73    if (!empty($_POST['password']))
74                  array_push( $errors, $lang['reg_err_pass'] );
75                else
76                {
77                // retrieving the encrypted password of the login submitted
78    $query = 'SELECT password FROM '.USERS_TABLE.'
79              WHERE username = \''.$user['username'].'\';';
80    $row = mysql_fetch_array(pwg_query($query));
81    if ($row['password'] == md5($_POST['password']))
82    {
83      $mail_error = validate_mail_address( $_POST['mail_address'] );
84      if ( !empty($mail_error)) array_push( $errors, $mail_error );
85    }
86    else
87      array_push( $errors, $lang['reg_err_pass'] );
88          }
89  }
90 
91  // password must be the same as its confirmation
92  if ( isset( $_POST['use_new_pwd'] )
93       and $_POST['use_new_pwd'] != $_POST['passwordConf'] )
94    array_push( $errors, $lang['reg_err_pass'] );
95 
96  if ( count( $errors ) == 0 )
97  {
98    $query = 'UPDATE '.USERS_TABLE;
99    $query.= ' SET ';
100    foreach ( $infos as $i => $info ) {
101      if ( $i > 0 ) $query.= ',';
102      $query.= $info;
103      $query.= ' = ';
104      if ( $_POST[$info] == '' ) $query.= 'NULL';
105      else                       $query.= "'".$_POST[$info]."'";
106    }
107    $query.= ' WHERE id = '.$user['id'];
108    $query.= ';';
109    pwg_query( $query );
110
111    if ( isset( $_POST['use_new_pwd'] ) )
112    {
113      $query = 'UPDATE '.USERS_TABLE;
114      $query.= " SET password = '".md5( $_POST['use_new_pwd'] )."'";
115      $query.= ' WHERE id = '.$user['id'];
116      $query.= ';';
117      pwg_query( $query );
118    }
119
120    // redirection
121    redirect(add_session_id(PHPWG_ROOT_PATH.'category.php?'.$_SERVER['QUERY_STRING']));
122  }
123}
124//----------------------------------------------------- template initialization
125$expand = ($user['expand']=='true')?'EXPAND_TREE_YES':'EXPAND_TREE_NO';
126$nb_comments = ($user['show_nb_comments']=='true')?'NB_COMMENTS_YES':'NB_COMMENTS_NO';
127
128$title = $lang['customize_page_title'];
129include(PHPWG_ROOT_PATH.'include/page_header.php');
130
131$template->set_filenames(array('profile'=>'profile.tpl'));
132
133$template->assign_vars(array(
134  'USERNAME'=>$user['username'],
135  'EMAIL'=>$user['mail_address'],
136  'LANG_SELECT'=>language_select($user['language'], 'language'),
137  'NB_IMAGE_LINE'=>$user['nb_image_line'],
138  'NB_ROW_PAGE'=>$user['nb_line_page'],
139  'STYLE_SELECT'=>style_select($user['template'], 'template'),
140  'RECENT_PERIOD'=>$user['recent_period'],
141  'MAXWIDTH'=>$user['maxwidth'],
142  'MAXHEIGHT'=>$user['maxheight'],
143 
144  $expand=>'checked="checked"',
145  $nb_comments=>'checked="checked"',
146 
147  'L_TITLE' => $lang['customize_title'],
148  'L_REGISTRATION_INFO' => $lang['register_title'],
149  'L_PREFERENCES' => $lang['preferences'],
150  'L_USERNAME' => $lang['login'],
151  'L_EMAIL' => $lang['mail_address'],
152  'L_CURRENT_PASSWORD' => $lang['password'],
153  'L_CURRENT_PASSWORD_HINT' => $lang['password_hint'],
154  'L_NEW_PASSWORD' =>  $lang['new_password'],
155  'L_NEW_PASSWORD_HINT' => $lang['new_password_hint'],
156  'L_CONFIRM_PASSWORD' =>  $lang['reg_confirm'],
157  'L_CONFIRM_PASSWORD_HINT' => $lang['confirm_password_hint'],
158  'L_LANG_SELECT'=>$lang['language'],
159  'L_NB_IMAGE_LINE'=>$lang['nb_image_per_row'],
160  'L_NB_ROW_PAGE'=>$lang['nb_row_per_page'],
161  'L_STYLE_SELECT'=>$lang['theme'],
162  'L_RECENT_PERIOD'=>$lang['recent_period'],
163  'L_EXPAND_TREE'=>$lang['auto_expand'],
164  'L_NB_COMMENTS'=>$lang['show_nb_comments'],
165  'L_MAXWIDTH'=>$lang['maxwidth'],
166  'L_MAXHEIGHT'=>$lang['maxheight'],
167  'L_YES'=>$lang['yes'],
168  'L_NO'=>$lang['no'],
169  'L_SUBMIT'=>$lang['submit'],
170  'L_RETURN' =>  $lang['home'],
171  'L_RETURN_HINT' =>  $lang['home_hint'], 
172 
173  'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'profile.php'),
174 
175  'U_RETURN' => add_session_id(PHPWG_ROOT_PATH.'category.php?'.$_SERVER['QUERY_STRING'])
176  ));
177 
178//-------------------------------------------------------------- errors display
179if ( sizeof( $errors ) != 0 )
180{
181  $template->assign_block_vars('errors',array());
182  for ( $i = 0; $i < sizeof( $errors ); $i++ )
183  {
184    $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
185  }
186}
187//----------------------------------------------------------- html code display
188$template->pparse('profile');
189include(PHPWG_ROOT_PATH.'include/page_tail.php');
190?>
Note: See TracBrowser for help on using the repository browser.