Merge branch 'MDL-54781_master' of git://github.com/markn86/moodle
[moodle.git] / admin / search.php
blob0e9a531944ef6fa3277c649659a4c1c1355e4f18
1 <?php
3 // searches for admin settings
5 require_once('../config.php');
6 require_once($CFG->libdir.'/adminlib.php');
8 $query = trim(optional_param('query', '', PARAM_NOTAGS)); // Search string
10 $PAGE->set_context(context_system::instance());
12 admin_externalpage_setup('search', '', array('query' => $query)); // now hidden page
14 $adminroot = admin_get_root(); // need all settings here
15 $adminroot->search = $query; // So we can reference it in search boxes later in this invocation
16 $statusmsg = '';
17 $errormsg = '';
18 $focus = '';
20 // now we'll deal with the case that the admin has submitted the form with changed settings
21 if ($data = data_submitted() and confirm_sesskey()) {
22 if (admin_write_settings($data)) {
23 redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
26 if (!empty($adminroot->errors)) {
27 $errormsg = get_string('errorwithsettings', 'admin');
28 $firsterror = reset($adminroot->errors);
29 $focus = $firsterror->id;
30 } else {
31 redirect($PAGE->url);
35 // and finally, if we get here, then there are matching settings and we have to print a form
36 // to modify them
37 echo $OUTPUT->header($focus);
39 echo $OUTPUT->heading(get_string('administrationsite'));
41 if ($errormsg !== '') {
42 echo $OUTPUT->notification($errormsg);
44 } else if ($statusmsg !== '') {
45 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
48 require_once("admin_settings_search_form.php");
49 $form = new admin_settings_search_form();
50 $form->display();
51 echo '<hr>';
53 if ($query) {
54 echo admin_search_settings_html($query);
55 } else {
56 $node = $PAGE->settingsnav->find('root', navigation_node::TYPE_SITE_ADMIN);
57 if ($node) {
58 echo $OUTPUT->render_from_template('core/settings_link_page', ['node' => $node]);
62 echo $OUTPUT->footer();