Merge branch 'MDL-39518-24' of git://github.com/damyon/moodle into MOODLE_24_STABLE
[moodle.git] / admin / tools.php
blob1c4d9158e70dbc06023dceee34125bf79e5a04e2
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 delete 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(dirname(__FILE__) . '/../config.php');
31 require_once($CFG->libdir.'/adminlib.php');
32 require_once($CFG->libdir.'/tablelib.php');
34 admin_externalpage_setup('managetools');
36 $delete = optional_param('delete', '', PARAM_PLUGIN);
37 $confirm = optional_param('confirm', '', PARAM_BOOL);
39 /// If data submitted, then process and store.
41 if (!empty($delete) and confirm_sesskey()) {
42 echo $OUTPUT->header();
43 echo $OUTPUT->heading(get_string('tools', 'admin'));
45 if (!$confirm) {
46 if (get_string_manager()->string_exists('pluginname', 'tool_' . $delete)) {
47 $strpluginname = get_string('pluginname', 'tool_' . $delete);
48 } else {
49 $strpluginname = $delete;
51 echo $OUTPUT->confirm(get_string('toolsdeleteconfirm', 'admin', $strpluginname),
52 new moodle_url($PAGE->url, array('delete' => $delete, 'confirm' => 1)),
53 $PAGE->url);
54 echo $OUTPUT->footer();
55 die();
57 } else {
58 uninstall_plugin('tool', $delete);
59 $a = new stdclass();
60 $a->name = $delete;
61 $pluginlocation = get_plugin_types();
62 $a->directory = $pluginlocation['tool'] . '/' . $delete;
63 echo $OUTPUT->notification(get_string('plugindeletefiles', '', $a), 'notifysuccess');
64 echo $OUTPUT->continue_button($PAGE->url);
65 echo $OUTPUT->footer();
66 die();
70 echo $OUTPUT->header();
71 echo $OUTPUT->heading(get_string('tools', 'admin'));
73 /// Print the table of all installed tool plugins
75 $table = new flexible_table('toolplugins_administration_table');
76 $table->define_columns(array('name', 'version', 'delete'));
77 $table->define_headers(array(get_string('plugin'), get_string('version'), get_string('delete')));
78 $table->define_baseurl($PAGE->url);
79 $table->set_attribute('id', 'toolplugins');
80 $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
81 $table->setup();
83 $plugins = array();
84 foreach (get_plugin_list('tool') as $plugin => $plugindir) {
85 if (get_string_manager()->string_exists('pluginname', 'tool_' . $plugin)) {
86 $strpluginname = get_string('pluginname', 'tool_' . $plugin);
87 } else {
88 $strpluginname = $plugin;
90 $plugins[$plugin] = $strpluginname;
92 collatorlib::asort($plugins);
94 $like = $DB->sql_like('plugin', '?', true, true, false, '|');
95 $params = array('tool|_%');
96 $installed = $DB->get_records_select('config_plugins', "$like AND name = 'version'", $params);
97 $versions = array();
98 foreach ($installed as $config) {
99 $name = preg_replace('/^tool_/', '', $config->plugin);
100 $versions[$name] = $config->value;
101 if (!isset($plugins[$name])) {
102 $plugins[$name] = $name;
106 foreach ($plugins as $plugin => $name) {
107 $delete = new moodle_url($PAGE->url, array('delete' => $plugin, 'sesskey' => sesskey()));
108 $delete = html_writer::link($delete, get_string('delete'));
110 if (!isset($versions[$plugin])) {
111 if (file_exists("$CFG->dirroot/$CFG->admin/tool/$plugin/version.php")) {
112 // not installed yet
113 $version = '?';
114 } else {
115 // no version info available
116 $version = '-';
118 } else {
119 $version = $versions[$plugin];
120 if (file_exists("$CFG->dirroot/$CFG->admin/tool/$plugin")) {
121 $version = $versions[$plugin];
122 } else {
123 // somebody removed plugin without uninstall
124 $name = '<span class="notifyproblem">'.$name.' ('.get_string('missingfromdisk').')</span>';
125 $version = $versions[$plugin];
129 $table->add_data(array($name, $version, $delete));
132 $table->print_html();
134 echo $OUTPUT->footer();