source: trunk/profile.php @ 351

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

Template modification
Split of the french language file

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                           profile.php                           |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : 1.4                                           |
7// | author        : Pierrick LE GALL <pierrick@z0rglub.com>               |
8// +-----------------------------------------------------------------------+
9// | file          : $RCSfile$
10// | last update   : $Date: 2004-02-07 11:50:26 +0000 (Sat, 07 Feb 2004) $
11// | last modifier : $Author: gweltas $
12// | revision      : $Revision: 351 $
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//----------------------------------------------------------- include
21$phpwg_root_path = './';
22include_once( $phpwg_root_path.'common.php' );
23//-------------------------------------------------- access authorization check
24check_login_authorization();
25if ( $user['is_the_guest'] )
26{
27  echo '<div style="text-align:center;">'.$lang['only_members'].'<br />';
28  echo '<a href="./identification.php">'.$lang['ident_title'].'</a></div>';
29  exit();
30}
31//------------------------------------------------------ update & customization
32$infos = array( 'nb_image_line', 'nb_line_page', 'language',
33                'maxwidth', 'maxheight', 'expand', 'show_nb_comments',
34                'short_period', 'long_period', 'template', 'mail_address' );
35// mise à jour dans la base de données des valeurs
36// des paramètres pour l'utilisateur courant
37//    - on teste si chacune des variables est passée en argument à la page
38//    - ce qui signifie que l'on doit venir de la page de personnalisation
39$errors = array();
40if ( isset( $_POST['submit'] ) )
41{
42  $int_pattern = '/^\d+$/';
43  if ( $_POST['maxwidth'] != ''
44       and ( !preg_match( $int_pattern, $_POST['maxwidth'] )
45             or $_POST['maxwidth'] < 50 ) )
46  {
47    array_push( $errors, $lang['err_maxwidth'] );
48  }
49  if ( $_POST['maxheight']
50       and ( !preg_match( $int_pattern, $_POST['maxheight'] )
51             or $_POST['maxheight'] < 50 ) )
52  {
53    array_push( $errors, $lang['err_maxheight'] );
54  }
55  // periods must be integer values, they represents number of days
56  if ( !preg_match( $int_pattern, $_POST['short_period'] )
57       or !preg_match( $int_pattern, $_POST['long_period'] ) )
58  {
59    array_push( $errors, $lang['err_periods'] );
60  }
61  else
62  {
63    // long period must be longer than short period
64    if ( $_POST['long_period'] <= $_POST['short_period']
65         or $_POST['short_period'] <= 0 )
66    {
67      array_push( $errors, $lang['err_periods_2'] );
68    }
69  }
70  $mail_error = validate_mail_address( $_POST['mail_address'] );
71  if ( $mail_error != '' ) array_push( $errors, $mail_error );
72  // password must be the same as its confirmation
73  if ( isset( $_POST['use_new_pwd'] )
74       and $_POST['password'] != $_POST['passwordConf'] )
75    array_push( $errors, $lang['reg_err_pass'] );
76 
77  if ( count( $errors ) == 0 )
78  {
79    $query = 'UPDATE '.PREFIX_TABLE.'users';
80    $query.= ' SET ';
81    foreach ( $infos as $i => $info ) {
82      if ( $i > 0 ) $query.= ',';
83      $query.= $info;
84      $query.= ' = ';
85      if ( $_POST[$info] == '' ) $query.= 'NULL';
86      else                       $query.= "'".$_POST[$info]."'";
87    }
88    $query.= ' WHERE id = '.$user['id'];
89    $query.= ';';
90    mysql_query( $query );
91
92    if ( isset( $_POST['use_new_pwd'] ) )
93    {
94      $query = 'UPDATE '.PREFIX_TABLE.'users';
95      $query.= " SET password = '".md5( $_POST['password'] )."'";
96      $query.= ' WHERE id = '.$user['id'];
97      $query.= ';';
98      mysql_query( $query );
99    }
100    if ( isset( $_POST['create_cookie'] ) )
101    {
102      setcookie( 'id',$page['session_id'],$_POST['cookie_expiration'],
103                 cookie_path() );
104      // update the expiration date of the session
105      $query = 'UPDATE '.PREFIX_TABLE.'sessions';
106      $query.= ' SET expiration = '.$_POST['cookie_expiration'];
107      $query.= " WHERE id = '".$page['session_id']."'";
108      $query.= ';';
109      mysql_query( $query );
110    }
111    // redirection
112    $url = 'category.php';
113    if ( !isset($_POST['create_cookie']) ) $url = add_session_id( $url,true );
114    header( 'Request-URI: '.$url ); 
115    header( 'Content-Location: '.$url ); 
116    header( 'Location: '.$url );
117    exit();
118  }
119}
120//----------------------------------------------------- template initialization
121//
122// Start output of page
123//
124$title = $lang['customize_page_title'];
125include('include/page_header.php');
126
127$handle = $vtp->Open( './template/'.$user['template'].'/profile.vtp' );
128initialize_template();
129$tpl = array( 'customize_title','password','new',
130              'reg_confirm','submit','create_cookie' );
131templatize_array( $tpl, 'lang', $handle );
132//----------------------------------------------------------------- form action
133$url = './profile.php';
134$vtp->setGlobalVar( $handle, 'form_action', add_session_id( $url ) );
135//-------------------------------------------------------------- errors display
136if ( count( $errors ) != 0 )
137{
138  $vtp->addSession( $handle, 'errors' );
139  foreach ( $errors as $error ) {
140    $vtp->addSession( $handle, 'li' );
141    $vtp->setVar( $handle, 'li.li', $error );
142    $vtp->closeSession( $handle, 'li' );
143  }
144  $vtp->closeSession( $handle, 'errors' );
145}
146//---------------------------------------------------- number of images per row
147if ( in_array( 'nb_image_line', $infos ) )
148{
149  $vtp->addSession( $handle, 'line' );
150  $vtp->setVar( $handle, 'line.name', $lang['customize_nb_image_per_row'] );
151  $vtp->addSession( $handle, 'select' );
152  $vtp->setVar( $handle, 'select.name', 'nb_image_line' );
153  for ( $i = 0; $i < sizeof( $conf['nb_image_row'] ); $i++ )
154  {
155    $vtp->addSession( $handle, 'option' );
156    $vtp->setVar( $handle, 'option.option', $conf['nb_image_row'][$i] );
157    if ( $conf['nb_image_row'][$i] == $user['nb_image_line'] )
158    {
159      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
160    }
161    $vtp->closeSession( $handle, 'option' );
162  }
163  $vtp->closeSession( $handle, 'select' );
164  $vtp->closeSession( $handle, 'line' );
165}
166//------------------------------------------------------ number of row per page
167if ( in_array( 'nb_line_page', $infos ) )
168{
169  $vtp->addSession( $handle, 'line' );
170  $vtp->setVar( $handle, 'line.name', $lang['customize_nb_row_per_page'] );
171  $vtp->addSession( $handle, 'select' );
172  $vtp->setVar( $handle, 'select.name', 'nb_line_page' );
173  for ( $i = 0; $i < sizeof( $conf['nb_row_page'] ); $i++ )
174  {
175    $vtp->addSession( $handle, 'option' );
176    $vtp->setVar( $handle, 'option.option', $conf['nb_row_page'][$i] );
177    if ( $conf['nb_row_page'][$i] == $user['nb_line_page'] )
178    {
179      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
180    }
181    $vtp->closeSession( $handle, 'option' );
182  }
183  $vtp->closeSession( $handle, 'select' );
184  $vtp->closeSession( $handle, 'line' );
185}
186//-------------------------------------------------------------------- template
187if ( in_array( 'template', $infos ) )
188{
189  $vtp->addSession( $handle, 'line' );
190  $vtp->setVar( $handle, 'line.name', $lang['customize_template'] );
191  $vtp->addSession( $handle, 'select' );
192  $vtp->setVar( $handle, 'select.name', 'template' );
193  $option = get_dirs( './template' );
194  for ( $i = 0; $i < sizeof( $option ); $i++ )
195  {
196    $vtp->addSession( $handle, 'option' );
197    $vtp->setVar( $handle, 'option.option', $option[$i] );
198    if ( $option[$i] == $user['template'] )
199    {
200      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
201    }
202    $vtp->closeSession( $handle, 'option' );
203  }
204  $vtp->closeSession( $handle, 'select' );
205  $vtp->closeSession( $handle, 'line' );
206}
207//-------------------------------------------------------------------- language
208if ( in_array( 'language', $infos ) )
209{
210  $vtp->addSession( $handle, 'line' );
211  $vtp->setVar( $handle, 'line.name', $lang['customize_language'] );
212  $vtp->addSession( $handle, 'select' );
213  $vtp->setVar( $handle, 'select.name', 'language' );
214  $option = get_languages( './language/' );
215  for ( $i = 0; $i < sizeof( $option ); $i++ )
216  {
217    $vtp->addSession( $handle, 'option' );
218    $vtp->setVar( $handle, 'option.option', $option[$i] );
219    if( $option[$i] == $user['language'] )
220    {
221      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
222    }
223    $vtp->closeSession( $handle, 'option' );
224  }
225  $vtp->closeSession( $handle, 'select' );
226  $vtp->closeSession( $handle, 'line' );
227}
228//---------------------------------------------------------------- short period
229if ( in_array( 'short_period', $infos ) )
230{
231  $vtp->addSession( $handle, 'line' );
232  $vtp->setVar( $handle, 'line.name', $lang['customize_short_period'] );
233  $vtp->addSession( $handle, 'text' );
234  $vtp->setVar( $handle, 'text.name', 'short_period' );
235  $vtp->setVar( $handle, 'text.value', $user['short_period'] );
236  $vtp->closeSession( $handle, 'text' );
237  $vtp->closeSession( $handle, 'line' );
238}
239//----------------------------------------------------------------- long period
240if ( in_array( 'long_period', $infos ) )
241{
242  $vtp->addSession( $handle, 'line' );
243  $vtp->setVar( $handle, 'line.name', $lang['customize_long_period'] );
244  $vtp->addSession( $handle, 'text' );
245  $vtp->setVar( $handle, 'text.name', 'long_period' );
246  $vtp->setVar( $handle, 'text.value', $user['long_period'] );
247  $vtp->closeSession( $handle, 'text' );
248  $vtp->closeSession( $handle, 'line' );
249}
250//--------------------------------------------------------- max displayed width
251if ( in_array( 'maxwidth', $infos ) )
252{
253  $vtp->addSession( $handle, 'line' );
254  $vtp->setVar( $handle, 'line.name', $lang['maxwidth'] );
255  $vtp->addSession( $handle, 'text' );
256  $vtp->setVar( $handle, 'text.name', 'maxwidth' );
257  $vtp->setVar( $handle, 'text.value', $user['maxwidth'] );
258  $vtp->closeSession( $handle, 'text' );
259  $vtp->closeSession( $handle, 'line' );
260}
261//-------------------------------------------------------- max displayed height
262if ( in_array( 'maxheight', $infos ) )
263{
264  $vtp->addSession( $handle, 'line' );
265  $vtp->setVar( $handle, 'line.name', $lang['maxheight'] );
266  $vtp->addSession( $handle, 'text' );
267  $vtp->setVar( $handle, 'text.name', 'maxheight' );
268  $vtp->setVar( $handle, 'text.value', $user['maxheight'] );
269  $vtp->closeSession( $handle, 'text' );
270  $vtp->closeSession( $handle, 'line' );
271}
272//---------------------------------------------------------------- mail address
273if ( in_array( 'mail_address', $infos ) )
274{
275  $vtp->addSession( $handle, 'line' );
276  $vtp->setVar( $handle, 'line.name', $lang['mail_address'] );
277  $vtp->addSession( $handle, 'text' );
278  $vtp->setVar( $handle, 'text.name', 'mail_address' );
279  $vtp->setVar( $handle, 'text.value', $user['mail_address'] );
280  $vtp->closeSession( $handle, 'text' );
281  $vtp->closeSession( $handle, 'line' );
282}
283//----------------------------------------------------- expand all categories ?
284if ( in_array( 'expand', $infos ) )
285{
286  $vtp->addSession( $handle, 'line' );
287  $vtp->setVar( $handle, 'line.name', $lang['customize_expand'] );
288  $vtp->addSession( $handle, 'group' );
289  $vtp->addSession( $handle, 'radio' );
290  $vtp->setVar( $handle, 'radio.name', 'expand' );
291  $vtp->setVar( $handle, 'radio.value', 'true' );
292  $checked = '';
293  if ( $user['expand'] )
294  {
295    $checked = ' checked="checked"';
296  }
297  $vtp->setVar( $handle, 'radio.checked', $checked );
298  $vtp->setVar( $handle, 'radio.option', $lang['yes'] );
299  $vtp->closeSession( $handle, 'radio' );
300  $vtp->addSession( $handle, 'radio' );
301  $vtp->setVar( $handle, 'radio.name', 'expand' );
302  $vtp->setVar( $handle, 'radio.value', 'false' );
303  $checked = '';
304  if ( !$user['expand'] )
305  {
306    $checked = ' checked="checked"';
307  }
308  $vtp->setVar( $handle, 'radio.checked', $checked );
309  $vtp->setVar( $handle, 'radio.option', $lang['no'] );
310  $vtp->closeSession( $handle, 'radio' );
311  $vtp->closeSession( $handle, 'group' );
312  $vtp->closeSession( $handle, 'line' );
313}
314//---------------------------------- show number of comments on thumbnails page
315if ( in_array( 'show_nb_comments', $infos ) )
316{
317  $vtp->addSession( $handle, 'line' );
318  $vtp->setVar( $handle, 'line.name', $lang['customize_show_nb_comments'] );
319  $vtp->addSession( $handle, 'group' );
320  $vtp->addSession( $handle, 'radio' );
321  $vtp->setVar( $handle, 'radio.name', 'show_nb_comments' );
322  $vtp->setVar( $handle, 'radio.value', 'true' );
323  $checked = '';
324  if ( $user['show_nb_comments'] )
325  {
326    $checked = ' checked="checked"';
327  }
328  $vtp->setVar( $handle, 'radio.checked', $checked );
329  $vtp->setVar( $handle, 'radio.option', $lang['yes'] );
330  $vtp->closeSession( $handle, 'radio' );
331  $vtp->addSession( $handle, 'radio' );
332  $vtp->setVar( $handle, 'radio.name', 'show_nb_comments' );
333  $vtp->setVar( $handle, 'radio.value', 'false' );
334  $checked = '';
335  if ( !$user['show_nb_comments'] )
336  {
337    $checked = ' checked="checked"';
338  }
339  $vtp->setVar( $handle, 'radio.checked', $checked );
340  $vtp->setVar( $handle, 'radio.option', $lang['no'] );
341  $vtp->closeSession( $handle, 'radio' );
342  $vtp->closeSession( $handle, 'group' );
343  $vtp->closeSession( $handle, 'line' );
344}
345//--------------------------------------------------------------- create cookie
346if ( $conf['authorize_cookies'] )
347{
348  $vtp->addSession( $handle, 'cookie' );
349  $options = array(
350    array( 'message' => '1 '.$lang['customize_day'],
351           'value' => time() + 24*60*60 ),
352    array( 'message' => '1 '.$lang['customize_week'],
353           'value' => time() + 7*24*60*60 ),
354    array( 'message' => '1 '.$lang['customize_month'],
355           'value' => time() + 30*24*60*60 ),
356    array( 'message' => '1 '.$lang['customize_year'],
357           'value' => time() + 365*24*60*60 )
358    );
359  foreach ( $options as $option ) {
360    $vtp->addSession( $handle, 'expiration_option' );
361    $vtp->setVar( $handle, 'expiration_option.option', $option['message'] );
362    $vtp->setVar( $handle, 'expiration_option.value', $option['value'] );
363    $vtp->closeSession( $handle, 'expiration_option' );
364  }
365  $vtp->closeSession( $handle, 'cookie' );
366}
367//----------------------------------------------------------- html code display
368$code = $vtp->Display( $handle, 0 );
369echo $code;
370include('include/page_tail.php');
371?>
Note: See TracBrowser for help on using the repository browser.