Merge branch 'MDL-74184' of https://github.com/timhunt/moodle
[moodle.git] / admin / search.php
blob8ddbd2b592b1b5829799ab7eb6222d93bee2cadc
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);
14 $PAGE->set_secondary_navigation(true, true);
16 $hassiteconfig = has_capability('moodle/site:config', $context);
18 if ($hassiteconfig && moodle_needs_upgrading()) {
19 redirect(new moodle_url('/admin/index.php'));
22 // If site registration needs updating, redirect.
23 \core\hub\registration::registration_reminder('/admin/search.php');
25 admin_externalpage_setup('search', '', array('query' => $query)); // now hidden page
26 $PAGE->set_heading(get_string('administrationsite')); // Has to be after setup since it has its' own heading set_heading.
28 if ($hassiteconfig) {
29 $data = [
30 'action' => new moodle_url('/admin/search.php'),
31 'btnclass' => 'btn-primary',
32 'inputname' => 'query',
33 'searchstring' => get_string('search'),
34 'query' => $query,
35 'extraclasses' => 'd-flex justify-content-end'
37 $PAGE->add_header_action($OUTPUT->render_from_template('core/search_input', $data));
40 $adminroot = admin_get_root(); // need all settings here
41 $adminroot->search = $query; // So we can reference it in search boxes later in this invocation
42 $statusmsg = '';
43 $errormsg = '';
44 $focus = '';
46 // now we'll deal with the case that the admin has submitted the form with changed settings
47 if ($data = data_submitted() and confirm_sesskey() and isset($data->action) and $data->action == 'save-settings') {
48 require_capability('moodle/site:config', $context);
49 $count = admin_write_settings($data);
50 if (!empty($adminroot->errors)) {
51 $errormsg = get_string('errorwithsettings', 'admin');
52 $firsterror = reset($adminroot->errors);
53 $focus = $firsterror->id;
54 } else {
55 // No errors. Did we change any setting? If so, then redirect with success.
56 if ($count) {
57 redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
59 redirect($PAGE->url);
63 $PAGE->set_primary_active_tab('siteadminnode');
65 // and finally, if we get here, then there are matching settings and we have to print a form
66 // to modify them
67 echo $OUTPUT->header($focus);
69 // Display a warning if site is not registered.
70 if (empty($query)) {
71 $adminrenderer = $PAGE->get_renderer('core', 'admin');
72 echo $adminrenderer->warn_if_not_registered();
75 if ($errormsg !== '') {
76 echo $OUTPUT->notification($errormsg);
78 } else if ($statusmsg !== '') {
79 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
82 $showsettingslinks = true;
84 if ($query && $hassiteconfig) {
85 echo '<hr>';
86 echo admin_search_settings_html($query);
87 $showsettingslinks = false;
90 if ($showsettingslinks) {
91 $node = $PAGE->settingsnav->find('root', navigation_node::TYPE_SITE_ADMIN);
92 if ($node) {
93 $secondarynavigation = false;
94 if ($PAGE->has_secondary_navigation()) {
95 $moremenu = new \core\navigation\output\more_menu($PAGE->secondarynav, 'nav-tabs', true, true);
96 $secondarynavigation = $moremenu->export_for_template($OUTPUT);
98 echo $OUTPUT->render_from_template('core/settings_link_page',
99 ['node' => $node, 'secondarynavigation' => $secondarynavigation]);
103 echo $OUTPUT->footer();