source: trunk/admin/configuration.php @ 670

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