id)) {             // Additional identity check
            if (!confirm_sesskey()) {
                error(get_string('confirmsesskeybad', 'error'));
            }
        }
        validate_form($config, $err);
        if (count($err) == 0) {
            foreach ($config as $name => $value) {
                if ($name == "sessioncookie") {
                    $value = eregi_replace("[^a-zA-Z]", "", $value);
                }
                unset($conf);
                $conf->name  = $name;
                $conf->value = $value;
                if ($current = get_record('config', 'name', $name)) {
                    $conf->id = $current->id;
                    if (! update_record('config', $conf)) {
                        notify("Could not update $name to $value");
                    }
                } else {
                    if (! insert_record('config', $conf)) {
                        notify("Error: could not add new variable $name !");
                    }
                }
            }
            redirect('index.php', get_string('changessaved'), 1);
            exit;
        } else {
            foreach ($err as $key => $value) {
                $focus = "form.$key";
            }
        }
    }
/// Otherwise fill and print the form.
    if (empty($config)) {
        $config = $CFG;
        if (!$config->locale = get_field('config', 'value', 'name', 'locale')) {
            $config->locale = $CFG->lang;
        }
    }
    if (empty($focus)) {
        $focus = '';
    }
    $sesskey = !empty($USER->id) ? $USER->sesskey : '';
    $stradmin = get_string('administration');
    $strconfiguration = get_string('configuration');
    $strconfigvariables = get_string('configvariables', 'admin');
    if ($site) {
        print_header("$site->shortname: $strconfigvariables", $site->fullname,
                      "$stradmin -> ".
                      "$strconfiguration -> $strconfigvariables", $focus);
        print_heading($strconfigvariables);
    } else {
        print_header();
        print_heading($strconfigvariables);
        print_simple_box(get_string('configintro', 'admin'), 'center', "50%");
        echo '
';
    }
/// Get all the configuration fields and helptext
    include('configvars.php');
/// Cycle through the sections to get the sectionnames
    $linktext = '';
    foreach($configvars as $sectionname=>$section) {
        if ($linktext !== '') {
            $linktext .= ' | ';
        }
        $linktext .= ''.get_string('configsection'.$sectionname, 'admin').'';
    }
        
    echo "