Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
/admin/ -> renderer.php (source)

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

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Standard HTML output renderer for core_admin subsystem.
  19   *
  20   * @package    core
  21   * @subpackage admin
  22   * @copyright  2011 David Mudrak <david@moodle.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  class core_admin_renderer extends plugin_renderer_base {
  26  
  27      /**
  28       * Display the 'Do you acknowledge the terms of the GPL' page. The first page
  29       * during install.
  30       * @return string HTML to output.
  31       */
  32      public function install_licence_page() {
  33          global $CFG;
  34          $output = '';
  35  
  36          $copyrightnotice = text_to_html(get_string('gpl3'));
  37          $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
  38  
  39          $continue = new single_button(new moodle_url($this->page->url, array(
  40              'lang' => $CFG->lang, 'agreelicense' => 1)), get_string('continue'), 'get');
  41  
  42          $output .= $this->header();
  43          $output .= $this->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
  44          $output .= $this->heading(get_string('copyrightnotice'));
  45          $output .= $this->box($copyrightnotice, 'copyrightnotice');
  46          $output .= html_writer::empty_tag('br');
  47          $output .= $this->confirm(get_string('doyouagree'), $continue, "https://moodledev.io/general/license");
  48          $output .= $this->footer();
  49  
  50          return $output;
  51      }
  52  
  53      /**
  54       * Display page explaining proper upgrade process,
  55       * there can not be any PHP file leftovers...
  56       *
  57       * @return string HTML to output.
  58       */
  59      public function upgrade_stale_php_files_page() {
  60          $output = '';
  61          $output .= $this->header();
  62          $output .= $this->heading(get_string('upgradestalefiles', 'admin'));
  63          $output .= $this->box_start('generalbox', 'notice');
  64          $output .= format_text(get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading')), FORMAT_MARKDOWN);
  65          $output .= html_writer::empty_tag('br');
  66          $output .= html_writer::tag('div', $this->single_button($this->page->url, get_string('reload'), 'get'), array('class' => 'buttons'));
  67          $output .= $this->box_end();
  68          $output .= $this->footer();
  69  
  70          return $output;
  71      }
  72  
  73      /**
  74       * Display the 'environment check' page that is displayed during install.
  75       * @param int $maturity
  76       * @param boolean $envstatus final result of the check (true/false)
  77       * @param array $environment_results array of results gathered
  78       * @param string $release moodle release
  79       * @return string HTML to output.
  80       */
  81      public function install_environment_page($maturity, $envstatus, $environment_results, $release) {
  82          global $CFG;
  83          $output = '';
  84  
  85          $output .= $this->header();
  86          $output .= $this->maturity_warning($maturity);
  87          $output .= $this->heading("Moodle $release");
  88          $output .= $this->release_notes_link();
  89  
  90          $output .= $this->environment_check_table($envstatus, $environment_results);
  91  
  92          if (!$envstatus) {
  93              $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('agreelicense' => 1, 'lang' => $CFG->lang)));
  94          } else {
  95              $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
  96              $output .= $this->continue_button(new moodle_url($this->page->url, array(
  97                  'agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang)));
  98          }
  99  
 100          $output .= $this->footer();
 101          return $output;
 102      }
 103  
 104      /**
 105       * Displays the list of plugins with unsatisfied dependencies
 106       *
 107       * @param double|string|int $version Moodle on-disk version
 108       * @param array $failed list of plugins with unsatisfied dependecies
 109       * @param moodle_url $reloadurl URL of the page to recheck the dependencies
 110       * @return string HTML
 111       */
 112      public function unsatisfied_dependencies_page($version, array $failed, moodle_url $reloadurl) {
 113          $output = '';
 114  
 115          $output .= $this->header();
 116          $output .= $this->heading(get_string('pluginscheck', 'admin'));
 117          $output .= $this->warning(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed)))));
 118          $output .= $this->plugins_check_table(core_plugin_manager::instance(), $version, array('xdep' => true));
 119          $output .= $this->warning(get_string('pluginschecktodo', 'admin'));
 120          $output .= $this->continue_button($reloadurl);
 121  
 122          $output .= $this->footer();
 123  
 124          return $output;
 125      }
 126  
 127      /**
 128       * Display the 'You are about to upgrade Moodle' page. The first page
 129       * during upgrade.
 130       * @param string $strnewversion
 131       * @param int $maturity
 132       * @param string $testsite
 133       * @return string HTML to output.
 134       */
 135      public function upgrade_confirm_page($strnewversion, $maturity, $testsite) {
 136          $output = '';
 137  
 138          $continueurl = new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0));
 139          $continue = new single_button($continueurl, get_string('continue'), 'get');
 140          $cancelurl = new moodle_url('/admin/index.php');
 141  
 142          $output .= $this->header();
 143          $output .= $this->maturity_warning($maturity);
 144          $output .= $this->test_site_warning($testsite);
 145          $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continue, $cancelurl);
 146          $output .= $this->footer();
 147  
 148          return $output;
 149      }
 150  
 151      /**
 152       * Display the environment page during the upgrade process.
 153       * @param string $release
 154       * @param boolean $envstatus final result of env check (true/false)
 155       * @param array $environment_results array of results gathered
 156       * @return string HTML to output.
 157       */
 158      public function upgrade_environment_page($release, $envstatus, $environment_results) {
 159          global $CFG;
 160          $output = '';
 161  
 162          $output .= $this->header();
 163          $output .= $this->heading("Moodle $release");
 164          $output .= $this->release_notes_link();
 165          $output .= $this->environment_check_table($envstatus, $environment_results);
 166  
 167          if (!$envstatus) {
 168              $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0)));
 169  
 170          } else {
 171              $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
 172  
 173              if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
 174                  $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
 175              }
 176  
 177              $output .= $this->continue_button(new moodle_url($this->page->url, array(
 178                  'confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)));
 179          }
 180  
 181          $output .= $this->footer();
 182  
 183          return $output;
 184      }
 185  
 186      /**
 187       * Display the upgrade page that lists all the plugins that require attention.
 188       * @param core_plugin_manager $pluginman provides information about the plugins.
 189       * @param \core\update\checker $checker provides information about available updates.
 190       * @param int $version the version of the Moodle code from version.php.
 191       * @param bool $showallplugins
 192       * @param moodle_url $reloadurl
 193       * @param moodle_url $continueurl
 194       * @return string HTML to output.
 195       */
 196      public function upgrade_plugin_check_page(core_plugin_manager $pluginman, \core\update\checker $checker,
 197              $version, $showallplugins, $reloadurl, $continueurl) {
 198  
 199          $output = '';
 200  
 201          $output .= $this->header();
 202          $output .= $this->box_start('generalbox', 'plugins-check-page');
 203          $output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'), array('class' => 'page-description'));
 204          $output .= $this->check_for_updates_button($checker, $reloadurl);
 205          $output .= $this->missing_dependencies($pluginman);
 206          $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
 207          $output .= $this->box_end();
 208          $output .= $this->upgrade_reload($reloadurl);
 209  
 210          if ($pluginman->some_plugins_updatable()) {
 211              $output .= $this->container_start('upgradepluginsinfo');
 212              $output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin'));
 213              $output .= $this->container_end();
 214          }
 215  
 216          $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get', true);
 217          $button->class = 'continuebutton';
 218          $output .= $this->render($button);
 219          $output .= $this->footer();
 220  
 221          return $output;
 222      }
 223  
 224      /**
 225       * Display a page to confirm plugin installation cancelation.
 226       *
 227       * @param array $abortable list of \core\update\plugininfo
 228       * @param moodle_url $continue
 229       * @return string
 230       */
 231      public function upgrade_confirm_abort_install_page(array $abortable, moodle_url $continue) {
 232  
 233          $pluginman = core_plugin_manager::instance();
 234  
 235          if (empty($abortable)) {
 236              // The UI should not allow this.
 237              throw new moodle_exception('err_no_plugin_install_abortable', 'core_plugin');
 238          }
 239  
 240          $out = $this->output->header();
 241          $out .= $this->output->heading(get_string('cancelinstallhead', 'core_plugin'), 3);
 242          $out .= $this->output->container(get_string('cancelinstallinfo', 'core_plugin'), 'cancelinstallinfo');
 243  
 244          foreach ($abortable as $pluginfo) {
 245              $out .= $this->output->heading($pluginfo->displayname.' ('.$pluginfo->component.')', 4);
 246              $out .= $this->output->container(get_string('cancelinstallinfodir', 'core_plugin', $pluginfo->rootdir));
 247              if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
 248                  $out .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
 249                      'alert alert-warning mt-2');
 250              }
 251          }
 252  
 253          $out .= $this->plugins_management_confirm_buttons($continue, $this->page->url);
 254          $out .= $this->output->footer();
 255  
 256          return $out;
 257      }
 258  
 259      /**
 260       * Display the admin notifications page.
 261       * @param int $maturity
 262       * @param bool $insecuredataroot warn dataroot is invalid
 263       * @param bool $errorsdisplayed warn invalid dispaly error setting
 264       * @param bool $cronoverdue warn cron not running
 265       * @param bool $dbproblems warn db has problems
 266       * @param bool $maintenancemode warn in maintenance mode
 267       * @param bool $buggyiconvnomb warn iconv problems
 268       * @param array|null $availableupdates array of \core\update\info objects or null
 269       * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown)
 270       * @param string[] $cachewarnings An array containing warnings from the Cache API.
 271       * @param array $eventshandlers Events 1 API handlers.
 272       * @param bool $themedesignermode Warn about the theme designer mode.
 273       * @param bool $devlibdir Warn about development libs directory presence.
 274       * @param bool $mobileconfigured Whether the mobile web services have been enabled
 275       * @param bool $overridetossl Whether or not ssl is being forced.
 276       * @param bool $invalidforgottenpasswordurl Whether the forgotten password URL does not link to a valid URL.
 277       * @param bool $croninfrequent If true, warn that cron hasn't run in the past few minutes
 278       * @param bool $showcampaigncontent Whether the campaign content should be visible or not.
 279       * @param bool $showfeedbackencouragement Whether the feedback encouragement content should be displayed or not.
 280       * @param bool $showservicesandsupport Whether the services and support content should be displayed or not.
 281       * @param string $xmlrpcwarning XML-RPC deprecation warning message.
 282       *
 283       * @return string HTML to output.
 284       */
 285      public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
 286              $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
 287              $buggyiconvnomb, $registered, array $cachewarnings = array(), $eventshandlers = 0,
 288              $themedesignermode = false, $devlibdir = false, $mobileconfigured = false,
 289              $overridetossl = false, $invalidforgottenpasswordurl = false, $croninfrequent = false,
 290              $showcampaigncontent = false, bool $showfeedbackencouragement = false, bool $showservicesandsupport = false,
 291              $xmlrpcwarning = '') {
 292  
 293          global $CFG;
 294          $output = '';
 295  
 296          $output .= $this->header();
 297          $output .= $this->output->heading(get_string('notifications', 'admin'));
 298          $output .= $this->maturity_info($maturity);
 299          $output .= $this->legacy_log_store_writing_error();
 300          $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
 301          $output .= $this->insecure_dataroot_warning($insecuredataroot);
 302          $output .= $this->development_libs_directories_warning($devlibdir);
 303          $output .= $this->themedesignermode_warning($themedesignermode);
 304          $output .= $this->display_errors_warning($errorsdisplayed);
 305          $output .= $this->buggy_iconv_warning($buggyiconvnomb);
 306          $output .= $this->cron_overdue_warning($cronoverdue);
 307          $output .= $this->cron_infrequent_warning($croninfrequent);
 308          $output .= $this->db_problems($dbproblems);
 309          $output .= $this->maintenance_mode_warning($maintenancemode);
 310          $output .= $this->overridetossl_warning($overridetossl);
 311          $output .= $this->cache_warnings($cachewarnings);
 312          $output .= $this->events_handlers($eventshandlers);
 313          $output .= $this->registration_warning($registered);
 314          $output .= $this->mobile_configuration_warning($mobileconfigured);
 315          $output .= $this->forgotten_password_url_warning($invalidforgottenpasswordurl);
 316          $output .= $this->mnet_deprecation_warning($xmlrpcwarning);
 317          $output .= $this->userfeedback_encouragement($showfeedbackencouragement);
 318          $output .= $this->services_and_support_content($showservicesandsupport);
 319          $output .= $this->campaign_content($showcampaigncontent);
 320  
 321          //////////////////////////////////////////////////////////////////////////////////////////////////
 322          ////  IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
 323          $output .= $this->moodle_copyright();
 324          //////////////////////////////////////////////////////////////////////////////////////////////////
 325  
 326          $output .= $this->footer();
 327  
 328          return $output;
 329      }
 330  
 331      /**
 332       * Display the plugin management page (admin/plugins.php).
 333       *
 334       * The filtering options array may contain following items:
 335       *  bool contribonly - show only contributed extensions
 336       *  bool updatesonly - show only plugins with an available update
 337       *
 338       * @param core_plugin_manager $pluginman
 339       * @param \core\update\checker $checker
 340       * @param array $options filtering options
 341       * @return string HTML to output.
 342       */
 343      public function plugin_management_page(core_plugin_manager $pluginman, \core\update\checker $checker, array $options = array()) {
 344  
 345          $output = '';
 346  
 347          $output .= $this->header();
 348          $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
 349          $output .= $this->check_for_updates_button($checker, $this->page->url);
 350          $output .= $this->plugins_overview_panel($pluginman, $options);
 351          $output .= $this->plugins_control_panel($pluginman, $options);
 352          $output .= $this->footer();
 353  
 354          return $output;
 355      }
 356  
 357      /**
 358       * Renders a button to fetch for available updates.
 359       *
 360       * @param \core\update\checker $checker
 361       * @param moodle_url $reloadurl
 362       * @return string HTML
 363       */
 364      public function check_for_updates_button(\core\update\checker $checker, $reloadurl) {
 365  
 366          $output = '';
 367  
 368          if ($checker->enabled()) {
 369              $output .= $this->container_start('checkforupdates mb-4');
 370              $output .= $this->single_button(
 371                  new moodle_url($reloadurl, array('fetchupdates' => 1)),
 372                  get_string('checkforupdates', 'core_plugin')
 373              );
 374              if ($timefetched = $checker->get_last_timefetched()) {
 375                  $timefetched = userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'));
 376                  $output .= $this->container(get_string('checkforupdateslast', 'core_plugin', $timefetched),
 377                      'lasttimefetched small text-muted mt-1');
 378              }
 379              $output .= $this->container_end();
 380          }
 381  
 382          return $output;
 383      }
 384  
 385      /**
 386       * Display a page to confirm the plugin uninstallation.
 387       *
 388       * @param core_plugin_manager $pluginman
 389       * @param \core\plugininfo\base $pluginfo
 390       * @param moodle_url $continueurl URL to continue after confirmation
 391       * @param moodle_url $cancelurl URL to to go if cancelled
 392       * @return string
 393       */
 394      public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
 395          $output = '';
 396  
 397          $pluginname = $pluginman->plugin_name($pluginfo->component);
 398  
 399          $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
 400          if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
 401              $confirm .= $extraconfirm;
 402          }
 403  
 404          $output .= $this->output->header();
 405          $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
 406          $output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
 407          $output .= $this->output->footer();
 408  
 409          return $output;
 410      }
 411  
 412      /**
 413       * Display a page with results of plugin uninstallation and offer removal of plugin files.
 414       *
 415       * @param core_plugin_manager $pluginman
 416       * @param \core\plugininfo\base $pluginfo
 417       * @param progress_trace_buffer $progress
 418       * @param moodle_url $continueurl URL to continue to remove the plugin folder
 419       * @return string
 420       */
 421      public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
 422                                                              progress_trace_buffer $progress, moodle_url $continueurl) {
 423          $output = '';
 424  
 425          $pluginname = $pluginman->plugin_name($pluginfo->component);
 426  
 427          // Do not show navigation here, they must click one of the buttons.
 428          $this->page->set_pagelayout('maintenance');
 429          $this->page->set_cacheable(false);
 430  
 431          $output .= $this->output->header();
 432          $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
 433  
 434          $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
 435  
 436          $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
 437              array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
 438  
 439          if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
 440              $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
 441                  'alert alert-warning mt-2');
 442          }
 443  
 444          // After any uninstall we must execute full upgrade to finish the cleanup!
 445          $output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
 446          $output .= $this->output->footer();
 447  
 448          return $output;
 449      }
 450  
 451      /**
 452       * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
 453       *
 454       * @param core_plugin_manager $pluginman
 455       * @param \core\plugininfo\base $pluginfo
 456       * @param progress_trace_buffer $progress
 457       * @return string
 458       */
 459      public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
 460          $output = '';
 461  
 462          $pluginname = $pluginfo->component;
 463  
 464          $output .= $this->output->header();
 465          $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
 466  
 467          $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
 468  
 469          $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
 470              array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
 471          $output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
 472          $output .= $this->output->footer();
 473  
 474          return $output;
 475      }
 476  
 477      /**
 478       * Display the plugin management page (admin/environment.php).
 479       * @param array $versions
 480       * @param string $version
 481       * @param boolean $envstatus final result of env check (true/false)
 482       * @param array $environment_results array of results gathered
 483       * @return string HTML to output.
 484       */
 485      public function environment_check_page($versions, $version, $envstatus, $environment_results) {
 486          $output = '';
 487          $output .= $this->header();
 488  
 489          // Print the component download link
 490          $output .= html_writer::tag('div', html_writer::link(
 491                      new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
 492                      get_string('updatecomponent', 'admin')),
 493                  array('class' => 'reportlink'));
 494  
 495          // Heading.
 496          $output .= $this->heading(get_string('environment', 'admin'));
 497  
 498          // Box with info and a menu to choose the version.
 499          $output .= $this->box_start();
 500          $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
 501          $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
 502          $select->label = get_string('moodleversion');
 503          $output .= $this->render($select);
 504          $output .= $this->box_end();
 505  
 506          // The results
 507          $output .= $this->environment_check_table($envstatus, $environment_results);
 508  
 509          $output .= $this->footer();
 510          return $output;
 511      }
 512  
 513      /**
 514       * Output a warning message, of the type that appears on the admin notifications page.
 515       * @param string $message the message to display.
 516       * @param string $type type class
 517       * @return string HTML to output.
 518       */
 519      protected function warning($message, $type = 'warning') {
 520          return $this->box($message, 'generalbox alert alert-' . $type);
 521      }
 522  
 523      /**
 524       * Render an appropriate message if dataroot is insecure.
 525       * @param bool $insecuredataroot
 526       * @return string HTML to output.
 527       */
 528      protected function insecure_dataroot_warning($insecuredataroot) {
 529          global $CFG;
 530  
 531          if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
 532              return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
 533  
 534          } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
 535              return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'danger');
 536  
 537          } else {
 538              return '';
 539          }
 540      }
 541  
 542      /**
 543       * Render a warning that a directory with development libs is present.
 544       *
 545       * @param bool $devlibdir True if the warning should be displayed.
 546       * @return string
 547       */
 548      protected function development_libs_directories_warning($devlibdir) {
 549  
 550          if ($devlibdir) {
 551              $moreinfo = new moodle_url('/report/security/index.php');
 552              $warning = get_string('devlibdirpresent', 'core_admin', ['moreinfourl' => $moreinfo->out()]);
 553              return $this->warning($warning, 'danger');
 554  
 555          } else {
 556              return '';
 557          }
 558      }
 559  
 560      /**
 561       * Render an appropriate message if dataroot is insecure.
 562       * @param bool $errorsdisplayed
 563       * @return string HTML to output.
 564       */
 565      protected function display_errors_warning($errorsdisplayed) {
 566          if (!$errorsdisplayed) {
 567              return '';
 568          }
 569  
 570          return $this->warning(get_string('displayerrorswarning', 'admin'));
 571      }
 572  
 573      /**
 574       * Render an appropriate message if themdesignermode is enabled.
 575       * @param bool $themedesignermode true if enabled
 576       * @return string HTML to output.
 577       */
 578      protected function themedesignermode_warning($themedesignermode) {
 579          if (!$themedesignermode) {
 580              return '';
 581          }
 582  
 583          return $this->warning(get_string('themedesignermodewarning', 'admin'));
 584      }
 585  
 586      /**
 587       * Render an appropriate message if iconv is buggy and mbstring missing.
 588       * @param bool $buggyiconvnomb
 589       * @return string HTML to output.
 590       */
 591      protected function buggy_iconv_warning($buggyiconvnomb) {
 592          if (!$buggyiconvnomb) {
 593              return '';
 594          }
 595  
 596          return $this->warning(get_string('warningiconvbuggy', 'admin'));
 597      }
 598  
 599      /**
 600       * Render an appropriate message if cron has not been run recently.
 601       * @param bool $cronoverdue
 602       * @return string HTML to output.
 603       */
 604      public function cron_overdue_warning($cronoverdue) {
 605          global $CFG;
 606          if (!$cronoverdue) {
 607              return '';
 608          }
 609  
 610          $check = new \tool_task\check\cronrunning();
 611          $result = $check->get_result();
 612          return $this->warning($result->get_summary() . '&nbsp;' . $this->help_icon('cron', 'admin'));
 613      }
 614  
 615      /**
 616       * Render an appropriate message if cron is not being run frequently (recommended every minute).
 617       *
 618       * @param bool $croninfrequent
 619       * @return string HTML to output.
 620       */
 621      public function cron_infrequent_warning(bool $croninfrequent) : string {
 622          global $CFG;
 623  
 624          if (!$croninfrequent) {
 625              return '';
 626          }
 627  
 628          $check = new \tool_task\check\cronrunning();
 629          $result = $check->get_result();
 630          return $this->warning($result->get_summary() . '&nbsp;' . $this->help_icon('cron', 'admin'));
 631      }
 632  
 633      /**
 634       * Render an appropriate message if there are any problems with the DB set-up.
 635       * @param bool $dbproblems
 636       * @return string HTML to output.
 637       */
 638      public function db_problems($dbproblems) {
 639          if (!$dbproblems) {
 640              return '';
 641          }
 642  
 643          return $this->warning($dbproblems);
 644      }
 645  
 646      /**
 647       * Renders cache warnings if there are any.
 648       *
 649       * @param string[] $cachewarnings
 650       * @return string
 651       */
 652      public function cache_warnings(array $cachewarnings) {
 653          if (!count($cachewarnings)) {
 654              return '';
 655          }
 656          return join("\n", array_map(array($this, 'warning'), $cachewarnings));
 657      }
 658  
 659      /**
 660       * Renders events 1 API handlers warning.
 661       *
 662       * @param array $eventshandlers
 663       * @return string
 664       */
 665      public function events_handlers($eventshandlers) {
 666          if ($eventshandlers) {
 667              $components = '';
 668              foreach ($eventshandlers as $eventhandler) {
 669                  $components .= $eventhandler->component . ', ';
 670              }
 671              $components = rtrim($components, ', ');
 672              return $this->warning(get_string('eventshandlersinuse', 'admin', $components));
 673          }
 674      }
 675  
 676      /**
 677       * Render an appropriate message if the site in in maintenance mode.
 678       * @param bool $maintenancemode
 679       * @return string HTML to output.
 680       */
 681      public function maintenance_mode_warning($maintenancemode) {
 682          if (!$maintenancemode) {
 683              return '';
 684          }
 685  
 686          $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
 687          $url = $url->out(); // get_string() does not support objects in params
 688  
 689          return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
 690      }
 691  
 692      /**
 693       * Render a warning that ssl is forced because the site was on loginhttps.
 694       *
 695       * @param bool $overridetossl Whether or not ssl is being forced.
 696       * @return string
 697       */
 698      protected function overridetossl_warning($overridetossl) {
 699          if (!$overridetossl) {
 700              return '';
 701          }
 702          $warning = get_string('overridetossl', 'core_admin');
 703          return $this->warning($warning, 'warning');
 704      }
 705  
 706      /**
 707       * Display a warning about installing development code if necesary.
 708       * @param int $maturity
 709       * @return string HTML to output.
 710       */
 711      protected function maturity_warning($maturity) {
 712          if ($maturity == MATURITY_STABLE) {
 713              return ''; // No worries.
 714          }
 715  
 716          $maturitylevel = get_string('maturity' . $maturity, 'admin');
 717          return $this->warning(
 718                      $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
 719                      $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
 720                  'danger');
 721      }
 722  
 723      /*
 724       * If necessary, displays a warning about upgrading a test site.
 725       *
 726       * @param string $testsite
 727       * @return string HTML
 728       */
 729      protected function test_site_warning($testsite) {
 730  
 731          if (!$testsite) {
 732              return '';
 733          }
 734  
 735          $warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
 736          return $this->warning($warning, 'danger');
 737      }
 738  
 739      /**
 740       * Output the copyright notice.
 741       * @return string HTML to output.
 742       */
 743      protected function moodle_copyright() {
 744          global $CFG;
 745  
 746          //////////////////////////////////////////////////////////////////////////////////////////////////
 747          ////  IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
 748          $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
 749                           '<a href="https://moodledev.io/general/releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
 750                           'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
 751                           'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
 752                           '<a href="https://moodledev.io/general/license">GNU Public License</a>';
 753          //////////////////////////////////////////////////////////////////////////////////////////////////
 754  
 755          return $this->box($copyrighttext, 'copyright');
 756      }
 757  
 758      /**
 759       * Display a warning about installing development code if necesary.
 760       * @param int $maturity
 761       * @return string HTML to output.
 762       */
 763      protected function maturity_info($maturity) {
 764          if ($maturity == MATURITY_STABLE) {
 765              return ''; // No worries.
 766          }
 767  
 768          $level = 'warning';
 769  
 770          if ($maturity == MATURITY_ALPHA) {
 771              $level = 'danger';
 772          }
 773  
 774          $maturitylevel = get_string('maturity' . $maturity, 'admin');
 775          $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
 776          $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
 777          return $this->warning($warningtext, $level);
 778      }
 779  
 780      /**
 781       * Displays the info about available Moodle core and plugin updates
 782       *
 783       * The structure of the $updates param has changed since 2.4. It contains not only updates
 784       * for the core itself, but also for all other installed plugins.
 785       *
 786       * @param array|null $updates array of (string)component => array of \core\update\info objects or null
 787       * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
 788       * @return string
 789       */
 790      protected function available_updates($updates, $fetch) {
 791  
 792          $updateinfo = '';
 793          $someupdateavailable = false;
 794          if (is_array($updates)) {
 795              if (is_array($updates['core'])) {
 796                  $someupdateavailable = true;
 797                  $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
 798                  foreach ($updates['core'] as $update) {
 799                      $updateinfo .= $this->moodle_available_update_info($update);
 800                  }
 801                  $updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
 802                      array('class' => 'updateavailablerecommendation'));
 803              }
 804              unset($updates['core']);
 805              // If something has left in the $updates array now, it is updates for plugins.
 806              if (!empty($updates)) {
 807                  $someupdateavailable = true;
 808                  $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
 809                  $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
 810                  $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
 811                      array('url' => $pluginsoverviewurl->out())));
 812              }
 813          }
 814  
 815          if (!$someupdateavailable) {
 816              $now = time();
 817              if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
 818                  $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
 819              }
 820          }
 821  
 822          $updateinfo .= $this->container_start('checkforupdates mt-1');
 823          $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
 824          $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
 825          if ($fetch) {
 826              $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
 827                  userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
 828          }
 829          $updateinfo .= $this->container_end();
 830  
 831          return $this->warning($updateinfo);
 832      }
 833  
 834      /**
 835       * Display a warning about not being registered on Moodle.org if necesary.
 836       *
 837       * @param boolean $registered true if the site is registered on Moodle.org
 838       * @return string HTML to output.
 839       */
 840      protected function registration_warning($registered) {
 841  
 842          if (!$registered && site_is_public()) {
 843              if (has_capability('moodle/site:config', context_system::instance())) {
 844                  $registerbutton = $this->single_button(new moodle_url('/admin/registration/index.php'),
 845                      get_string('register', 'admin'));
 846                  $str = 'registrationwarning';
 847              } else {
 848                  $registerbutton = '';
 849                  $str = 'registrationwarningcontactadmin';
 850              }
 851  
 852              return $this->warning( get_string($str, 'admin')
 853                      . '&nbsp;' . $this->help_icon('registration', 'admin') . $registerbutton ,
 854                  'error alert alert-danger');
 855          }
 856  
 857          return '';
 858      }
 859  
 860      /**
 861       * Return an admin page warning if site is not registered with moodle.org
 862       *
 863       * @return string
 864       */
 865      public function warn_if_not_registered() {
 866          return $this->registration_warning(\core\hub\registration::is_registered());
 867      }
 868  
 869      /**
 870       * Display a warning about the Mobile Web Services being disabled.
 871       *
 872       * @param boolean $mobileconfigured true if mobile web services are enabled
 873       * @return string HTML to output.
 874       */
 875      protected function mobile_configuration_warning($mobileconfigured) {
 876          $output = '';
 877          if (!$mobileconfigured) {
 878              $settingslink = new moodle_url('/admin/settings.php', ['section' => 'mobilesettings']);
 879              $configurebutton = $this->single_button($settingslink, get_string('enablemobilewebservice', 'admin'));
 880              $output .= $this->warning(get_string('mobilenotconfiguredwarning', 'admin') . '&nbsp;' . $configurebutton);
 881          }
 882  
 883          return $output;
 884      }
 885  
 886      /**
 887       * Display campaign content.
 888       *
 889       * @param bool $showcampaigncontent Whether the campaign content should be visible or not.
 890       * @return string the campaign content raw html.
 891       */
 892      protected function campaign_content(bool $showcampaigncontent): string {
 893          if (!$showcampaigncontent) {
 894              return '';
 895          }
 896  
 897          $lang = current_language();
 898          $url = "https://campaign.moodle.org/current/lms/{$lang}/install/";
 899          $params = [
 900              'url' => $url,
 901              'iframeid' => 'campaign-content',
 902              'title' => get_string('campaign', 'admin'),
 903          ];
 904  
 905          return $this->render_from_template('core/external_content_banner', $params);
 906      }
 907  
 908      /**
 909       * Display services and support content.
 910       *
 911       * @param bool $showservicesandsupport Whether the services and support content should be visible or not.
 912       * @return string the campaign content raw html.
 913       */
 914      protected function services_and_support_content(bool $showservicesandsupport): string {
 915          if (!$showservicesandsupport) {
 916              return '';
 917          }
 918  
 919          $lang = current_language();
 920          $url = "https://campaign.moodle.org/current/lms/{$lang}/servicesandsupport/";
 921          $params = [
 922              'url' => $url,
 923              'iframeid' => 'services-support-content',
 924              'title' => get_string('supportandservices', 'admin'),
 925          ];
 926  
 927          return $this->render_from_template('core/external_content_banner', $params);
 928      }
 929  
 930      /**
 931       * Display a warning about the forgotten password URL not linking to a valid URL.
 932       *
 933       * @param boolean $invalidforgottenpasswordurl true if the forgotten password URL is not valid
 934       * @return string HTML to output.
 935       */
 936      protected function forgotten_password_url_warning($invalidforgottenpasswordurl) {
 937          $output = '';
 938          if ($invalidforgottenpasswordurl) {
 939              $settingslink = new moodle_url('/admin/settings.php', ['section' => 'manageauths']);
 940              $configurebutton = $this->single_button($settingslink, get_string('check', 'moodle'));
 941              $output .= $this->warning(get_string('invalidforgottenpasswordurl', 'admin') . '&nbsp;' . $configurebutton,
 942                  'error alert alert-danger');
 943          }
 944  
 945          return $output;
 946      }
 947  
 948      /**
 949       * Helper method to render the information about the available Moodle update
 950       *
 951       * @param \core\update\info $updateinfo information about the available Moodle core update
 952       */
 953      protected function moodle_available_update_info(\core\update\info $updateinfo) {
 954  
 955          $boxclasses = 'moodleupdateinfo mb-2';
 956          $info = array();
 957  
 958          if (isset($updateinfo->release)) {
 959              $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
 960                  array('class' => 'info release'));
 961          }
 962  
 963          if (isset($updateinfo->version)) {
 964              $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
 965                  array('class' => 'info version'));
 966          }
 967  
 968          if (isset($updateinfo->maturity)) {
 969              $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
 970                  array('class' => 'info maturity'));
 971              $boxclasses .= ' maturity'.$updateinfo->maturity;
 972          }
 973  
 974          if (isset($updateinfo->download)) {
 975              $info[] = html_writer::link($updateinfo->download, get_string('download'),
 976                  array('class' => 'info download btn btn-secondary'));
 977          }
 978  
 979          if (isset($updateinfo->url)) {
 980              $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
 981                  array('class' => 'info more'));
 982          }
 983  
 984          $box  = $this->output->container_start($boxclasses);
 985          $box .= $this->output->container(implode(html_writer::tag('span', ' | ', array('class' => 'separator')), $info), '');
 986          $box .= $this->output->container_end();
 987  
 988          return $box;
 989      }
 990  
 991      /**
 992       * Display a link to the release notes.
 993       * @return string HTML to output.
 994       */
 995      protected function release_notes_link() {
 996          $releasenoteslink = get_string('releasenoteslink', 'admin', 'https://moodledev.io/general/releases');
 997          $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
 998          return $this->box($releasenoteslink, 'generalbox alert alert-info');
 999      }
1000  
1001      /**
1002       * Display the reload link that appears on several upgrade/install pages.
1003       * @return string HTML to output.
1004       */
1005      function upgrade_reload($url) {
1006          return html_writer::empty_tag('br') .
1007                  html_writer::tag('div',
1008                      html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
1009                              get_string('reload'), array('title' => get_string('reload'))),
1010                  array('class' => 'continuebutton')) . html_writer::empty_tag('br');
1011      }
1012  
1013      /**
1014       * Displays all known plugins and information about their installation or upgrade
1015       *
1016       * This default implementation renders all plugins into one big table. The rendering
1017       * options support:
1018       *     (bool)full = false: whether to display up-to-date plugins, too
1019       *     (bool)xdep = false: display the plugins with unsatisified dependecies only
1020       *
1021       * @param core_plugin_manager $pluginman provides information about the plugins.
1022       * @param int $version the version of the Moodle code from version.php.
1023       * @param array $options rendering options
1024       * @return string HTML code
1025       */
1026      public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) {
1027          global $CFG;
1028          $plugininfo = $pluginman->get_plugins();
1029  
1030          if (empty($plugininfo)) {
1031              return '';
1032          }
1033  
1034          $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
1035          $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
1036  
1037          $table = new html_table();
1038          $table->id = 'plugins-check';
1039          $table->head = array(
1040              get_string('displayname', 'core_plugin').' / '.get_string('rootdir', 'core_plugin'),
1041              get_string('versiondb', 'core_plugin'),
1042              get_string('versiondisk', 'core_plugin'),
1043              get_string('requires', 'core_plugin'),
1044              get_string('source', 'core_plugin').' / '.get_string('status', 'core_plugin'),
1045          );
1046          $table->colclasses = array(
1047              'displayname', 'versiondb', 'versiondisk', 'requires', 'status',
1048          );
1049          $table->data = array();
1050  
1051          // Number of displayed plugins per type.
1052          $numdisplayed = array();
1053          // Number of plugins known to the plugin manager.
1054          $sumtotal = 0;
1055          // Number of plugins requiring attention.
1056          $sumattention = 0;
1057          // List of all components we can cancel installation of.
1058          $installabortable = $pluginman->list_cancellable_installations();
1059          // List of all components we can cancel upgrade of.
1060          $upgradeabortable = $pluginman->list_restorable_archives();
1061  
1062          foreach ($plugininfo as $type => $plugins) {
1063  
1064              $header = new html_table_cell($pluginman->plugintype_name_plural($type));
1065              $header->header = true;
1066              $header->colspan = count($table->head);
1067              $header = new html_table_row(array($header));
1068              $header->attributes['class'] = 'plugintypeheader type-' . $type;
1069  
1070              $numdisplayed[$type] = 0;
1071  
1072              if (empty($plugins) and $options['full']) {
1073                  $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1074                  $msg->colspan = count($table->head);
1075                  $row = new html_table_row(array($msg));
1076                  $row->attributes['class'] .= 'msg msg-noneinstalled';
1077                  $table->data[] = $header;
1078                  $table->data[] = $row;
1079                  continue;
1080              }
1081  
1082              $plugintyperows = array();
1083  
1084              foreach ($plugins as $name => $plugin) {
1085                  $component = "{$plugin->type}_{$plugin->name}";
1086  
1087                  $sumtotal++;
1088                  $row = new html_table_row();
1089                  $row->attributes['class'] = "type-{$plugin->type} name-{$component}";
1090  
1091                  $iconidentifier = 'icon';
1092                  if ($plugin->type === 'mod') {
1093                      $iconidentifier = 'monologo';
1094                  }
1095  
1096                  if ($this->page->theme->resolve_image_location($iconidentifier, $component, null)) {
1097                      $icon = $this->output->pix_icon($iconidentifier, '', $component, [
1098                          'class' => 'smallicon pluginicon',
1099                      ]);
1100                  } else {
1101                      $icon = '';
1102                  }
1103  
1104                  $displayname = new html_table_cell(
1105                      $icon.
1106                      html_writer::span($plugin->displayname, 'pluginname').
1107                      html_writer::div($plugin->get_dir(), 'plugindir text-muted small')
1108                  );
1109  
1110                  $versiondb = new html_table_cell($plugin->versiondb);
1111                  $versiondisk = new html_table_cell($plugin->versiondisk);
1112  
1113                  if ($isstandard = $plugin->is_standard()) {
1114                      $row->attributes['class'] .= ' standard';
1115                      $sourcelabel = html_writer::span(get_string('sourcestd', 'core_plugin'), 'sourcetext badge badge-secondary');
1116                  } else {
1117                      $row->attributes['class'] .= ' extension';
1118                      $sourcelabel = html_writer::span(get_string('sourceext', 'core_plugin'), 'sourcetext badge badge-info');
1119                  }
1120  
1121                  $coredependency = $plugin->is_core_dependency_satisfied($version);
1122                  $incompatibledependency = $plugin->is_core_compatible_satisfied($CFG->branch);
1123  
1124                  $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
1125                  $dependenciesok = $coredependency && $otherpluginsdependencies && $incompatibledependency;
1126  
1127                  $statuscode = $plugin->get_status();
1128                  $row->attributes['class'] .= ' status-' . $statuscode;
1129                  $statusclass = 'statustext badge ';
1130                  switch ($statuscode) {
1131                      case core_plugin_manager::PLUGIN_STATUS_NEW:
1132                          $statusclass .= $dependenciesok ? 'badge-success' : 'badge-warning';
1133                          break;
1134                      case core_plugin_manager::PLUGIN_STATUS_UPGRADE:
1135                          $statusclass .= $dependenciesok ? 'badge-info' : 'badge-warning';
1136                          break;
1137                      case core_plugin_manager::PLUGIN_STATUS_MISSING:
1138                      case core_plugin_manager::PLUGIN_STATUS_DOWNGRADE:
1139                      case core_plugin_manager::PLUGIN_STATUS_DELETE:
1140                          $statusclass .= 'badge-danger';
1141                          break;
1142                      case core_plugin_manager::PLUGIN_STATUS_NODB:
1143                      case core_plugin_manager::PLUGIN_STATUS_UPTODATE:
1144                          $statusclass .= $dependenciesok ? 'badge-light' : 'badge-warning';
1145                          break;
1146                  }
1147                  $status = html_writer::span(get_string('status_' . $statuscode, 'core_plugin'), $statusclass);
1148  
1149                  if (!empty($installabortable[$plugin->component])) {
1150                      $status .= $this->output->single_button(
1151                          new moodle_url($this->page->url, array('abortinstall' => $plugin->component, 'confirmplugincheck' => 0)),
1152                          get_string('cancelinstallone', 'core_plugin'),
1153                          'post',
1154                          array('class' => 'actionbutton cancelinstallone d-block mt-1')
1155                      );
1156                  }
1157  
1158                  if (!empty($upgradeabortable[$plugin->component])) {
1159                      $status .= $this->output->single_button(
1160                          new moodle_url($this->page->url, array('abortupgrade' => $plugin->component)),
1161                          get_string('cancelupgradeone', 'core_plugin'),
1162                          'post',
1163                          array('class' => 'actionbutton cancelupgradeone d-block mt-1')
1164                      );
1165                  }
1166  
1167                  $availableupdates = $plugin->available_updates();
1168                  if (!empty($availableupdates)) {
1169                      foreach ($availableupdates as $availableupdate) {
1170                          $status .= $this->plugin_available_update_info($pluginman, $availableupdate);
1171                      }
1172                  }
1173  
1174                  $status = new html_table_cell($sourcelabel.' '.$status);
1175                  if ($plugin->pluginsupported != null) {
1176                      $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version, $CFG->branch));
1177                  } else {
1178                      $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
1179                  }
1180  
1181                  $statusisboring = in_array($statuscode, array(
1182                          core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE));
1183  
1184                  if ($options['xdep']) {
1185                      // we want to see only plugins with failed dependencies
1186                      if ($dependenciesok) {
1187                          continue;
1188                      }
1189  
1190                  } else if ($statusisboring and $dependenciesok and empty($availableupdates)) {
1191                      // no change is going to happen to the plugin - display it only
1192                      // if the user wants to see the full list
1193                      if (empty($options['full'])) {
1194                          continue;
1195                      }
1196  
1197                  } else {
1198                      $sumattention++;
1199                  }
1200  
1201                  // The plugin should be displayed.
1202                  $numdisplayed[$type]++;
1203                  $row->cells = array($displayname, $versiondb, $versiondisk, $requires, $status);
1204                  $plugintyperows[] = $row;
1205              }
1206  
1207              if (empty($numdisplayed[$type]) and empty($options['full'])) {
1208                  continue;
1209              }
1210  
1211              $table->data[] = $header;
1212              $table->data = array_merge($table->data, $plugintyperows);
1213          }
1214  
1215          // Total number of displayed plugins.
1216          $sumdisplayed = array_sum($numdisplayed);
1217  
1218          if ($options['xdep']) {
1219              // At the plugins dependencies check page, display the table only.
1220              return html_writer::table($table);
1221          }
1222  
1223          $out = $this->output->container_start('', 'plugins-check-info');
1224  
1225          if ($sumdisplayed == 0) {
1226              $out .= $this->output->heading(get_string('pluginchecknone', 'core_plugin'));
1227  
1228          } else {
1229              if (empty($options['full'])) {
1230                  $out .= $this->output->heading(get_string('plugincheckattention', 'core_plugin'));
1231              } else {
1232                  $out .= $this->output->heading(get_string('plugincheckall', 'core_plugin'));
1233              }
1234          }
1235  
1236          $out .= $this->output->container_start('actions mb-2');
1237  
1238          $installableupdates = $pluginman->filter_installable($pluginman->available_updates());
1239          if ($installableupdates) {
1240              $out .= $this->output->single_button(
1241                  new moodle_url($this->page->url, array('installupdatex' => 1)),
1242                  get_string('updateavailableinstallall', 'core_admin', count($installableupdates)),
1243                  'post',
1244                  array('class' => 'singlebutton updateavailableinstallall mr-1')
1245              );
1246          }
1247  
1248          if ($installabortable) {
1249              $out .= $this->output->single_button(
1250                  new moodle_url($this->page->url, array('abortinstallx' => 1, 'confirmplugincheck' => 0)),
1251                  get_string('cancelinstallall', 'core_plugin', count($installabortable)),
1252                  'post',
1253                  array('class' => 'singlebutton cancelinstallall mr-1')
1254              );
1255          }
1256  
1257          if ($upgradeabortable) {
1258              $out .= $this->output->single_button(
1259                  new moodle_url($this->page->url, array('abortupgradex' => 1)),
1260                  get_string('cancelupgradeall', 'core_plugin', count($upgradeabortable)),
1261                  'post',
1262                  array('class' => 'singlebutton cancelupgradeall mr-1')
1263              );
1264          }
1265  
1266          $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 0)),
1267              get_string('plugincheckattention', 'core_plugin')).' '.html_writer::span($sumattention, 'badge badge-light'),
1268              'btn btn-link mr-1');
1269  
1270          $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 1)),
1271              get_string('plugincheckall', 'core_plugin')).' '.html_writer::span($sumtotal, 'badge badge-light'),
1272              'btn btn-link mr-1');
1273  
1274          $out .= $this->output->container_end(); // End of .actions container.
1275          $out .= $this->output->container_end(); // End of #plugins-check-info container.
1276  
1277          if ($sumdisplayed > 0 or $options['full']) {
1278              $out .= html_writer::table($table);
1279          }
1280  
1281          return $out;
1282      }
1283  
1284      /**
1285       * Display the continue / cancel widgets for the plugins management pages.
1286       *
1287       * @param null|moodle_url $continue URL for the continue button, should it be displayed
1288       * @param null|moodle_url $cancel URL for the cancel link, defaults to the current page
1289       * @return string HTML
1290       */
1291      public function plugins_management_confirm_buttons(moodle_url $continue=null, moodle_url $cancel=null) {
1292  
1293          $out = html_writer::start_div('plugins-management-confirm-buttons');
1294  
1295          if (!empty($continue)) {
1296              $out .= $this->output->single_button($continue, get_string('continue'), 'post', array('class' => 'continue'));
1297          }
1298  
1299          if (empty($cancel)) {
1300              $cancel = $this->page->url;
1301          }
1302          $out .= html_writer::div(html_writer::link($cancel, get_string('cancel')), 'cancel');
1303  
1304          return $out;
1305      }
1306  
1307      /**
1308       * Displays the information about missing dependencies
1309       *
1310       * @param core_plugin_manager $pluginman
1311       * @return string
1312       */
1313      protected function missing_dependencies(core_plugin_manager $pluginman) {
1314  
1315          $dependencies = $pluginman->missing_dependencies();
1316  
1317          if (empty($dependencies)) {
1318              return '';
1319          }
1320  
1321          $available = array();
1322          $unavailable = array();
1323          $unknown = array();
1324  
1325          foreach ($dependencies as $component => $remoteinfo) {
1326              if ($remoteinfo === false) {
1327                  // The required version is not available. Let us check if there
1328                  // is at least some version in the plugins directory.
1329                  $remoteinfoanyversion = $pluginman->get_remote_plugin_info($component, ANY_VERSION, false);
1330                  if ($remoteinfoanyversion === false) {
1331                      $unknown[$component] = $component;
1332                  } else {
1333                      $unavailable[$component] = $remoteinfoanyversion;
1334                  }
1335              } else {
1336                  $available[$component] = $remoteinfo;
1337              }
1338          }
1339  
1340          $out  = $this->output->container_start('plugins-check-dependencies mb-4');
1341  
1342          if ($unavailable or $unknown) {
1343              $out .= $this->output->heading(get_string('misdepsunavail', 'core_plugin'));
1344              if ($unknown) {
1345                  $out .= $this->output->render((new \core\output\notification(get_string('misdepsunknownlist', 'core_plugin',
1346                      implode(', ', $unknown))))->set_show_closebutton(false));
1347              }
1348              if ($unavailable) {
1349                  $unavailablelist = array();
1350                  foreach ($unavailable as $component => $remoteinfoanyversion) {
1351                      $unavailablelistitem = html_writer::link('https://moodle.org/plugins/view.php?plugin='.$component,
1352                          '<strong>'.$remoteinfoanyversion->name.'</strong>');
1353                      if ($remoteinfoanyversion->version) {
1354                          $unavailablelistitem .= ' ('.$component.' &gt; '.$remoteinfoanyversion->version->version.')';
1355                      } else {
1356                          $unavailablelistitem .= ' ('.$component.')';
1357                      }
1358                      $unavailablelist[] = $unavailablelistitem;
1359                  }
1360                  $out .= $this->output->render((new \core\output\notification(get_string('misdepsunavaillist', 'core_plugin',
1361                      implode(', ', $unavailablelist))))->set_show_closebutton(false));
1362              }
1363              $out .= $this->output->container_start('plugins-check-dependencies-actions mb-4');
1364              $out .= ' '.html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1365                  get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-secondary'));
1366              $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
1367          }
1368  
1369          if ($available) {
1370              $out .= $this->output->heading(get_string('misdepsavail', 'core_plugin'));
1371              $out .= $this->output->container_start('plugins-check-dependencies-actions mb-2');
1372  
1373              $installable = $pluginman->filter_installable($available);
1374              if ($installable) {
1375                  $out .= $this->output->single_button(
1376                      new moodle_url($this->page->url, array('installdepx' => 1)),
1377                      get_string('dependencyinstallmissing', 'core_plugin', count($installable)),
1378                      'post',
1379                      array('class' => 'singlebutton dependencyinstallmissing d-inline-block mr-1')
1380                  );
1381              }
1382  
1383              $out .= html_writer::div(html_writer::link(new moodle_url('/admin/tool/installaddon/'),
1384                  get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-link')),
1385                  'dependencyuploadmissing d-inline-block mr-1');
1386  
1387              $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container.
1388  
1389              $out .= $this->available_missing_dependencies_list($pluginman, $available);
1390          }
1391  
1392          $out .= $this->output->container_end(); // End of .plugins-check-dependencies container.
1393  
1394          return $out;
1395      }
1396  
1397      /**
1398       * Displays the list if available missing dependencies.
1399       *
1400       * @param core_plugin_manager $pluginman
1401       * @param array $dependencies
1402       * @return string
1403       */
1404      protected function available_missing_dependencies_list(core_plugin_manager $pluginman, array $dependencies) {
1405          global $CFG;
1406  
1407          $table = new html_table();
1408          $table->id = 'plugins-check-available-dependencies';
1409          $table->head = array(
1410              get_string('displayname', 'core_plugin'),
1411              get_string('release', 'core_plugin'),
1412              get_string('version', 'core_plugin'),
1413              get_string('supportedmoodleversions', 'core_plugin'),
1414              get_string('info', 'core'),
1415          );
1416          $table->colclasses = array('displayname', 'release', 'version', 'supportedmoodleversions', 'info');
1417          $table->data = array();
1418  
1419          foreach ($dependencies as $plugin) {
1420  
1421              $supportedmoodles = array();
1422              foreach ($plugin->version->supportedmoodles as $moodle) {
1423                  if ($CFG->branch == str_replace('.', '', $moodle->release)) {
1424                      $supportedmoodles[] = html_writer::span($moodle->release, 'badge badge-success');
1425                  } else {
1426                      $supportedmoodles[] = html_writer::span($moodle->release, 'badge badge-light');
1427                  }
1428              }
1429  
1430              $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1431              if ($requriedby) {
1432                  foreach ($requriedby as $ix => $val) {
1433                      $inf = $pluginman->get_plugin_info($val);
1434                      if ($inf) {
1435                          $requriedby[$ix] = $inf->displayname.' ('.$inf->component.')';
1436                      }
1437                  }
1438                  $info = html_writer::div(
1439                      get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1440                      'requiredby mb-1'
1441                  );
1442              } else {
1443                  $info = '';
1444              }
1445  
1446              $info .= $this->output->container_start('actions');
1447  
1448              $info .= html_writer::div(
1449                  html_writer::link('https://moodle.org/plugins/view.php?plugin='.$plugin->component,
1450                      get_string('misdepinfoplugin', 'core_plugin')),
1451                  'misdepinfoplugin d-inline-block mr-3 mb-1'
1452              );
1453  
1454              $info .= html_writer::div(
1455                  html_writer::link('https://moodle.org/plugins/pluginversion.php?id='.$plugin->version->id,
1456                      get_string('misdepinfoversion', 'core_plugin')),
1457                  'misdepinfoversion d-inline-block mr-3 mb-1'
1458              );
1459  
1460              $info .= html_writer::div(html_writer::link($plugin->version->downloadurl, get_string('download')),
1461                  'misdepdownload d-inline-block mr-3 mb-1');
1462  
1463              if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version, $reason)) {
1464                  $info .= $this->output->single_button(
1465                      new moodle_url($this->page->url, array('installdep' => $plugin->component)),
1466                      get_string('dependencyinstall', 'core_plugin'),
1467                      'post',
1468                      array('class' => 'singlebutton dependencyinstall mr-3 mb-1')
1469                  );
1470              } else {
1471                  $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1472                  if ($reasonhelp) {
1473                      $info .= html_writer::div($reasonhelp, 'reasonhelp dependencyinstall d-inline-block mr-3 mb-1');
1474                  }
1475              }
1476  
1477              $info .= $this->output->container_end(); // End of .actions container.
1478  
1479              $table->data[] = array(
1480                  html_writer::div($plugin->name, 'name').' '.html_writer::div($plugin->component, 'component text-muted small'),
1481                  $plugin->version->release,
1482                  $plugin->version->version,
1483                  implode(' ', $supportedmoodles),
1484                  $info
1485              );
1486          }
1487  
1488          return html_writer::table($table);
1489      }
1490  
1491      /**
1492       * Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false.
1493       *
1494       * @param string $reason the reason code as returned by the plugin manager
1495       * @return string
1496       */
1497      protected function info_remote_plugin_not_installable($reason) {
1498  
1499          if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') {
1500              return $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
1501          }
1502  
1503          if ($reason === 'remoteunavailable') {
1504              return $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
1505          }
1506  
1507          return false;
1508      }
1509  
1510      /**
1511       * Formats the information that needs to go in the 'Requires' column.
1512       * @param \core\plugininfo\base $plugin the plugin we are rendering the row for.
1513       * @param core_plugin_manager $pluginman provides data on all the plugins.
1514       * @param string $version
1515       * @param int $branch the current Moodle branch
1516       * @return string HTML code
1517       */
1518      protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version, $branch = null) {
1519  
1520          $requires = array();
1521          $displayuploadlink = false;
1522          $displayupdateslink = false;
1523  
1524          $requirements = $pluginman->resolve_requirements($plugin, $version, $branch);
1525          foreach ($requirements as $reqname => $reqinfo) {
1526              if ($reqname === 'core') {
1527                  if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1528                      $class = 'requires-ok text-muted';
1529                      $label = '';
1530                  } else {
1531                      $class = 'requires-failed';
1532                      $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger');
1533                  }
1534  
1535                  if ($branch != null && !$plugin->is_core_compatible_satisfied($branch)) {
1536                      $requires[] = html_writer::tag('li',
1537                      html_writer::span(get_string('incompatibleversion', 'core_plugin', $branch), 'dep dep-core').
1538                      ' '.$label, array('class' => $class));
1539  
1540                  } else if ($branch != null && $plugin->pluginsupported != null) {
1541                      $requires[] = html_writer::tag('li',
1542                          html_writer::span(get_string('moodlebranch', 'core_plugin',
1543                          array('min' => $plugin->pluginsupported[0], 'max' => $plugin->pluginsupported[1])), 'dep dep-core').
1544                          ' '.$label, array('class' => $class));
1545  
1546                  } else if ($reqinfo->reqver != ANY_VERSION) {
1547                      $requires[] = html_writer::tag('li',
1548                          html_writer::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires), 'dep dep-core').
1549                          ' '.$label, array('class' => $class));
1550                  }
1551  
1552              } else {
1553                  $actions = array();
1554  
1555                  if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) {
1556                      $label = '';
1557                      $class = 'requires-ok text-muted';
1558  
1559                  } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_MISSING) {
1560                      if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1561                          $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-warning');
1562                          $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning');
1563                          $class = 'requires-failed requires-missing requires-available';
1564                          $actions[] = html_writer::link(
1565                              new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)),
1566                              get_string('misdepinfoplugin', 'core_plugin')
1567                          );
1568  
1569                      } else {
1570                          $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-danger');
1571                          $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1572                              'badge badge-danger');
1573                          $class = 'requires-failed requires-missing requires-unavailable';
1574                      }
1575                      $displayuploadlink = true;
1576  
1577                  } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OUTDATED) {
1578                      if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
1579                          $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-warning');
1580                          $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning');
1581                          $class = 'requires-failed requires-outdated requires-available';
1582                          $displayupdateslink = true;
1583  
1584                      } else {
1585                          $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger');
1586                          $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
1587                              'badge badge-danger');
1588                          $class = 'requires-failed requires-outdated requires-unavailable';
1589                      }
1590                      $displayuploadlink = true;
1591                  }
1592  
1593                  if ($reqinfo->reqver != ANY_VERSION) {
1594                      $str = 'otherpluginversion';
1595                  } else {
1596                      $str = 'otherplugin';
1597                  }
1598  
1599                  $requires[] = html_writer::tag('li', html_writer::span(
1600                      get_string($str, 'core_plugin', array('component' => $reqname, 'version' => $reqinfo->reqver)),
1601                      'dep dep-plugin').' '.$label.' '.html_writer::span(implode(' | ', $actions), 'actions'),
1602                      array('class' => $class)
1603                  );
1604              }
1605          }
1606  
1607          if (!$requires) {
1608              return '';
1609          }
1610  
1611          $out = html_writer::tag('ul', implode("\n", $requires), array('class' => 'm-0'));
1612  
1613          if ($displayuploadlink) {
1614              $out .= html_writer::div(
1615                  html_writer::link(
1616                      new moodle_url('/admin/tool/installaddon/'),
1617                      get_string('dependencyuploadmissing', 'core_plugin'),
1618                      array('class' => 'btn btn-secondary btn-sm m-1')
1619                  ),
1620                  'dependencyuploadmissing'
1621              );
1622          }
1623  
1624          if ($displayupdateslink) {
1625              $out .= html_writer::div(
1626                  html_writer::link(
1627                      new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1)),
1628                      get_string('checkforupdates', 'core_plugin'),
1629                      array('class' => 'btn btn-secondary btn-sm m-1')
1630                  ),
1631                  'checkforupdates'
1632              );
1633          }
1634  
1635          // Check if supports is present, and $branch is not in, only if $incompatible check was ok.
1636          if ($plugin->pluginsupported != null && $class == 'requires-ok' && $branch != null) {
1637              if ($pluginman->check_explicitly_supported($plugin, $branch) == $pluginman::VERSION_NOT_SUPPORTED) {
1638                  $out .= html_writer::div(get_string('notsupported', 'core_plugin', $branch));
1639              }
1640          }
1641  
1642          return $out;
1643  
1644      }
1645  
1646      /**
1647       * Prints an overview about the plugins - number of installed, number of extensions etc.
1648       *
1649       * @param core_plugin_manager $pluginman provides information about the plugins
1650       * @param array $options filtering options
1651       * @return string as usually
1652       */
1653      public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) {
1654  
1655          $plugininfo = $pluginman->get_plugins();
1656  
1657          $numtotal = $numextension = $numupdatable = $numinstallable = 0;
1658  
1659          foreach ($plugininfo as $type => $plugins) {
1660              foreach ($plugins as $name => $plugin) {
1661                  if ($res = $plugin->available_updates()) {
1662                      $numupdatable++;
1663                      foreach ($res as $updateinfo) {
1664                          if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason, false)) {
1665                              $numinstallable++;
1666                              break;
1667                          }
1668                      }
1669                  }
1670                  if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1671                      continue;
1672                  }
1673                  $numtotal++;
1674                  if (!$plugin->is_standard()) {
1675                      $numextension++;
1676                  }
1677              }
1678          }
1679  
1680          $infoall = html_writer::link(
1681              new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 0)),
1682              get_string('overviewall', 'core_plugin'),
1683              array('title' => get_string('filterall', 'core_plugin'))
1684          ).' '.html_writer::span($numtotal, 'badge number number-all');
1685  
1686          $infoext = html_writer::link(
1687              new moodle_url($this->page->url, array('contribonly' => 1, 'updatesonly' => 0)),
1688              get_string('overviewext', 'core_plugin'),
1689              array('title' => get_string('filtercontribonly', 'core_plugin'))
1690          ).' '.html_writer::span($numextension, 'badge number number-additional');
1691  
1692          if ($numupdatable) {
1693              $infoupdatable = html_writer::link(
1694                  new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 1)),
1695                  get_string('overviewupdatable', 'core_plugin'),
1696                  array('title' => get_string('filterupdatesonly', 'core_plugin'))
1697              ).' '.html_writer::span($numupdatable, 'badge badge-info number number-updatable');
1698          } else {
1699              // No updates, or the notifications disabled.
1700              $infoupdatable = '';
1701          }
1702  
1703          $out = html_writer::start_div('', array('id' => 'plugins-overview-panel'));
1704  
1705          if (!empty($options['updatesonly'])) {
1706              $out .= $this->output->heading(get_string('overviewupdatable', 'core_plugin'), 3);
1707          } else if (!empty($options['contribonly'])) {
1708              $out .= $this->output->heading(get_string('overviewext', 'core_plugin'), 3);
1709          }
1710  
1711          if ($numinstallable) {
1712              $out .= $this->output->single_button(
1713                  new moodle_url($this->page->url, array('installupdatex' => 1)),
1714                  get_string('updateavailableinstallall', 'core_admin', $numinstallable),
1715                  'post',
1716                  array('class' => 'singlebutton updateavailableinstallall')
1717              );
1718          }
1719  
1720          $out .= html_writer::div($infoall, 'info info-all').
1721              html_writer::div($infoext, 'info info-ext').
1722              html_writer::div($infoupdatable, 'info info-updatable');
1723  
1724          $out .= html_writer::end_div(); // End of #plugins-overview-panel block.
1725  
1726          return $out;
1727      }
1728  
1729      /**
1730       * Displays all known plugins and links to manage them
1731       *
1732       * This default implementation renders all plugins into one big table.
1733       *
1734       * @param core_plugin_manager $pluginman provides information about the plugins.
1735       * @param array $options filtering options
1736       * @return string HTML code
1737       */
1738      public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) {
1739  
1740          $plugininfo = $pluginman->get_plugins();
1741  
1742          // Filter the list of plugins according the options.
1743          if (!empty($options['updatesonly'])) {
1744              $updateable = array();
1745              foreach ($plugininfo as $plugintype => $pluginnames) {
1746                  foreach ($pluginnames as $pluginname => $pluginfo) {
1747                      $pluginavailableupdates = $pluginfo->available_updates();
1748                      if (!empty($pluginavailableupdates)) {
1749                          foreach ($pluginavailableupdates as $pluginavailableupdate) {
1750                              $updateable[$plugintype][$pluginname] = $pluginfo;
1751                          }
1752                      }
1753                  }
1754              }
1755              $plugininfo = $updateable;
1756          }
1757  
1758          if (!empty($options['contribonly'])) {
1759              $contribs = array();
1760              foreach ($plugininfo as $plugintype => $pluginnames) {
1761                  foreach ($pluginnames as $pluginname => $pluginfo) {
1762                      if (!$pluginfo->is_standard()) {
1763                          $contribs[$plugintype][$pluginname] = $pluginfo;
1764                      }
1765                  }
1766              }
1767              $plugininfo = $contribs;
1768          }
1769  
1770          if (empty($plugininfo)) {
1771              return '';
1772          }
1773  
1774          $table = new html_table();
1775          $table->id = 'plugins-control-panel';
1776          $table->head = array(
1777              get_string('displayname', 'core_plugin'),
1778              get_string('version', 'core_plugin'),
1779              get_string('availability', 'core_plugin'),
1780              get_string('actions', 'core_plugin'),
1781              get_string('notes','core_plugin'),
1782          );
1783          $table->headspan = array(1, 1, 1, 2, 1);
1784          $table->colclasses = array(
1785              'pluginname', 'version', 'availability', 'settings', 'uninstall', 'notes'
1786          );
1787  
1788          foreach ($plugininfo as $type => $plugins) {
1789              $heading = $pluginman->plugintype_name_plural($type);
1790              $pluginclass = core_plugin_manager::resolve_plugininfo_class($type);
1791              if ($manageurl = $pluginclass::get_manage_url()) {
1792                  $heading .= $this->output->action_icon($manageurl, new pix_icon('i/settings',
1793                      get_string('settings', 'core_plugin')));
1794              }
1795              $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type)));
1796              $header->header = true;
1797              $header->colspan = array_sum($table->headspan);
1798              $header = new html_table_row(array($header));
1799              $header->attributes['class'] = 'plugintypeheader type-' . $type;
1800              $table->data[] = $header;
1801  
1802              if (empty($plugins)) {
1803                  $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
1804                  $msg->colspan = array_sum($table->headspan);
1805                  $row = new html_table_row(array($msg));
1806                  $row->attributes['class'] .= 'msg msg-noneinstalled';
1807                  $table->data[] = $row;
1808                  continue;
1809              }
1810  
1811              foreach ($plugins as $name => $plugin) {
1812                  $component = "{$plugin->type}_{$plugin->name}";
1813  
1814                  $row = new html_table_row();
1815                  $row->attributes['class'] = "type-{$plugin->type} name-{$component}";
1816  
1817                  $iconidentifier = 'icon';
1818                  if ($plugin->type === 'mod') {
1819                      $iconidentifier = 'monologo';
1820                  }
1821  
1822                  if ($this->page->theme->resolve_image_location($iconidentifier, $component, null)) {
1823                      $icon = $this->output->pix_icon($iconidentifier, '', $component, [
1824                          'class' => 'icon pluginicon',
1825                      ]);
1826                  } else {
1827                      $icon = $this->output->spacer();
1828                  }
1829                  $status = $plugin->get_status();
1830                  $row->attributes['class'] .= ' status-'.$status;
1831                  $pluginname  = html_writer::tag('div', $icon.$plugin->displayname, array('class' => 'displayname')).
1832                                 html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
1833                  $pluginname  = new html_table_cell($pluginname);
1834  
1835                  $version = html_writer::div($plugin->versiondb, 'versionnumber');
1836                  if ((string)$plugin->release !== '') {
1837                      $version = html_writer::div($plugin->release, 'release').$version;
1838                  }
1839                  $version = new html_table_cell($version);
1840  
1841                  $isenabled = $plugin->is_enabled();
1842                  if (is_null($isenabled)) {
1843                      $availability = new html_table_cell('');
1844                  } else if ($isenabled) {
1845                      $row->attributes['class'] .= ' enabled';
1846                      $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
1847                  } else {
1848                      $row->attributes['class'] .= ' disabled';
1849                      $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
1850                  }
1851  
1852                  $settingsurl = $plugin->get_settings_url();
1853                  if (!is_null($settingsurl)) {
1854                      $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
1855                  } else {
1856                      $settings = '';
1857                  }
1858                  $settings = new html_table_cell($settings);
1859  
1860                  if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) {
1861                      $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
1862                  } else {
1863                      $uninstall = '';
1864                  }
1865                  $uninstall = new html_table_cell($uninstall);
1866  
1867                  if ($plugin->is_standard()) {
1868                      $row->attributes['class'] .= ' standard';
1869                      $source = '';
1870                  } else {
1871                      $row->attributes['class'] .= ' extension';
1872                      $source = html_writer::div(get_string('sourceext', 'core_plugin'), 'source badge badge-info');
1873                  }
1874  
1875                  if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
1876                      $msg = html_writer::div(get_string('status_missing', 'core_plugin'), 'statusmsg badge badge-danger');
1877                  } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
1878                      $msg = html_writer::div(get_string('status_new', 'core_plugin'), 'statusmsg badge badge-success');
1879                  } else {
1880                      $msg = '';
1881                  }
1882  
1883                  $requriedby = $pluginman->other_plugins_that_require($plugin->component);
1884                  if ($requriedby) {
1885                      $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
1886                          array('class' => 'requiredby'));
1887                  } else {
1888                      $requiredby = '';
1889                  }
1890  
1891                  $updateinfo = '';
1892                  if (is_array($plugin->available_updates())) {
1893                      foreach ($plugin->available_updates() as $availableupdate) {
1894                          $updateinfo .= $this->plugin_available_update_info($pluginman, $availableupdate);
1895                      }
1896                  }
1897  
1898                  $notes = new html_table_cell($source.$msg.$requiredby.$updateinfo);
1899  
1900                  $row->cells = array(
1901                      $pluginname, $version, $availability, $settings, $uninstall, $notes
1902                  );
1903                  $table->data[] = $row;
1904              }
1905          }
1906  
1907          return html_writer::table($table);
1908      }
1909  
1910      /**
1911       * Helper method to render the information about the available plugin update
1912       *
1913       * @param core_plugin_manager $pluginman plugin manager instance
1914       * @param \core\update\info $updateinfo information about the available update for the plugin
1915       */
1916      protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) {
1917  
1918          $boxclasses = 'pluginupdateinfo';
1919          $info = array();
1920  
1921          if (isset($updateinfo->release)) {
1922              $info[] = html_writer::div(
1923                  get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
1924                  'info release'
1925              );
1926          }
1927  
1928          if (isset($updateinfo->maturity)) {
1929              $info[] = html_writer::div(
1930                  get_string('maturity'.$updateinfo->maturity, 'core_admin'),
1931                  'info maturity'
1932              );
1933              $boxclasses .= ' maturity'.$updateinfo->maturity;
1934          }
1935  
1936          if (isset($updateinfo->download)) {
1937              $info[] = html_writer::div(
1938                  html_writer::link($updateinfo->download, get_string('download')),
1939                  'info download'
1940              );
1941          }
1942  
1943          if (isset($updateinfo->url)) {
1944              $info[] = html_writer::div(
1945                  html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin')),
1946                  'info more'
1947              );
1948          }
1949  
1950          $box = html_writer::start_div($boxclasses);
1951          $box .= html_writer::div(
1952              get_string('updateavailable', 'core_plugin', $updateinfo->version),
1953              'version'
1954          );
1955          $box .= html_writer::div(
1956              implode(html_writer::span(' ', 'separator'), $info),
1957              'infos'
1958          );
1959  
1960          if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason, false)) {
1961              $box .= $this->output->single_button(
1962                  new moodle_url($this->page->url, array('installupdate' => $updateinfo->component,
1963                      'installupdateversion' => $updateinfo->version)),
1964                  get_string('updateavailableinstall', 'core_admin'),
1965                  'post',
1966                  array('class' => 'singlebutton updateavailableinstall')
1967              );
1968          } else {
1969              $reasonhelp = $this->info_remote_plugin_not_installable($reason);
1970              if ($reasonhelp) {
1971                  $box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall');
1972              }
1973          }
1974          $box .= html_writer::end_div();
1975  
1976          return $box;
1977      }
1978  
1979      /**
1980       * This function will render one beautiful table with all the environmental
1981       * configuration and how it suits Moodle needs.
1982       *
1983       * @param boolean $result final result of the check (true/false)
1984       * @param environment_results[] $environment_results array of results gathered
1985       * @return string HTML to output.
1986       */
1987      public function environment_check_table($result, $environment_results) {
1988          global $CFG;
1989  
1990          // Table headers
1991          $servertable = new html_table();//table for server checks
1992          $servertable->head  = array(
1993              get_string('name'),
1994              get_string('info'),
1995              get_string('report'),
1996              get_string('plugin'),
1997              get_string('status'),
1998          );
1999          $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status');
2000          $servertable->attributes['class'] = 'admintable environmenttable generaltable table-sm';
2001          $servertable->id = 'serverstatus';
2002  
2003          $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
2004  
2005          $othertable = new html_table();//table for custom checks
2006          $othertable->head  = array(
2007              get_string('info'),
2008              get_string('report'),
2009              get_string('plugin'),
2010              get_string('status'),
2011          );
2012          $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status');
2013          $othertable->attributes['class'] = 'admintable environmenttable generaltable table-sm';
2014          $othertable->id = 'otherserverstatus';
2015  
2016          $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
2017  
2018          // Iterate over each environment_result
2019          $continue = true;
2020          foreach ($environment_results as $environment_result) {
2021              $errorline   = false;
2022              $warningline = false;
2023              $stringtouse = '';
2024              if ($continue) {
2025                  $type = $environment_result->getPart();
2026                  $info = $environment_result->getInfo();
2027                  $status = $environment_result->getStatus();
2028                  $plugin = $environment_result->getPluginName();
2029                  $error_code = $environment_result->getErrorCode();
2030                  // Process Report field
2031                  $rec = new stdClass();
2032                  // Something has gone wrong at parsing time
2033                  if ($error_code) {
2034                      $stringtouse = 'environmentxmlerror';
2035                      $rec->error_code = $error_code;
2036                      $status = get_string('error');
2037                      $errorline = true;
2038                      $continue = false;
2039                  }
2040  
2041                  if ($continue) {
2042                      if ($rec->needed = $environment_result->getNeededVersion()) {
2043                          // We are comparing versions
2044                          $rec->current = $environment_result->getCurrentVersion();
2045                          if ($environment_result->getLevel() == 'required') {
2046                              $stringtouse = 'environmentrequireversion';
2047                          } else {
2048                              $stringtouse = 'environmentrecommendversion';
2049                          }
2050  
2051                      } else if ($environment_result->getPart() == 'custom_check') {
2052                          // We are checking installed & enabled things
2053                          if ($environment_result->getLevel() == 'required') {
2054                              $stringtouse = 'environmentrequirecustomcheck';
2055                          } else {
2056                              $stringtouse = 'environmentrecommendcustomcheck';
2057                          }
2058  
2059                      } else if ($environment_result->getPart() == 'php_setting') {
2060                          if ($status) {
2061                              $stringtouse = 'environmentsettingok';
2062                          } else if ($environment_result->getLevel() == 'required') {
2063                              $stringtouse = 'environmentmustfixsetting';
2064                          } else {
2065                              $stringtouse = 'environmentshouldfixsetting';
2066                          }
2067  
2068                      } else {
2069                          if ($environment_result->getLevel() == 'required') {
2070                              $stringtouse = 'environmentrequireinstall';
2071                          } else {
2072                              $stringtouse = 'environmentrecommendinstall';
2073                          }
2074                      }
2075  
2076                      // Calculate the status value
2077                      if ($environment_result->getBypassStr() != '') {            //Handle bypassed result (warning)
2078                          $status = get_string('bypassed');
2079                          $warningline = true;
2080                      } else if ($environment_result->getRestrictStr() != '') {   //Handle restricted result (error)
2081                          $status = get_string('restricted');
2082                          $errorline = true;
2083                      } else {
2084                          if ($status) {                                          //Handle ok result (ok)
2085                              $status = get_string('statusok');
2086                          } else {
2087                              if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
2088                                  $status = get_string('check');
2089                                  $warningline = true;
2090                              } else {                                            //Handle error result (error)
2091                                  $status = get_string('check');
2092                                  $errorline = true;
2093                              }
2094                          }
2095                      }
2096                  }
2097  
2098                  // Build the text
2099                  $linkparts = array();
2100                  $linkparts[] = 'admin/environment';
2101                  $linkparts[] = $type;
2102                  if (!empty($info)){
2103                     $linkparts[] = $info;
2104                  }
2105                  // Plugin environments do not have docs pages yet.
2106                  if (empty($CFG->docroot) or $environment_result->plugin) {
2107                      $report = get_string($stringtouse, 'admin', $rec);
2108                  } else {
2109                      $report = $this->doc_link(join('/', $linkparts), get_string($stringtouse, 'admin', $rec), true);
2110                  }
2111                  // Enclose report text in div so feedback text will be displayed underneath it.
2112                  $report = html_writer::div($report);
2113  
2114                  // Format error or warning line
2115                  if ($errorline) {
2116                      $messagetype = 'error';
2117                      $statusclass = 'badge-danger';
2118                  } else if ($warningline) {
2119                      $messagetype = 'warn';
2120                      $statusclass = 'badge-warning';
2121                  } else {
2122                      $messagetype = 'ok';
2123                      $statusclass = 'badge-success';
2124                  }
2125                  $status = html_writer::span($status, 'badge ' . $statusclass);
2126                  // Here we'll store all the feedback found
2127                  $feedbacktext = '';
2128                  // Append the feedback if there is some
2129                  $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
2130                  //Append the bypass if there is some
2131                  $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
2132                  //Append the restrict if there is some
2133                  $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
2134  
2135                  $report .= $feedbacktext;
2136  
2137                  // Add the row to the table
2138                  if ($environment_result->getPart() == 'custom_check'){
2139                      $otherdata[$messagetype][] = array ($info, $report, $plugin, $status);
2140                  } else {
2141                      $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status);
2142                  }
2143              }
2144          }
2145  
2146          //put errors first in
2147          $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
2148          $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
2149  
2150          // Print table
2151          $output = '';
2152          $output .= $this->heading(get_string('serverchecks', 'admin'));
2153          $output .= html_writer::table($servertable);
2154          if (count($othertable->data)){
2155              $output .= $this->heading(get_string('customcheck', 'admin'));
2156              $output .= html_writer::table($othertable);
2157          }
2158  
2159          // Finally, if any error has happened, print the summary box
2160          if (!$result) {
2161              $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
2162          }
2163  
2164          return $output;
2165      }
2166  
2167      /**
2168       * Render a simple page for providing the upgrade key.
2169       *
2170       * @param moodle_url|string $url
2171       * @return string
2172       */
2173      public function upgradekey_form_page($url) {
2174  
2175          $output = '';
2176          $output .= $this->header();
2177          $output .= $this->container_start('upgradekeyreq');
2178          $output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
2179          $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
2180          $output .= html_writer::empty_tag('input', [
2181              'name' => 'upgradekey',
2182              'type' => 'password',
2183              'class' => 'form-control w-auto',
2184          ]);
2185          $output .= html_writer::empty_tag('input', [
2186              'type' => 'submit',
2187              'value' => get_string('submit'),
2188              'class' => 'btn btn-primary mt-3',
2189          ]);
2190          $output .= html_writer::end_tag('form');
2191          $output .= $this->container_end();
2192          $output .= $this->footer();
2193  
2194          return $output;
2195      }
2196  
2197      /**
2198       * Check to see if writing to the deprecated legacy log store is enabled.
2199       *
2200       * @return string An error message if writing to the legacy log store is enabled.
2201       */
2202      protected function legacy_log_store_writing_error() {
2203          $enabled = get_config('logstore_legacy', 'loglegacy');
2204          $plugins = explode(',', get_config('tool_log', 'enabled_stores'));
2205          $enabled = $enabled && in_array('logstore_legacy', $plugins);
2206  
2207          if ($enabled) {
2208              return $this->warning(get_string('legacylogginginuse'));
2209          }
2210      }
2211  
2212      /**
2213       * Display message about the benefits of registering on Moodle.org
2214       *
2215       * @return string
2216       */
2217      public function moodleorg_registration_message() {
2218  
2219          $out = format_text(get_string('registerwithmoodleorginfo', 'core_hub'), FORMAT_MARKDOWN);
2220  
2221          $out .= html_writer::link(
2222              new moodle_url('/admin/settings.php', ['section' => 'moodleservices']),
2223              $this->output->pix_icon('i/info', '').' '.get_string('registerwithmoodleorginfoapp', 'core_hub'),
2224              ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2225          );
2226  
2227          $out .= html_writer::link(
2228              HUB_MOODLEORGHUBURL,
2229              $this->output->pix_icon('i/stats', '').' '.get_string('registerwithmoodleorginfostats', 'core_hub'),
2230              ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2231          );
2232  
2233          $out .= html_writer::link(
2234              HUB_MOODLEORGHUBURL.'/sites',
2235              $this->output->pix_icon('i/location', '').' '.get_string('registerwithmoodleorginfosites', 'core_hub'),
2236              ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href']
2237          );
2238  
2239          return $this->output->box($out);
2240      }
2241  
2242      /**
2243       * Display message about benefits of enabling the user feedback feature.
2244       *
2245       * @param bool $showfeedbackencouragement Whether the encouragement content should be displayed or not
2246       * @return string
2247       */
2248      protected function userfeedback_encouragement(bool $showfeedbackencouragement): string {
2249          $output = '';
2250  
2251          if ($showfeedbackencouragement) {
2252              $settingslink = new moodle_url('/admin/settings.php', ['section' => 'userfeedback']);
2253              $output .= $this->warning(get_string('userfeedbackencouragement', 'admin', $settingslink->out()), 'info');
2254          }
2255  
2256          return $output;
2257      }
2258  
2259      /**
2260       * Display a warning about the deprecation of Mnet.
2261       *
2262       * @param string $xmlrpcwarning The warning message
2263       * @return string HTML to output.
2264       */
2265      protected function mnet_deprecation_warning($xmlrpcwarning) {
2266          if (empty($xmlrpcwarning)) {
2267              return '';
2268          }
2269  
2270          return $this->warning($xmlrpcwarning);
2271      }
2272  }