diff --git a/admin/modules.php b/admin/modules.php index b5e61fa2763..8fd9be196e8 100644 --- a/admin/modules.php +++ b/admin/modules.php @@ -1,151 +1,174 @@ . - require_once('../config.php'); - require_once('../course/lib.php'); - require_once($CFG->libdir.'/adminlib.php'); - require_once($CFG->libdir.'/tablelib.php'); +/** + * A page to manage activity modules. + * + * @package core_admin + * @copyright 2023 Andrew Lyons + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ - // defines - define('MODULE_TABLE','module_administration_table'); +require_once('../config.php'); +require_once('../course/lib.php'); +require_once("{$CFG->libdir}/adminlib.php"); +require_once("{$CFG->libdir}/tablelib.php"); - admin_externalpage_setup('managemodules'); +define('MODULE_TABLE', 'module_administration_table'); - $show = optional_param('show', '', PARAM_PLUGIN); - $hide = optional_param('hide', '', PARAM_PLUGIN); +admin_externalpage_setup('managemodules'); +$show = optional_param('show', '', PARAM_PLUGIN); +$hide = optional_param('hide', '', PARAM_PLUGIN); -/// Print headings +// Print headings. +$stractivities = get_string("activities"); +$struninstall = get_string('uninstallplugin', 'core_admin'); +$strversion = get_string("version"); +$strhide = get_string("hide"); +$strshow = get_string("show"); +$strsettings = get_string("settings"); +$stractivities = get_string("activities"); +$stractivitymodule = get_string("activitymodule"); +$strshowmodulecourse = get_string('showmodulecourse'); - $stractivities = get_string("activities"); - $struninstall = get_string('uninstallplugin', 'core_admin'); - $strversion = get_string("version"); - $strhide = get_string("hide"); - $strshow = get_string("show"); - $strsettings = get_string("settings"); - $stractivities = get_string("activities"); - $stractivitymodule = get_string("activitymodule"); - $strshowmodulecourse = get_string('showmodulecourse'); +// If data submitted, then process and store. +if (!empty($hide) && confirm_sesskey()) { + $class = \core_plugin_manager::resolve_plugininfo_class('mod'); + $class::enable_plugin($hide, false); -/// If data submitted, then process and store. + // Settings not required - only pages. + admin_get_root(true, false); + redirect(new moodle_url('/admin/modules.php')); +} - if (!empty($hide) and confirm_sesskey()) { +if (!empty($show) && confirm_sesskey()) { + $canenablemodule = true; + $modulename = $show; + + // Invoking a callback function that enables plugins to force additional actions (e.g. displaying notifications, + // modals, etc.) and also specify through its returned value (bool) whether the process of enabling the plugin + // should continue after these actions or not. + if (component_callback_exists("mod_{$modulename}", 'pre_enable_plugin_actions')) { + $canenablemodule = component_callback("mod_{$modulename}", 'pre_enable_plugin_actions'); + } + + if ($canenablemodule) { $class = \core_plugin_manager::resolve_plugininfo_class('mod'); - $class::enable_plugin($hide, false); - - admin_get_root(true, false); // settings not required - only pages + $class::enable_plugin($show, true); + // Settings not required - only pages. + admin_get_root(true, false); redirect(new moodle_url('/admin/modules.php')); } +} - if (!empty($show) and confirm_sesskey()) { - $canenablemodule = true; - $modulename = $show; +echo $OUTPUT->header(); +echo $OUTPUT->heading($stractivities); - // Invoking a callback function that enables plugins to force additional actions (e.g. displaying notifications, - // modals, etc.) and also specify through its returned value (bool) whether the process of enabling the plugin - // should continue after these actions or not. - if (component_callback_exists("mod_{$modulename}", 'pre_enable_plugin_actions')) { - $canenablemodule = component_callback("mod_{$modulename}", 'pre_enable_plugin_actions'); - } +// Get and sort the existing modules. +if (!$modules = $DB->get_records('modules', [], 'name ASC')) { + throw new \moodle_exception('moduledoesnotexist', 'error'); +} - if ($canenablemodule) { - $class = \core_plugin_manager::resolve_plugininfo_class('mod'); - $class::enable_plugin($show, true); - admin_get_root(true, false); // Settings not required - only pages. - redirect(new moodle_url('/admin/modules.php')); - } +// Print the table of all modules. +// Construct the flexible table ready to display. +$table = new flexible_table(MODULE_TABLE); +$table->define_columns(['name', 'instances', 'version', 'hideshow', 'uninstall', 'settings']); +$table->define_headers([$stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strsettings, $struninstall]); +$table->define_baseurl($CFG->wwwroot . '/' . $CFG->admin . '/modules.php'); +$table->set_attribute('id', 'modules'); +$table->set_attribute('class', 'admintable generaltable'); +$table->setup(); + +$pluginmanager = core_plugin_manager::instance(); + +foreach ($modules as $module) { + $plugininfo = $pluginmanager->get_plugin_info('mod_' . $module->name); + $status = $plugininfo->get_status(); + + if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) { + $strmodulename = '' . $module->name . ' (' . get_string('missingfromdisk') . ')'; + $missing = true; + } else { + $icon = "image_url('monologo', $module->name) . "\" class=\"icon\" alt=\"\" />"; + $strmodulename = $icon . ' ' . get_string('modulename', $module->name); + $missing = false; } - echo $OUTPUT->header(); - echo $OUTPUT->heading($stractivities); - -/// Get and sort the existing modules - - if (!$modules = $DB->get_records('modules', array(), 'name ASC')) { - throw new \moodle_exception('moduledoesnotexist', 'error'); + $uninstall = ''; + if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('mod_' . $module->name, 'manage')) { + $uninstall = html_writer::link($uninstallurl, $struninstall); } -/// Print the table of all modules - // construct the flexible table ready to display - $table = new flexible_table(MODULE_TABLE); - $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'uninstall', 'settings')); - $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strsettings, $struninstall)); - $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php'); - $table->set_attribute('id', 'modules'); - $table->set_attribute('class', 'admintable generaltable'); - $table->setup(); - - $pluginmanager = core_plugin_manager::instance(); - - foreach ($modules as $module) { - $plugininfo = $pluginmanager->get_plugin_info('mod_'.$module->name); - $status = $plugininfo->get_status(); - - if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) { - $strmodulename = ''.$module->name.' ('.get_string('missingfromdisk').')'; - $missing = true; - } else { - // took out hspace="\10\", because it does not validate. don't know what to replace with. - $icon = "image_url('monologo', $module->name) . "\" class=\"icon\" alt=\"\" />"; - $strmodulename = $icon.' '.get_string('modulename', $module->name); - $missing = false; - } - - $uninstall = ''; - if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('mod_'.$module->name, 'manage')) { - $uninstall = html_writer::link($uninstallurl, $struninstall); - } - - if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") || - file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) { - $settings = "name\">$strsettings"; - } else { - $settings = ""; - } - - try { - $count = $DB->count_records_select($module->name, "course<>0"); - } catch (dml_exception $e) { - $count = -1; - } - if ($count>0) { - $countlink = $OUTPUT->action_link(new moodle_url('/course/search.php', ['modulelist' => $module->name]), - $count, null, ['title' => $strshowmodulecourse]); - } else if ($count < 0) { - $countlink = get_string('error'); - } else { - $countlink = "$count"; - } - - if ($missing) { - $visible = ''; - $class = ''; - } else if ($module->visible) { - $visible = "name&sesskey=".sesskey()."\" title=\"$strhide\">". - $OUTPUT->pix_icon('t/hide', $strhide) . ''; - $class = ''; - } else { - $visible = "name&sesskey=".sesskey()."\" title=\"$strshow\">". - $OUTPUT->pix_icon('t/show', $strshow) . ''; - $class = 'dimmed_text'; - } - if ($module->name == "forum") { - $uninstall = ""; - $visible = ""; - $class = ""; - } - $version = get_config('mod_'.$module->name, 'version'); - - $table->add_data(array( - $strmodulename, - $countlink, - $version, - $visible, - $settings, - $uninstall, - ), $class); + if ( + file_exists("$CFG->dirroot/mod/$module->name/settings.php") || + file_exists("$CFG->dirroot/mod/$module->name/settingstree.php") + ) { + $settings = "name\">$strsettings"; + } else { + $settings = ""; } - $table->print_html(); + try { + $count = $DB->count_records_select($module->name, "course<>0"); + } catch (dml_exception $e) { + $count = -1; + } + if ($count > 0) { + $countlink = $OUTPUT->action_link( + new moodle_url('/course/search.php', ['modulelist' => $module->name]), + $count, + null, + ['title' => $strshowmodulecourse] + ); + } else if ($count < 0) { + $countlink = get_string('error'); + } else { + $countlink = "$count"; + } - echo $OUTPUT->footer(); + if ($missing) { + $visible = ''; + $class = ''; + } else if ($module->visible) { + $visible = "name&sesskey=" . sesskey() . "\" title=\"$strhide\">" . + $OUTPUT->pix_icon('t/hide', $strhide) . ''; + $class = ''; + } else { + $visible = "name&sesskey=" . sesskey() . "\" title=\"$strshow\">" . + $OUTPUT->pix_icon('t/show', $strshow) . ''; + $class = 'dimmed_text'; + } + if ($module->name == "forum") { + $uninstall = ""; + $visible = ""; + $class = ""; + } + $version = get_config('mod_' . $module->name, 'version'); + + $table->add_data([ + $strmodulename, + $countlink, + $version, + $visible, + $settings, + $uninstall, + ], $class); +} + +$table->finish_html(); + +echo $OUTPUT->footer();