Merge branch 'MDL-63303_master-deleteduserfix' of https://github.com/markn86/moodle
[moodle.git] / admin / tools.php
blobe0559eec7786fc3c878c411f15bd6b8ca951c9c9
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.
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/>.
17 /**
18 * Provides an overview of installed admin tools
20 * Displays the list of found admin tools, their version (if found) and
21 * a link to uninstall the admin tool.
23 * The code is based on admin/localplugins.php by David Mudrak.
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
30 require_once(__DIR__ . '/../config.php');
31 require_once($CFG->libdir.'/adminlib.php');
32 require_once($CFG->libdir.'/tablelib.php');
34 admin_externalpage_setup('managetools');
36 echo $OUTPUT->header();
37 echo $OUTPUT->heading(get_string('tools', 'admin'));
39 /// Print the table of all installed tool plugins
41 $struninstall = get_string('uninstallplugin', 'core_admin');
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();
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;
58 $plugins[$plugin] = $strpluginname;
60 core_collator::asort($plugins);
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;
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);
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 = '-';
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];
99 $table->add_data(array($name, $version, $uninstall));
102 $table->print_html();
104 echo $OUTPUT->footer();