Moodle release 4.0.1
[moodle.git] / admin / modules.php
blob3a17cf5b78027dfcfc088d1d90bd76ef00a41a9b
1 <?php
2 // Allows the admin to manage activity modules
4 require_once('../config.php');
5 require_once('../course/lib.php');
6 require_once($CFG->libdir.'/adminlib.php');
7 require_once($CFG->libdir.'/tablelib.php');
9 // defines
10 define('MODULE_TABLE','module_administration_table');
12 admin_externalpage_setup('managemodules');
14 $show = optional_param('show', '', PARAM_PLUGIN);
15 $hide = optional_param('hide', '', PARAM_PLUGIN);
18 /// Print headings
20 $stractivities = get_string("activities");
21 $struninstall = get_string('uninstallplugin', 'core_admin');
22 $strversion = get_string("version");
23 $strhide = get_string("hide");
24 $strshow = get_string("show");
25 $strsettings = get_string("settings");
26 $stractivities = get_string("activities");
27 $stractivitymodule = get_string("activitymodule");
28 $strshowmodulecourse = get_string('showmodulecourse');
30 /// If data submitted, then process and store.
32 if (!empty($hide) and confirm_sesskey()) {
33 $class = \core_plugin_manager::resolve_plugininfo_class('mod');
34 $class::enable_plugin($hide, false);
36 admin_get_root(true, false); // settings not required - only pages
37 redirect(new moodle_url('/admin/modules.php'));
40 if (!empty($show) and confirm_sesskey()) {
41 $canenablemodule = true;
42 $modulename = $show;
44 // Invoking a callback function that enables plugins to force additional actions (e.g. displaying notifications,
45 // modals, etc.) and also specify through its returned value (bool) whether the process of enabling the plugin
46 // should continue after these actions or not.
47 if (component_callback_exists("mod_{$modulename}", 'pre_enable_plugin_actions')) {
48 $canenablemodule = component_callback("mod_{$modulename}", 'pre_enable_plugin_actions');
51 if ($canenablemodule) {
52 $class = \core_plugin_manager::resolve_plugininfo_class('mod');
53 $class::enable_plugin($show, true);
54 admin_get_root(true, false); // Settings not required - only pages.
55 redirect(new moodle_url('/admin/modules.php'));
59 echo $OUTPUT->header();
60 echo $OUTPUT->heading($stractivities);
62 /// Get and sort the existing modules
64 if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
65 print_error('moduledoesnotexist', 'error');
68 /// Print the table of all modules
69 // construct the flexible table ready to display
70 $table = new flexible_table(MODULE_TABLE);
71 $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'uninstall', 'settings'));
72 $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strsettings, $struninstall));
73 $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php');
74 $table->set_attribute('id', 'modules');
75 $table->set_attribute('class', 'admintable generaltable');
76 $table->setup();
78 $pluginmanager = core_plugin_manager::instance();
80 foreach ($modules as $module) {
81 $plugininfo = $pluginmanager->get_plugin_info('mod_'.$module->name);
82 $status = $plugininfo->get_status();
84 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
85 $strmodulename = '<span class="notifyproblem">'.$module->name.' ('.get_string('missingfromdisk').')</span>';
86 $missing = true;
87 } else {
88 // took out hspace="\10\", because it does not validate. don't know what to replace with.
89 $icon = "<img src=\"" . $OUTPUT->image_url('monologo', $module->name) . "\" class=\"icon\" alt=\"\" />";
90 $strmodulename = $icon.' '.get_string('modulename', $module->name);
91 $missing = false;
94 $uninstall = '';
95 if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('mod_'.$module->name, 'manage')) {
96 $uninstall = html_writer::link($uninstallurl, $struninstall);
99 if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") ||
100 file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) {
101 $settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
102 } else {
103 $settings = "";
106 try {
107 $count = $DB->count_records_select($module->name, "course<>0");
108 } catch (dml_exception $e) {
109 $count = -1;
111 if ($count>0) {
112 $countlink = $OUTPUT->action_link(new moodle_url('/course/search.php', ['modulelist' => $module->name]),
113 $count, null, ['title' => $strshowmodulecourse]);
114 } else if ($count < 0) {
115 $countlink = get_string('error');
116 } else {
117 $countlink = "$count";
120 if ($missing) {
121 $visible = '';
122 $class = '';
123 } else if ($module->visible) {
124 $visible = "<a href=\"modules.php?hide=$module->name&amp;sesskey=".sesskey()."\" title=\"$strhide\">".
125 $OUTPUT->pix_icon('t/hide', $strhide) . '</a>';
126 $class = '';
127 } else {
128 $visible = "<a href=\"modules.php?show=$module->name&amp;sesskey=".sesskey()."\" title=\"$strshow\">".
129 $OUTPUT->pix_icon('t/show', $strshow) . '</a>';
130 $class = 'dimmed_text';
132 if ($module->name == "forum") {
133 $uninstall = "";
134 $visible = "";
135 $class = "";
137 $version = get_config('mod_'.$module->name, 'version');
139 $table->add_data(array(
140 $strmodulename,
141 $countlink,
142 $version,
143 $visible,
144 $settings,
145 $uninstall,
146 ), $class);
149 $table->print_html();
151 echo $OUTPUT->footer();