source: trunk/profile.php @ 364

Last change on this file since 364 was 364, checked in by gweltas, 20 years ago

Split of langage files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
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: 2004-02-19 00:31:09 +0000 (Thu, 19 Feb 2004) $
10// | last modifier : $Author: gweltas $
11// | revision      : $Revision: 364 $
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    header( 'Request-URI: '.$url ); 
124    header( 'Content-Location: '.$url ); 
125    header( 'Location: '.$url );
126    exit();
127  }
128}
129//----------------------------------------------------- template initialization
130//
131// Start output of page
132//
133$title = $lang['customize_page_title'];
134include('include/page_header.php');
135
136$template->set_filenames(array('profile'=>'profile.tpl'));
137initialize_template();
138
139$template->assign_vars(array(
140  'L_TITLE' => $lang['customize_title'],
141  'L_PASSWORD' => $lang['password'],
142  'L_NEW' =>  $lang['new'], 
143  'L_CONFIRM' =>  $lang['reg_confirm'], 
144  'L_SUBMIT' =>  $lang['submit'], 
145  'L_COOKIE' =>  $lang['create_cookie'],
146       
147  'F_ACTION' => add_session_id( './profile.php' ),
148
149  'U_RETURN' => add_session_id('./category.php?'.$_SERVER['QUERY_STRING'])
150  ));
151       
152//-------------------------------------------------------------- errors display
153if ( sizeof( $errors ) != 0 )
154{
155  $template->assign_block_vars('errors',array());
156  for ( $i = 0; $i < sizeof( $errors ); $i++ )
157  {
158    $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
159  }
160}
161
162$template->assign_block_vars('select',array(
163  'F_LABEL'=>$lang['customize_nb_image_per_row'],
164  'F_NAME'=>'nb_image_line',
165  'F_OPTIONS'=>make_jumpbox($conf['nb_image_row'], $user['nb_image_line'])
166  ));
167
168$template->assign_block_vars('select',array(
169  'F_LABEL'=>$lang['customize_nb_row_per_page'],
170  'F_NAME'=>'nb_line_page',
171  'F_OPTIONS'=>make_jumpbox($conf['nb_row_page'], $user['nb_line_page'])
172  ));
173
174$template->assign_block_vars('select',array(
175  'F_LABEL'=>$lang['customize_template'],
176  'F_NAME'=>'template',
177  'F_OPTIONS'=>make_jumpbox(get_dirs( './template' ), $user['template'])
178  ));
179
180$template->assign_block_vars('select',array(
181  'F_LABEL'=>$lang['customize_language'],
182  'F_NAME'=>'language',
183  'F_OPTIONS'=>make_jumpbox($lang['lang'], $user['language'], true)
184  ));
185
186$template->assign_block_vars('text',array(
187  'F_LABEL'=>$lang['customize_short_period'],
188  'F_NAME'=>'short_period',
189  'F_VALUE'=>$user['short_period']
190  ));
191
192$template->assign_block_vars('text',array(
193  'F_LABEL'=>$lang['customize_long_period'],
194  'F_NAME'=>'long_period',
195  'F_VALUE'=>$user['long_period']
196  ));
197
198$template->assign_block_vars('text',array(
199  'F_LABEL'=>$lang['maxwidth'],
200  'F_NAME'=>'maxwidth',
201  'F_VALUE'=>$user['maxwidth']
202  ));
203
204$template->assign_block_vars('text',array(
205  'F_LABEL'=>$lang['maxheight'],
206  'F_NAME'=>'maxheight',
207  'F_VALUE'=>$user['maxheight']
208  ));
209
210$template->assign_block_vars('text',array(
211  'F_LABEL'=>$lang['mail_address'],
212  'F_NAME'=>'mail_address',
213  'F_VALUE'=>$user['mail_address']
214  ));
215
216$template->assign_block_vars('radio',array(
217  'F_LABEL'=>$lang['customize_expand'],
218  'F_OPTIONS'=>make_radio('expand', array(true=>$lang['yes'], false=>$lang['no']), $user['expand'], true)
219  ));
220
221$template->assign_block_vars('radio',array(
222  'F_LABEL'=>$lang['customize_show_nb_comments'],
223  'F_OPTIONS'=>make_radio('show_nb_comments', array(true=>$lang['yes'], false=>$lang['no']), $user['show_nb_comments'], true)
224  ));
225
226//--------------------------------------------------------------- create cookie
227if ( $conf['authorize_cookies'] )
228{
229  $vtp->addSession( $handle, 'cookie' );
230  $options = array(
231    array( 'message' => '1 '.$lang['customize_day'],
232           'value' => time() + 24*60*60 ),
233    array( 'message' => '1 '.$lang['customize_week'],
234           'value' => time() + 7*24*60*60 ),
235    array( 'message' => '1 '.$lang['customize_month'],
236           'value' => time() + 30*24*60*60 ),
237    array( 'message' => '1 '.$lang['customize_year'],
238           'value' => time() + 365*24*60*60 )
239    );
240  foreach ( $options as $option ) {
241    $vtp->addSession( $handle, 'expiration_option' );
242    $vtp->setVar( $handle, 'expiration_option.option', $option['message'] );
243    $vtp->setVar( $handle, 'expiration_option.value', $option['value'] );
244    $vtp->closeSession( $handle, 'expiration_option' );
245  }
246  $vtp->closeSession( $handle, 'cookie' );
247}
248//----------------------------------------------------------- html code display
249$template->pparse('profile');
250include('include/page_tail.php');
251?>
Note: See TracBrowser for help on using the repository browser.