Merge branch 'MDL-71187-39' of git://github.com/lucaboesch/moodle into MOODLE_39_STABLE
[moodle.git] / admin / modules.php
blobe76a8e11a3c067007f89e46849fe0f8207dd7f41
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 if (!$module = $DB->get_record("modules", array("name"=>$hide))) {
34 print_error('moduledoesnotexist', 'error');
36 $DB->set_field("modules", "visible", "0", array("id"=>$module->id)); // Hide main module
37 // Remember the visibility status in visibleold
38 // and hide...
39 $sql = "UPDATE {course_modules}
40 SET visibleold=visible, visible=0
41 WHERE module=?";
42 $DB->execute($sql, array($module->id));
43 // Increment course.cacherev for courses where we just made something invisible.
44 // This will force cache rebuilding on the next request.
45 increment_revision_number('course', 'cacherev',
46 "id IN (SELECT DISTINCT course
47 FROM {course_modules}
48 WHERE visibleold=1 AND module=?)",
49 array($module->id));
50 core_plugin_manager::reset_caches();
51 admin_get_root(true, false); // settings not required - only pages
52 redirect(new moodle_url('/admin/modules.php'));
55 if (!empty($show) and confirm_sesskey()) {
56 if (!$module = $DB->get_record("modules", array("name"=>$show))) {
57 print_error('moduledoesnotexist', 'error');
59 $DB->set_field("modules", "visible", "1", array("id"=>$module->id)); // Show main module
60 $DB->set_field('course_modules', 'visible', '1', array('visibleold'=>1, 'module'=>$module->id)); // Get the previous saved visible state for the course module.
61 // Increment course.cacherev for courses where we just made something visible.
62 // This will force cache rebuilding on the next request.
63 increment_revision_number('course', 'cacherev',
64 "id IN (SELECT DISTINCT course
65 FROM {course_modules}
66 WHERE visible=1 AND module=?)",
67 array($module->id));
68 core_plugin_manager::reset_caches();
69 admin_get_root(true, false); // settings not required - only pages
70 redirect(new moodle_url('/admin/modules.php'));
73 echo $OUTPUT->header();
74 echo $OUTPUT->heading($stractivities);
76 /// Get and sort the existing modules
78 if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
79 print_error('moduledoesnotexist', 'error');
82 /// Print the table of all modules
83 // construct the flexible table ready to display
84 $table = new flexible_table(MODULE_TABLE);
85 $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'uninstall', 'settings'));
86 $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strsettings, $struninstall));
87 $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php');
88 $table->set_attribute('id', 'modules');
89 $table->set_attribute('class', 'admintable generaltable');
90 $table->setup();
92 $pluginmanager = core_plugin_manager::instance();
94 foreach ($modules as $module) {
95 $plugininfo = $pluginmanager->get_plugin_info('mod_'.$module->name);
96 $status = $plugininfo->get_status();
98 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
99 $strmodulename = '<span class="notifyproblem">'.$module->name.' ('.get_string('missingfromdisk').')</span>';
100 $missing = true;
101 } else {
102 // took out hspace="\10\", because it does not validate. don't know what to replace with.
103 $icon = "<img src=\"" . $OUTPUT->image_url('icon', $module->name) . "\" class=\"icon\" alt=\"\" />";
104 $strmodulename = $icon.' '.get_string('modulename', $module->name);
105 $missing = false;
108 $uninstall = '';
109 if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('mod_'.$module->name, 'manage')) {
110 $uninstall = html_writer::link($uninstallurl, $struninstall);
113 if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") ||
114 file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) {
115 $settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
116 } else {
117 $settings = "";
120 try {
121 $count = $DB->count_records_select($module->name, "course<>0");
122 } catch (dml_exception $e) {
123 $count = -1;
125 if ($count>0) {
126 $countlink = $OUTPUT->action_link(new moodle_url('/course/search.php', ['modulelist' => $module->name]),
127 $count, null, ['title' => $strshowmodulecourse]);
128 } else if ($count < 0) {
129 $countlink = get_string('error');
130 } else {
131 $countlink = "$count";
134 if ($missing) {
135 $visible = '';
136 $class = '';
137 } else if ($module->visible) {
138 $visible = "<a href=\"modules.php?hide=$module->name&amp;sesskey=".sesskey()."\" title=\"$strhide\">".
139 $OUTPUT->pix_icon('t/hide', $strhide) . '</a>';
140 $class = '';
141 } else {
142 $visible = "<a href=\"modules.php?show=$module->name&amp;sesskey=".sesskey()."\" title=\"$strshow\">".
143 $OUTPUT->pix_icon('t/show', $strshow) . '</a>';
144 $class = 'dimmed_text';
146 if ($module->name == "forum") {
147 $uninstall = "";
148 $visible = "";
149 $class = "";
151 $version = get_config('mod_'.$module->name, 'version');
153 $table->add_data(array(
154 $strmodulename,
155 $countlink,
156 $version,
157 $visible,
158 $settings,
159 $uninstall,
160 ), $class);
163 $table->print_html();
165 echo $OUTPUT->footer();