source: moodle/trunk/fuentes/admin/upgradesettings.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 4 years ago

Ported code to xenial

File size: 2.5 KB
Line 
1<?php
2
3// detects settings that were added during an upgrade, displays a screen for the admin to
4// modify them, and then processes modifications
5
6require_once('../config.php');
7require_once($CFG->libdir.'/adminlib.php');
8
9$return = optional_param('return', '', PARAM_ALPHA);
10
11/// no guest autologin
12require_login(0, false);
13if (isguestuser()) {
14    // Login as real user!
15    $SESSION->wantsurl = (string)new moodle_url('/admin/upgradesettings.php', array('return'=>$return));
16    redirect(get_login_url());
17}
18
19admin_externalpage_setup('upgradesettings'); // now hidden page
20$PAGE->set_pagelayout('maintenance'); // do not print any blocks or other rubbish, we want to force saving
21$PAGE->blocks->show_only_fake_blocks();
22$adminroot = admin_get_root(); // need all settings
23
24// now we'll deal with the case that the admin has submitted the form with new settings
25if ($data = data_submitted() and confirm_sesskey()) {
26    $count = admin_write_settings($data);
27    $adminroot = admin_get_root(true); //reload tree
28}
29
30$newsettings = admin_output_new_settings_by_page($adminroot);
31if (isset($newsettings['frontpagesettings'])) {
32    $frontpage = $newsettings['frontpagesettings'];
33    unset($newsettings['frontpagesettings']);
34    array_unshift($newsettings, $frontpage);
35}
36$newsettingshtml = implode($newsettings);
37unset($newsettings);
38
39$focus = '';
40
41if (empty($adminroot->errors) and $newsettingshtml === '') {
42    // there must be either redirect without message or continue button or else upgrade would be sometimes broken
43    if ($return == 'site') {
44        redirect("$CFG->wwwroot/");
45    } else {
46        redirect("$CFG->wwwroot/$CFG->admin/index.php");
47    }
48}
49
50if (!empty($adminroot->errors)) {
51    $firsterror = reset($adminroot->errors);
52    $focus = $firsterror->id;
53}
54
55// and finally, if we get here, then there are new settings and we have to print a form
56// to modify them
57echo $OUTPUT->header($focus);
58
59if (!empty($SITE->fullname) and !empty($SITE->shortname)) {
60    echo $OUTPUT->box(get_string('upgradesettingsintro','admin'), 'generalbox');
61}
62
63echo '<form action="upgradesettings.php" method="post" id="adminsettings">';
64echo '<div>';
65echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
66echo '<input type="hidden" name="return" value="'.$return.'" />';
67echo '<fieldset>';
68echo '<div class="clearer"><!-- --></div>';
69echo $newsettingshtml;
70echo '</fieldset>';
71echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
72echo '</div>';
73echo '</form>';
74
75echo $OUTPUT->footer();
76
77
Note: See TracBrowser for help on using the repository browser.