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

Last change on this file since 299 was 290, checked in by gweltas, 20 years ago

Conformity with the XHTML 1.0 transitional standard
Creation of the following files :

  • template/default/header.php and template/default/footer.php to ensure a common standard
  • default.css to be CSS valid

Obsolescence of the following files :

  • template/default/theme/conf.php
  • template/default/style.inc.php

Custom galleries should reflect those changes.

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