2004-10-06 00:08:08 +00:00
|
|
|
<?php // $Id$
|
2002-09-19 12:01:55 +00:00
|
|
|
// config.php - allows admin to edit all configuration variables
|
|
|
|
|
2005-01-24 01:21:16 +00:00
|
|
|
require_once('../config.php');
|
2003-01-02 07:37:28 +00:00
|
|
|
|
2006-03-06 10:02:59 +00:00
|
|
|
$focus = '';
|
|
|
|
|
2002-09-19 12:01:55 +00:00
|
|
|
if ($site = get_site()) { // If false then this is a new installation
|
|
|
|
require_login();
|
|
|
|
if (!isadmin()) {
|
2005-01-24 01:21:16 +00:00
|
|
|
error('Only the admin can use this page');
|
2002-09-19 12:01:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-15 15:59:52 +00:00
|
|
|
/// This is to overcome the "insecure forms paradox"
|
|
|
|
if (isset($secureforms) and $secureforms == 0) {
|
2005-01-24 01:21:16 +00:00
|
|
|
$match = 'nomatch';
|
2003-05-15 15:59:52 +00:00
|
|
|
} else {
|
2005-01-24 01:21:16 +00:00
|
|
|
$match = '';
|
2003-05-15 15:59:52 +00:00
|
|
|
}
|
|
|
|
|
2002-09-19 12:01:55 +00:00
|
|
|
/// If data submitted, then process and store.
|
|
|
|
|
2005-02-24 08:49:32 +00:00
|
|
|
if ($config = data_submitted($match)) {
|
2002-09-19 12:01:55 +00:00
|
|
|
|
2004-10-06 00:08:08 +00:00
|
|
|
if (!empty($USER->id)) { // Additional identity check
|
2004-10-04 13:50:37 +00:00
|
|
|
if (!confirm_sesskey()) {
|
|
|
|
error(get_string('confirmsesskeybad', 'error'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-19 12:01:55 +00:00
|
|
|
validate_form($config, $err);
|
|
|
|
|
|
|
|
if (count($err) == 0) {
|
|
|
|
foreach ($config as $name => $value) {
|
2003-12-18 16:46:34 +00:00
|
|
|
if ($name == "sessioncookie") {
|
2004-03-31 04:14:13 +00:00
|
|
|
$value = eregi_replace("[^a-zA-Z]", "", $value);
|
2003-12-18 16:46:34 +00:00
|
|
|
}
|
2005-08-16 06:15:49 +00:00
|
|
|
if ($name == "defaultallowedmodules") {
|
|
|
|
$value = implode(',',$value);
|
|
|
|
}
|
2005-11-20 21:29:59 +00:00
|
|
|
if ($name == 'hiddenuserfields') {
|
|
|
|
if (in_array('none', $value)) {
|
|
|
|
$value = '';
|
|
|
|
} else {
|
|
|
|
$value = implode(',',$value);
|
|
|
|
}
|
|
|
|
}
|
2002-09-19 12:01:55 +00:00
|
|
|
unset($conf);
|
|
|
|
$conf->name = $name;
|
|
|
|
$conf->value = $value;
|
2005-01-24 01:21:16 +00:00
|
|
|
if ($current = get_record('config', 'name', $name)) {
|
2002-09-19 12:01:55 +00:00
|
|
|
$conf->id = $current->id;
|
2005-01-24 01:21:16 +00:00
|
|
|
if (! update_record('config', $conf)) {
|
2002-09-19 12:01:55 +00:00
|
|
|
notify("Could not update $name to $value");
|
|
|
|
}
|
|
|
|
} else {
|
2005-01-24 01:21:16 +00:00
|
|
|
if (! insert_record('config', $conf)) {
|
2002-09-19 12:01:55 +00:00
|
|
|
notify("Error: could not add new variable $name !");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-01-24 01:21:16 +00:00
|
|
|
redirect('index.php', get_string('changessaved'), 1);
|
2002-09-19 12:01:55 +00:00
|
|
|
exit;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
foreach ($err as $key => $value) {
|
|
|
|
$focus = "form.$key";
|
|
|
|
}
|
|
|
|
}
|
2005-02-24 08:49:32 +00:00
|
|
|
}
|
2002-09-19 12:01:55 +00:00
|
|
|
|
|
|
|
/// Otherwise fill and print the form.
|
|
|
|
|
2003-01-02 15:25:51 +00:00
|
|
|
if (empty($config)) {
|
2002-09-19 12:01:55 +00:00
|
|
|
$config = $CFG;
|
2005-01-24 01:21:16 +00:00
|
|
|
if (!$config->locale = get_field('config', 'value', 'name', 'locale')) {
|
2003-08-25 17:30:08 +00:00
|
|
|
$config->locale = $CFG->lang;
|
|
|
|
}
|
2002-09-19 12:01:55 +00:00
|
|
|
}
|
|
|
|
|
2005-02-09 13:04:04 +00:00
|
|
|
$sesskey = !empty($USER->id) ? $USER->sesskey : '';
|
|
|
|
|
|
|
|
|
2005-01-24 01:21:16 +00:00
|
|
|
$stradmin = get_string('administration');
|
|
|
|
$strconfiguration = get_string('configuration');
|
2005-02-09 13:04:04 +00:00
|
|
|
$strconfigvariables = get_string('configvariables', 'admin');
|
2002-09-19 12:01:55 +00:00
|
|
|
|
|
|
|
if ($site) {
|
2002-12-29 17:32:32 +00:00
|
|
|
print_header("$site->shortname: $strconfigvariables", $site->fullname,
|
2003-08-18 16:40:27 +00:00
|
|
|
"<a href=\"index.php\">$stradmin</a> -> ".
|
|
|
|
"<a href=\"configure.php\">$strconfiguration</a> -> $strconfigvariables", $focus);
|
2002-09-19 12:01:55 +00:00
|
|
|
print_heading($strconfigvariables);
|
|
|
|
} else {
|
|
|
|
print_header();
|
|
|
|
print_heading($strconfigvariables);
|
2005-02-24 08:49:32 +00:00
|
|
|
print_simple_box(get_string('configintro', 'admin'), 'center', "50%");
|
2005-02-09 13:04:04 +00:00
|
|
|
echo '<br />';
|
2002-09-19 12:01:55 +00:00
|
|
|
}
|
|
|
|
|
2005-02-09 13:04:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// Get all the configuration fields and helptext
|
2006-03-06 10:02:59 +00:00
|
|
|
require('configvars.php');
|
2005-02-09 13:04:04 +00:00
|
|
|
|
|
|
|
/// Cycle through the sections to get the sectionnames
|
|
|
|
$linktext = '';
|
|
|
|
foreach($configvars as $sectionname=>$section) {
|
|
|
|
if ($linktext !== '') {
|
|
|
|
$linktext .= ' | ';
|
|
|
|
}
|
|
|
|
$linktext .= '<a href="#configsection'.$sectionname.'">'.get_string('configsection'.$sectionname, 'admin').'</a>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "<center>$linktext</center>\n";
|
2004-10-04 13:50:37 +00:00
|
|
|
|
2005-01-25 17:08:05 +00:00
|
|
|
print_simple_box_start('center');
|
2005-02-09 13:04:04 +00:00
|
|
|
|
|
|
|
echo '<form method="post" action="config.php" name="form">';
|
2005-06-06 03:36:44 +00:00
|
|
|
echo '<center><input type="submit" value="'.get_string('savechanges').'" /></center>';
|
2005-02-09 13:04:04 +00:00
|
|
|
|
|
|
|
/// Cycle through each section of the configuration
|
|
|
|
foreach ($configvars as $sectionname=>$section) {
|
|
|
|
|
|
|
|
print_heading('<a name="configsection'.$sectionname.'"></a>'.get_string('configsection'.$sectionname, 'admin'));
|
|
|
|
|
|
|
|
$table = NULL;
|
|
|
|
$table->data = array();
|
|
|
|
foreach ($section as $configvariable=>$configobject) {
|
|
|
|
$table->data[] = array ( $configvariable.': ',
|
|
|
|
$configobject->field
|
|
|
|
);
|
|
|
|
if ($configobject->display_warning()) {
|
|
|
|
$table->data[] = array ( ' ',
|
|
|
|
'<span class="configwarning">'.$configobject->warning.'</span>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$table->data[] = array ( ' ',
|
|
|
|
'<span class="confighelp">'.$configobject->help.'</span>'
|
|
|
|
);
|
|
|
|
$table->align = array ('right', 'left');
|
|
|
|
}
|
|
|
|
print_table($table);
|
|
|
|
|
|
|
|
}
|
|
|
|
echo '<center>';
|
|
|
|
echo '<input type="hidden" name="sesskey" value="'.$sesskey.'" />';
|
|
|
|
echo '<input type="submit" value="'.get_string('savechanges').'" />';
|
|
|
|
echo '</center>';
|
|
|
|
|
|
|
|
echo '</form>';
|
|
|
|
|
2002-09-19 12:01:55 +00:00
|
|
|
print_simple_box_end();
|
2003-05-06 15:58:20 +00:00
|
|
|
|
2005-02-09 13:04:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2004-08-31 08:41:26 +00:00
|
|
|
/// Lock some options
|
|
|
|
|
|
|
|
$httpsurl = str_replace('http://', 'https://', $CFG->wwwroot);
|
|
|
|
if ($httpsurl != $CFG->wwwroot) {
|
2005-02-23 15:40:53 +00:00
|
|
|
if (ini_get('allow_url_fopen')) {
|
|
|
|
if ((($fh = @fopen($httpsurl, 'r')) == false) and ($config->loginhttps == 0)) {
|
|
|
|
echo '<script type="text/javascript">'."\n";
|
|
|
|
echo '<!--'."\n";
|
|
|
|
echo "eval('document.form.loginhttps.disabled=true');\n";
|
|
|
|
echo '-->'."\n";
|
|
|
|
echo '</script>'."\n";
|
|
|
|
}
|
2004-08-31 08:41:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-06 15:58:20 +00:00
|
|
|
if ($site) {
|
|
|
|
print_footer();
|
|
|
|
}
|
2002-09-19 12:01:55 +00:00
|
|
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
/// Functions /////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
function validate_form(&$form, &$err) {
|
|
|
|
|
2004-10-04 13:50:37 +00:00
|
|
|
// Currently no checks are needed ...
|
2002-09-19 12:01:55 +00:00
|
|
|
|
2004-10-04 13:50:37 +00:00
|
|
|
return true;
|
2002-09-19 12:01:55 +00:00
|
|
|
}
|
|
|
|
|
2005-01-25 17:08:05 +00:00
|
|
|
?>
|