source: trunk/profile.php @ 60

Last change on this file since 60 was 60, checked in by z0rglub, 21 years ago

Modify the expiration date of the session to correspond to the cookie
expiration date if a cookie is created (else the cookie session is deleted
in PhpWebGallery when modifying the configuration in the admin panel)

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