Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
/admin/ -> reports.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   * Provides an overview of installed reports
  19   *
  20   * Displays the list of found reports, their version (if found) and
  21   * a link to uninstall the report.
  22   *
  23   * The code is based on admin/localplugins.php by David Mudrak.
  24   *
  25   * @package   admin
  26   * @copyright 2011 Petr Skoda {@link http://skodak.org}
  27   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28   */
  29  
  30  require_once(__DIR__ . '/../config.php');
  31  require_once($CFG->libdir.'/adminlib.php');
  32  require_once($CFG->libdir.'/tablelib.php');
  33  
  34  admin_externalpage_setup('managereports');
  35  
  36  echo $OUTPUT->header();
  37  echo $OUTPUT->heading(get_string('reports'));
  38  
  39  /// Print the table of all installed report plugins
  40  
  41  $struninstall = get_string('uninstallplugin', 'core_admin');
  42  
  43  $table = new flexible_table('reportplugins_administration_table');
  44  $table->define_columns(array('name', 'logstoressupported', 'version', 'uninstall'));
  45  $table->define_headers(array(get_string('plugin'), get_string('logstoressupported', 'admin'), get_string('version'),
  46          $struninstall));
  47  $table->define_baseurl($PAGE->url);
  48  $table->set_attribute('id', 'reportplugins');
  49  $table->set_attribute('class', 'admintable generaltable');
  50  $table->setup();
  51  
  52  $plugins = array();
  53  $availableplugins = core_component::get_plugin_list('report');
  54  foreach ($availableplugins as $plugin => $plugindir) {
  55      if (get_string_manager()->string_exists('pluginname', 'report_' . $plugin)) {
  56          $strpluginname = get_string('pluginname', 'report_' . $plugin);
  57      } else {
  58          $strpluginname = $plugin;
  59      }
  60      $plugins[$plugin] = $strpluginname;
  61  }
  62  core_collator::asort($plugins);
  63  
  64  $like = $DB->sql_like('plugin', '?', true, true, false, '|');
  65  $params = array('report|_%');
  66  $installed = $DB->get_records_select('config_plugins', "$like AND name = 'version'", $params);
  67  $versions = array();
  68  foreach ($installed as $config) {
  69      $name = preg_replace('/^report_/', '', $config->plugin);
  70      $versions[$name] = $config->value;
  71      if (!isset($plugins[$name])) {
  72          $plugins[$name] = $name;
  73      }
  74  }
  75  
  76  $logmanager = get_log_manager();
  77  
  78  foreach ($plugins as $plugin => $name) {
  79      $uninstall = '';
  80      if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('report_'.$plugin, 'manage')) {
  81          $uninstall = html_writer::link($uninstallurl, $struninstall);
  82      }
  83  
  84      $stores = array();
  85      if (isset($availableplugins[$plugin])) {
  86          $stores = $logmanager->get_supported_logstores('report_' . $plugin);
  87      }
  88      if ($stores === false) {
  89          $supportedstores = get_string('logstorenotrequired', 'admin');
  90      } else if (!empty($stores)) {
  91          $supportedstores = implode(', ', $stores);
  92      } else {
  93          $supportedstores = get_string('nosupportedlogstore', 'admin');;
  94      }
  95  
  96      if (!isset($versions[$plugin])) {
  97          if (file_exists("$CFG->dirroot/report/$plugin/version.php")) {
  98              // not installed yet
  99              $version = '?';
 100          } else {
 101              // no version info available
 102              $version = '-';
 103          }
 104      } else {
 105          $version = $versions[$plugin];
 106          if (file_exists("$CFG->dirroot/report/$plugin")) {
 107              $version = $versions[$plugin];
 108          } else {
 109              // somebody removed plugin without uninstall
 110              $name = '<span class="notifyproblem">'.$name.' ('.get_string('missingfromdisk').')</span>';
 111              $version = $versions[$plugin];
 112          }
 113      }
 114  
 115      $table->add_data(array($name, $supportedstores, $version, $uninstall));
 116  }
 117  
 118  $table->print_html();
 119  
 120  echo $OUTPUT->footer();