MDL-73532 navigation: Fix the secondary navigation highlighting
[moodle.git] / admin / modules.php
blob5bfe9cd2477dcade8eaf8db379db5f77cc91cfe7
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 $class = \core_plugin_manager::resolve_plugininfo_class('mod');
42 $class::enable_plugin($show, true);
44 admin_get_root(true, false); // settings not required - only pages
45 redirect(new moodle_url('/admin/modules.php'));
48 echo $OUTPUT->header();
49 echo $OUTPUT->heading($stractivities);
51 /// Get and sort the existing modules
53 if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
54 print_error('moduledoesnotexist', 'error');
57 /// Print the table of all modules
58 // construct the flexible table ready to display
59 $table = new flexible_table(MODULE_TABLE);
60 $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'uninstall', 'settings'));
61 $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strsettings, $struninstall));
62 $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php');
63 $table->set_attribute('id', 'modules');
64 $table->set_attribute('class', 'admintable generaltable');
65 $table->setup();
67 $pluginmanager = core_plugin_manager::instance();
69 foreach ($modules as $module) {
70 $plugininfo = $pluginmanager->get_plugin_info('mod_'.$module->name);
71 $status = $plugininfo->get_status();
73 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
74 $strmodulename = '<span class="notifyproblem">'.$module->name.' ('.get_string('missingfromdisk').')</span>';
75 $missing = true;
76 } else {
77 // took out hspace="\10\", because it does not validate. don't know what to replace with.
78 $icon = "<img src=\"" . $OUTPUT->image_url('icon', $module->name) . "\" class=\"icon\" alt=\"\" />";
79 $strmodulename = $icon.' '.get_string('modulename', $module->name);
80 $missing = false;
83 $uninstall = '';
84 if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('mod_'.$module->name, 'manage')) {
85 $uninstall = html_writer::link($uninstallurl, $struninstall);
88 if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") ||
89 file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) {
90 $settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
91 } else {
92 $settings = "";
95 try {
96 $count = $DB->count_records_select($module->name, "course<>0");
97 } catch (dml_exception $e) {
98 $count = -1;
100 if ($count>0) {
101 $countlink = $OUTPUT->action_link(new moodle_url('/course/search.php', ['modulelist' => $module->name]),
102 $count, null, ['title' => $strshowmodulecourse]);
103 } else if ($count < 0) {
104 $countlink = get_string('error');
105 } else {
106 $countlink = "$count";
109 if ($missing) {
110 $visible = '';
111 $class = '';
112 } else if ($module->visible) {
113 $visible = "<a href=\"modules.php?hide=$module->name&amp;sesskey=".sesskey()."\" title=\"$strhide\">".
114 $OUTPUT->pix_icon('t/hide', $strhide) . '</a>';
115 $class = '';
116 } else {
117 $visible = "<a href=\"modules.php?show=$module->name&amp;sesskey=".sesskey()."\" title=\"$strshow\">".
118 $OUTPUT->pix_icon('t/show', $strshow) . '</a>';
119 $class = 'dimmed_text';
121 if ($module->name == "forum") {
122 $uninstall = "";
123 $visible = "";
124 $class = "";
126 $version = get_config('mod_'.$module->name, 'version');
128 $table->add_data(array(
129 $strmodulename,
130 $countlink,
131 $version,
132 $visible,
133 $settings,
134 $uninstall,
135 ), $class);
138 $table->print_html();
140 echo $OUTPUT->footer();