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