[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/ -> renderer.php (source)

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


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1