MDL-41806 Add assessors to moodle_url class
[moodle.git] / admin / modules.php
blobc8f69d45f3798fd9f583b759e88e49c458b94280
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 // Purge all caches related to activity modules administration.
31 cache::make('core', 'plugininfo_mod')->purge();
33 /// If data submitted, then process and store.
35 if (!empty($hide) and confirm_sesskey()) {
36 if (!$module = $DB->get_record("modules", array("name"=>$hide))) {
37 print_error('moduledoesnotexist', 'error');
39 $DB->set_field("modules", "visible", "0", array("id"=>$module->id)); // Hide main module
40 // Remember the visibility status in visibleold
41 // and hide...
42 $sql = "UPDATE {course_modules}
43 SET visibleold=visible, visible=0
44 WHERE module=?";
45 $DB->execute($sql, array($module->id));
46 // Increment course.cacherev for courses where we just made something invisible.
47 // This will force cache rebuilding on the next request.
48 increment_revision_number('course', 'cacherev',
49 "id IN (SELECT DISTINCT course
50 FROM {course_modules}
51 WHERE visibleold=1 AND module=?)",
52 array($module->id));
53 admin_get_root(true, false); // settings not required - only pages
56 if (!empty($show) and confirm_sesskey()) {
57 if (!$module = $DB->get_record("modules", array("name"=>$show))) {
58 print_error('moduledoesnotexist', 'error');
60 $DB->set_field("modules", "visible", "1", array("id"=>$module->id)); // Show main module
61 $DB->set_field('course_modules', 'visible', '1', array('visibleold'=>1, 'module'=>$module->id)); // Get the previous saved visible state for the course module.
62 // Increment course.cacherev for courses where we just made something visible.
63 // This will force cache rebuilding on the next request.
64 increment_revision_number('course', 'cacherev',
65 "id IN (SELECT DISTINCT course
66 FROM {course_modules}
67 WHERE visible=1 AND module=?)",
68 array($module->id));
69 admin_get_root(true, false); // settings not required - only pages
72 echo $OUTPUT->header();
73 echo $OUTPUT->heading($stractivities);
75 /// Get and sort the existing modules
77 if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
78 print_error('moduledoesnotexist', 'error');
81 /// Print the table of all modules
82 // construct the flexible table ready to display
83 $table = new flexible_table(MODULE_TABLE);
84 $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'uninstall', 'settings'));
85 $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $struninstall, $strsettings));
86 $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php');
87 $table->set_attribute('id', 'modules');
88 $table->set_attribute('class', 'generaltable');
89 $table->setup();
91 foreach ($modules as $module) {
93 if (!file_exists("$CFG->dirroot/mod/$module->name/lib.php")) {
94 $strmodulename = '<span class="notifyproblem">'.$module->name.' ('.get_string('missingfromdisk').')</span>';
95 $missing = true;
96 } else {
97 // took out hspace="\10\", because it does not validate. don't know what to replace with.
98 $icon = "<img src=\"" . $OUTPUT->pix_url('icon', $module->name) . "\" class=\"icon\" alt=\"\" />";
99 $strmodulename = $icon.' '.get_string('modulename', $module->name);
100 $missing = false;
103 $uninstall = '';
104 if ($uninstallurl = plugin_manager::instance()->get_uninstall_url('mod_'.$module->name)) {
105 $uninstall = html_writer::link($uninstallurl, $struninstall);
108 if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") ||
109 file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) {
110 $settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
111 } else {
112 $settings = "";
115 try {
116 $count = $DB->count_records_select($module->name, "course<>0");
117 } catch (dml_exception $e) {
118 $count = -1;
120 if ($count>0) {
121 $countlink = "<a href=\"{$CFG->wwwroot}/course/search.php?modulelist=$module->name" .
122 "&amp;sesskey=".sesskey()."\" title=\"$strshowmodulecourse\">$count</a>";
123 } else if ($count < 0) {
124 $countlink = get_string('error');
125 } else {
126 $countlink = "$count";
129 if ($missing) {
130 $visible = '';
131 $class = '';
132 } else if ($module->visible) {
133 $visible = "<a href=\"modules.php?hide=$module->name&amp;sesskey=".sesskey()."\" title=\"$strhide\">".
134 "<img src=\"" . $OUTPUT->pix_url('t/hide') . "\" class=\"iconsmall\" alt=\"$strhide\" /></a>";
135 $class = '';
136 } else {
137 $visible = "<a href=\"modules.php?show=$module->name&amp;sesskey=".sesskey()."\" title=\"$strshow\">".
138 "<img src=\"" . $OUTPUT->pix_url('t/show') . "\" class=\"iconsmall\" alt=\"$strshow\" /></a>";
139 $class = ' class="dimmed_text"';
141 if ($module->name == "forum") {
142 $uninstall = "";
143 $visible = "";
144 $class = "";
148 $table->add_data(array(
149 '<span'.$class.'>'.$strmodulename.'</span>',
150 $countlink,
151 '<span'.$class.'>'.$module->version.'</span>',
152 $visible,
153 $uninstall,
154 $settings
158 $table->print_html();
160 echo $OUTPUT->footer();