Automatic installer.php lang files by installer_builder (20070202)
[moodle.git] / admin / config.php
blob02ce76beb27e81497d1e629ae4eb5ccc4cb1cde8
1 <?php // $Id$
2 // config.php - allows admin to edit all configuration variables
4 require_once('../config.php');
6 $installing = optional_param('installing', 0, PARAM_BOOL);
8 $focus = '';
10 if ($site = get_site()) { // If false then this is a new installation
11 require_login();
12 if (!isadmin()) {
13 error('Only the admin can use this page');
17 /// This is to overcome the "insecure forms paradox"
18 if (isset($secureforms) and $secureforms == 0) {
19 $match = 'nomatch';
20 } else {
21 $match = '';
24 /// If data submitted, then process and store.
26 if ($config = data_submitted($match)) {
28 if (!empty($USER->id)) { // Additional identity check
29 if (!confirm_sesskey()) {
30 error(get_string('confirmsesskeybad', 'error'));
34 validate_form($config, $err);
36 if (count($err) == 0) {
37 foreach ($config as $name => $value) {
38 if ($name == "sessioncookie") {
39 $value = eregi_replace("[^a-zA-Z0-9_]", "", $value);
41 if ($name == "defaultallowedmodules") {
42 $value = implode(',',$value);
44 if ($name == 'hiddenuserfields') {
45 if (in_array('none', $value)) {
46 $value = '';
47 } else {
48 $value = implode(',',$value);
51 if ($name == "locale") {
52 $value = trim($value);
54 $conf = new object();
55 $conf->name = $name;
56 $conf->value = $value;
57 if ($current = get_record('config', 'name', $name)) {
58 $conf->id = $current->id;
59 if (! update_record('config', $conf)) {
60 notify("Could not update $name to $value");
62 } else {
63 if (! insert_record('config', $conf)) {
64 notify("Error: could not add new variable $name !");
68 if ($installing) {
69 print_header();
70 notify(get_string('changessaved'), 'notifysuccess');
71 print_continue('index.php');
72 exit;
73 } else {
74 // the following redirect was randomly breaking upgrades because it did double redirects,
75 // we must not use it during install/upgrade
76 redirect('index.php', get_string('changessaved'), 1);
79 } else {
80 foreach ($err as $key => $value) {
81 $focus = "form.$key";
86 /// Otherwise fill and print the form.
88 if (empty($config)) {
89 $config = $CFG;
92 $sesskey = !empty($USER->id) ? $USER->sesskey : '';
95 $stradmin = get_string('administration');
96 $strconfiguration = get_string('configuration');
97 $strconfigvariables = get_string('configvariables', 'admin');
99 if ($site) {
100 print_header("$site->shortname: $strconfigvariables", $site->fullname,
101 "<a href=\"index.php\">$stradmin</a> -> ".
102 "<a href=\"configure.php\">$strconfiguration</a> -> $strconfigvariables", $focus);
103 print_heading($strconfigvariables);
104 } else {
105 print_header();
106 print_heading($strconfigvariables);
107 print_simple_box(get_string('configintro', 'admin'), 'center', "50%");
108 echo '<br />';
113 /// Get all the configuration fields and helptext
114 require('configvars.php');
116 /// Cycle through the sections to get the sectionnames
117 $linktext = '';
118 foreach($configvars as $sectionname=>$section) {
119 if ($linktext !== '') {
120 $linktext .= ' | ';
122 $linktext .= '<a href="#configsection'.$sectionname.'">'.get_string('configsection'.$sectionname, 'admin').'</a>';
125 echo "<center>$linktext</center>\n";
128 echo '<form method="post" action="config.php" name="form">';
129 echo '<center><input type="submit" value="'.get_string('savechanges').'" /></center>';
131 /// Cycle through each section of the configuration
132 foreach ($configvars as $sectionname=>$section) {
134 print_heading('<a name="configsection'.$sectionname.'"></a>'.get_string('configsection'.$sectionname, 'admin'));
136 $table = NULL;
137 $table->data = array();
138 foreach ($section as $configvariable=>$configobject) {
139 $table->data[] = array ( $configvariable.': ',
140 $configobject->field
142 if ($configobject->display_warning()) {
143 $table->data[] = array ( '&nbsp;',
144 '<span class="configwarning">'.$configobject->warning.'</span>'
147 $table->data[] = array ( '&nbsp;',
148 '<span class="confighelp">'.$configobject->help.'</span>'
150 $table->align = array ('right', 'left');
152 print_table($table);
155 echo '<center>';
156 echo '<input type="hidden" name="installing" value="'.$installing.'" />';
157 echo '<input type="hidden" name="sesskey" value="'.$sesskey.'" />';
158 echo '<input type="submit" value="'.get_string('savechanges').'" />';
159 echo '</center>';
161 echo '</form>';
167 /// Lock some options
169 $httpsurl = str_replace('http://', 'https://', $CFG->wwwroot);
170 if ($httpsurl != $CFG->wwwroot) {
171 if (ini_get('allow_url_fopen')) {
172 if ((($fh = @fopen($httpsurl, 'r')) == false) and ($config->loginhttps == 0)) {
173 echo '<script type="text/javascript">'."\n";
174 echo '<!--'."\n";
175 echo "eval('document.form.loginhttps.disabled=true');\n";
176 echo '-->'."\n";
177 echo '</script>'."\n";
183 if ($site) {
184 print_footer();
187 exit;
189 /// Functions /////////////////////////////////////////////////////////////////
191 function validate_form(&$form, &$err) {
193 // Currently no checks are needed ...
195 return true;