MDL-77046 availability: validate profile field in condition.
[moodle.git] / admin / modules.php
blobdeec4a677e88061721febba4db9593fa15b3ab21
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 if ($class::enable_plugin($hide, false)) {
35 // Settings not required - only pages.
36 admin_get_root(true, false);
38 redirect(new moodle_url('/admin/modules.php'));
41 if (!empty($show) && confirm_sesskey()) {
42 $class = \core_plugin_manager::resolve_plugininfo_class('mod');
43 if ($class::enable_plugin($show, true)) {
44 // Settings not required - only pages.
45 admin_get_root(true, false);
47 redirect(new moodle_url('/admin/modules.php'));
50 echo $OUTPUT->header();
51 echo $OUTPUT->heading($stractivities);
53 /// Get and sort the existing modules
55 if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
56 throw new \moodle_exception('moduledoesnotexist', 'error');
59 /// Print the table of all modules
60 // construct the flexible table ready to display
61 $table = new flexible_table(MODULE_TABLE);
62 $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'uninstall', 'settings'));
63 $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strsettings, $struninstall));
64 $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php');
65 $table->set_attribute('id', 'modules');
66 $table->set_attribute('class', 'admintable generaltable');
67 $table->setup();
69 $pluginmanager = core_plugin_manager::instance();
71 foreach ($modules as $module) {
72 $plugininfo = $pluginmanager->get_plugin_info('mod_'.$module->name);
73 $status = $plugininfo->get_status();
75 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
76 $strmodulename = '<span class="notifyproblem">'.$module->name.' ('.get_string('missingfromdisk').')</span>';
77 $missing = true;
78 } else {
79 // took out hspace="\10\", because it does not validate. don't know what to replace with.
80 $icon = "<img src=\"" . $OUTPUT->image_url('monologo', $module->name) . "\" class=\"icon\" alt=\"\" />";
81 $strmodulename = $icon.' '.get_string('modulename', $module->name);
82 $missing = false;
85 $uninstall = '';
86 if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('mod_'.$module->name, 'manage')) {
87 $uninstall = html_writer::link($uninstallurl, $struninstall);
90 if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") ||
91 file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) {
92 $settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
93 } else {
94 $settings = "";
97 try {
98 $count = $DB->count_records_select($module->name, "course<>0");
99 } catch (dml_exception $e) {
100 $count = -1;
102 if ($count>0) {
103 $countlink = $OUTPUT->action_link(new moodle_url('/course/search.php', ['modulelist' => $module->name]),
104 $count, null, ['title' => $strshowmodulecourse]);
105 } else if ($count < 0) {
106 $countlink = get_string('error');
107 } else {
108 $countlink = "$count";
111 if ($missing) {
112 $visible = '';
113 $class = '';
114 } else if ($module->visible) {
115 $visible = "<a href=\"modules.php?hide=$module->name&amp;sesskey=".sesskey()."\" title=\"$strhide\">".
116 $OUTPUT->pix_icon('t/hide', $strhide) . '</a>';
117 $class = '';
118 } else {
119 $visible = "<a href=\"modules.php?show=$module->name&amp;sesskey=".sesskey()."\" title=\"$strshow\">".
120 $OUTPUT->pix_icon('t/show', $strshow) . '</a>';
121 $class = 'dimmed_text';
123 if ($module->name == "forum") {
124 $uninstall = "";
125 $visible = "";
126 $class = "";
128 $version = get_config('mod_'.$module->name, 'version');
130 $table->add_data(array(
131 $strmodulename,
132 $countlink,
133 $version,
134 $visible,
135 $settings,
136 $uninstall,
137 ), $class);
140 $table->print_html();
142 echo $OUTPUT->footer();