File: config.php

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (198 lines) | stat: -rw-r--r-- 6,481 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php  // $Id: config.php,v 1.36.2.3 2006/09/07 20:33:03 skodak Exp $
       // config.php - allows admin to edit all configuration variables

    require_once('../config.php');

    $installing = optional_param('installing', 0, PARAM_BOOL);

    $focus = '';

    if ($site = get_site()) {   // If false then this is a new installation
        require_login();
        if (!isadmin()) {
            error('Only the admin can use this page');
        }
    }

/// This is to overcome the "insecure forms paradox"
    if (isset($secureforms) and $secureforms == 0) {
        $match = 'nomatch';
    } else {
        $match = '';
    }

/// If data submitted, then process and store.

    if ($config = data_submitted($match)) {  

        if (!empty($USER->id)) {             // Additional identity check
            if (!confirm_sesskey()) {
                error(get_string('confirmsesskeybad', 'error'));
            }
        }

        validate_form($config, $err);

        if (count($err) == 0) {
            foreach ($config as $name => $value) {
                if ($name == "sessioncookie") {
                    $value = eregi_replace("[^a-zA-Z0-9_]", "", $value);
                }
                if ($name == "defaultallowedmodules") {
                    $value = implode(',',$value);
                }
                if ($name == 'hiddenuserfields') {
                    if (in_array('none', $value)) {
                        $value = '';
                    } else {
                        $value = implode(',',$value);
                    }
                }
                if ($name == "locale") {
                    $value = trim($value);
                }
                $conf = new object();
                $conf->name  = $name;
                $conf->value = $value;
                if ($current = get_record('config', 'name', $name)) {
                    $conf->id = $current->id;
                    if (! update_record('config', $conf)) {
                        notify("Could not update $name to $value");
                    }
                } else {
                    if (! insert_record('config', $conf)) {
                        notify("Error: could not add new variable $name !");
                    }
                }
            }
            if ($installing) {
                print_header();
                notify(get_string('changessaved'), 'notifysuccess');
                print_continue('index.php');
                exit;
            } else {
                // the following redirect was randomly breaking upgrades because it did double redirects,
                // we must not use it during install/upgrade
                redirect('index.php', get_string('changessaved'), 1);
            }

        } else {
            foreach ($err as $key => $value) {
                $focus = "form.$key";
            }
        }
    }

/// Otherwise fill and print the form.

    if (empty($config)) {
        $config = $CFG;
    }

    $sesskey = !empty($USER->id) ? $USER->sesskey : '';


    $stradmin = get_string('administration');
    $strconfiguration = get_string('configuration');
    $strconfigvariables = get_string('configvariables', 'admin');

    if ($site) {
        print_header("$site->shortname: $strconfigvariables", $site->fullname,
                      "<a href=\"index.php\">$stradmin</a> -> ".
                      "<a href=\"configure.php\">$strconfiguration</a> -> $strconfigvariables", $focus);
        print_heading($strconfigvariables);
    } else {
        print_header();
        print_heading($strconfigvariables);
        print_simple_box(get_string('configintro', 'admin'), 'center', "50%");
        echo '<br />';
    }



/// Get all the configuration fields and helptext
    require('configvars.php');

/// Cycle through the sections to get the sectionnames
    $linktext = '';
    foreach($configvars as $sectionname=>$section) {
        if ($linktext !== '') {
            $linktext .= ' | ';
        }
        $linktext .= '<a href="#configsection'.$sectionname.'">'.get_string('configsection'.$sectionname, 'admin').'</a>';
    }
        
    echo "<center>$linktext</center>\n";

    
    echo '<form method="post" action="config.php" name="form">';
    echo '<center><input type="submit" value="'.get_string('savechanges').'" /></center>';

/// Cycle through each section of the configuration
    foreach ($configvars as $sectionname=>$section) {

        print_heading('<a name="configsection'.$sectionname.'"></a>'.get_string('configsection'.$sectionname, 'admin'));

        $table = NULL;
        $table->data = array();
        foreach ($section as $configvariable=>$configobject) {
            $table->data[] = array ( $configvariable.': ',
                                     $configobject->field
                                   );
            if ($configobject->display_warning()) {
                $table->data[] = array ( '&nbsp;',
                                         '<span class="configwarning">'.$configobject->warning.'</span>'
                                       );
            }
            $table->data[] = array ( '&nbsp;',
                                     '<span class="confighelp">'.$configobject->help.'</span>'
                                   );
            $table->align = array ('right', 'left');
        }
        print_table($table);

    }
    echo '<center>';
    echo '<input type="hidden" name="installing" value="'.$installing.'" />';
    echo '<input type="hidden" name="sesskey" value="'.$sesskey.'" />';
    echo '<input type="submit" value="'.get_string('savechanges').'" />';
    echo '</center>';
                
    echo '</form>';
    


    

    /// Lock some options

    $httpsurl = str_replace('http://', 'https://', $CFG->wwwroot);
    if ($httpsurl != $CFG->wwwroot) {
        if (ini_get('allow_url_fopen')) {
            if ((($fh = @fopen($httpsurl, 'r')) == false) and ($config->loginhttps == 0)) {
                echo '<script type="text/javascript">'."\n";
                echo '<!--'."\n";
                echo "eval('document.form.loginhttps.disabled=true');\n";
                echo '-->'."\n";
                echo '</script>'."\n";
            }
        }
    }


    if ($site) {
        print_footer();
    }

    exit;

/// Functions /////////////////////////////////////////////////////////////////

function validate_form(&$form, &$err) {

    // Currently no checks are needed ...

    return true;
}

?>