source: branches/release-1_3/profile.php @ 277

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

Minor corrections of PHP warnings

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.6 KB
Line 
1<?php
2/***************************************************************************
3 *                                profile.php                              *
4 *                            -------------------                          *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: profile.php 276 2004-01-12 23:41:53Z gweltas $
9 *                                                                         *
10 ***************************************************************************/
11
12/***************************************************************************
13 *                                                                         *
14 *   This program is free software; you can redistribute it and/or modify  *
15 *   it under the terms of the GNU General Public License as published by  *
16 *   the Free Software Foundation;                                         *
17 *                                                                         *
18 ***************************************************************************/
19// customize appearance of the site for a user
20//----------------------------------------------------------- personnal include
21include_once( './include/init.inc.php' );
22//-------------------------------------------------- access authorization check
23check_login_authorization();
24if ( $user['is_the_guest'] )
25{
26  echo '<div style="text-align:center;">'.$lang['only_members'].'<br />';
27  echo '<a href="./identification.php">'.$lang['ident_title'].'</a></div>';
28  exit();
29}
30//------------------------------------------------------ update & customization
31$infos = array( 'nb_image_line', 'nb_line_page', 'language',
32                'maxwidth', 'maxheight', 'expand', 'show_nb_comments',
33                'short_period', 'long_period', 'template', 'mail_address' );
34// mise à jour dans la base de données des valeurs
35// des paramètres pour l'utilisateur courant
36//    - on teste si chacune des variables est passée en argument à la page
37//    - ce qui signifie que l'on doit venir de la page de personnalisation
38$errors = array();
39if ( isset( $_POST['submit'] ) )
40{
41  $int_pattern = '/^\d+$/';
42  if ( $_POST['maxwidth'] != ''
43       and ( !preg_match( $int_pattern, $_POST['maxwidth'] )
44             or $_POST['maxwidth'] < 50 ) )
45  {
46    array_push( $errors, $lang['err_maxwidth'] );
47  }
48  if ( $_POST['maxheight']
49       and ( !preg_match( $int_pattern, $_POST['maxheight'] )
50             or $_POST['maxheight'] < 50 ) )
51  {
52    array_push( $errors, $lang['err_maxheight'] );
53  }
54  // periods must be integer values, they represents number of days
55  if ( !preg_match( $int_pattern, $_POST['short_period'] )
56       or !preg_match( $int_pattern, $_POST['long_period'] ) )
57  {
58    array_push( $errors, $lang['err_periods'] );
59  }
60  else
61  {
62    // long period must be longer than short period
63    if ( $_POST['long_period'] <= $_POST['short_period']
64         or $_POST['short_period'] <= 0 )
65    {
66      array_push( $errors, $lang['err_periods_2'] );
67    }
68  }
69  $mail_error = validate_mail_address( $_POST['mail_address'] );
70  if ( $mail_error != '' )
71  {
72    array_push( $errors, $mail_error );
73  }
74  if ( $_POST['use_new_pwd'] == 1 )
75  {
76    // password must be the same as its confirmation
77    if ( $_POST['password'] != $_POST['passwordConf'] )
78    {
79      array_push( $errors, $lang['reg_err_pass'] );
80    }
81  }
82
83  if ( count( $errors ) == 0 )
84  {
85    $query = 'UPDATE '.PREFIX_TABLE.'users';
86    $query.= ' SET ';
87    foreach ( $infos as $i => $info ) {
88      if ( $i > 0 ) $query.= ',';
89      $query.= $info;
90      $query.= ' = ';
91      if ( $_POST[$info] == '' ) $query.= 'NULL';
92      else                       $query.= "'".$_POST[$info]."'";
93    }
94    $query.= ' WHERE id = '.$user['id'];
95    $query.= ';';
96    mysql_query( $query );
97
98    if ( $_POST['use_new_pwd'] == 1 )
99    {
100      $query = 'UPDATE '.PREFIX_TABLE.'users';
101      $query.= " SET password = '".md5( $_POST['password'] )."'";
102      $query.= ' WHERE id = '.$user['id'];
103      $query.= ';';
104      mysql_query( $query );
105    }
106    if ( $_POST['create_cookie'] == 1 )
107    {
108      setcookie( 'id',$page['session_id'],$_POST['cookie_expiration'],
109                 cookie_path() );
110      // update the expiration date of the session
111      $query = 'UPDATE '.PREFIX_TABLE.'sessions';
112      $query.= ' SET expiration = '.$_POST['cookie_expiration'];
113      $query.= " WHERE id = '".$page['session_id']."'";
114      $query.= ';';
115      mysql_query( $query );
116    }
117    // redirection
118    $url = 'category.php?cat='.$page['cat'].'&expand='.$_GET['expand'];
119    if ( $page['cat'] == 'search' )
120    {
121      $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode'];
122    }
123    if ( $_POST['create_cookie'] != 1 ) $url = add_session_id( $url, true );
124    header( 'Request-URI: '.$url ); 
125    header( 'Content-Location: '.$url ); 
126    header( 'Location: '.$url );
127    exit();
128  }
129}
130//----------------------------------------------------- template initialization
131$vtp = new VTemplate;
132$handle = $vtp->Open( './template/'.$user['template'].'/profile.vtp' );
133initialize_template();
134$tpl = array( 'customize_page_title','customize_title','password','new',
135              'reg_confirm','submit','create_cookie' );
136templatize_array( $tpl, 'lang', $handle );
137//----------------------------------------------------------------- form action
138$url = './profile.php?cat='.$page['cat'].'&amp;expand='.$page['expand'];
139if ( $page['cat'] == 'search' )
140{
141  $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
142}
143$vtp->setGlobalVar( $handle, 'form_action', add_session_id( $url ) );
144//-------------------------------------------------------------- errors display
145if ( count( $errors ) != 0 )
146{
147  $vtp->addSession( $handle, 'errors' );
148  foreach ( $errors as $error ) {
149    $vtp->addSession( $handle, 'li' );
150    $vtp->setVar( $handle, 'li.li', $error );
151    $vtp->closeSession( $handle, 'li' );
152  }
153  $vtp->closeSession( $handle, 'errors' );
154}
155//---------------------------------------------------- number of images per row
156if ( in_array( 'nb_image_line', $infos ) )
157{
158  $vtp->addSession( $handle, 'line' );
159  $vtp->setVar( $handle, 'line.name', $lang['customize_nb_image_per_row'] );
160  $vtp->addSession( $handle, 'select' );
161  $vtp->setVar( $handle, 'select.name', 'nb_image_line' );
162  for ( $i = 0; $i < sizeof( $conf['nb_image_row'] ); $i++ )
163  {
164    $vtp->addSession( $handle, 'option' );
165    $vtp->setVar( $handle, 'option.option', $conf['nb_image_row'][$i] );
166    if ( $conf['nb_image_row'][$i] == $user['nb_image_line'] )
167    {
168      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
169    }
170    $vtp->closeSession( $handle, 'option' );
171  }
172  $vtp->closeSession( $handle, 'select' );
173  $vtp->closeSession( $handle, 'line' );
174}
175//------------------------------------------------------ number of row per page
176if ( in_array( 'nb_line_page', $infos ) )
177{
178  $vtp->addSession( $handle, 'line' );
179  $vtp->setVar( $handle, 'line.name', $lang['customize_nb_row_per_page'] );
180  $vtp->addSession( $handle, 'select' );
181  $vtp->setVar( $handle, 'select.name', 'nb_line_page' );
182  for ( $i = 0; $i < sizeof( $conf['nb_row_page'] ); $i++ )
183  {
184    $vtp->addSession( $handle, 'option' );
185    $vtp->setVar( $handle, 'option.option', $conf['nb_row_page'][$i] );
186    if ( $conf['nb_row_page'][$i] == $user['nb_line_page'] )
187    {
188      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
189    }
190    $vtp->closeSession( $handle, 'option' );
191  }
192  $vtp->closeSession( $handle, 'select' );
193  $vtp->closeSession( $handle, 'line' );
194}
195//-------------------------------------------------------------------- template
196if ( in_array( 'template', $infos ) )
197{
198  $vtp->addSession( $handle, 'line' );
199  $vtp->setVar( $handle, 'line.name', $lang['customize_template'] );
200  $vtp->addSession( $handle, 'select' );
201  $vtp->setVar( $handle, 'select.name', 'template' );
202  $option = get_dirs( './template' );
203  for ( $i = 0; $i < sizeof( $option ); $i++ )
204  {
205    $vtp->addSession( $handle, 'option' );
206    $vtp->setVar( $handle, 'option.option', $option[$i] );
207    if ( $option[$i] == $user['template'] )
208    {
209      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
210    }
211    $vtp->closeSession( $handle, 'option' );
212  }
213  $vtp->closeSession( $handle, 'select' );
214  $vtp->closeSession( $handle, 'line' );
215}
216//-------------------------------------------------------------------- language
217if ( in_array( 'language', $infos ) )
218{
219  $vtp->addSession( $handle, 'line' );
220  $vtp->setVar( $handle, 'line.name', $lang['customize_language'] );
221  $vtp->addSession( $handle, 'select' );
222  $vtp->setVar( $handle, 'select.name', 'language' );
223  $option = get_languages( './language/' );
224  for ( $i = 0; $i < sizeof( $option ); $i++ )
225  {
226    $vtp->addSession( $handle, 'option' );
227    $vtp->setVar( $handle, 'option.option', $option[$i] );
228    if( $option[$i] == $user['language'] )
229    {
230      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
231    }
232    $vtp->closeSession( $handle, 'option' );
233  }
234  $vtp->closeSession( $handle, 'select' );
235  $vtp->closeSession( $handle, 'line' );
236}
237//---------------------------------------------------------------- short period
238if ( in_array( 'short_period', $infos ) )
239{
240  $vtp->addSession( $handle, 'line' );
241  $vtp->setVar( $handle, 'line.name', $lang['customize_short_period'] );
242  $vtp->addSession( $handle, 'text' );
243  $vtp->setVar( $handle, 'text.name', 'short_period' );
244  $vtp->setVar( $handle, 'text.value', $user['short_period'] );
245  $vtp->closeSession( $handle, 'text' );
246  $vtp->closeSession( $handle, 'line' );
247}
248//----------------------------------------------------------------- long period
249if ( in_array( 'long_period', $infos ) )
250{
251  $vtp->addSession( $handle, 'line' );
252  $vtp->setVar( $handle, 'line.name', $lang['customize_long_period'] );
253  $vtp->addSession( $handle, 'text' );
254  $vtp->setVar( $handle, 'text.name', 'long_period' );
255  $vtp->setVar( $handle, 'text.value', $user['long_period'] );
256  $vtp->closeSession( $handle, 'text' );
257  $vtp->closeSession( $handle, 'line' );
258}
259//--------------------------------------------------------- max displayed width
260if ( in_array( 'maxwidth', $infos ) )
261{
262  $vtp->addSession( $handle, 'line' );
263  $vtp->setVar( $handle, 'line.name', $lang['maxwidth'] );
264  $vtp->addSession( $handle, 'text' );
265  $vtp->setVar( $handle, 'text.name', 'maxwidth' );
266  $vtp->setVar( $handle, 'text.value', $user['maxwidth'] );
267  $vtp->closeSession( $handle, 'text' );
268  $vtp->closeSession( $handle, 'line' );
269}
270//-------------------------------------------------------- max displayed height
271if ( in_array( 'maxheight', $infos ) )
272{
273  $vtp->addSession( $handle, 'line' );
274  $vtp->setVar( $handle, 'line.name', $lang['maxheight'] );
275  $vtp->addSession( $handle, 'text' );
276  $vtp->setVar( $handle, 'text.name', 'maxheight' );
277  $vtp->setVar( $handle, 'text.value', $user['maxheight'] );
278  $vtp->closeSession( $handle, 'text' );
279  $vtp->closeSession( $handle, 'line' );
280}
281//---------------------------------------------------------------- mail address
282if ( in_array( 'mail_address', $infos ) )
283{
284  $vtp->addSession( $handle, 'line' );
285  $vtp->setVar( $handle, 'line.name', $lang['mail_address'] );
286  $vtp->addSession( $handle, 'text' );
287  $vtp->setVar( $handle, 'text.name', 'mail_address' );
288  $vtp->setVar( $handle, 'text.value', $user['mail_address'] );
289  $vtp->closeSession( $handle, 'text' );
290  $vtp->closeSession( $handle, 'line' );
291}
292//----------------------------------------------------- expand all categories ?
293if ( in_array( 'expand', $infos ) )
294{
295  $vtp->addSession( $handle, 'line' );
296  $vtp->setVar( $handle, 'line.name', $lang['customize_expand'] );
297  $vtp->addSession( $handle, 'group' );
298  $vtp->addSession( $handle, 'radio' );
299  $vtp->setVar( $handle, 'radio.name', 'expand' );
300  $vtp->setVar( $handle, 'radio.value', 'true' );
301  $checked = '';
302  if ( $user['expand'] )
303  {
304    $checked = ' checked="checked"';
305  }
306  $vtp->setVar( $handle, 'radio.checked', $checked );
307  $vtp->setVar( $handle, 'radio.option', $lang['yes'] );
308  $vtp->closeSession( $handle, 'radio' );
309  $vtp->addSession( $handle, 'radio' );
310  $vtp->setVar( $handle, 'radio.name', 'expand' );
311  $vtp->setVar( $handle, 'radio.value', 'false' );
312  $checked = '';
313  if ( !$user['expand'] )
314  {
315    $checked = ' checked="checked"';
316  }
317  $vtp->setVar( $handle, 'radio.checked', $checked );
318  $vtp->setVar( $handle, 'radio.option', $lang['no'] );
319  $vtp->closeSession( $handle, 'radio' );
320  $vtp->closeSession( $handle, 'group' );
321  $vtp->closeSession( $handle, 'line' );
322}
323//---------------------------------- show number of comments on thumbnails page
324if ( in_array( 'show_nb_comments', $infos ) )
325{
326  $vtp->addSession( $handle, 'line' );
327  $vtp->setVar( $handle, 'line.name', $lang['customize_show_nb_comments'] );
328  $vtp->addSession( $handle, 'group' );
329  $vtp->addSession( $handle, 'radio' );
330  $vtp->setVar( $handle, 'radio.name', 'show_nb_comments' );
331  $vtp->setVar( $handle, 'radio.value', 'true' );
332  $checked = '';
333  if ( $user['show_nb_comments'] )
334  {
335    $checked = ' checked="checked"';
336  }
337  $vtp->setVar( $handle, 'radio.checked', $checked );
338  $vtp->setVar( $handle, 'radio.option', $lang['yes'] );
339  $vtp->closeSession( $handle, 'radio' );
340  $vtp->addSession( $handle, 'radio' );
341  $vtp->setVar( $handle, 'radio.name', 'show_nb_comments' );
342  $vtp->setVar( $handle, 'radio.value', 'false' );
343  $checked = '';
344  if ( !$user['show_nb_comments'] )
345  {
346    $checked = ' checked="checked"';
347  }
348  $vtp->setVar( $handle, 'radio.checked', $checked );
349  $vtp->setVar( $handle, 'radio.option', $lang['no'] );
350  $vtp->closeSession( $handle, 'radio' );
351  $vtp->closeSession( $handle, 'group' );
352  $vtp->closeSession( $handle, 'line' );
353}
354//--------------------------------------------------------------- create cookie
355if ( $conf['authorize_cookies'] )
356{
357  $vtp->addSession( $handle, 'cookie' );
358  $options = array(
359    array( 'message' => '1 '.$lang['customize_day'],
360           'value' => time() + 24*60*60 ),
361    array( 'message' => '1 '.$lang['customize_week'],
362           'value' => time() + 7*24*60*60 ),
363    array( 'message' => '1 '.$lang['customize_month'],
364           'value' => time() + 30*24*60*60 ),
365    array( 'message' => '1 '.$lang['customize_year'],
366           'value' => time() + 365*24*60*60 )
367    );
368  foreach ( $options as $option ) {
369    $vtp->addSession( $handle, 'expiration_option' );
370    $vtp->setVar( $handle, 'expiration_option.option', $option['message'] );
371    $vtp->setVar( $handle, 'expiration_option.value', $option['value'] );
372    $vtp->closeSession( $handle, 'expiration_option' );
373  }
374  $vtp->closeSession( $handle, 'cookie' );
375}
376//----------------------------------------------------------- html code display
377$code = $vtp->Display( $handle, 0 );
378echo $code;
379?>
Note: See TracBrowser for help on using the repository browser.