2 // config.php - allows admin to edit all configuration variables
4 require_once('../config.php');
6 $installing = optional_param('installing', 0, PARAM_BOOL
);
10 if ($site = get_site()) { // If false then this is a new installation
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) {
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)) {
48 $value = implode(',',$value);
51 if ($name == "locale") {
52 $value = trim($value);
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");
63 if (! insert_record('config', $conf)) {
64 notify("Error: could not add new variable $name !");
70 notify(get_string('changessaved'), 'notifysuccess');
71 print_continue('index.php');
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);
80 foreach ($err as $key => $value) {
86 /// Otherwise fill and print the form.
92 $sesskey = !empty($USER->id
) ?
$USER->sesskey
: '';
95 $stradmin = get_string('administration');
96 $strconfiguration = get_string('configuration');
97 $strconfigvariables = get_string('configvariables', 'admin');
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);
106 print_heading($strconfigvariables);
107 print_simple_box(get_string('configintro', 'admin'), 'center', "50%");
113 /// Get all the configuration fields and helptext
114 require('configvars.php');
116 /// Cycle through the sections to get the sectionnames
118 foreach($configvars as $sectionname=>$section) {
119 if ($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'));
137 $table->data
= array();
138 foreach ($section as $configvariable=>$configobject) {
139 $table->data
[] = array ( $configvariable.': ',
142 if ($configobject->display_warning()) {
143 $table->data
[] = array ( ' ',
144 '<span class="configwarning">'.$configobject->warning
.'</span>'
147 $table->data
[] = array ( ' ',
148 '<span class="confighelp">'.$configobject->help
.'</span>'
150 $table->align
= array ('right', 'left');
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').'" />';
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";
175 echo "eval('document.form.loginhttps.disabled=true');\n";
177 echo '</script>'."\n";
189 /// Functions /////////////////////////////////////////////////////////////////
191 function validate_form(&$form, &$err) {
193 // Currently no checks are needed ...