MDL-59496 registration: display unregistered warning consistently
[moodle.git] / admin / search.php
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 $context = context_system::instance();
11 $PAGE->set_context($context);
13 admin_externalpage_setup('search', '', array('query' => $query)); // now hidden page
15 $adminroot = admin_get_root(); // need all settings here
16 $adminroot->search = $query; // So we can reference it in search boxes later in this invocation
17 $statusmsg = '';
18 $errormsg  = '';
19 $focus = '';
21 // now we'll deal with the case that the admin has submitted the form with changed settings
22 if ($data = data_submitted() and confirm_sesskey() and isset($data->action) and $data->action == 'save-settings') {
23     require_capability('moodle/site:config', $context);
24     if (admin_write_settings($data)) {
25         redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
26     }
28     if (!empty($adminroot->errors)) {
29         $errormsg = get_string('errorwithsettings', 'admin');
30         $firsterror = reset($adminroot->errors);
31         $focus = $firsterror->id;
32     } else {
33         redirect($PAGE->url);
34     }
35 }
37 // and finally, if we get here, then there are matching settings and we have to print a form
38 // to modify them
39 echo $OUTPUT->header($focus);
41 // Display a warning if site is not registered.
42 if (empty($query)) {
43     $adminrenderer = $PAGE->get_renderer('core', 'admin');
44     echo $adminrenderer->warn_if_not_registered();
45 }
47 echo $OUTPUT->heading(get_string('administrationsite'));
49 if ($errormsg !== '') {
50     echo $OUTPUT->notification($errormsg);
52 } else if ($statusmsg !== '') {
53     echo $OUTPUT->notification($statusmsg, 'notifysuccess');
54 }
56 $showsettingslinks = true;
58 if (has_capability('moodle/site:config', $context)) {
59     require_once("admin_settings_search_form.php");
60     $form = new admin_settings_search_form();
61     $form->display();
62     echo '<hr>';
63     if ($query) {
64         echo admin_search_settings_html($query);
65         $showsettingslinks = false;
66     }
67 }
69 if ($showsettingslinks) {
70     $node = $PAGE->settingsnav->find('root', navigation_node::TYPE_SITE_ADMIN);
71     if ($node) {
72         echo $OUTPUT->render_from_template('core/settings_link_page', ['node' => $node]);
73     }
74 }
76 echo $OUTPUT->footer();