source: branches/branch-1_4/admin/configuration.php @ 1455

Last change on this file since 1455 was 788, checked in by plg, 20 years ago
  • bug 114 corrected : webmaster mail address protection. Ability to set an invalid mail address (but not during installation)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.2 KB
RevLine 
[362]1<?php
2// +-----------------------------------------------------------------------+
[593]3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
[675]5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
[362]6// +-----------------------------------------------------------------------+
[593]7// | branch        : BSF (Best So Far)
[362]8// | file          : $RCSfile$
9// | last update   : $Date: 2005-05-14 12:56:48 +0000 (Sat, 14 May 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 788 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
[2]27
[527]28if( !defined("PHPWG_ROOT_PATH") )
[393]29{
[527]30        die ("Hacking attempt!");
[393]31}
[527]32
33include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' );
[512]34//-------------------------------------------------------- sections definitions
35if (!isset($_GET['section']))
36{
37  $page['section'] = 'general';
38}
39else
40{
41  $page['section'] = $_GET['section'];
42}
43//------------------------------------------------------ $conf reinitialization
[587]44$result = pwg_query('SELECT param,value FROM '.CONFIG_TABLE);
[512]45while ($row = mysql_fetch_array($result))
46{
47  $conf[$row['param']] = $row['value'];
[516]48  // if the parameter is present in $_POST array (if a form is submited), we
49  // override it with the submited value
[700]50  if (isset($_POST[$row['param']]))
[512]51  {
52    $conf[$row['param']] = $_POST[$row['param']];
53  }
[527]54}                                         
[2]55//------------------------------ verification and registration of modifications
[512]56$errors = array();
57if (isset($_POST['submit']))
[2]58{
[21]59  $int_pattern = '/^\d+$/';
[512]60  switch ($page['section'])
[2]61  {
[512]62    case 'general' :
[130]63    {
[512]64      // thumbnail prefix must only contain simple ASCII characters
65      if (!preg_match('/^[\w-]*$/', $_POST['prefix_thumbnail']))
66      {
[527]67        array_push($errors, $lang['conf_prefix_thumbnail_error']);
[512]68      }
[788]69      // as webmaster mail address shown on the website, it can be obfuscated
70      // and no comply with normal mail address pattern
[512]71      break;
[130]72    }
[512]73    case 'comments' :
74    {
75      // the number of comments per page must be an integer between 5 and 50
76      // included
77      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
78           or $_POST['nb_comment_page'] < 5
79           or $_POST['nb_comment_page'] > 50)
80      {
[527]81        array_push($errors, $lang['conf_nb_comment_page_error']);
[512]82      }
83      break;
84    }
85    case 'default' :
86    {
87      // periods must be integer values, they represents number of days
88      if (!preg_match($int_pattern, $_POST['recent_period'])
89          or $_POST['recent_period'] <= 0)
90      {
[527]91        array_push($errors, $lang['periods_error']);
[512]92      }
[779]93      // maxwidth
94      if (isset($_POST['default_maxwidth'])
95          and !empty($_POST['default_maxwidth'])
96          and (!preg_match($int_pattern, $_POST['default_maxwidth'])
97               or $_POST['default_maxwidth'] < 50))
98      {
99        array_push($errors, $lang['maxwidth_error']);
100      }
101      // maxheight
102      if (isset($_POST['default_maxheight'])
103          and !empty($_POST['default_maxheight'])
104          and (!preg_match($int_pattern, $_POST['default_maxheight'])
105               or $_POST['default_maxheight'] < 50))
106      {
107        array_push($errors, $lang['maxheight_error']);
108      }
[512]109      break;
110    }
111    case 'upload' :
112    {
113      // the maximum upload filesize must be an integer between 10 and 1000
114      if (!preg_match($int_pattern, $_POST['upload_maxfilesize'])
115          or $_POST['upload_maxfilesize'] < 10
116          or $_POST['upload_maxfilesize'] > 1000)
117      {
[527]118        array_push($errors, $lang['conf_upload_maxfilesize_error']);
[512]119      }
120     
121      foreach (array('upload_maxwidth',
122                     'upload_maxheight',
123                     'upload_maxwidth_thumbnail',
124                     'upload_maxheight_thumbnail')
125               as $field)
126      {
127        if (!preg_match($int_pattern, $_POST[$field])
128          or $_POST[$field] < 10)
129        {
[527]130          array_push($errors, $lang['conf_'.$field.'_error']);
[512]131        }
132      }
133      break;
134    }
[2]135  }
[512]136 
[528]137  // updating configuration if no error found
[512]138  if (count($errors) == 0)
[345]139  {
[587]140    $result = pwg_query('SELECT * FROM '.CONFIG_TABLE);
[512]141    while ($row = mysql_fetch_array($result))
142    {
143      if (isset($_POST[$row['param']]))
144      {
[528]145        $query = '
146UPDATE '.CONFIG_TABLE.'
147  SET value = \''. str_replace("\'", "''", $_POST[$row['param']]).'\'
148  WHERE param = \''.$row['param'].'\'
149;';
[587]150        pwg_query($query);
[512]151      }
152    }
[345]153  }
[512]154}
[527]155
[512]156//----------------------------------------------------- template initialization
[527]157$template->set_filenames( array('config'=>'admin/configuration.tpl') );
[512]158
[528]159$action = PHPWG_ROOT_PATH.'admin.php?page=configuration';
160$action.= '&amp;section='.$page['section'];
[21]161
[528]162$template->assign_vars(
163  array(
164    'L_CONFIRM'=>$lang['conf_confirmation'],
165    'L_YES'=>$lang['yes'],
166    'L_NO'=>$lang['no'],
167    'L_SUBMIT'=>$lang['submit'],
168    'L_RESET'=>$lang['reset'],
169   
170    'F_ACTION'=>add_session_id($action)
171    ));
172
[527]173switch ($page['section'])
[528]174{
175  case 'general' :
[2]176  {
[528]177    $history_yes = ($conf['log']=='true')?'checked="checked"':'';
178    $history_no  = ($conf['log']=='false')?'checked="checked"':'';
179    $notif_yes = ($conf['mail_notification']=='true')?'checked="checked"':'';
180    $notif_no = ($conf['mail_notification']=='false')?'checked="checked"':'';
[653]181    $lock_yes = ($conf['gallery_locked']=='true')?'checked="checked"':'';
182    $lock_no = ($conf['gallery_locked']=='false')?'checked="checked"':'';
[528]183   
184    $template->assign_block_vars(
185      'general',
186      array(
187        'L_CONF_TITLE'=>$lang['conf_general_title'],
188        'L_CONF_MAIL'=>$lang['conf_mail_webmaster'],
189        'L_CONF_MAIL_INFO'=>$lang['conf_mail_webmaster_info'],
190        'L_CONF_TN_PREFIX'=>$lang['conf_prefix'],
191        'L_CONF_TN_PREFIX_INFO'=>$lang['conf_prefix_info'],
192        'L_CONF_HISTORY'=>$lang['history'],
193        'L_CONF_HISTORY_INFO'=>$lang['conf_log_info'],
194        'L_CONF_NOTIFICATION'=>$lang['conf_notification'],
195        'L_CONF_NOTIFICATION_INFO'=>$lang['conf_notification_info'],
[653]196        'L_CONF_GALLERY_LOCKED'=>$lang['conf_gallery_locked'],
197        'L_CONF_GALLERY_LOCKED_INFO'=>$lang['conf_gallery_locked_info'],
[528]198         
199        'ADMIN_MAIL'=>$conf['mail_webmaster'],
200        'THUMBNAIL_PREFIX'=>$conf['prefix_thumbnail'],
201        'HISTORY_YES'=>$history_yes,
202        'HISTORY_NO'=>$history_no,
203        'NOTIFICATION_YES'=>$notif_yes,
[653]204        'NOTIFICATION_NO'=>$notif_no,
205        'GALLERY_LOCKED_YES'=>$lock_yes,
206        'GALLERY_LOCKED_NO'=>$lock_no,
[528]207        ));
208    break;
209  }
210  case 'comments' :
211  {
212    $all_yes = ($conf['comments_forall']=='true')?'checked="checked"':'';
213    $all_no  = ($conf['comments_forall']=='false')?'checked="checked"':'';
214    $validate_yes = ($conf['comments_validation']=='true')?'checked="checked"':'';
215    $validate_no = ($conf['comments_validation']=='false')?'checked="checked"':'';
216     
217    $template->assign_block_vars(
218      'comments',
219      array(
220        'L_CONF_TITLE'=>$lang['conf_comments_title'],
221        'L_CONF_COMMENTS_ALL'=>$lang['conf_comments_forall'],
222        'L_CONF_COMMENTS_ALL_INFO'=>$lang['conf_comments_forall_info'],
223        'L_CONF_NB_COMMENTS_PAGE'=>$lang['conf_nb_comment_page'],
224        'L_CONF_NB_COMMENTS_PAGE_INFO'=>$lang['conf_nb_comment_page'],
225        'L_CONF_VALIDATE'=>$lang['conf_comments_validation'],
226        'L_CONF_VALIDATE_INFO'=>$lang['conf_comments_validation_info'],
227         
228        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
229        'COMMENTS_ALL_YES'=>$all_yes,
230        'COMMENTS_ALL_NO'=>$all_no,
231        'VALIDATE_YES'=>$validate_yes,
232        'VALIDATE_NO'=>$validate_no
233        ));
234    break;
235  }
236  case 'default' :
237  {
238    $show_yes = ($conf['show_nb_comments']=='true')?'checked="checked"':'';
239    $show_no = ($conf['show_nb_comments']=='false')?'checked="checked"':'';
240    $expand_yes = ($conf['auto_expand']=='true')?'checked="checked"':'';
241    $expand_no  = ($conf['auto_expand']=='false')?'checked="checked"':'';
242     
243    $template->assign_block_vars(
244      'default',
245      array(
246        'L_CONF_TITLE'=>$lang['conf_default_title'],
247        'L_CONF_LANG'=>$lang['language'],
248        'L_CONF_LANG_INFO'=>$lang['conf_default_language_info'],
249        'L_NB_IMAGE_LINE'=>$lang['nb_image_per_row'],
250        'L_NB_IMAGE_LINE_INFO'=>$lang['conf_nb_image_line_info'],
251        'L_NB_ROW_PAGE'=>$lang['nb_row_per_page'],
252        'L_NB_ROW_PAGE_INFO'=>$lang['conf_nb_line_page_info'],
253        'L_CONF_STYLE'=>$lang['theme'],
254        'L_CONF_STYLE_INFO'=>$lang['conf_default_theme_info'],
255        'L_CONF_RECENT'=>$lang['recent_period'],
256        'L_CONF_RECENT_INFO'=>$lang['conf_recent_period_info'],
257        'L_CONF_EXPAND'=>$lang['auto_expand'],
258        'L_CONF_EXPAND_INFO'=>$lang['conf_default_expand_info'],
259        'L_NB_COMMENTS'=>$lang['show_nb_comments'],
260        'L_NB_COMMENTS_INFO'=>$lang['conf_show_nb_comments_info'],
[649]261        'L_MAXWIDTH'=>$lang['maxwidth'],
262        'L_MAXHEIGHT'=>$lang['maxheight'],
[527]263 
[528]264        'CONF_LANG_SELECT'=>language_select($conf['default_language'], 'default_language'),
265        'NB_IMAGE_LINE'=>$conf['nb_image_line'],
266        'NB_ROW_PAGE'=>$conf['nb_line_page'],
267        'CONF_STYLE_SELECT'=>style_select($conf['default_template'], 'default_template'),
268        'CONF_RECENT'=>$conf['recent_period'],
269        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
[779]270        'MAXWIDTH'=>$conf['default_maxwidth'],
271        'MAXHEIGHT'=>$conf['default_maxheight'],
[528]272        'EXPAND_YES'=>$expand_yes,
273        'EXPAND_NO'=>$expand_no,
274        'SHOW_COMMENTS_YES'=>$show_yes,
275        'SHOW_COMMENTS_NO'=>$show_no
276        ));
277    break;
[2]278  }
[528]279  case 'upload' :
280  {
281    $template->assign_block_vars(
282      'upload',
283      array(
284        'L_CONF_TITLE'=>$lang['conf_upload_title'],
285        'L_CONF_MAXSIZE'=>$lang['conf_upload_maxfilesize'],
286        'L_CONF_MAXSIZE_INFO'=>$lang['conf_upload_maxfilesize_info'],
287        'L_CONF_MAXWIDTH'=>$lang['conf_upload_maxwidth'],
288        'L_CONF_MAXWIDTH_INFO'=>$lang['conf_upload_maxwidth_info'],
289        'L_CONF_MAXHEIGHT'=>$lang['conf_upload_maxheight'],
290        'L_CONF_MAXHEIGHT_INFO'=>$lang['conf_upload_maxheight_info'],
291        'L_CONF_TN_MAXWIDTH'=>$lang['conf_upload_tn_maxwidth'],
292        'L_CONF_TN_MAXWIDTH_INFO'=>$lang['conf_upload_tn_maxwidth_info'],
293        'L_CONF_TN_MAXHEIGHT'=>$lang['conf_upload_tn_maxheight'],
294        'L_CONF_TN_MAXHEIGHT_INFO'=>$lang['conf_upload_tn_maxheight_info'],
295         
296        'UPLOAD_MAXSIZE'=>$conf['upload_maxfilesize'],
297        'UPLOAD_MAXWIDTH'=>$conf['upload_maxwidth'],
298        'UPLOAD_MAXHEIGHT'=>$conf['upload_maxheight'],
299        'TN_UPLOAD_MAXWIDTH'=>$conf['upload_maxwidth_thumbnail'],
300        'TN_UPLOAD_MAXHEIGHT'=>$conf['upload_maxheight_thumbnail'],
301        ));
302    break;
303  }
304  case 'session' :
305  {
[541]306    $authorize_remembering_yes =
307      ($conf['authorize_remembering']=='true')?'checked="checked"':'';
308    $authorize_remembering_no =
309      ($conf['authorize_remembering']=='false')?'checked="checked"':'';
[528]310     
311    $template->assign_block_vars(
312      'session',
313      array(
314        'L_CONF_TITLE'=>$lang['conf_session_title'],
[541]315        'L_CONF_AUTHORIZE_REMEMBERING'=>$lang['conf_authorize_remembering'],
316        'L_CONF_AUTHORIZE_REMEMBERING_INFO' =>
317        $lang['conf_authorize_remembering_info'],
318
319        'AUTHORIZE_REMEMBERING_YES'=>$authorize_remembering_yes,
320        'AUTHORIZE_REMEMBERING_NO'=>$authorize_remembering_no
[528]321        ));
322    break;
323  }
324  case 'metadata' :
325  {
326    $exif_yes = ($conf['use_exif']=='true')?'checked="checked"':'';
327    $exif_no = ($conf['use_exif']=='false')?'checked="checked"':'';
328    $iptc_yes = ($conf['use_iptc']=='true')?'checked="checked"':'';
329    $iptc_no = ($conf['use_iptc']=='false')?'checked="checked"':'';
330    $show_exif_yes = ($conf['show_exif']=='true')?'checked="checked"':'';
331    $show_exif_no = ($conf['show_exif']=='false')?'checked="checked"':'';
332    $show_iptc_yes = ($conf['show_iptc']=='true')?'checked="checked"':'';
333    $show_iptc_no = ($conf['show_iptc']=='false')?'checked="checked"':'';
334     
335    $template->assign_block_vars(
336      'metadata',
337      array(
338        'L_CONF_TITLE'=>$lang['conf_metadata_title'],
339        'L_CONF_EXIF'=>$lang['conf_use_exif'],
340        'L_CONF_EXIF_INFO'=>$lang['conf_use_exif_info'],
341        'L_CONF_IPTC'=>$lang['conf_use_iptc'],
342        'L_CONF_IPTC_INFO'=>$lang['conf_use_iptc_info'],
343        'L_CONF_SHOW_EXIF'=>$lang['conf_show_exif'],
344        'L_CONF_SHOW_EXIF_INFO'=>$lang['conf_show_exif_info'],
345        'L_CONF_SHOW_IPTC'=>$lang['conf_show_iptc'],
346        'L_CONF_SHOW_IPTC_INFO'=>$lang['conf_show_iptc_info'],
347         
348        'USE_EXIF_YES'=>$exif_yes,
349        'USE_EXIF_NO'=>$exif_no,
350        'USE_IPTC_YES'=>$iptc_yes,
351        'USE_IPTC_NO'=>$iptc_no,
352        'SHOW_EXIF_YES'=>$show_exif_yes,
353        'SHOW_EXIF_NO'=>$show_exif_no,
354        'SHOW_IPTC_YES'=>$show_iptc_yes,
355        'SHOW_IPTC_NO'=>$show_iptc_no
356        ));
357    break;
358  }
359}
[2]360//-------------------------------------------------------------- errors display
[527]361if ( sizeof( $errors ) != 0 )
[2]362{
[393]363  $template->assign_block_vars('errors',array());
[527]364  for ( $i = 0; $i < sizeof( $errors ); $i++ )
[2]365  {
[527]366    $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
[2]367  }
368}
[527]369elseif ( isset( $_POST['submit'] ) )
[2]370{
[393]371  $template->assign_block_vars('confirmation' ,array());
[2]372}
373//----------------------------------------------------------- sending html code
[393]374$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
[362]375?>
Note: See TracBrowser for help on using the repository browser.