More efficient querying of courses (from Martin Langhoff)
[moodle.git] / admin / config.php
blobbd7561acc4ecc3443a3c3405bfc37ff0b14289ba
1 <?PHP // $Id$
2 // config.php - allows admin to edit all configuration variables
4 require_once("../config.php");
6 if ($site = get_site()) { // If false then this is a new installation
7 require_login();
8 if (!isadmin()) {
9 error("Only the admin can use this page");
13 /// This is to overcome the "insecure forms paradox"
14 if (isset($secureforms) and $secureforms == 0) {
15 $match = "nomatch";
16 } else {
17 $match = "";
20 /// If data submitted, then process and store.
22 if ($config = data_submitted($match)) {
24 if (!empty($USER->id)) { // Additional identity check
25 if (!confirm_sesskey()) {
26 error(get_string('confirmsesskeybad', 'error'));
30 validate_form($config, $err);
32 if (count($err) == 0) {
33 print_header();
34 foreach ($config as $name => $value) {
35 if ($name == "sessioncookie") {
36 $value = eregi_replace("[^a-zA-Z]", "", $value);
38 unset($conf);
39 $conf->name = $name;
40 $conf->value = $value;
41 if ($current = get_record("config", "name", $name)) {
42 $conf->id = $current->id;
43 if (! update_record("config", $conf)) {
44 notify("Could not update $name to $value");
46 } else {
47 if (! insert_record("config", $conf)) {
48 notify("Error: could not add new variable $name !");
52 redirect("index.php", get_string("changessaved"), 1);
53 exit;
55 } else {
56 foreach ($err as $key => $value) {
57 $focus = "form.$key";
62 /// Otherwise fill and print the form.
64 if (empty($config)) {
65 $config = $CFG;
66 if (!$config->locale = get_field("config", "value", "name", "locale")) {
67 $config->locale = $CFG->lang;
70 if (empty($focus)) {
71 $focus = "";
74 $stradmin = get_string("administration");
75 $strconfiguration = get_string("configuration");
76 $strconfigvariables = get_string("configvariables");
78 if ($site) {
79 print_header("$site->shortname: $strconfigvariables", $site->fullname,
80 "<a href=\"index.php\">$stradmin</a> -> ".
81 "<a href=\"configure.php\">$strconfiguration</a> -> $strconfigvariables", $focus);
82 print_heading($strconfigvariables);
83 } else {
84 print_header();
85 print_heading($strconfigvariables);
86 print_simple_box(get_string("configintro"), "center", "50%");
87 echo "<br />";
90 $sesskey = !empty($USER->id) ? $USER->sesskey : '';
92 print_simple_box_start("center", "", "$THEME->cellheading");
93 include("config.html");
94 print_simple_box_end();
96 /// Lock some options
98 $httpsurl = str_replace('http://', 'https://', $CFG->wwwroot);
99 if ($httpsurl != $CFG->wwwroot) {
100 if ((($fh = @fopen($httpsurl, 'r')) == false) and ($config->loginhttps == 0)) {
101 echo '<script>'."\n";
102 echo '<!--'."\n";
103 echo "eval('document.form.loginhttps.disabled=true');\n";
104 echo '-->'."\n";
105 echo '</script>'."\n";
110 if ($site) {
111 print_footer();
114 exit;
116 /// Functions /////////////////////////////////////////////////////////////////
118 function validate_form(&$form, &$err) {
120 // Currently no checks are needed ...
122 return true;