source: trunk/profile.php @ 57

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

improve the header of each file

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.4 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 57 2003-08-24 07:40:56Z 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    }
113    // redirection
114    $url = 'category.php?cat='.$page['cat'].'&expand='.$_GET['expand'];
115    if ( $page['cat'] == 'search' )
116    {
117      $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode'];
118    }
119    if ( $_POST['create_cookie'] != 1 ) $url = add_session_id( $url, true );
120    header( 'Request-URI: '.$url ); 
121    header( 'Content-Location: '.$url ); 
122    header( 'Location: '.$url );
123    exit();
124  }
125}
126//----------------------------------------------------- template initialization
127$vtp = new VTemplate;
128$handle = $vtp->Open( './template/'.$user['template'].'/profile.vtp' );
129initialize_template();
130$tpl = array( 'customize_page_title','customize_title','password','new',
131              'reg_confirm','submit','create_cookie' );
132templatize_array( $tpl, 'lang', $handle );
133//----------------------------------------------------------------- form action
134$url = './profile.php?cat='.$page['cat'].'&amp;expand='.$page['expand'];
135if ( $page['cat'] == 'search' )
136{
137  $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
138}
139$vtp->setGlobalVar( $handle, 'form_action', add_session_id( $url ) );
140//-------------------------------------------------------------- errors display
141if ( count( $errors ) != 0 )
142{
143  $vtp->addSession( $handle, 'errors' );
144  foreach ( $errors as $error ) {
145    $vtp->addSession( $handle, 'li' );
146    $vtp->setVar( $handle, 'li.li', $error );
147    $vtp->closeSession( $handle, 'li' );
148  }
149  $vtp->closeSession( $handle, 'errors' );
150}
151//---------------------------------------------------- number of images per row
152if ( in_array( 'nb_image_line', $infos ) )
153{
154  $vtp->addSession( $handle, 'line' );
155  $vtp->setVar( $handle, 'line.name', $lang['customize_nb_image_per_row'] );
156  $vtp->addSession( $handle, 'select' );
157  $vtp->setVar( $handle, 'select.name', 'nb_image_line' );
158  for ( $i = 0; $i < sizeof( $conf['nb_image_row'] ); $i++ )
159  {
160    $vtp->addSession( $handle, 'option' );
161    $vtp->setVar( $handle, 'option.option', $conf['nb_image_row'][$i] );
162    if ( $conf['nb_image_row'][$i] == $user['nb_image_line'] )
163    {
164      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
165    }
166    $vtp->closeSession( $handle, 'option' );
167  }
168  $vtp->closeSession( $handle, 'select' );
169  $vtp->closeSession( $handle, 'line' );
170}
171//------------------------------------------------------ number of row per page
172if ( in_array( 'nb_line_page', $infos ) )
173{
174  $vtp->addSession( $handle, 'line' );
175  $vtp->setVar( $handle, 'line.name', $lang['customize_nb_row_per_page'] );
176  $vtp->addSession( $handle, 'select' );
177  $vtp->setVar( $handle, 'select.name', 'nb_line_page' );
178  for ( $i = 0; $i < sizeof( $conf['nb_row_page'] ); $i++ )
179  {
180    $vtp->addSession( $handle, 'option' );
181    $vtp->setVar( $handle, 'option.option', $conf['nb_row_page'][$i] );
182    if ( $conf['nb_row_page'][$i] == $user['nb_line_page'] )
183    {
184      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
185    }
186    $vtp->closeSession( $handle, 'option' );
187  }
188  $vtp->closeSession( $handle, 'select' );
189  $vtp->closeSession( $handle, 'line' );
190}
191//-------------------------------------------------------------------- template
192if ( in_array( 'template', $infos ) )
193{
194  $vtp->addSession( $handle, 'line' );
195  $vtp->setVar( $handle, 'line.name', $lang['customize_template'] );
196  $vtp->addSession( $handle, 'select' );
197  $vtp->setVar( $handle, 'select.name', 'template' );
198  $option = get_dirs( './template/' );
199  for ( $i = 0; $i < sizeof( $option ); $i++ )
200  {
201    $vtp->addSession( $handle, 'option' );
202    $vtp->setVar( $handle, 'option.option', $option[$i] );
203    if ( $option[$i] == $user['template'] )
204    {
205      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
206    }
207    $vtp->closeSession( $handle, 'option' );
208  }
209  $vtp->closeSession( $handle, 'select' );
210  $vtp->closeSession( $handle, 'line' );
211}
212//-------------------------------------------------------------------- language
213if ( in_array( 'language', $infos ) )
214{
215  $vtp->addSession( $handle, 'line' );
216  $vtp->setVar( $handle, 'line.name', $lang['customize_language'] );
217  $vtp->addSession( $handle, 'select' );
218  $vtp->setVar( $handle, 'select.name', 'language' );
219  $option = get_languages( './language/' );
220  for ( $i = 0; $i < sizeof( $option ); $i++ )
221  {
222    $vtp->addSession( $handle, 'option' );
223    $vtp->setVar( $handle, 'option.option', $option[$i] );
224    if( $option[$i] == $user['language'] )
225    {
226      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
227    }
228    $vtp->closeSession( $handle, 'option' );
229  }
230  $vtp->closeSession( $handle, 'select' );
231  $vtp->closeSession( $handle, 'line' );
232}
233//---------------------------------------------------------------- short period
234if ( in_array( 'short_period', $infos ) )
235{
236  $vtp->addSession( $handle, 'line' );
237  $vtp->setVar( $handle, 'line.name', $lang['customize_short_period'] );
238  $vtp->addSession( $handle, 'text' );
239  $vtp->setVar( $handle, 'text.name', 'short_period' );
240  $vtp->setVar( $handle, 'text.value', $user['short_period'] );
241  $vtp->closeSession( $handle, 'text' );
242  $vtp->closeSession( $handle, 'line' );
243}
244//----------------------------------------------------------------- long period
245if ( in_array( 'long_period', $infos ) )
246{
247  $vtp->addSession( $handle, 'line' );
248  $vtp->setVar( $handle, 'line.name', $lang['customize_long_period'] );
249  $vtp->addSession( $handle, 'text' );
250  $vtp->setVar( $handle, 'text.name', 'long_period' );
251  $vtp->setVar( $handle, 'text.value', $user['long_period'] );
252  $vtp->closeSession( $handle, 'text' );
253  $vtp->closeSession( $handle, 'line' );
254}
255//--------------------------------------------------------- max displayed width
256if ( in_array( 'maxwidth', $infos ) )
257{
258  $vtp->addSession( $handle, 'line' );
259  $vtp->setVar( $handle, 'line.name', $lang['maxwidth'] );
260  $vtp->addSession( $handle, 'text' );
261  $vtp->setVar( $handle, 'text.name', 'maxwidth' );
262  $vtp->setVar( $handle, 'text.value', $user['maxwidth'] );
263  $vtp->closeSession( $handle, 'text' );
264  $vtp->closeSession( $handle, 'line' );
265}
266//-------------------------------------------------------- max displayed height
267if ( in_array( 'maxheight', $infos ) )
268{
269  $vtp->addSession( $handle, 'line' );
270  $vtp->setVar( $handle, 'line.name', $lang['maxheight'] );
271  $vtp->addSession( $handle, 'text' );
272  $vtp->setVar( $handle, 'text.name', 'maxheight' );
273  $vtp->setVar( $handle, 'text.value', $user['maxheight'] );
274  $vtp->closeSession( $handle, 'text' );
275  $vtp->closeSession( $handle, 'line' );
276}
277//---------------------------------------------------------------- mail address
278if ( in_array( 'mail_address', $infos ) )
279{
280  $vtp->addSession( $handle, 'line' );
281  $vtp->setVar( $handle, 'line.name', $lang['mail_address'] );
282  $vtp->addSession( $handle, 'text' );
283  $vtp->setVar( $handle, 'text.name', 'mail_address' );
284  $vtp->setVar( $handle, 'text.value', $user['mail_address'] );
285  $vtp->closeSession( $handle, 'text' );
286  $vtp->closeSession( $handle, 'line' );
287}
288//----------------------------------------------------- expand all categories ?
289if ( in_array( 'expand', $infos ) )
290{
291  $vtp->addSession( $handle, 'line' );
292  $vtp->setVar( $handle, 'line.name', $lang['customize_expand'] );
293  $vtp->addSession( $handle, 'group' );
294  $vtp->addSession( $handle, 'radio' );
295  $vtp->setVar( $handle, 'radio.name', 'expand' );
296  $vtp->setVar( $handle, 'radio.value', 'true' );
297  $checked = '';
298  if ( $user['expand'] )
299  {
300    $checked = ' checked="checked"';
301  }
302  $vtp->setVar( $handle, 'radio.checked', $checked );
303  $vtp->setVar( $handle, 'radio.option', $lang['yes'] );
304  $vtp->closeSession( $handle, 'radio' );
305  $vtp->addSession( $handle, 'radio' );
306  $vtp->setVar( $handle, 'radio.name', 'expand' );
307  $vtp->setVar( $handle, 'radio.value', 'false' );
308  $checked = '';
309  if ( !$user['expand'] )
310  {
311    $checked = ' checked="checked"';
312  }
313  $vtp->setVar( $handle, 'radio.checked', $checked );
314  $vtp->setVar( $handle, 'radio.option', $lang['no'] );
315  $vtp->closeSession( $handle, 'radio' );
316  $vtp->closeSession( $handle, 'group' );
317  $vtp->closeSession( $handle, 'line' );
318}
319//---------------------------------- show number of comments on thumbnails page
320if ( in_array( 'show_nb_comments', $infos ) )
321{
322  $vtp->addSession( $handle, 'line' );
323  $vtp->setVar( $handle, 'line.name', $lang['customize_show_nb_comments'] );
324  $vtp->addSession( $handle, 'group' );
325  $vtp->addSession( $handle, 'radio' );
326  $vtp->setVar( $handle, 'radio.name', 'show_nb_comments' );
327  $vtp->setVar( $handle, 'radio.value', 'true' );
328  $checked = '';
329  if ( $user['show_nb_comments'] )
330  {
331    $checked = ' checked="checked"';
332  }
333  $vtp->setVar( $handle, 'radio.checked', $checked );
334  $vtp->setVar( $handle, 'radio.option', $lang['yes'] );
335  $vtp->closeSession( $handle, 'radio' );
336  $vtp->addSession( $handle, 'radio' );
337  $vtp->setVar( $handle, 'radio.name', 'show_nb_comments' );
338  $vtp->setVar( $handle, 'radio.value', 'false' );
339  $checked = '';
340  if ( !$user['show_nb_comments'] )
341  {
342    $checked = ' checked="checked"';
343  }
344  $vtp->setVar( $handle, 'radio.checked', $checked );
345  $vtp->setVar( $handle, 'radio.option', $lang['no'] );
346  $vtp->closeSession( $handle, 'radio' );
347  $vtp->closeSession( $handle, 'group' );
348  $vtp->closeSession( $handle, 'line' );
349}
350//--------------------------------------------------------------- create cookie
351if ( $conf['authorize_cookies'] )
352{
353  $vtp->addSession( $handle, 'cookie' );
354  $options = array(
355    array( 'message' => '1 '.$lang['customize_day'],
356           'value' => time() + 24*60*60 ),
357    array( 'message' => '1 '.$lang['customize_week'],
358           'value' => time() + 7*24*60*60 ),
359    array( 'message' => '1 '.$lang['customize_month'],
360           'value' => time() + 30*24*60*60 ),
361    array( 'message' => '1 '.$lang['customize_year'],
362           'value' => time() + 365*24*60*60 )
363    );
364  foreach ( $options as $option ) {
365    $vtp->addSession( $handle, 'expiration_option' );
366    $vtp->setVar( $handle, 'expiration_option.option', $option['message'] );
367    $vtp->setVar( $handle, 'expiration_option.value', $option['value'] );
368    $vtp->closeSession( $handle, 'expiration_option' );
369  }
370  $vtp->closeSession( $handle, 'cookie' );
371}
372//----------------------------------------------------------- html code display
373$code = $vtp->Display( $handle, 0 );
374echo $code;
375?>
Note: See TracBrowser for help on using the repository browser.