source: trunk/admin/configuration.php @ 517

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