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

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

Corretion of PHP warnings

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