moodle/admin/config.php

126 lines
3.6 KiB
PHP
Raw Normal View History

<?php // $Id$
// config.php - allows admin to edit all configuration variables
2005-01-24 01:21:16 +00:00
require_once('../config.php');
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');
}
}
/// This is to overcome the "insecure forms paradox"
if (isset($secureforms) and $secureforms == 0) {
2005-01-24 01:21:16 +00:00
$match = 'nomatch';
} else {
2005-01-24 01:21:16 +00:00
$match = '';
}
/// If data submitted, then process and store.
if ($config = data_submitted($match)) {
if (!empty($USER->id)) { // Additional identity check
2004-10-04 13:50:37 +00:00
if (!confirm_sesskey()) {
error(get_string('confirmsesskeybad', 'error'));
}
}
validate_form($config, $err);
if (count($err) == 0) {
print_header();
foreach ($config as $name => $value) {
2003-12-18 16:46:34 +00:00
if ($name == "sessioncookie") {
$value = eregi_replace("[^a-zA-Z]", "", $value);
2003-12-18 16:46:34 +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)) {
$conf->id = $current->id;
2005-01-24 01:21:16 +00:00
if (! update_record('config', $conf)) {
notify("Could not update $name to $value");
}
} else {
2005-01-24 01:21:16 +00:00
if (! insert_record('config', $conf)) {
notify("Error: could not add new variable $name !");
}
}
}
2005-01-24 01:21:16 +00:00
redirect('index.php', get_string('changessaved'), 1);
exit;
} else {
foreach ($err as $key => $value) {
$focus = "form.$key";
}
}
}
/// Otherwise fill and print the form.
2003-01-02 15:25:51 +00:00
if (empty($config)) {
$config = $CFG;
2005-01-24 01:21:16 +00:00
if (!$config->locale = get_field('config', 'value', 'name', 'locale')) {
$config->locale = $CFG->lang;
}
}
2003-01-02 15:25:51 +00:00
if (empty($focus)) {
2005-01-24 01:21:16 +00:00
$focus = '';
}
2005-01-24 01:21:16 +00:00
$stradmin = get_string('administration');
$strconfiguration = get_string('configuration');
$strconfigvariables = get_string('configvariables');
if ($site) {
print_header("$site->shortname: $strconfigvariables", $site->fullname,
"<a href=\"index.php\">$stradmin</a> -> ".
"<a href=\"configure.php\">$strconfiguration</a> -> $strconfigvariables", $focus);
print_heading($strconfigvariables);
} else {
print_header();
print_heading($strconfigvariables);
2005-01-24 01:21:16 +00:00
print_simple_box(get_string('configintro'), 'center', "50%");
echo "<br />";
}
$sesskey = !empty($USER->id) ? $USER->sesskey : '';
2004-10-04 13:50:37 +00:00
2005-01-25 17:08:05 +00:00
print_simple_box_start('center');
2005-01-24 01:21:16 +00:00
include('config.html');
print_simple_box_end();
2004-08-31 08:41:26 +00:00
/// Lock some options
$httpsurl = str_replace('http://', 'https://', $CFG->wwwroot);
if ($httpsurl != $CFG->wwwroot) {
if ((($fh = @fopen($httpsurl, 'r')) == false) and ($config->loginhttps == 0)) {
echo '<script type="text/javascript">'."\n";
2004-08-31 08:41:26 +00:00
echo '<!--'."\n";
echo "eval('document.form.loginhttps.disabled=true');\n";
echo '-->'."\n";
echo '</script>'."\n";
}
}
if ($site) {
print_footer();
}
exit;
/// Functions /////////////////////////////////////////////////////////////////
function validate_form(&$form, &$err) {
2004-10-04 13:50:37 +00:00
// Currently no checks are needed ...
2004-10-04 13:50:37 +00:00
return true;
}
2005-01-25 17:08:05 +00:00
?>