source: branches/1.3/profile.php @ 27569

Last change on this file since 27569 was 350, checked in by z0rglub, 20 years ago

append central HTML to $output, do not echo $code anymore

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