Merge branch 'MDL-80060' of https://github.com/paulholden/moodle
[moodle.git] / admin / search.php
blob2d1920d5ec186b69229c70d995d1a9a8de61618a
1 <?php
3 // searches for admin settings
5 require_once('../config.php');
6 require_once($CFG->libdir.'/adminlib.php');
8 redirect_if_major_upgrade_required();
10 $query = trim(optional_param('query', '', PARAM_NOTAGS)); // Search string
12 $context = context_system::instance();
13 $PAGE->set_context($context);
15 // If we are performing a search we need to display the secondary navigation with links as opposed to just anchors.
16 // NOTE: hassecondarynavigation will be overridden in classic.
17 $PAGE->set_secondary_navigation(true, !$query);
19 $hassiteconfig = has_capability('moodle/site:config', $context);
21 if ($hassiteconfig && moodle_needs_upgrading()) {
22 redirect(new moodle_url('/admin/index.php'));
25 // If site registration needs updating, redirect.
26 \core\hub\registration::registration_reminder('/admin/search.php');
28 admin_externalpage_setup('search', '', array('query' => $query)); // now hidden page
29 $PAGE->set_heading(get_string('administrationsite')); // Has to be after setup since it has its' own heading set_heading.
31 $adminroot = admin_get_root(); // need all settings here
32 $adminroot->search = $query; // So we can reference it in search boxes later in this invocation
33 $statusmsg = '';
34 $errormsg = '';
35 $focus = '';
37 // now we'll deal with the case that the admin has submitted the form with changed settings
38 if ($data = data_submitted() and confirm_sesskey() and isset($data->action) and $data->action == 'save-settings') {
39 require_capability('moodle/site:config', $context);
40 $count = admin_write_settings($data);
41 if (!empty($adminroot->errors)) {
42 $errormsg = get_string('errorwithsettings', 'admin');
43 $firsterror = reset($adminroot->errors);
44 $focus = $firsterror->id;
45 } else {
46 // No errors. Did we change any setting? If so, then redirect with success.
47 if ($count) {
48 redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
50 redirect($PAGE->url);
54 $PAGE->set_primary_active_tab('siteadminnode');
56 // and finally, if we get here, then there are matching settings and we have to print a form
57 // to modify them
58 echo $OUTPUT->header($focus);
60 // Display a warning if site is not registered.
61 if (empty($query)) {
62 $adminrenderer = $PAGE->get_renderer('core', 'admin');
63 echo $adminrenderer->warn_if_not_registered();
66 if ($errormsg !== '') {
67 echo $OUTPUT->notification($errormsg);
69 } else if ($statusmsg !== '') {
70 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
73 $showsettingslinks = true;
75 if ($query && $hassiteconfig) {
76 echo '<hr>';
77 echo admin_search_settings_html($query);
78 $showsettingslinks = false;
81 if ($showsettingslinks) {
82 $node = $PAGE->settingsnav->find('root', navigation_node::TYPE_SITE_ADMIN);
83 if ($node) {
84 $secondarynavigation = false;
85 if ($PAGE->has_secondary_navigation()) {
86 $moremenu = new \core\navigation\output\more_menu($PAGE->secondarynav, 'nav-tabs', true, true);
87 $secondarynavigation = $moremenu->export_for_template($OUTPUT);
89 echo $OUTPUT->render_from_template('core/settings_link_page',
90 ['node' => $node, 'secondarynavigation' => $secondarynavigation]);
94 echo $OUTPUT->footer();