MDL-21655 "big scary enrolment and roles improvements" fixed a typo in previous check...
[moodle.git] / admin / localplugins.php
blob10b994e7ece812658802c748394fcb33fb82d38a
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Provides an overview of installed local plugins
21 * Displays the list of found local plugins, their version (if found) and
22 * a link to delete the local plugin.
24 * @see http://docs.moodle.org/en/Development:Local_customisation
25 * @package admin
26 * @copyright 2010 David Mudrak <david.mudrak@gmail.com>
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 require_once(dirname(dirname(__FILE__)) . '/config.php');
31 require_once($CFG->libdir.'/adminlib.php');
32 require_once($CFG->libdir.'/tablelib.php');
34 admin_externalpage_setup('managelocalplugins');
36 $delete = optional_param('delete', '', PARAM_SAFEDIR);
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('localplugins'));
45 if (!$confirm) {
46 echo $OUTPUT->confirm(get_string('localplugindeleteconfirm', '', get_string('pluginname', 'local_' . $delete)),
47 new moodle_url($PAGE->url, array('delete' => $delete, 'confirm' => 1)),
48 $PAGE->url);
49 echo $OUTPUT->footer();
50 die();
52 } else {
53 uninstall_plugin('local', $delete);
54 $a = new stdclass();
55 $a->name = $delete;
56 $pluginlocation = get_plugin_types();
57 $a->directory = $pluginlocation['local'] . '/' . $delete;
58 echo $OUTPUT->notification(get_string('plugindeletefiles', '', $a), 'notifysuccess');
59 echo $OUTPUT->continue_button($PAGE->url);
60 echo $OUTPUT->footer();
61 die();
65 echo $OUTPUT->header();
66 echo $OUTPUT->heading(get_string('localplugins'));
68 /// Print the table of all installed local plugins
70 $table = new flexible_table('localplugins_administration_table');
71 $table->define_columns(array('name', 'version', 'delete'));
72 $table->define_headers(array(get_string('plugin'), get_string('version'), get_string('delete')));
73 $table->define_baseurl($PAGE->url);
74 $table->set_attribute('id', 'localplugins');
75 $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
76 $table->setup();
78 $plugins = array();
79 foreach (get_plugin_list('local') as $plugin => $plugindir) {
80 $strpluginname = get_string('pluginname', 'local_' . $plugin);
81 if ($strpluginname == '[[pluginname]]') {
82 $strpluginname = $plugin;
84 $plugins[$plugin] = $strpluginname;
86 asort($plugins, SORT_LOCALE_STRING);
88 foreach ($plugins as $plugin => $name) {
89 $delete = new moodle_url($PAGE->url, array('delete' => $plugin, 'sesskey' => sesskey()));
90 $delete = html_writer::link($delete, get_string('delete'));
92 $version = get_config('local_' . $plugin);
93 if (!empty($version->version)) {
94 $version = $version->version;
95 } else {
96 $version = '?';
99 $table->add_data(array($name, $version, $delete));
102 $table->print_html();
104 echo $OUTPUT->footer();