source: trunk/profile.php @ 10

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

* empty log message *

  • 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 is a part of PhpWebGallery               *
4 *                            -------------------                          *
5 *   last update          : Tuesday, July 16, 2002                         *
6 *   email                : pierrick@z0rglub.com                           *
7 *                                                                         *
8 ***************************************************************************/
9
10/***************************************************************************
11 *                                                                         *
12 *   This program is free software; you can redistribute it and/or modify  *
13 *   it under the terms of the GNU General Public License as published by  *
14 *   the Free Software Foundation;                                         *
15 *                                                                         *
16 ***************************************************************************/
17// customize appearance of the site for a user
18//----------------------------------------------------------- personnal include
19include_once( './include/init.inc.php' );
20//-------------------------------------------------- access authorization check
21check_login_authorization();
22if ( $user['is_the_guest'] )
23{
24  echo '<div style="text-align:center;">'.$lang['only_members'].'<br />';
25  echo '<a href="./identification.php">'.$lang['ident_title'].'</a></div>';
26  exit();
27}
28//-------------------------------------------------------------- initialization
29check_cat_id( $_GET['cat'] );
30//------------------------------------------------------ update & customization
31$infos = array( 'nb_image_line', 'nb_line_page', 'theme', '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$error = array();
39if ( isset( $_POST['submit'] ) )
40{
41  $i = 0;
42  if ( $_POST['maxwidth'] != '' )
43  {
44    if ( !ereg( "^[0-9]{2,}$", $_POST['maxwidth'] )
45         || $_POST['maxwidth'] < 50 )
46    {
47      $error[$i++] = $lang['err_maxwidth'];
48    }
49  }
50  if ( $_POST['maxheight'] != '' )
51  {
52    if ( !ereg( "^[0-9]{2,}$", $_POST['maxheight'] )
53         || $_POST['maxheight'] < 50 )
54    {
55      $error[$i++] = $lang['err_maxheight'];
56    }
57  }
58  // les période doivent être des entiers, il représentent des nombres de jours
59  if ( !ereg( "^[0-9]*$", $_POST['short_period'] )
60       || !ereg("^[0-9]*$", $_POST['long_period'] ) )
61  {
62    $error[$i++] = $lang['err_periods'];
63  }
64  else
65  {
66    // la période longue doit être supérieure à la période courte
67    if ( $_POST['long_period'] <= $_POST['short_period']
68         || $_POST['short_period'] <= 0 )
69    {
70      $error[$i++] = $lang['err_periods_2'];
71    }
72  }
73  // le mail doit être conforme à qqch du type : nom@serveur.com
74  if( $_POST['mail_address'] != ""
75      && !ereg( "([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+)",
76                $_POST['mail_address'] ) )
77  {
78    $error[$i++] = $lang['reg_err_mail_address'];
79  }
80  if ( $_POST['use_new_pwd'] == 1 )
81  {
82    // on vérifie que le password rentré correspond bien
83    // à la confirmation faite par l'utilisateur
84    if ( $_POST['password'] != $_POST['passwordConf'] )
85    {
86      $error[$i++] = $lang['reg_err_pass'];
87    }
88  }
89
90  if ( sizeof( $error ) == 0 )
91  {
92    $tab_theme = explode( ' - ', $_POST['theme'] );
93    $_POST['theme'] = $tab_theme[0].'/'.$tab_theme[1];
94
95    $query = 'update '.PREFIX_TABLE.'users';
96    $query.= ' set';
97    for ( $i = 0; $i < sizeof( $infos ); $i++ )
98    {
99      if ( $i > 0 )
100      {
101        $query.= ',';
102      }
103      else
104      {
105        $query.= ' ';
106      }
107      $query.= $infos[$i];
108      $query.= ' = ';
109      if ( $_POST[$infos[$i]] == '' )
110      {
111        $query.= 'NULL';
112      }
113      else
114      {
115        $query.= "'".$_POST[$infos[$i]]."'";
116      }
117    }
118    $query.= ' where id = '.$user['id'];
119    $query.= ';';
120    mysql_query( $query );
121
122    if ( $_POST['use_new_pwd'] == 1 )
123    {
124      $query = 'update '.PREFIX_TABLE.'users';
125      $query.= " set password = '".md5( $_POST['password'] )."'";
126      $query.= ' where id = '.$user['id'];
127      $query.= ';';
128      mysql_query( $query );
129      echo '<br />'.$query;
130    }
131    // redirection
132    $url = 'category.php?cat='.$page['cat'].'&expand='.$_GET['expand'];
133    if ( $page['cat'] == 'search' )
134    {
135      $url.= '&search='.$_GET['search'];
136    }
137    $url = add_session_id( $url, true );
138    header( 'Request-URI: '.$url ); 
139    header( 'Content-Location: '.$url ); 
140    header( 'Location: '.$url );
141    exit();
142  }
143}
144//----------------------------------------------------- template initialization
145$vtp = new VTemplate;
146$handle = $vtp->Open( './template/'.$user['template'].'/profile.vtp' );
147// language
148$vtp->setGlobalVar( $handle, 'customize_page_title',
149                    $lang['customize_page_title'] );
150$vtp->setGlobalVar( $handle, 'customize_title',  $lang['customize_title'] );
151$vtp->setGlobalVar( $handle, 'password',         $lang['password'] );
152$vtp->setGlobalVar( $handle, 'new',              $lang['new'] );
153$vtp->setGlobalVar( $handle, 'reg_confirm',      $lang['reg_confirm'] );
154$vtp->setGlobalVar( $handle, 'submit',           $lang['submit'] );
155
156initialize_template();
157//----------------------------------------------------------------- form action
158$url = './profile.php?cat='.$page['cat'].'&amp;expand='.$page['expand'];
159if ( $page['cat'] == 'search' )
160{
161  $url.= '&amp;search='.$_GET['search'];
162}
163$vtp->setGlobalVar( $handle, 'form_action', add_session_id( $url ) );
164//-------------------------------------------------------------- errors display
165if ( sizeof( $error ) != 0 )
166{
167  $vtp->addSession( $handle, 'errors' );
168  for ( $i = 0; $i < sizeof( $error ); $i++ )
169  {
170    $vtp->addSession( $handle, 'li' );
171    $vtp->setVar( $handle, 'li.li', $error[$i] );
172    $vtp->closeSession( $handle, 'li' );
173  }
174  $vtp->closeSession( $handle, 'errors' );
175}
176//---------------------------------------------------- number of images per row
177if ( in_array( 'nb_image_line', $infos ) )
178{
179  $vtp->addSession( $handle, 'line' );
180  $vtp->setVar( $handle, 'line.name', $lang['customize_nb_image_per_row'] );
181  $vtp->addSession( $handle, 'select' );
182  $vtp->setVar( $handle, 'select.name', 'nb_image_line' );
183  for ( $i = 0; $i < sizeof( $conf['nb_image_row'] ); $i++ )
184  {
185    $vtp->addSession( $handle, 'option' );
186    $vtp->setVar( $handle, 'option.option', $conf['nb_image_row'][$i] );
187    if ( $conf['nb_image_row'][$i] == $user['nb_image_line'] )
188    {
189      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
190    }
191    $vtp->closeSession( $handle, 'option' );
192  }
193  $vtp->closeSession( $handle, 'select' );
194  $vtp->closeSession( $handle, 'line' );
195}
196//------------------------------------------------------ number of row per page
197if ( in_array( 'nb_line_page', $infos ) )
198{
199  $vtp->addSession( $handle, 'line' );
200  $vtp->setVar( $handle, 'line.name', $lang['customize_nb_row_per_page'] );
201  $vtp->addSession( $handle, 'select' );
202  $vtp->setVar( $handle, 'select.name', 'nb_line_page' );
203  for ( $i = 0; $i < sizeof( $conf['nb_row_page'] ); $i++ )
204  {
205    $vtp->addSession( $handle, 'option' );
206    $vtp->setVar( $handle, 'option.option', $conf['nb_row_page'][$i] );
207    if ( $conf['nb_row_page'][$i] == $user['nb_line_page'] )
208    {
209      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
210    }
211    $vtp->closeSession( $handle, 'option' );
212  }
213  $vtp->closeSession( $handle, 'select' );
214  $vtp->closeSession( $handle, 'line' );
215}
216//-------------------------------------------------------------------- template
217if ( in_array( 'template', $infos ) )
218{
219  $vtp->addSession( $handle, 'line' );
220  $vtp->setVar( $handle, 'line.name', $lang['customize_template'] );
221  $vtp->addSession( $handle, 'select' );
222  $vtp->setVar( $handle, 'select.name', 'template' );
223  $option = get_dirs( './template/' );
224  for ( $i = 0; $i < sizeof( $option ); $i++ )
225  {
226    $vtp->addSession( $handle, 'option' );
227    $vtp->setVar( $handle, 'option.option', $option[$i] );
228    if ( $option[$i] == $user['template'] )
229    {
230      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
231    }
232    $vtp->closeSession( $handle, 'option' );
233  }
234  $vtp->closeSession( $handle, 'select' );
235  $vtp->closeSession( $handle, 'line' );
236}
237//----------------------------------------------------------------------- theme
238if ( in_array( 'theme', $infos ) )
239{
240  $vtp->addSession( $handle, 'line' );
241  $vtp->setVar( $handle, 'line.name', $lang['customize_theme'] );
242  $vtp->addSession( $handle, 'select' );
243  $vtp->setVar( $handle, 'select.name', 'theme' );
244  $option = get_themes( './theme/' );
245  for ( $i = 0; $i < sizeof( $option ); $i++ )
246  {
247    $vtp->addSession( $handle, 'option' );
248    $vtp->setVar( $handle, 'option.option', $option[$i] );
249    if ( $option[$i] == str_replace( '/', ' - ', $user['theme'] ) )
250    {
251      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
252    }
253    $vtp->closeSession( $handle, 'option' );
254  }
255  $vtp->closeSession( $handle, 'select' );
256  $vtp->closeSession( $handle, 'line' );
257}
258//-------------------------------------------------------------------- language
259if ( in_array( 'language', $infos ) )
260{
261  $vtp->addSession( $handle, 'line' );
262  $vtp->setVar( $handle, 'line.name', $lang['customize_language'] );
263  $vtp->addSession( $handle, 'select' );
264  $vtp->setVar( $handle, 'select.name', 'language' );
265  $option = get_languages( './language/' );
266  for ( $i = 0; $i < sizeof( $option ); $i++ )
267  {
268    $vtp->addSession( $handle, 'option' );
269    $vtp->setVar( $handle, 'option.option', $option[$i] );
270    if( $option[$i] == $user['language'] )
271    {
272      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
273    }
274    $vtp->closeSession( $handle, 'option' );
275  }
276  $vtp->closeSession( $handle, 'select' );
277  $vtp->closeSession( $handle, 'line' );
278}
279//---------------------------------------------------------------- short period
280if ( in_array( 'short_period', $infos ) )
281{
282  $vtp->addSession( $handle, 'line' );
283  $vtp->setVar( $handle, 'line.name', $lang['customize_short_period'] );
284  $vtp->addSession( $handle, 'text' );
285  $vtp->setVar( $handle, 'text.name', 'short_period' );
286  $vtp->setVar( $handle, 'text.value', $user['short_period'] );
287  $vtp->closeSession( $handle, 'text' );
288  $vtp->closeSession( $handle, 'line' );
289}
290//----------------------------------------------------------------- long period
291if ( in_array( 'long_period', $infos ) )
292{
293  $vtp->addSession( $handle, 'line' );
294  $vtp->setVar( $handle, 'line.name', $lang['customize_long_period'] );
295  $vtp->addSession( $handle, 'text' );
296  $vtp->setVar( $handle, 'text.name', 'long_period' );
297  $vtp->setVar( $handle, 'text.value', $user['long_period'] );
298  $vtp->closeSession( $handle, 'text' );
299  $vtp->closeSession( $handle, 'line' );
300}
301//--------------------------------------------------------- max displayed width
302if ( in_array( 'maxwidth', $infos ) )
303{
304  $vtp->addSession( $handle, 'line' );
305  $vtp->setVar( $handle, 'line.name', $lang['maxwidth'] );
306  $vtp->addSession( $handle, 'text' );
307  $vtp->setVar( $handle, 'text.name', 'maxwidth' );
308  $vtp->setVar( $handle, 'text.value', $user['maxwidth'] );
309  $vtp->closeSession( $handle, 'text' );
310  $vtp->closeSession( $handle, 'line' );
311}
312//-------------------------------------------------------- max displayed height
313if ( in_array( 'maxheight', $infos ) )
314{
315  $vtp->addSession( $handle, 'line' );
316  $vtp->setVar( $handle, 'line.name', $lang['maxheight'] );
317  $vtp->addSession( $handle, 'text' );
318  $vtp->setVar( $handle, 'text.name', 'maxheight' );
319  $vtp->setVar( $handle, 'text.value', $user['maxheight'] );
320  $vtp->closeSession( $handle, 'text' );
321  $vtp->closeSession( $handle, 'line' );
322}
323//---------------------------------------------------------------- mail address
324if ( in_array( 'mail_address', $infos ) )
325{
326  $vtp->addSession( $handle, 'line' );
327  $vtp->setVar( $handle, 'line.name', $lang['mail_address'] );
328  $vtp->addSession( $handle, 'text' );
329  $vtp->setVar( $handle, 'text.name', 'mail_address' );
330  $vtp->setVar( $handle, 'text.value', $user['mail_address'] );
331  $vtp->closeSession( $handle, 'text' );
332  $vtp->closeSession( $handle, 'line' );
333}
334//----------------------------------------------------- expand all categories ?
335if ( in_array( 'expand', $infos ) )
336{
337  $vtp->addSession( $handle, 'line' );
338  $vtp->setVar( $handle, 'line.name', $lang['customize_expand'] );
339  $vtp->addSession( $handle, 'group' );
340  $vtp->addSession( $handle, 'radio' );
341  $vtp->setVar( $handle, 'radio.name', 'expand' );
342  $vtp->setVar( $handle, 'radio.value', 'true' );
343  $checked = '';
344  if ( $user['expand'] )
345  {
346    $checked = ' checked="checked"';
347  }
348  $vtp->setVar( $handle, 'radio.checked', $checked );
349  $vtp->setVar( $handle, 'radio.option', $lang['yes'] );
350  $vtp->closeSession( $handle, 'radio' );
351  $vtp->addSession( $handle, 'radio' );
352  $vtp->setVar( $handle, 'radio.name', 'expand' );
353  $vtp->setVar( $handle, 'radio.value', 'false' );
354  $checked = '';
355  if ( !$user['expand'] )
356  {
357    $checked = ' checked="checked"';
358  }
359  $vtp->setVar( $handle, 'radio.checked', $checked );
360  $vtp->setVar( $handle, 'radio.option', $lang['no'] );
361  $vtp->closeSession( $handle, 'radio' );
362  $vtp->closeSession( $handle, 'group' );
363  $vtp->closeSession( $handle, 'line' );
364}
365//---------------------------------- show number of comments on thumbnails page
366if ( in_array( 'show_nb_comments', $infos ) )
367{
368  $vtp->addSession( $handle, 'line' );
369  $vtp->setVar( $handle, 'line.name', $lang['customize_show_nb_comments'] );
370  $vtp->addSession( $handle, 'group' );
371  $vtp->addSession( $handle, 'radio' );
372  $vtp->setVar( $handle, 'radio.name', 'show_nb_comments' );
373  $vtp->setVar( $handle, 'radio.value', 'true' );
374  $checked = '';
375  if ( $user['show_nb_comments'] )
376  {
377    $checked = ' checked="checked"';
378  }
379  $vtp->setVar( $handle, 'radio.checked', $checked );
380  $vtp->setVar( $handle, 'radio.option', $lang['yes'] );
381  $vtp->closeSession( $handle, 'radio' );
382  $vtp->addSession( $handle, 'radio' );
383  $vtp->setVar( $handle, 'radio.name', 'show_nb_comments' );
384  $vtp->setVar( $handle, 'radio.value', 'false' );
385  $checked = '';
386  if ( !$user['show_nb_comments'] )
387  {
388    $checked = ' checked="checked"';
389  }
390  $vtp->setVar( $handle, 'radio.checked', $checked );
391  $vtp->setVar( $handle, 'radio.option', $lang['no'] );
392  $vtp->closeSession( $handle, 'radio' );
393  $vtp->closeSession( $handle, 'group' );
394  $vtp->closeSession( $handle, 'line' );
395}
396//----------------------------------------------------------- html code display
397$code = $vtp->Display( $handle, 0 );
398echo $code;
399?>
Note: See TracBrowser for help on using the repository browser.