Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
/admin/ -> search.php (source)

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   1  <?php
   2  
   3  // searches for admin settings
   4  
   5  require_once('../config.php');
   6  require_once($CFG->libdir.'/adminlib.php');
   7  
   8  redirect_if_major_upgrade_required();
   9  
  10  $query = trim(optional_param('query', '', PARAM_NOTAGS));  // Search string
  11  
  12  $context = context_system::instance();
  13  $PAGE->set_context($context);
  14  
  15  $hassiteconfig = has_capability('moodle/site:config', $context);
  16  
  17  if ($hassiteconfig && moodle_needs_upgrading()) {
  18      redirect(new moodle_url('/admin/index.php'));
  19  }
  20  
  21  // If site registration needs updating, redirect.
  22  \core\hub\registration::registration_reminder('/admin/search.php');
  23  
  24  admin_externalpage_setup('search', '', array('query' => $query)); // now hidden page
  25  
  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 = '';
  31  
  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      $count = admin_write_settings($data);
  36      if (!empty($adminroot->errors)) {
  37          $errormsg = get_string('errorwithsettings', 'admin');
  38          $firsterror = reset($adminroot->errors);
  39          $focus = $firsterror->id;
  40      } else {
  41          // No errors. Did we change any setting? If so, then redirect with success.
  42          if ($count) {
  43              redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
  44          }
  45          redirect($PAGE->url);
  46      }
  47  }
  48  
  49  // and finally, if we get here, then there are matching settings and we have to print a form
  50  // to modify them
  51  echo $OUTPUT->header($focus);
  52  
  53  // Display a warning if site is not registered.
  54  if (empty($query)) {
  55      $adminrenderer = $PAGE->get_renderer('core', 'admin');
  56      echo $adminrenderer->warn_if_not_registered();
  57  }
  58  
  59  echo $OUTPUT->heading(get_string('administrationsite'));
  60  
  61  if ($errormsg !== '') {
  62      echo $OUTPUT->notification($errormsg);
  63  
  64  } else if ($statusmsg !== '') {
  65      echo $OUTPUT->notification($statusmsg, 'notifysuccess');
  66  }
  67  
  68  $showsettingslinks = true;
  69  
  70  if ($hassiteconfig) {
  71      $data = [
  72          'action' => new moodle_url('/admin/search.php'),
  73          'btnclass' => 'btn-primary',
  74          'inputname' => 'query',
  75          'searchstring' => get_string('search'),
  76          'query' => $query,
  77          'extraclasses' => 'd-flex justify-content-center'
  78      ];
  79      echo $OUTPUT->render_from_template('core/search_input', $data);
  80  
  81      echo '<hr>';
  82      if ($query) {
  83          echo admin_search_settings_html($query);
  84          $showsettingslinks = false;
  85      }
  86  }
  87  
  88  if ($showsettingslinks) {
  89      $node = $PAGE->settingsnav->find('root', navigation_node::TYPE_SITE_ADMIN);
  90      if ($node) {
  91          echo $OUTPUT->render_from_template('core/settings_link_page', ['node' => $node]);
  92      }
  93  }
  94  
  95  echo $OUTPUT->footer();