source: trunk/profile.php @ 17

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

search improved

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