source: trunk/admin/configuration.php @ 512

Last change on this file since 512 was 512, checked in by z0rglub, 20 years ago
  • in admin/configuration, add new step with "sections" (general, comments, default, upload, metadata, sessions)
  • admin/configuration.php and its template have been higly simplificated by making things more generic : for example, for each configuration parameter, its name must correspond to the name we find in the config table and belongs to a section, in the lang array we find :
  • more described message when connection to database server is impossible
  • redefinitions of get_languages and get_templates functions
  • deletion of configuration parameters : webmaster, session_keyword
  • rename of configuration parameters :
  • default_lang => default_language
  • default_style => default_template
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.3 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-09-03 15:01:05 +0000 (Fri, 03 Sep 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 512 $
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}
32include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
33//-------------------------------------------------------- sections definitions
34if (!isset($_GET['section']))
35{
36  $page['section'] = 'general';
37}
38else
39{
40  $page['section'] = $_GET['section'];
41}
42
43// templates for fields definitions
44$true_false = array('type' => 'radio',
45                    'options' => array('true' => $lang['yes'],
46                                       'false' => $lang['no']));
47$textfield = array('type' => 'textfield');
48
49$sections = array(
50  'general' => array(
51    'mail_webmaster' => $textfield,
52    'prefix_thumbnail' => $textfield,
53    'access' => array('type' => 'radio',
54                      'options' => array(
55                        'free' => $lang['conf_general_access_1'],
56                        'restricted' => $lang['conf_general_access_2'])),
57    'log' => $true_false,
58    'mail_notification' => $true_false,
59   ),
60  'comments' => array(
61    'show_comments' => $true_false,
62    'comments_forall' => $true_false,
63    'nb_comment_page' => $textfield,
64    'comments_validation' => $true_false
65   ),
66  'default' => array(
67    'default_language' => array('type' => 'select',
68                                'options' => get_languages()),
69    'nb_image_line' => $textfield,
70    'nb_line_page' => $textfield,
71    'default_template' => array('type' => 'select',
72                                'options' => get_templates()),
73    'recent_period' => $textfield,
74    'auto_expand' => $true_false,
75    'show_nb_comments' => $true_false
76   ),
77  'upload' => array(
78    'upload_available' => $true_false,
79    'upload_maxfilesize' => $textfield,
80    'upload_maxwidth' => $textfield,
81    'upload_maxheight' => $textfield,
82    'upload_maxwidth_thumbnail' => $textfield,
83    'upload_maxheight_thumbnail' => $textfield
84   ),
85  'session' => array(
86    'authorize_cookies' => $true_false,
87    'session_time' => $textfield,
88    'session_id_size' => $textfield
89   ),
90  'metadata' => array(
91    'use_exif' => $true_false,
92    'use_iptc' => $true_false,
93    'show_exif' => $true_false,
94    'show_iptc' => $true_false
95   )
96 );
97//------------------------------------------------------ $conf reinitialization
98$result = mysql_query('SELECT param,value FROM '.CONFIG_TABLE);
99while ($row = mysql_fetch_array($result))
100{
101  $conf[$row['param']] = $row['value'];
102
103  if (isset($_POST[$row['param']]))
104  {
105    $conf[$row['param']] = $_POST[$row['param']];
106  }
107}
108//------------------------------ verification and registration of modifications
109$errors = array();
110if (isset($_POST['submit']))
111{
112//   echo '<pre>';
113//   print_r($_POST);
114//   echo '</pre>';
115 
116  $int_pattern = '/^\d+$/';
117  switch ($page['section'])
118  {
119    case 'general' :
120    {
121      // thumbnail prefix must only contain simple ASCII characters
122      if (!preg_match('/^[\w-]*$/', $_POST['prefix_thumbnail']))
123      {
124        array_push($errors, $lang['conf_general_prefix_thumbnail_error']);
125      }
126      // mail must be formatted as follows : name@server.com
127      $pattern = '/^[\w-]+(\.[\w-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/';
128      if (!preg_match($pattern, $_POST['mail_webmaster']))
129      {
130        array_push($errors, $lang['conf_general_mail_webmaster_error']);
131      }
132      break;
133    }
134    case 'comments' :
135    {
136      // the number of comments per page must be an integer between 5 and 50
137      // included
138      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
139           or $_POST['nb_comment_page'] < 5
140           or $_POST['nb_comment_page'] > 50)
141      {
142        array_push($errors, $lang['conf_comments_nb_comment_page_error']);
143      }
144      break;
145    }
146    case 'default' :
147    {
148      // periods must be integer values, they represents number of days
149      if (!preg_match($int_pattern, $_POST['recent_period'])
150          or $_POST['recent_period'] <= 0)
151      {
152        array_push($errors, $lang['conf_default_recent_period_error']);
153      }
154      break;
155    }
156    case 'upload' :
157    {
158      // the maximum upload filesize must be an integer between 10 and 1000
159      if (!preg_match($int_pattern, $_POST['upload_maxfilesize'])
160          or $_POST['upload_maxfilesize'] < 10
161          or $_POST['upload_maxfilesize'] > 1000)
162      {
163        array_push($errors, $lang['conf_upload_upload_maxfilesize_error']);
164      }
165     
166      foreach (array('upload_maxwidth',
167                     'upload_maxheight',
168                     'upload_maxwidth_thumbnail',
169                     'upload_maxheight_thumbnail')
170               as $field)
171      {
172        if (!preg_match($int_pattern, $_POST[$field])
173          or $_POST[$field] < 10)
174        {
175          array_push($errors, $lang['conf_upload_'.$field.'_error']);
176        }
177      }
178      break;
179    }
180    case 'session' :
181    {
182      // session_id size must be an integer between 4 and 50
183      if (!preg_match($int_pattern, $_POST['session_id_size'])
184          or $_POST['session_id_size'] < 4
185          or $_POST['session_id_size'] > 50)
186      {
187        array_push($errors, $lang['conf_session_session_id_size_error']);
188      }
189      // session_time must be an integer between 5 and 60, in minutes
190      if (!preg_match($int_pattern, $_POST['session_time'])
191          or $_POST['session_time'] < 5
192          or $_POST['session_time'] > 60)
193      {
194        array_push($errors, $lang['conf_session_session_time_error']);
195      }
196      break;
197    }
198  }
199 
200  // updating configuraiton if no error found
201  if (count($errors) == 0)
202  {
203    $result = mysql_query('SELECT * FROM '.CONFIG_TABLE);
204    while ($row = mysql_fetch_array($result))
205    {
206      if (isset($_POST[$row['param']]))
207      {
208        $query = '
209UPDATE '.CONFIG_TABLE.'
210  SET value = \''. str_replace("\'", "''", $_POST[$row['param']]).'\'
211  WHERE param = \''.$row['param'].'\'
212;';
213        mysql_query($query);
214      }
215    }
216  }
217}
218//----------------------------------------------------- template initialization
219$template->set_filenames(array('config'=>'admin/configuration.tpl'));
220
221$action = PHPWG_ROOT_PATH.'admin.php?page=configuration';
222$action.= '&amp;section='.$page['section'];
223
224$template->assign_vars(
225  array(
226    'L_CONFIRM'=>$lang['conf_confirmation'],
227    'L_SUBMIT'=>$lang['submit'],
228    'F_ACTION'=>add_session_id($action)
229   )
230 );
231
232$base_url = PHPWG_ROOT_PATH.'admin.php?page=configuration&amp;section=';
233foreach (array_keys($sections) as $section)
234{
235  if (isset($_GET['section']) and $_GET['section'] == $section)
236  {
237    $class = 'opened';
238  }
239  else
240  {
241    $class = '';
242  }
243 
244  $template->assign_block_vars(
245    'confmenu_item',
246    array(
247      'CLASS' => $class,
248      'URL' => add_session_id($base_url.$section),
249      'NAME' => $lang['conf_'.$section.'_title']
250     ));
251}
252
253$fields = $sections[$page['section']];
254foreach ($fields as $field_name => $field)
255{
256  $template->assign_block_vars(
257    'line',
258    array(
259      'NAME' => $lang['conf_'.$page['section'].'_'.$field_name],
260      'INFO' => $lang['conf_'.$page['section'].'_'.$field_name.'_info']
261     ));
262  if ($field['type'] == 'textfield')
263  {
264    $template->assign_block_vars(
265      'line.textfield',
266      array(
267        'NAME' => $field_name,
268        'VALUE' => $conf[$field_name]
269       ));
270  }
271  else if ($field['type'] == 'radio')
272  {
273    foreach ($field['options'] as $option_value => $option)
274    {
275      if ($conf[$field_name] == $option_value)
276      {
277        $checked = 'checked="checked"';
278      }
279      else
280      {
281        $checked = '';
282      }
283     
284      $template->assign_block_vars(
285        'line.radio',
286        array(
287          'NAME' => $field_name,
288          'VALUE' => $option_value,
289          'CHECKED' => $checked,
290          'OPTION' => $option
291         ));
292    }
293  }
294  else if ($field['type'] == 'select')
295  {
296    $template->assign_block_vars(
297      'line.select',
298      array(
299        'NAME' => $field_name
300       ));
301    foreach ($field['options'] as $option_value => $option)
302    {
303      if ($conf[$field_name] == $option_value)
304      {
305        $selected = 'selected="selected"';
306      }
307      else
308      {
309        $selected = '';
310      }
311     
312      $template->assign_block_vars(
313        'line.select.select_option',
314        array(
315          'VALUE' => $option_value,
316          'SELECTED' => $selected,
317          'OPTION' => $option
318         ));
319    }
320  }
321}
322//-------------------------------------------------------------- errors display
323if (count($errors) != 0)
324{
325  $template->assign_block_vars('errors',array());
326  foreach ($errors as $error)
327  {
328    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
329  }
330}
331else if (isset($_POST['submit']))
332{
333  $template->assign_block_vars('confirmation' ,array());
334}
335//----------------------------------------------------------- sending html code
336$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
337?>
Note: See TracBrowser for help on using the repository browser.