Merge branch 'MDL-48946-master' of https://github.com/sammarshallou/moodle
[moodle.git] / admin / search.php
blob748ef5b2d70bc016d7201b9ee7aaeded98a80004
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 $statusmsg = get_string('changessaved');
26 if (!empty($adminroot->errors)) {
27 $errormsg = get_string('errorwithsettings', 'admin');
28 $firsterror = reset($adminroot->errors);
29 $focus = $firsterror->id;
33 // and finally, if we get here, then there are matching settings and we have to print a form
34 // to modify them
35 echo $OUTPUT->header($focus);
37 if ($errormsg !== '') {
38 echo $OUTPUT->notification($errormsg);
40 } else if ($statusmsg !== '') {
41 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
44 $resultshtml = admin_search_settings_html($query); // case insensitive search only
46 echo '<form action="search.php" method="post" id="adminsettings">';
47 echo '<div>';
48 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
49 echo '<input type="hidden" name="query" value="'.s($query).'" />';
50 echo '</div>';
51 echo '<fieldset>';
52 echo '<div class="clearer"><!-- --></div>';
53 if ($resultshtml != '') {
54 echo $resultshtml;
55 } else {
56 echo get_string('noresults','admin');
58 echo '</fieldset>';
59 echo '</form>';
61 echo $OUTPUT->footer();