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');
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
);
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
39 $sql = "UPDATE {course_modules}
40 SET visibleold=visible, visible=0
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
48 WHERE visibleold=1 AND module=?)",
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
66 WHERE visible=1 AND module=?)",
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');
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>';
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
);
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>";
121 $count = $DB->count_records_select($module->name
, "course<>0");
122 } catch (dml_exception
$e) {
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');
131 $countlink = "$count";
137 } else if ($module->visible
) {
138 $visible = "<a href=\"modules.php?hide=$module->name&sesskey=".sesskey()."\" title=\"$strhide\">".
139 $OUTPUT->pix_icon('t/hide', $strhide) . '</a>';
142 $visible = "<a href=\"modules.php?show=$module->name&sesskey=".sesskey()."\" title=\"$strshow\">".
143 $OUTPUT->pix_icon('t/show', $strshow) . '</a>';
144 $class = 'dimmed_text';
146 if ($module->name
== "forum") {
151 $version = get_config('mod_'.$module->name
, 'version');
153 $table->add_data(array(
163 $table->print_html();
165 echo $OUTPUT->footer();