source: trunk/admin/configuration.php @ 587

Last change on this file since 587 was 587, checked in by z0rglub, 20 years ago
  • function mysql_query replaced by pwg_query : the same with debugging features
  • by default, DEBUG is set to 0 (off)
  • 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// |                           configuration.php                           |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-10-30 15:42:29 +0000 (Sat, 30 Oct 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 587 $
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    $access_free = ($conf['access']=='free')?'checked="checked"':'';
166    $access_restricted = ($conf['access']=='restricted')?'checked="checked"':'';
167    $history_yes = ($conf['log']=='true')?'checked="checked"':'';
168    $history_no  = ($conf['log']=='false')?'checked="checked"':'';
169    $notif_yes = ($conf['mail_notification']=='true')?'checked="checked"':'';
170    $notif_no = ($conf['mail_notification']=='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_ACCESS'=>$lang['conf_access'],
181        'L_CONF_ACCESS_INFO'=>$lang['conf_access_info'],
182        'L_CONF_ACCESS_FREE'=>$lang['free'],
183        'L_CONF_ACCESS_RESTRICTED'=>$lang['restricted'],
184        'L_CONF_HISTORY'=>$lang['history'],
185        'L_CONF_HISTORY_INFO'=>$lang['conf_log_info'],
186        'L_CONF_NOTIFICATION'=>$lang['conf_notification'],
187        'L_CONF_NOTIFICATION_INFO'=>$lang['conf_notification_info'],
188         
189        'ADMIN_MAIL'=>$conf['mail_webmaster'],
190        'THUMBNAIL_PREFIX'=>$conf['prefix_thumbnail'],
191        'ACCESS_FREE'=>$access_free,
192        'ACCESS_RESTRICTED'=>$access_restricted,
193        'HISTORY_YES'=>$history_yes,
194        'HISTORY_NO'=>$history_no,
195        'NOTIFICATION_YES'=>$notif_yes,
196        'NOTIFICATION_NO'=>$notif_no
197        ));
198    break;
199  }
200  case 'comments' :
201  {
202    $show_yes = ($conf['show_comments']=='true')?'checked="checked"':'';
203    $show_no = ($conf['show_comments']=='false')?'checked="checked"':'';
204    $all_yes = ($conf['comments_forall']=='true')?'checked="checked"':'';
205    $all_no  = ($conf['comments_forall']=='false')?'checked="checked"':'';
206    $validate_yes = ($conf['comments_validation']=='true')?'checked="checked"':'';
207    $validate_no = ($conf['comments_validation']=='false')?'checked="checked"':'';
208     
209    $template->assign_block_vars(
210      'comments',
211      array(
212        'L_CONF_TITLE'=>$lang['conf_comments_title'],
213        'L_CONF_SHOW_COMMENTS'=>$lang['conf_show_comments'],
214        'L_CONF_SHOW_COMMENTS_INFO'=>$lang['conf_show_comments_info'],
215        'L_CONF_COMMENTS_ALL'=>$lang['conf_comments_forall'],
216        'L_CONF_COMMENTS_ALL_INFO'=>$lang['conf_comments_forall_info'],
217        'L_CONF_NB_COMMENTS_PAGE'=>$lang['conf_nb_comment_page'],
218        'L_CONF_NB_COMMENTS_PAGE_INFO'=>$lang['conf_nb_comment_page'],
219        'L_CONF_VALIDATE'=>$lang['conf_comments_validation'],
220        'L_CONF_VALIDATE_INFO'=>$lang['conf_comments_validation_info'],
221         
222        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
223        'SHOW_COMMENTS_YES'=>$show_yes,
224        'SHOW_COMMENTS_NO'=>$show_no,
225        'COMMENTS_ALL_YES'=>$all_yes,
226        'COMMENTS_ALL_NO'=>$all_no,
227        'VALIDATE_YES'=>$validate_yes,
228        'VALIDATE_NO'=>$validate_no
229        ));
230    break;
231  }
232  case 'default' :
233  {
234    $show_yes = ($conf['show_nb_comments']=='true')?'checked="checked"':'';
235    $show_no = ($conf['show_nb_comments']=='false')?'checked="checked"':'';
236    $expand_yes = ($conf['auto_expand']=='true')?'checked="checked"':'';
237    $expand_no  = ($conf['auto_expand']=='false')?'checked="checked"':'';
238     
239    $template->assign_block_vars(
240      'default',
241      array(
242        'L_CONF_TITLE'=>$lang['conf_default_title'],
243        'L_CONF_LANG'=>$lang['language'],
244        'L_CONF_LANG_INFO'=>$lang['conf_default_language_info'],
245        'L_NB_IMAGE_LINE'=>$lang['nb_image_per_row'],
246        'L_NB_IMAGE_LINE_INFO'=>$lang['conf_nb_image_line_info'],
247        'L_NB_ROW_PAGE'=>$lang['nb_row_per_page'],
248        'L_NB_ROW_PAGE_INFO'=>$lang['conf_nb_line_page_info'],
249        'L_CONF_STYLE'=>$lang['theme'],
250        'L_CONF_STYLE_INFO'=>$lang['conf_default_theme_info'],
251        'L_CONF_RECENT'=>$lang['recent_period'],
252        'L_CONF_RECENT_INFO'=>$lang['conf_recent_period_info'],
253        'L_CONF_EXPAND'=>$lang['auto_expand'],
254        'L_CONF_EXPAND_INFO'=>$lang['conf_default_expand_info'],
255        'L_NB_COMMENTS'=>$lang['show_nb_comments'],
256        'L_NB_COMMENTS_INFO'=>$lang['conf_show_nb_comments_info'],
257 
258        'CONF_LANG_SELECT'=>language_select($conf['default_language'], 'default_language'),
259        'NB_IMAGE_LINE'=>$conf['nb_image_line'],
260        'NB_ROW_PAGE'=>$conf['nb_line_page'],
261        'CONF_STYLE_SELECT'=>style_select($conf['default_template'], 'default_template'),
262        'CONF_RECENT'=>$conf['recent_period'],
263        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
264        'EXPAND_YES'=>$expand_yes,
265        'EXPAND_NO'=>$expand_no,
266        'SHOW_COMMENTS_YES'=>$show_yes,
267        'SHOW_COMMENTS_NO'=>$show_no
268        ));
269    break;
270  }
271  case 'upload' :
272  {
273    $upload_yes = ($conf['upload_available']=='true')?'checked="checked"':'';
274    $upload_no = ($conf['upload_available']=='false')?'checked="checked"':'';
275     
276    $template->assign_block_vars(
277      'upload',
278      array(
279        'L_CONF_TITLE'=>$lang['conf_upload_title'],
280        'L_CONF_UPLOAD'=>$lang['conf_authorize_upload'],
281        'L_CONF_UPLOAD_INFO'=>$lang['conf_authorize_upload_info'],
282        'L_CONF_MAXSIZE'=>$lang['conf_upload_maxfilesize'],
283        'L_CONF_MAXSIZE_INFO'=>$lang['conf_upload_maxfilesize_info'],
284        'L_CONF_MAXWIDTH'=>$lang['conf_upload_maxwidth'],
285        'L_CONF_MAXWIDTH_INFO'=>$lang['conf_upload_maxwidth_info'],
286        'L_CONF_MAXHEIGHT'=>$lang['conf_upload_maxheight'],
287        'L_CONF_MAXHEIGHT_INFO'=>$lang['conf_upload_maxheight_info'],
288        'L_CONF_TN_MAXWIDTH'=>$lang['conf_upload_tn_maxwidth'],
289        'L_CONF_TN_MAXWIDTH_INFO'=>$lang['conf_upload_tn_maxwidth_info'],
290        'L_CONF_TN_MAXHEIGHT'=>$lang['conf_upload_tn_maxheight'],
291        'L_CONF_TN_MAXHEIGHT_INFO'=>$lang['conf_upload_tn_maxheight_info'],
292         
293        'UPLOAD_MAXSIZE'=>$conf['upload_maxfilesize'],
294        'UPLOAD_MAXWIDTH'=>$conf['upload_maxwidth'],
295        'UPLOAD_MAXHEIGHT'=>$conf['upload_maxheight'],
296        'TN_UPLOAD_MAXWIDTH'=>$conf['upload_maxwidth_thumbnail'],
297        'TN_UPLOAD_MAXHEIGHT'=>$conf['upload_maxheight_thumbnail'],
298        'UPLOAD_YES'=>$upload_yes,
299        'UPLOAD_NO'=>$upload_no
300        ));
301    break;
302  }
303  case 'session' :
304  {
305    $authorize_remembering_yes =
306      ($conf['authorize_remembering']=='true')?'checked="checked"':'';
307    $authorize_remembering_no =
308      ($conf['authorize_remembering']=='false')?'checked="checked"':'';
309     
310    $template->assign_block_vars(
311      'session',
312      array(
313        'L_CONF_TITLE'=>$lang['conf_session_title'],
314        'L_CONF_AUTHORIZE_REMEMBERING'=>$lang['conf_authorize_remembering'],
315        'L_CONF_AUTHORIZE_REMEMBERING_INFO' =>
316        $lang['conf_authorize_remembering_info'],
317
318        'AUTHORIZE_REMEMBERING_YES'=>$authorize_remembering_yes,
319        'AUTHORIZE_REMEMBERING_NO'=>$authorize_remembering_no
320        ));
321    break;
322  }
323  case 'metadata' :
324  {
325    $exif_yes = ($conf['use_exif']=='true')?'checked="checked"':'';
326    $exif_no = ($conf['use_exif']=='false')?'checked="checked"':'';
327    $iptc_yes = ($conf['use_iptc']=='true')?'checked="checked"':'';
328    $iptc_no = ($conf['use_iptc']=='false')?'checked="checked"':'';
329    $show_exif_yes = ($conf['show_exif']=='true')?'checked="checked"':'';
330    $show_exif_no = ($conf['show_exif']=='false')?'checked="checked"':'';
331    $show_iptc_yes = ($conf['show_iptc']=='true')?'checked="checked"':'';
332    $show_iptc_no = ($conf['show_iptc']=='false')?'checked="checked"':'';
333     
334    $template->assign_block_vars(
335      'metadata',
336      array(
337        'L_CONF_TITLE'=>$lang['conf_metadata_title'],
338        'L_CONF_EXIF'=>$lang['conf_use_exif'],
339        'L_CONF_EXIF_INFO'=>$lang['conf_use_exif_info'],
340        'L_CONF_IPTC'=>$lang['conf_use_iptc'],
341        'L_CONF_IPTC_INFO'=>$lang['conf_use_iptc_info'],
342        'L_CONF_SHOW_EXIF'=>$lang['conf_show_exif'],
343        'L_CONF_SHOW_EXIF_INFO'=>$lang['conf_show_exif_info'],
344        'L_CONF_SHOW_IPTC'=>$lang['conf_show_iptc'],
345        'L_CONF_SHOW_IPTC_INFO'=>$lang['conf_show_iptc_info'],
346         
347        'USE_EXIF_YES'=>$exif_yes,
348        'USE_EXIF_NO'=>$exif_no,
349        'USE_IPTC_YES'=>$iptc_yes,
350        'USE_IPTC_NO'=>$iptc_no,
351        'SHOW_EXIF_YES'=>$show_exif_yes,
352        'SHOW_EXIF_NO'=>$show_exif_no,
353        'SHOW_IPTC_YES'=>$show_iptc_yes,
354        'SHOW_IPTC_NO'=>$show_iptc_no
355        ));
356    break;
357  }
358}
359//-------------------------------------------------------------- errors display
360if ( sizeof( $errors ) != 0 )
361{
362  $template->assign_block_vars('errors',array());
363  for ( $i = 0; $i < sizeof( $errors ); $i++ )
364  {
365    $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
366  }
367}
368elseif ( isset( $_POST['submit'] ) )
369{
370  $template->assign_block_vars('confirmation' ,array());
371}
372//----------------------------------------------------------- sending html code
373$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
374?>
Note: See TracBrowser for help on using the repository browser.