Merge branch 'MDL-61801-33' of git://github.com/andrewnicols/moodle into MOODLE_33_STABLE
[moodle.git] / admin / search.php
blob22d839ed9559583438671ae3e1853ef7a43e9cc1
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 admin_externalpage_setup('search', '', array('query' => $query)); // now hidden page
23 $adminroot = admin_get_root(); // need all settings here
24 $adminroot->search = $query; // So we can reference it in search boxes later in this invocation
25 $statusmsg = '';
26 $errormsg = '';
27 $focus = '';
29 // now we'll deal with the case that the admin has submitted the form with changed settings
30 if ($data = data_submitted() and confirm_sesskey() and isset($data->action) and $data->action == 'save-settings') {
31 require_capability('moodle/site:config', $context);
32 $count = admin_write_settings($data);
33 if (!empty($adminroot->errors)) {
34 $errormsg = get_string('errorwithsettings', 'admin');
35 $firsterror = reset($adminroot->errors);
36 $focus = $firsterror->id;
37 } else {
38 // No errors. Did we change any setting? If so, then redirect with success.
39 if ($count) {
40 redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
42 redirect($PAGE->url);
46 // and finally, if we get here, then there are matching settings and we have to print a form
47 // to modify them
48 echo $OUTPUT->header($focus);
50 // Display a warning if site is not registered.
51 if (empty($query)) {
52 $adminrenderer = $PAGE->get_renderer('core', 'admin');
53 echo $adminrenderer->warn_if_not_registered();
56 echo $OUTPUT->heading(get_string('administrationsite'));
58 if ($errormsg !== '') {
59 echo $OUTPUT->notification($errormsg);
61 } else if ($statusmsg !== '') {
62 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
65 $showsettingslinks = true;
67 if ($hassiteconfig) {
68 require_once("admin_settings_search_form.php");
69 $form = new admin_settings_search_form();
70 $form->display();
71 echo '<hr>';
72 if ($query) {
73 echo admin_search_settings_html($query);
74 $showsettingslinks = false;
78 if ($showsettingslinks) {
79 $node = $PAGE->settingsnav->find('root', navigation_node::TYPE_SITE_ADMIN);
80 if ($node) {
81 echo $OUTPUT->render_from_template('core/settings_link_page', ['node' => $node]);
85 echo $OUTPUT->footer();