MDL-47919 tool_monitor: adjustments to behat tests
[moodle.git] / admin / reports.php
blobb02ba0d15427605a3e8d100474aefc8fcc94918a
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 reports
20 * Displays the list of found reports, their version (if found) and
21 * a link to uninstall the report.
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('managereports');
36 echo $OUTPUT->header();
37 echo $OUTPUT->heading(get_string('reports'));
39 /// Print the table of all installed report plugins
41 $struninstall = get_string('uninstallplugin', 'core_admin');
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();
52 $plugins = array();
53 foreach (core_component::get_plugin_list('report') as $plugin => $plugindir) {
54 if (get_string_manager()->string_exists('pluginname', 'report_' . $plugin)) {
55 $strpluginname = get_string('pluginname', 'report_' . $plugin);
56 } else {
57 $strpluginname = $plugin;
59 $plugins[$plugin] = $strpluginname;
61 core_collator::asort($plugins);
63 $like = $DB->sql_like('plugin', '?', true, true, false, '|');
64 $params = array('report|_%');
65 $installed = $DB->get_records_select('config_plugins', "$like AND name = 'version'", $params);
66 $versions = array();
67 foreach ($installed as $config) {
68 $name = preg_replace('/^report_/', '', $config->plugin);
69 $versions[$name] = $config->value;
70 if (!isset($plugins[$name])) {
71 $plugins[$name] = $name;
75 $logmanager = get_log_manager();
77 foreach ($plugins as $plugin => $name) {
78 $uninstall = '';
79 if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('report_'.$plugin, 'manage')) {
80 $uninstall = html_writer::link($uninstallurl, $struninstall);
83 $stores = $logmanager->get_supported_logstores('report_' . $plugin);
84 if ($stores === false) {
85 $supportedstores = get_string('logstorenotrequired', 'admin');
86 } else if (!empty($stores)) {
87 $supportedstores = implode(', ', $stores);
88 } else {
89 $supportedstores = get_string('nosupportedlogstore', 'admin');;
92 if (!isset($versions[$plugin])) {
93 if (file_exists("$CFG->dirroot/report/$plugin/version.php")) {
94 // not installed yet
95 $version = '?';
96 } else {
97 // no version info available
98 $version = '-';
100 } else {
101 $version = $versions[$plugin];
102 if (file_exists("$CFG->dirroot/report/$plugin")) {
103 $version = $versions[$plugin];
104 } else {
105 // somebody removed plugin without uninstall
106 $name = '<span class="notifyproblem">'.$name.' ('.get_string('missingfromdisk').')</span>';
107 $version = $versions[$plugin];
111 $table->add_data(array($name, $supportedstores, $version, $uninstall));
114 $table->print_html();
116 echo $OUTPUT->footer();