Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
/admin/ -> search.php (source)

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400]

   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  // If we are performing a search we need to display the secondary navigation with links as opposed to just anchors.
  16  // NOTE: hassecondarynavigation will be overridden in classic.
  17  $PAGE->set_secondary_navigation(true, !$query);
  18  
  19  $hassiteconfig = has_capability('moodle/site:config', $context);
  20  
  21  if ($hassiteconfig && moodle_needs_upgrading()) {
  22      redirect(new moodle_url('/admin/index.php'));
  23  }
  24  
  25  // If site registration needs updating, redirect.
  26  \core\hub\registration::registration_reminder('/admin/search.php');
  27  
  28  admin_externalpage_setup('search', '', array('query' => $query)); // now hidden page
  29  $PAGE->set_heading(get_string('administrationsite')); // Has to be after setup since it has its' own heading set_heading.
  30  
  31  $adminroot = admin_get_root(); // need all settings here
  32  $adminroot->search = $query; // So we can reference it in search boxes later in this invocation
  33  $statusmsg = '';
  34  $errormsg  = '';
  35  $focus = '';
  36  
  37  // now we'll deal with the case that the admin has submitted the form with changed settings
  38  if ($data = data_submitted() and confirm_sesskey() and isset($data->action) and $data->action == 'save-settings') {
  39      require_capability('moodle/site:config', $context);
  40      $count = admin_write_settings($data);
  41      if (!empty($adminroot->errors)) {
  42          $errormsg = get_string('errorwithsettings', 'admin');
  43          $firsterror = reset($adminroot->errors);
  44          $focus = $firsterror->id;
  45      } else {
  46          // No errors. Did we change any setting? If so, then redirect with success.
  47          if ($count) {
  48              redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
  49          }
  50          redirect($PAGE->url);
  51      }
  52  }
  53  
  54  $PAGE->set_primary_active_tab('siteadminnode');
  55  
  56  // and finally, if we get here, then there are matching settings and we have to print a form
  57  // to modify them
  58  echo $OUTPUT->header($focus);
  59  
  60  // Display a warning if site is not registered.
  61  if (empty($query)) {
  62      $adminrenderer = $PAGE->get_renderer('core', 'admin');
  63      echo $adminrenderer->warn_if_not_registered();
  64  }
  65  
  66  if ($errormsg !== '') {
  67      echo $OUTPUT->notification($errormsg);
  68  
  69  } else if ($statusmsg !== '') {
  70      echo $OUTPUT->notification($statusmsg, 'notifysuccess');
  71  }
  72  
  73  $showsettingslinks = true;
  74  
  75  if ($query && $hassiteconfig) {
  76      echo '<hr>';
  77      echo admin_search_settings_html($query);
  78      $showsettingslinks = false;
  79  }
  80  
  81  if ($showsettingslinks) {
  82      $node = $PAGE->settingsnav->find('root', navigation_node::TYPE_SITE_ADMIN);
  83      if ($node) {
  84          $secondarynavigation = false;
  85          if ($PAGE->has_secondary_navigation()) {
  86              $moremenu = new \core\navigation\output\more_menu($PAGE->secondarynav, 'nav-tabs', true, true);
  87              $secondarynavigation = $moremenu->export_for_template($OUTPUT);
  88          }
  89          echo $OUTPUT->render_from_template('core/settings_link_page',
  90              ['node' => $node, 'secondarynavigation' => $secondarynavigation]);
  91      }
  92  }
  93  
  94  echo $OUTPUT->footer();