source: tags/version_1_3/profile.php @ 14166

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

Initial revision

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