<?php
// Id used to identify this page within functions.
$PageID = "CONFIGURATION";
require_once "common.inc";
require_once "config.inc";
require_once "constants.inc";
require_once "db.inc";
require_once "error.inc";
require_once "mgmnt.inc";
require_once "language.inc";
require_once "layout.inc";
require_once "ldap.inc";
layout_header();
$sections = array(
'general' => _("General"),
'zebra' => _("ZEBRA Server"),
'system' => _("System"),
'security' => _("Security"),
'appearance' => _("Appearance")
);
if (isset($_REQUEST['set_defaults']) || isset($_REQUEST['update']))
{
$res = sql_cquery("SELECT config_key FROM configuration WHERE config_type='bool' AND config_section IN ('" . join('\',\'', array_keys($sections)) . "')");
while ($row = mysql_fetch_array($res))
{
if (isset($_REQUEST[$row['config_key']])) {
$_REQUEST[$row['config_key']] = '1';
} else {
$_REQUEST[$row['config_key']] = '0';
}
}
}
if (isset($_REQUEST['set_defaults']))
{
$allowed = array();
$res = sql_cquery("SELECT * FROM configuration WHERE config_section IN ('" . join('\',\'', array_keys($sections)) . "')");
while ($row = mysql_fetch_array($res)) {
$allowed[$row['config_key']] = $row['config_default'];
}
foreach($_REQUEST as $key => $value)
{
if(isset($allowed[$key]))
{
$sql = "UPDATE configuration SET config_value=config_default WHERE config_key='$key'";
sql_query($sql);
if(!mysql_error()) {
layout_page_title(_("Configuration Reset"), 'ok');
} else {
layout_page_title(_("Configuration Error"), 'error');
}
}
}
}
?>
<form name="config" action="configuration.php" method="post">
<input type="hidden" name="id" value="<?php echo $_REQUEST['id'] ?>">
<input type="hidden" name="auth" value="<?php echo $_REQUEST['auth'] ?>">
<?php
if (isset($_REQUEST['section'])) {
print '<input type="hidden" name="section" value="' . $_REQUEST['section'] . '">';
}
if(isset($_REQUEST['update']))
{
$allowed = array();
$res = sql_cquery("SELECT * FROM configuration WHERE config_section IN ('" . join('\',\'', array_keys($sections)) . "')");
while ($row = mysql_fetch_array($res)) {
$allowed[$row['config_key']] = $row['config_value'];
}
foreach($_REQUEST as $key => $value)
{
if(isset($allowed[$key]) && $allowed[$key] != $value)
{
$sql = "UPDATE configuration SET config_value='$value' WHERE config_key='$key'";
sql_query($sql);
if(!mysql_error()) {
layout_page_title(_("Configuration Updated"), 'ok');
// Logging
writeLog("Configuration updated");
} else {
layout_page_title(_("Configuration Error"), 'error');
}
}
}
}
layout_page_title();
$my_table =& new Table(_("Configuration Sections"));
foreach ($sections as $id => $name)
{
$$id =& new Table($name);
$my_table->adopt($$id);
if (isset($_REQUEST['section']) && $_REQUEST['section'] == $id) {
$$id->enable_hide();
} else {
$$id->hide();
}
$res = sql_cquery("SELECT * FROM configuration WHERE config_section='$id'");
while($row = mysql_fetch_array($res))
{
switch ($row['config_type'])
{
case 'bool':
$checked = ($row['config_value'] == 1) ? 'checked="checked"' : '';
$input = '<input type="checkbox" name="' . $row['config_key'] . '" ' . $checked . ' />';
break;
case 'char':
$input = '<input type="text" size="2" maxlen="1" name="' . $row['config_key'] . '" value="' . $row['config_value'] . '" />';
break;
case 'int':
$input = '<input type="text" size="6" name="' . $row['config_key'] . '" value="' . $row['config_value'] . '" />';
break;
case 'enum':
$input = '<select name="' . $row['config_key'] . '">';
foreach (explode('|', $row['config_allowed']) as $option) {
$selected = ($option == $row['config_value']) ? 'selected' : '';
$input .= "<option value='$option' $selected>$option</option>";
}
$input .= '</select>';
break;
case 'num':
case 'string':
$input = '<input type="text" size="30" name="' . $row['config_key'] . '" value="' . $row['config_value'] . '" />';
break;
}
$desc = $row['config_desc']; //to avoid xgettext extraction
$$id->add_row(
_($desc),
$input
);
}
}
$my_table->set_footer(
'<input type="submit" name="set_defaults" value="' . _("Defaults") . '" class="button" onClick="return confirm(\'' . _("All variables will be given their default values!\\nAre you sure you want to continue?") . '\')" />' .
' ' .
'<input type="submit" name="update" value="' . _("Update") . '" class="button" />'
);
$my_table->render();
layout_footer();
?>