Noted that xml format can now handle images.
[moodle-linuxchix.git] / admin / config.php
blob459675cf77f74399db6ec3fc09d4a53f705ccba7
1 <?php // $Id$
2 // config.php - allows admin to edit all configuration variables
4 require_once('../config.php');
6 $focus = '';
8 if ($site = get_site()) { // If false then this is a new installation
9 require_login();
10 if (!isadmin()) {
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) {
17 $match = 'nomatch';
18 } else {
19 $match = '';
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)) {
44 $value = '';
45 } else {
46 $value = implode(',',$value);
49 unset($conf);
50 $conf->name = $name;
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");
57 } else {
58 if (! insert_record('config', $conf)) {
59 notify("Error: could not add new variable $name !");
63 redirect('index.php', get_string('changessaved'), 1);
64 exit;
66 } else {
67 foreach ($err as $key => $value) {
68 $focus = "form.$key";
73 /// Otherwise fill and print the form.
75 if (empty($config)) {
76 $config = $CFG;
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');
89 if ($site) {
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);
94 } else {
95 print_header();
96 print_heading($strconfigvariables);
97 print_simple_box(get_string('configintro', 'admin'), 'center', "50%");
98 echo '<br />';
103 /// Get all the configuration fields and helptext
104 require('configvars.php');
106 /// Cycle through the sections to get the sectionnames
107 $linktext = '';
108 foreach($configvars as $sectionname=>$section) {
109 if ($linktext !== '') {
110 $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'));
126 $table = NULL;
127 $table->data = array();
128 foreach ($section as $configvariable=>$configobject) {
129 $table->data[] = array ( $configvariable.': ',
130 $configobject->field
132 if ($configobject->display_warning()) {
133 $table->data[] = array ( '&nbsp;',
134 '<span class="configwarning">'.$configobject->warning.'</span>'
137 $table->data[] = array ( '&nbsp;',
138 '<span class="confighelp">'.$configobject->help.'</span>'
140 $table->align = array ('right', 'left');
142 print_table($table);
145 echo '<center>';
146 echo '<input type="hidden" name="sesskey" value="'.$sesskey.'" />';
147 echo '<input type="submit" value="'.get_string('savechanges').'" />';
148 echo '</center>';
150 echo '</form>';
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";
163 echo '<!--'."\n";
164 echo "eval('document.form.loginhttps.disabled=true');\n";
165 echo '-->'."\n";
166 echo '</script>'."\n";
172 if ($site) {
173 print_footer();
176 exit;
178 /// Functions /////////////////////////////////////////////////////////////////
180 function validate_form(&$form, &$err) {
182 // Currently no checks are needed ...
184 return true;