source: trunk/profile.php @ 393

Last change on this file since 393 was 393, checked in by gweltas, 20 years ago
  • Template migration
  • Admin Control Panel migration
  • Language migration
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 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-03-20 00:52:37 +0000 (Sat, 20 Mar 2004) $
10// | last modifier : $Author: gweltas $
11// | revision      : $Revision: 393 $
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$expand = ($user['expand']=='true')?'EXPAND_TREE_YES':'EXPAND_TREE_NO';
131$nb_comments = ($user['show_nb_comments']=='true')?'NB_COMMENTS_YES':'NB_COMMENTS_NO';
132
133$title = $lang['customize_page_title'];
134include(PHPWG_ROOT_PATH.'include/page_header.php');
135
136$template->set_filenames(array('profile'=>'profile.tpl'));
137
138$template->assign_vars(array(
139  'LANG_SELECT'=>language_select($user['language'], 'language'),
140  'NB_IMAGE_LINE'=>$user['nb_image_line'],
141  'NB_ROW_PAGE'=>$user['nb_line_page'],
142  'STYLE_SELECT'=>style_select($user['template'], 'template'),
143  'SHORT_PERIOD'=>$user['short_period'],
144  'LONG_PERIOD'=>$user['long_period'],
145 
146  $expand=>'checked="checked"',
147  $nb_comments=>'checked="checked"',
148 
149   'L_TITLE' => $lang['customize_title'],
150  'L_PASSWORD' => $lang['password'],
151  'L_NEW' =>  $lang['new'], 
152  'L_CONFIRM' =>  $lang['reg_confirm'], 
153  'L_COOKIE' =>  $lang['create_cookie'],
154  'L_CONFIRM'=>$lang['conf_confirmation'],
155  'L_LANG_SELECT'=>$lang['customize_language'],
156  'L_NB_IMAGE_LINE'=>$lang['customize_nb_image_per_row'],
157  'L_NB_ROW_PAGE'=>$lang['customize_nb_row_per_page'],
158  'L_STYLE_SELECT'=>$lang['customize_theme'],
159  'L_SHORT_PERIOD'=>$lang['customize_short_period'],
160  'L_LONG_PERIOD'=>$lang['customize_long_period'],
161  'L_EXPAND_TREE'=>$lang['customize_expand'],
162  'L_NB_COMMENTS'=>$lang['customize_show_nb_comments'],
163  'L_YES'=>$lang['yes'],
164  'L_NO'=>$lang['no'],
165  'L_SUBMIT'=>$lang['submit'],
166 
167  'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'profile.php'),
168 
169  'U_RETURN' => add_session_id(PHPWG_ROOT_PATH.'category.php?'.$_SERVER['QUERY_STRING'])
170  ));
171       
172//-------------------------------------------------------------- errors display
173if ( sizeof( $errors ) != 0 )
174{
175  $template->assign_block_vars('errors',array());
176  for ( $i = 0; $i < sizeof( $errors ); $i++ )
177  {
178    $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
179  }
180}
181
182$template->assign_block_vars('text',array(
183  'F_LABEL'=>$lang['maxwidth'],
184  'F_NAME'=>'maxwidth',
185  'F_VALUE'=>$user['maxwidth']
186  ));
187
188$template->assign_block_vars('text',array(
189  'F_LABEL'=>$lang['maxheight'],
190  'F_NAME'=>'maxheight',
191  'F_VALUE'=>$user['maxheight']
192  ));
193
194$template->assign_block_vars('text',array(
195  'F_LABEL'=>$lang['mail_address'],
196  'F_NAME'=>'mail_address',
197  'F_VALUE'=>$user['mail_address']
198  ));
199
200//----------------------------------------------------------- html code display
201$template->pparse('profile');
202include(PHPWG_ROOT_PATH.'include/page_tail.php');
203?>
Note: See TracBrowser for help on using the repository browser.