2 // config.php - allows admin to edit all configuration variables
4 require_once('../config.php');
8 if ($site = get_site()) { // If false then this is a new installation
11 error('Only the admin can use this page');
15 /// This is to overcome the "insecure forms paradox"
16 if (isset($secureforms) and $secureforms == 0) {
22 /// If data submitted, then process and store.
24 if ($config = data_submitted($match)) {
26 if (!empty($USER->id
)) { // Additional identity check
27 if (!confirm_sesskey()) {
28 error(get_string('confirmsesskeybad', 'error'));
32 validate_form($config, $err);
34 if (count($err) == 0) {
35 foreach ($config as $name => $value) {
36 if ($name == "sessioncookie") {
37 $value = eregi_replace("[^a-zA-Z]", "", $value);
39 if ($name == "defaultallowedmodules") {
40 $value = implode(',',$value);
42 if ($name == 'hiddenuserfields') {
43 if (in_array('none', $value)) {
46 $value = implode(',',$value);
51 $conf->value
= $value;
52 if ($current = get_record('config', 'name', $name)) {
53 $conf->id
= $current->id
;
54 if (! update_record('config', $conf)) {
55 notify("Could not update $name to $value");
58 if (! insert_record('config', $conf)) {
59 notify("Error: could not add new variable $name !");
63 redirect('index.php', get_string('changessaved'), 1);
67 foreach ($err as $key => $value) {
73 /// Otherwise fill and print the form.
77 if (!$config->locale
= get_field('config', 'value', 'name', 'locale')) {
78 $config->locale
= $CFG->lang
;
82 $sesskey = !empty($USER->id
) ?
$USER->sesskey
: '';
85 $stradmin = get_string('administration');
86 $strconfiguration = get_string('configuration');
87 $strconfigvariables = get_string('configvariables', 'admin');
90 print_header("$site->shortname: $strconfigvariables", $site->fullname
,
91 "<a href=\"index.php\">$stradmin</a> -> ".
92 "<a href=\"configure.php\">$strconfiguration</a> -> $strconfigvariables", $focus);
93 print_heading($strconfigvariables);
96 print_heading($strconfigvariables);
97 print_simple_box(get_string('configintro', 'admin'), 'center', "50%");
103 /// Get all the configuration fields and helptext
104 require('configvars.php');
106 /// Cycle through the sections to get the sectionnames
108 foreach($configvars as $sectionname=>$section) {
109 if ($linktext !== '') {
112 $linktext .= '<a href="#configsection'.$sectionname.'">'.get_string('configsection'.$sectionname, 'admin').'</a>';
115 echo "<center>$linktext</center>\n";
118 echo '<form method="post" action="config.php" name="form">';
119 echo '<center><input type="submit" value="'.get_string('savechanges').'" /></center>';
121 /// Cycle through each section of the configuration
122 foreach ($configvars as $sectionname=>$section) {
124 print_heading('<a name="configsection'.$sectionname.'"></a>'.get_string('configsection'.$sectionname, 'admin'));
127 $table->data
= array();
128 foreach ($section as $configvariable=>$configobject) {
129 $table->data
[] = array ( $configvariable.': ',
132 if ($configobject->display_warning()) {
133 $table->data
[] = array ( ' ',
134 '<span class="configwarning">'.$configobject->warning
.'</span>'
137 $table->data
[] = array ( ' ',
138 '<span class="confighelp">'.$configobject->help
.'</span>'
140 $table->align
= array ('right', 'left');
146 echo '<input type="hidden" name="sesskey" value="'.$sesskey.'" />';
147 echo '<input type="submit" value="'.get_string('savechanges').'" />';
156 /// Lock some options
158 $httpsurl = str_replace('http://', 'https://', $CFG->wwwroot
);
159 if ($httpsurl != $CFG->wwwroot
) {
160 if (ini_get('allow_url_fopen')) {
161 if ((($fh = @fopen
($httpsurl, 'r')) == false) and ($config->loginhttps
== 0)) {
162 echo '<script type="text/javascript">'."\n";
164 echo "eval('document.form.loginhttps.disabled=true');\n";
166 echo '</script>'."\n";
178 /// Functions /////////////////////////////////////////////////////////////////
180 function validate_form(&$form, &$err) {
182 // Currently no checks are needed ...