From 4f6bba205d6761c162a0be1a136943e8c09dd809 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sun, 6 Nov 2011 12:48:37 +0100 Subject: [PATCH] MDL-29030 add report management UI --- admin/reports.php | 134 +++++++++++++++++++++++++++++++++++++ admin/settings/plugins.php | 11 ++- lang/en/admin.php | 2 + lib/pluginlib.php | 10 +++ 4 files changed, 151 insertions(+), 6 deletions(-) create mode 100644 admin/reports.php diff --git a/admin/reports.php b/admin/reports.php new file mode 100644 index 00000000000..e03c9282993 --- /dev/null +++ b/admin/reports.php @@ -0,0 +1,134 @@ +. + +/** + * Provides an overview of installed reports + * + * Displays the list of found reports, their version (if found) and + * a link to delete the report. + * + * The code is based on admin/localplugins.php by David Mudrak. + * + * @package admin + * @copyright 2011 Petr Skoda {@link http://skodak.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(dirname(__FILE__) . '/../config.php'); +require_once($CFG->libdir.'/adminlib.php'); +require_once($CFG->libdir.'/tablelib.php'); + +admin_externalpage_setup('managereports'); + +$delete = optional_param('delete', '', PARAM_PLUGIN); +$confirm = optional_param('confirm', '', PARAM_BOOL); + +/// If data submitted, then process and store. + +if (!empty($delete) and confirm_sesskey()) { + echo $OUTPUT->header(); + echo $OUTPUT->heading(get_string('reports')); + + if (!$confirm) { + if (get_string_manager()->string_exists('pluginname', 'report_' . $delete)) { + $strpluginname = get_string('pluginname', 'report_' . $delete); + } else { + $strpluginname = $delete; + } + echo $OUTPUT->confirm(get_string('reportsdeleteconfirm', 'admin', $strpluginname), + new moodle_url($PAGE->url, array('delete' => $delete, 'confirm' => 1)), + $PAGE->url); + echo $OUTPUT->footer(); + die(); + + } else { + uninstall_plugin('report', $delete); + $a = new stdclass(); + $a->name = $delete; + $pluginlocation = get_plugin_types(); + $a->directory = $pluginlocation['report'] . '/' . $delete; + echo $OUTPUT->notification(get_string('plugindeletefiles', '', $a), 'notifysuccess'); + echo $OUTPUT->continue_button($PAGE->url); + echo $OUTPUT->footer(); + die(); + } +} + +echo $OUTPUT->header(); +echo $OUTPUT->heading(get_string('reports')); + +/// Print the table of all installed report plugins + +$table = new flexible_table('reportplugins_administration_table'); +$table->define_columns(array('name', 'version', 'delete')); +$table->define_headers(array(get_string('plugin'), get_string('version'), get_string('delete'))); +$table->define_baseurl($PAGE->url); +$table->set_attribute('id', 'reportplugins'); +$table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide'); +$table->setup(); + +$plugins = array(); +foreach (get_plugin_list('report') as $plugin => $plugindir) { + if (get_string_manager()->string_exists('pluginname', 'report_' . $plugin)) { + $strpluginname = get_string('pluginname', 'report_' . $plugin); + } else { + $strpluginname = $plugin; + } + $plugins[$plugin] = $strpluginname; +} +collatorlib::asort($plugins); + +$like = $DB->sql_like('plugin', '?', true, true, false, '|'); +$params = array('report|_%'); +$installed = $DB->get_records_select('config_plugins', "$like AND name = 'version'", $params); +$versions = array(); +foreach ($installed as $config) { + $name = preg_replace('/^report_/', '', $config->plugin); + $versions[$name] = $config->value; + if (!isset($plugins[$name])) { + $plugins[$name] = $name; + } +} + +foreach ($plugins as $plugin => $name) { + $delete = new moodle_url($PAGE->url, array('delete' => $plugin, 'sesskey' => sesskey())); + $delete = html_writer::link($delete, get_string('delete')); + + if (!isset($versions[$plugin])) { + if (file_exists("$CFG->dirroot/report/$plugin/version.php")) { + // not installed yet + $version = '?'; + } else { + // no version info available + $version = '-'; + } + } else { + $version = $versions[$plugin]; + if (file_exists("$CFG->dirroot/report/$plugin")) { + $version = $versions[$plugin]; + } else { + // somebody removed plugin without uninstall + $name = ''.$name.' ('.get_string('missingfromdisk').')'; + $version = $versions[$plugin]; + } + } + + $table->add_data(array($name, $version, $delete)); +} + +$table->print_html(); + +echo $OUTPUT->footer(); diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index c9e2c9b206e..15bac9d841e 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -470,13 +470,12 @@ foreach (get_plugin_list('report') as $report => $plugindir) { } } } -if (!empty($pages)) { - $ADMIN->add('modules', new admin_category('reports', get_string('reports'))); - foreach ($pages as $page) { - $ADMIN->add('reports', $page); - } +$ADMIN->add('modules', new admin_category('reportplugins', get_string('reports'))); +$ADMIN->add('reportplugins', new admin_externalpage('managereports', get_string('reportsmanage', 'admin'), + $CFG->wwwroot . '/' . $CFG->admin . '/reports.php')); +foreach ($pages as $page) { + $ADMIN->add('reportplugins', $page); } -unset($pages); // Now add various admin tools foreach (get_plugin_list('tool') as $plugin => $plugindir) { diff --git a/lang/en/admin.php b/lang/en/admin.php index fcb3a957a34..14d9d337811 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -835,6 +835,8 @@ $string['registration'] = 'Registration'; $string['releasenoteslink'] = 'For information about this version of Moodle, please see the online Release Notes'; $string['rememberusername'] = 'Remember username'; $string['rememberusername_desc'] = 'Enable if you want to store permanent cookies with usernames during user login. Permanent cookies may be considered a privacy issue if used without consent.'; +$string['reportsmanage'] = 'Manage reports'; +$string['reportsdeleteconfirm'] = 'You are about to completely delete the report \'{$a}\'. This will completely delete everything in the database associated with this plugin. Are you SURE you want to continue?'; $string['requiredentrieschanged'] = 'IMPORTANT - PLEASE READ
(This warning message will only be displayed during this upgrade)

Due to a bug fix, the behaviour of database activities using the \'Required entries\' and \'Required entries before viewing settings\' settings will change. A more detailed explanation of the changes can be read on the database module forum. The expected behavior of these settings can also be read on Moodle Docs.

This change affects the following databases in your system: (Please save this list now, and after the upgrade, check that these activities still work the way that the teacher intends.)
{$a->text}
'; $string['requiremodintro'] = 'Require activity description'; diff --git a/lib/pluginlib.php b/lib/pluginlib.php index c770b68b2db..5ea8d1ef4d4 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -1654,3 +1654,13 @@ class plugintype_tool extends plugintype_base implements plugin_information { return new moodle_url('/admin/tools.php', array('delete' => $this->name, 'sesskey' => sesskey())); } } + +/** + * Class for admin tool plugins + */ +class plugintype_report extends plugintype_base implements plugin_information { + + public function get_uninstall_url() { + return new moodle_url('/admin/reports.php', array('delete' => $this->name, 'sesskey' => sesskey())); + } +}