Merge branch 'install_master' of https://git.in.moodle.com/amosbot/moodle-install
[moodle.git] / admin / search.php
blobdfb60433cd8c9f72d2d14326273ae56328ca30f2
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
26 $adminroot = admin_get_root(); // need all settings here
27 $adminroot->search = $query; // So we can reference it in search boxes later in this invocation
28 $statusmsg = '';
29 $errormsg = '';
30 $focus = '';
32 // now we'll deal with the case that the admin has submitted the form with changed settings
33 if ($data = data_submitted() and confirm_sesskey() and isset($data->action) and $data->action == 'save-settings') {
34 require_capability('moodle/site:config', $context);
35 if (admin_write_settings($data)) {
36 redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
39 if (!empty($adminroot->errors)) {
40 $errormsg = get_string('errorwithsettings', 'admin');
41 $firsterror = reset($adminroot->errors);
42 $focus = $firsterror->id;
43 } else {
44 redirect($PAGE->url);
48 // and finally, if we get here, then there are matching settings and we have to print a form
49 // to modify them
50 echo $OUTPUT->header($focus);
52 // Display a warning if site is not registered.
53 if (empty($query)) {
54 $adminrenderer = $PAGE->get_renderer('core', 'admin');
55 echo $adminrenderer->warn_if_not_registered();
58 echo $OUTPUT->heading(get_string('administrationsite'));
60 if ($errormsg !== '') {
61 echo $OUTPUT->notification($errormsg);
63 } else if ($statusmsg !== '') {
64 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
67 $showsettingslinks = true;
69 if ($hassiteconfig) {
70 require_once("admin_settings_search_form.php");
71 $form = new admin_settings_search_form();
72 $form->display();
73 echo '<hr>';
74 if ($query) {
75 echo admin_search_settings_html($query);
76 $showsettingslinks = false;
80 if ($showsettingslinks) {
81 $node = $PAGE->settingsnav->find('root', navigation_node::TYPE_SITE_ADMIN);
82 if ($node) {
83 echo $OUTPUT->render_from_template('core/settings_link_page', ['node' => $node]);
87 echo $OUTPUT->footer();