source: moodle/trunk/fuentes/admin/settings.php @ 1331

Last change on this file since 1331 was 1331, checked in by jrpelegrina, 3 years ago

Updated to moodle 3.0.3

File size: 4.9 KB
Line 
1<?php
2
3require_once('../config.php');
4require_once($CFG->libdir.'/adminlib.php');
5
6$section = required_param('section', PARAM_SAFEDIR);
7$return = optional_param('return','', PARAM_ALPHA);
8$adminediting = optional_param('adminedit', -1, PARAM_BOOL);
9
10/// no guest autologin
11require_login(0, false);
12$PAGE->set_context(context_system::instance());
13$PAGE->set_url('/admin/settings.php', array('section' => $section));
14$PAGE->set_pagetype('admin-setting-' . $section);
15$PAGE->set_pagelayout('admin');
16$PAGE->navigation->clear_cache();
17navigation_node::require_admin_tree();
18
19$adminroot = admin_get_root(); // need all settings
20$settingspage = $adminroot->locate($section, true);
21
22if (empty($settingspage) or !($settingspage instanceof admin_settingpage)) {
23    print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
24    die;
25}
26
27if (!($settingspage->check_access())) {
28    print_error('accessdenied', 'admin');
29    die;
30}
31
32/// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
33
34$statusmsg = '';
35$errormsg  = '';
36
37if ($data = data_submitted() and confirm_sesskey()) {
38    if (admin_write_settings($data)) {
39        $statusmsg = get_string('changessaved');
40    }
41
42    if (empty($adminroot->errors)) {
43        switch ($return) {
44            case 'site': redirect("$CFG->wwwroot/");
45            case 'admin': redirect("$CFG->wwwroot/$CFG->admin/");
46        }
47    } else {
48        $errormsg = get_string('errorwithsettings', 'admin');
49        $firsterror = reset($adminroot->errors);
50    }
51    $settingspage = $adminroot->locate($section, true);
52}
53
54if ($PAGE->user_allowed_editing() && $adminediting != -1) {
55    $USER->editing = $adminediting;
56}
57
58/// print header stuff ------------------------------------------------------------
59if (empty($SITE->fullname)) {
60    $PAGE->set_title($settingspage->visiblename);
61    $PAGE->set_heading($settingspage->visiblename);
62
63    echo $OUTPUT->header();
64    echo $OUTPUT->box(get_string('configintrosite', 'admin'));
65
66    if ($errormsg !== '') {
67        echo $OUTPUT->notification($errormsg);
68
69    } else if ($statusmsg !== '') {
70        echo $OUTPUT->notification($statusmsg, 'notifysuccess');
71    }
72
73    // ---------------------------------------------------------------------------------------------------------------
74
75    echo '<form action="settings.php" method="post" id="adminsettings">';
76    echo '<div class="settingsform clearfix">';
77    echo html_writer::input_hidden_params($PAGE->url);
78    echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
79    echo '<input type="hidden" name="return" value="'.$return.'" />';
80    // HACK to prevent browsers from automatically inserting the user's password into the wrong fields.
81    echo prevent_form_autofill_password();
82
83    echo $settingspage->output_html();
84
85    echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
86
87    echo '</div>';
88    echo '</form>';
89
90} else {
91    if ($PAGE->user_allowed_editing()) {
92        $url = clone($PAGE->url);
93        if ($PAGE->user_is_editing()) {
94            $caption = get_string('blockseditoff');
95            $url->param('adminedit', 'off');
96        } else {
97            $caption = get_string('blocksediton');
98            $url->param('adminedit', 'on');
99        }
100        $buttons = $OUTPUT->single_button($url, $caption, 'get');
101        $PAGE->set_button($buttons);
102    }
103
104    $visiblepathtosection = array_reverse($settingspage->visiblepath);
105
106    $PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection));
107    $PAGE->set_heading($SITE->fullname);
108    echo $OUTPUT->header();
109
110    if ($errormsg !== '') {
111        echo $OUTPUT->notification($errormsg);
112
113    } else if ($statusmsg !== '') {
114        echo $OUTPUT->notification($statusmsg, 'notifysuccess');
115    }
116
117    // ---------------------------------------------------------------------------------------------------------------
118
119    echo '<form action="settings.php" method="post" id="adminsettings">';
120    echo '<div class="settingsform clearfix">';
121    echo html_writer::input_hidden_params($PAGE->url);
122    echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
123    echo '<input type="hidden" name="return" value="'.$return.'" />';
124    // HACK to prevent browsers from automatically inserting the user's password into the wrong fields.
125    echo prevent_form_autofill_password();
126    echo $OUTPUT->heading($settingspage->visiblename);
127
128    echo $settingspage->output_html();
129
130    if ($settingspage->show_save()) {
131        echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
132    }
133
134    echo '</div>';
135    echo '</form>';
136}
137
138$PAGE->requires->yui_module('moodle-core-formchangechecker',
139        'M.core_formchangechecker.init',
140        array(array(
141            'formid' => 'adminsettings'
142        ))
143);
144$PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle');
145
146echo $OUTPUT->footer();
Note: See TracBrowser for help on using the repository browser.