Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
/admin/ -> tools.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 admin tools
  19   *
  20   * Displays the list of found admin tools, their version (if found) and
  21   * a link to uninstall the admin tool.
  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('managetools');
  35  
  36  echo $OUTPUT->header();
  37  echo $OUTPUT->heading(get_string('tools', 'admin'));
  38  
  39  /// Print the table of all installed tool plugins
  40  
  41  $struninstall = get_string('uninstallplugin', 'core_admin');
  42  
  43  $table = new flexible_table('toolplugins_administration_table');
  44  $table->define_columns(array('name', 'version', 'uninstall'));
  45  $table->define_headers(array(get_string('plugin'), get_string('version'), $struninstall));
  46  $table->define_baseurl($PAGE->url);
  47  $table->set_attribute('id', 'toolplugins');
  48  $table->set_attribute('class', 'admintable generaltable');
  49  $table->setup();
  50  
  51  $plugins = array();
  52  foreach (core_component::get_plugin_list('tool') as $plugin => $plugindir) {
  53      if (get_string_manager()->string_exists('pluginname', 'tool_' . $plugin)) {
  54          $strpluginname = get_string('pluginname', 'tool_' . $plugin);
  55      } else {
  56          $strpluginname = $plugin;
  57      }
  58      $plugins[$plugin] = $strpluginname;
  59  }
  60  core_collator::asort($plugins);
  61  
  62  $like = $DB->sql_like('plugin', '?', true, true, false, '|');
  63  $params = array('tool|_%');
  64  $installed = $DB->get_records_select('config_plugins', "$like AND name = 'version'", $params);
  65  $versions = array();
  66  foreach ($installed as $config) {
  67      $name = preg_replace('/^tool_/', '', $config->plugin);
  68      $versions[$name] = $config->value;
  69      if (!isset($plugins[$name])) {
  70          $plugins[$name] = $name;
  71      }
  72  }
  73  
  74  foreach ($plugins as $plugin => $name) {
  75      $uninstall = '';
  76      if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('tool_'.$plugin, 'manage')) {
  77          $uninstall = html_writer::link($uninstallurl, $struninstall);
  78      }
  79  
  80      if (!isset($versions[$plugin])) {
  81          if (file_exists("$CFG->dirroot/$CFG->admin/tool/$plugin/version.php")) {
  82              // not installed yet
  83              $version = '?';
  84          } else {
  85              // no version info available
  86              $version = '-';
  87          }
  88      } else {
  89          $version = $versions[$plugin];
  90          if (file_exists("$CFG->dirroot/$CFG->admin/tool/$plugin")) {
  91              $version = $versions[$plugin];
  92          } else {
  93              // somebody removed plugin without uninstall
  94              $name = '<span class="notifyproblem">'.$name.' ('.get_string('missingfromdisk').')</span>';
  95              $version = $versions[$plugin];
  96          }
  97      }
  98  
  99      $table->add_data(array($name, $version, $uninstall));
 100  }
 101  
 102  $table->print_html();
 103  
 104  echo $OUTPUT->footer();