source: trunk/profile.php @ 405

Revision 405, 7.7 KB checked in by z0rglub, 15 years ago (diff)

redirections modification : use of a HTML refresh page instead of header PHP
function. The purpose is to avoid redirections failure when extra characters
are found in included PHP files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                              profile.php                              |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date$
10// | last modifier : $Author$
11// | revision      : $Revision$
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                'short_period', 'long_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['err_maxwidth'] );
57  }
58  if ( $_POST['maxheight']
59       and ( !preg_match( $int_pattern, $_POST['maxheight'] )
60             or $_POST['maxheight'] < 50 ) )
61  {
62    array_push( $errors, $lang['err_maxheight'] );
63  }
64  // periods must be integer values, they represents number of days
65  if ( !preg_match( $int_pattern, $_POST['short_period'] )
66       or !preg_match( $int_pattern, $_POST['long_period'] ) )
67  {
68    array_push( $errors, $lang['err_periods'] );
69  }
70  else
71  {
72    // long period must be longer than short period
73    if ( $_POST['long_period'] <= $_POST['short_period']
74         or $_POST['short_period'] <= 0 )
75    {
76      array_push( $errors, $lang['err_periods_2'] );
77    }
78  }
79  $mail_error = validate_mail_address( $_POST['mail_address'] );
80  if ( $mail_error != '' ) array_push( $errors, $mail_error );
81  // password must be the same as its confirmation
82  if ( isset( $_POST['use_new_pwd'] )
83       and $_POST['password'] != $_POST['passwordConf'] )
84    array_push( $errors, $lang['reg_err_pass'] );
85 
86  if ( count( $errors ) == 0 )
87  {
88    $query = 'UPDATE '.USERS_TABLE;
89    $query.= ' SET ';
90    foreach ( $infos as $i => $info ) {
91      if ( $i > 0 ) $query.= ',';
92      $query.= $info;
93      $query.= ' = ';
94      if ( $_POST[$info] == '' ) $query.= 'NULL';
95      else                       $query.= "'".$_POST[$info]."'";
96    }
97    $query.= ' WHERE id = '.$user['id'];
98    $query.= ';';
99    mysql_query( $query );
100
101    if ( isset( $_POST['use_new_pwd'] ) )
102    {
103      $query = 'UPDATE '.USERS_TABLE;
104      $query.= " SET password = '".md5( $_POST['password'] )."'";
105      $query.= ' WHERE id = '.$user['id'];
106      $query.= ';';
107      mysql_query( $query );
108    }
109    if ( isset( $_POST['create_cookie'] ) )
110    {
111      setcookie( 'id',$page['session_id'],$_POST['cookie_expiration'],
112                 cookie_path() );
113      // update the expiration date of the session
114      $query = 'UPDATE '.SESSIONS_TABLE;
115      $query.= ' SET expiration = '.$_POST['cookie_expiration'];
116      $query.= " WHERE id = '".$page['session_id']."'";
117      $query.= ';';
118      mysql_query( $query );
119    }
120    // redirection
121    $url = 'category.php';
122    if ( !isset($_POST['create_cookie']) ) $url = add_session_id( $url,true );
123    redirect( $url );
124  }
125}
126//----------------------------------------------------- template initialization
127$expand = ($user['expand']=='true')?'EXPAND_TREE_YES':'EXPAND_TREE_NO';
128$nb_comments = ($user['show_nb_comments']=='true')?'NB_COMMENTS_YES':'NB_COMMENTS_NO';
129
130$title = $lang['customize_page_title'];
131include(PHPWG_ROOT_PATH.'include/page_header.php');
132
133$template->set_filenames(array('profile'=>'profile.tpl'));
134
135$template->assign_vars(array(
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  'SHORT_PERIOD'=>$user['short_period'],
141  'LONG_PERIOD'=>$user['long_period'],
142 
143  $expand=>'checked="checked"',
144  $nb_comments=>'checked="checked"',
145 
146   'L_TITLE' => $lang['customize_title'],
147  'L_PASSWORD' => $lang['password'],
148  'L_NEW' =>  $lang['new'], 
149  'L_CONFIRM' =>  $lang['reg_confirm'], 
150  'L_COOKIE' =>  $lang['create_cookie'],
151  'L_CONFIRM'=>$lang['conf_confirmation'],
152  'L_LANG_SELECT'=>$lang['customize_language'],
153  'L_NB_IMAGE_LINE'=>$lang['customize_nb_image_per_row'],
154  'L_NB_ROW_PAGE'=>$lang['customize_nb_row_per_page'],
155  'L_STYLE_SELECT'=>$lang['customize_theme'],
156  'L_SHORT_PERIOD'=>$lang['customize_short_period'],
157  'L_LONG_PERIOD'=>$lang['customize_long_period'],
158  'L_EXPAND_TREE'=>$lang['customize_expand'],
159  'L_NB_COMMENTS'=>$lang['customize_show_nb_comments'],
160  'L_YES'=>$lang['yes'],
161  'L_NO'=>$lang['no'],
162  'L_SUBMIT'=>$lang['submit'],
163 
164  'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'profile.php'),
165 
166  'U_RETURN' => add_session_id(PHPWG_ROOT_PATH.'category.php?'.$_SERVER['QUERY_STRING'])
167  ));
168       
169//-------------------------------------------------------------- errors display
170if ( sizeof( $errors ) != 0 )
171{
172  $template->assign_block_vars('errors',array());
173  for ( $i = 0; $i < sizeof( $errors ); $i++ )
174  {
175    $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
176  }
177}
178
179$template->assign_block_vars('text',array(
180  'F_LABEL'=>$lang['maxwidth'],
181  'F_NAME'=>'maxwidth',
182  'F_VALUE'=>$user['maxwidth']
183  ));
184
185$template->assign_block_vars('text',array(
186  'F_LABEL'=>$lang['maxheight'],
187  'F_NAME'=>'maxheight',
188  'F_VALUE'=>$user['maxheight']
189  ));
190
191$template->assign_block_vars('text',array(
192  'F_LABEL'=>$lang['mail_address'],
193  'F_NAME'=>'mail_address',
194  'F_VALUE'=>$user['mail_address']
195  ));
196
197//----------------------------------------------------------- html code display
198$template->pparse('profile');
199include(PHPWG_ROOT_PATH.'include/page_tail.php');
200?>
Note: See TracBrowser for help on using the repository browser.