Merge branch 'MDL-67731-37' of https://github.com/paulholden/moodle into MOODLE_37_STABLE
[moodle.git] / admin / modules.php
blob01f67a11666a91aaef4970e44a465c4ee5682b88
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
54 if (!empty($show) and confirm_sesskey()) {
55 if (!$module = $DB->get_record("modules", array("name"=>$show))) {
56 print_error('moduledoesnotexist', 'error');
58 $DB->set_field("modules", "visible", "1", array("id"=>$module->id)); // Show main module
59 $DB->set_field('course_modules', 'visible', '1', array('visibleold'=>1, 'module'=>$module->id)); // Get the previous saved visible state for the course module.
60 // Increment course.cacherev for courses where we just made something visible.
61 // This will force cache rebuilding on the next request.
62 increment_revision_number('course', 'cacherev',
63 "id IN (SELECT DISTINCT course
64 FROM {course_modules}
65 WHERE visible=1 AND module=?)",
66 array($module->id));
67 core_plugin_manager::reset_caches();
68 admin_get_root(true, false); // settings not required - only pages
71 echo $OUTPUT->header();
72 echo $OUTPUT->heading($stractivities);
74 /// Get and sort the existing modules
76 if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
77 print_error('moduledoesnotexist', 'error');
80 /// Print the table of all modules
81 // construct the flexible table ready to display
82 $table = new flexible_table(MODULE_TABLE);
83 $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'uninstall', 'settings'));
84 $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strsettings, $struninstall));
85 $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php');
86 $table->set_attribute('id', 'modules');
87 $table->set_attribute('class', 'admintable generaltable');
88 $table->setup();
90 $pluginmanager = core_plugin_manager::instance();
92 foreach ($modules as $module) {
93 $plugininfo = $pluginmanager->get_plugin_info('mod_'.$module->name);
94 $status = $plugininfo->get_status();
96 if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
97 $strmodulename = '<span class="notifyproblem">'.$module->name.' ('.get_string('missingfromdisk').')</span>';
98 $missing = true;
99 } else {
100 // took out hspace="\10\", because it does not validate. don't know what to replace with.
101 $icon = "<img src=\"" . $OUTPUT->image_url('icon', $module->name) . "\" class=\"icon\" alt=\"\" />";
102 $strmodulename = $icon.' '.get_string('modulename', $module->name);
103 $missing = false;
106 $uninstall = '';
107 if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('mod_'.$module->name, 'manage')) {
108 $uninstall = html_writer::link($uninstallurl, $struninstall);
111 if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") ||
112 file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) {
113 $settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
114 } else {
115 $settings = "";
118 try {
119 $count = $DB->count_records_select($module->name, "course<>0");
120 } catch (dml_exception $e) {
121 $count = -1;
123 if ($count>0) {
124 $countlink = "<a href=\"{$CFG->wwwroot}/course/search.php?modulelist=$module->name" .
125 "&amp;sesskey=".sesskey()."\" title=\"$strshowmodulecourse\">$count</a>";
126 } else if ($count < 0) {
127 $countlink = get_string('error');
128 } else {
129 $countlink = "$count";
132 if ($missing) {
133 $visible = '';
134 $class = '';
135 } else if ($module->visible) {
136 $visible = "<a href=\"modules.php?hide=$module->name&amp;sesskey=".sesskey()."\" title=\"$strhide\">".
137 $OUTPUT->pix_icon('t/hide', $strhide) . '</a>';
138 $class = '';
139 } else {
140 $visible = "<a href=\"modules.php?show=$module->name&amp;sesskey=".sesskey()."\" title=\"$strshow\">".
141 $OUTPUT->pix_icon('t/show', $strshow) . '</a>';
142 $class = 'dimmed_text';
144 if ($module->name == "forum") {
145 $uninstall = "";
146 $visible = "";
147 $class = "";
149 $version = get_config('mod_'.$module->name, 'version');
151 $table->add_data(array(
152 $strmodulename,
153 $countlink,
154 $version,
155 $visible,
156 $settings,
157 $uninstall,
158 ), $class);
161 $table->print_html();
163 echo $OUTPUT->footer();