Files
Piwigo/admin/configuration.php
z0rglub 1f71a31084 - 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 :

  - $lang['conf_<section>_<param>']
  - $lang['conf_<section>_<param>_info']
  - $lang['conf_<section>_<param>_error'] optionnaly

- 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


git-svn-id: http://piwigo.org/svn/trunk@512 68402e56-0260-453c-a942-63ccdbb3a9ee
2004-09-03 15:01:05 +00:00

338 lines
10 KiB
PHP

<?php
// +-----------------------------------------------------------------------+
// | configuration.php |
// +-----------------------------------------------------------------------+
// | application : PhpWebGallery <http://phpwebgallery.net> |
// | branch : BSF (Best So Far) |
// +-----------------------------------------------------------------------+
// | file : $RCSfile$
// | last update : $Date$
// | last modifier : $Author$
// | revision : $Revision$
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation |
// | |
// | This program is distributed in the hope that it will be useful, but |
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA. |
// +-----------------------------------------------------------------------+
if (!defined('PHPWG_ROOT_PATH'))
{
die ("Hacking attempt!");
}
include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
//-------------------------------------------------------- sections definitions
if (!isset($_GET['section']))
{
$page['section'] = 'general';
}
else
{
$page['section'] = $_GET['section'];
}
// templates for fields definitions
$true_false = array('type' => 'radio',
'options' => array('true' => $lang['yes'],
'false' => $lang['no']));
$textfield = array('type' => 'textfield');
$sections = array(
'general' => array(
'mail_webmaster' => $textfield,
'prefix_thumbnail' => $textfield,
'access' => array('type' => 'radio',
'options' => array(
'free' => $lang['conf_general_access_1'],
'restricted' => $lang['conf_general_access_2'])),
'log' => $true_false,
'mail_notification' => $true_false,
),
'comments' => array(
'show_comments' => $true_false,
'comments_forall' => $true_false,
'nb_comment_page' => $textfield,
'comments_validation' => $true_false
),
'default' => array(
'default_language' => array('type' => 'select',
'options' => get_languages()),
'nb_image_line' => $textfield,
'nb_line_page' => $textfield,
'default_template' => array('type' => 'select',
'options' => get_templates()),
'recent_period' => $textfield,
'auto_expand' => $true_false,
'show_nb_comments' => $true_false
),
'upload' => array(
'upload_available' => $true_false,
'upload_maxfilesize' => $textfield,
'upload_maxwidth' => $textfield,
'upload_maxheight' => $textfield,
'upload_maxwidth_thumbnail' => $textfield,
'upload_maxheight_thumbnail' => $textfield
),
'session' => array(
'authorize_cookies' => $true_false,
'session_time' => $textfield,
'session_id_size' => $textfield
),
'metadata' => array(
'use_exif' => $true_false,
'use_iptc' => $true_false,
'show_exif' => $true_false,
'show_iptc' => $true_false
)
);
//------------------------------------------------------ $conf reinitialization
$result = mysql_query('SELECT param,value FROM '.CONFIG_TABLE);
while ($row = mysql_fetch_array($result))
{
$conf[$row['param']] = $row['value'];
if (isset($_POST[$row['param']]))
{
$conf[$row['param']] = $_POST[$row['param']];
}
}
//------------------------------ verification and registration of modifications
$errors = array();
if (isset($_POST['submit']))
{
// echo '<pre>';
// print_r($_POST);
// echo '</pre>';
$int_pattern = '/^\d+$/';
switch ($page['section'])
{
case 'general' :
{
// thumbnail prefix must only contain simple ASCII characters
if (!preg_match('/^[\w-]*$/', $_POST['prefix_thumbnail']))
{
array_push($errors, $lang['conf_general_prefix_thumbnail_error']);
}
// mail must be formatted as follows : name@server.com
$pattern = '/^[\w-]+(\.[\w-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/';
if (!preg_match($pattern, $_POST['mail_webmaster']))
{
array_push($errors, $lang['conf_general_mail_webmaster_error']);
}
break;
}
case 'comments' :
{
// the number of comments per page must be an integer between 5 and 50
// included
if (!preg_match($int_pattern, $_POST['nb_comment_page'])
or $_POST['nb_comment_page'] < 5
or $_POST['nb_comment_page'] > 50)
{
array_push($errors, $lang['conf_comments_nb_comment_page_error']);
}
break;
}
case 'default' :
{
// periods must be integer values, they represents number of days
if (!preg_match($int_pattern, $_POST['recent_period'])
or $_POST['recent_period'] <= 0)
{
array_push($errors, $lang['conf_default_recent_period_error']);
}
break;
}
case 'upload' :
{
// the maximum upload filesize must be an integer between 10 and 1000
if (!preg_match($int_pattern, $_POST['upload_maxfilesize'])
or $_POST['upload_maxfilesize'] < 10
or $_POST['upload_maxfilesize'] > 1000)
{
array_push($errors, $lang['conf_upload_upload_maxfilesize_error']);
}
foreach (array('upload_maxwidth',
'upload_maxheight',
'upload_maxwidth_thumbnail',
'upload_maxheight_thumbnail')
as $field)
{
if (!preg_match($int_pattern, $_POST[$field])
or $_POST[$field] < 10)
{
array_push($errors, $lang['conf_upload_'.$field.'_error']);
}
}
break;
}
case 'session' :
{
// session_id size must be an integer between 4 and 50
if (!preg_match($int_pattern, $_POST['session_id_size'])
or $_POST['session_id_size'] < 4
or $_POST['session_id_size'] > 50)
{
array_push($errors, $lang['conf_session_session_id_size_error']);
}
// session_time must be an integer between 5 and 60, in minutes
if (!preg_match($int_pattern, $_POST['session_time'])
or $_POST['session_time'] < 5
or $_POST['session_time'] > 60)
{
array_push($errors, $lang['conf_session_session_time_error']);
}
break;
}
}
// updating configuraiton if no error found
if (count($errors) == 0)
{
$result = mysql_query('SELECT * FROM '.CONFIG_TABLE);
while ($row = mysql_fetch_array($result))
{
if (isset($_POST[$row['param']]))
{
$query = '
UPDATE '.CONFIG_TABLE.'
SET value = \''. str_replace("\'", "''", $_POST[$row['param']]).'\'
WHERE param = \''.$row['param'].'\'
;';
mysql_query($query);
}
}
}
}
//----------------------------------------------------- template initialization
$template->set_filenames(array('config'=>'admin/configuration.tpl'));
$action = PHPWG_ROOT_PATH.'admin.php?page=configuration';
$action.= '&amp;section='.$page['section'];
$template->assign_vars(
array(
'L_CONFIRM'=>$lang['conf_confirmation'],
'L_SUBMIT'=>$lang['submit'],
'F_ACTION'=>add_session_id($action)
)
);
$base_url = PHPWG_ROOT_PATH.'admin.php?page=configuration&amp;section=';
foreach (array_keys($sections) as $section)
{
if (isset($_GET['section']) and $_GET['section'] == $section)
{
$class = 'opened';
}
else
{
$class = '';
}
$template->assign_block_vars(
'confmenu_item',
array(
'CLASS' => $class,
'URL' => add_session_id($base_url.$section),
'NAME' => $lang['conf_'.$section.'_title']
));
}
$fields = $sections[$page['section']];
foreach ($fields as $field_name => $field)
{
$template->assign_block_vars(
'line',
array(
'NAME' => $lang['conf_'.$page['section'].'_'.$field_name],
'INFO' => $lang['conf_'.$page['section'].'_'.$field_name.'_info']
));
if ($field['type'] == 'textfield')
{
$template->assign_block_vars(
'line.textfield',
array(
'NAME' => $field_name,
'VALUE' => $conf[$field_name]
));
}
else if ($field['type'] == 'radio')
{
foreach ($field['options'] as $option_value => $option)
{
if ($conf[$field_name] == $option_value)
{
$checked = 'checked="checked"';
}
else
{
$checked = '';
}
$template->assign_block_vars(
'line.radio',
array(
'NAME' => $field_name,
'VALUE' => $option_value,
'CHECKED' => $checked,
'OPTION' => $option
));
}
}
else if ($field['type'] == 'select')
{
$template->assign_block_vars(
'line.select',
array(
'NAME' => $field_name
));
foreach ($field['options'] as $option_value => $option)
{
if ($conf[$field_name] == $option_value)
{
$selected = 'selected="selected"';
}
else
{
$selected = '';
}
$template->assign_block_vars(
'line.select.select_option',
array(
'VALUE' => $option_value,
'SELECTED' => $selected,
'OPTION' => $option
));
}
}
}
//-------------------------------------------------------------- errors display
if (count($errors) != 0)
{
$template->assign_block_vars('errors',array());
foreach ($errors as $error)
{
$template->assign_block_vars('errors.error',array('ERROR'=>$error));
}
}
else if (isset($_POST['submit']))
{
$template->assign_block_vars('confirmation' ,array());
}
//----------------------------------------------------------- sending html code
$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
?>