MDL-41311 tool_generator: remove legacy code
[moodle.git] / admin / modules.php
blob8eab4bc50a68c061e3d35a80dd70776402e1d0ed
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 // clear the course modinfo cache for courses
47 // where we just uninstalld something
48 $sql = "UPDATE {course}
49 SET modinfo=''
50 WHERE id IN (SELECT DISTINCT course
51 FROM {course_modules}
52 WHERE visibleold=1 AND module=?)";
53 $DB->execute($sql, array($module->id));
54 admin_get_root(true, false); // settings not required - only pages
57 if (!empty($show) and confirm_sesskey()) {
58 if (!$module = $DB->get_record("modules", array("name"=>$show))) {
59 print_error('moduledoesnotexist', 'error');
61 $DB->set_field("modules", "visible", "1", array("id"=>$module->id)); // Show main module
62 $DB->set_field('course_modules', 'visible', '1', array('visibleold'=>1, 'module'=>$module->id)); // Get the previous saved visible state for the course module.
63 // clear the course modinfo cache for courses
64 // where we just made something visible
65 $sql = "UPDATE {course}
66 SET modinfo = ''
67 WHERE id IN (SELECT DISTINCT course
68 FROM {course_modules}
69 WHERE visible=1 AND module=?)";
70 $DB->execute($sql, array($module->id));
71 admin_get_root(true, false); // settings not required - only pages
74 echo $OUTPUT->header();
75 echo $OUTPUT->heading($stractivities);
77 /// Get and sort the existing modules
79 if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
80 print_error('moduledoesnotexist', 'error');
83 /// Print the table of all modules
84 // construct the flexible table ready to display
85 $table = new flexible_table(MODULE_TABLE);
86 $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'uninstall', 'settings'));
87 $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $struninstall, $strsettings));
88 $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php');
89 $table->set_attribute('id', 'modules');
90 $table->set_attribute('class', 'generaltable');
91 $table->setup();
93 foreach ($modules as $module) {
95 if (!file_exists("$CFG->dirroot/mod/$module->name/lib.php")) {
96 $strmodulename = '<span class="notifyproblem">'.$module->name.' ('.get_string('missingfromdisk').')</span>';
97 $missing = true;
98 } else {
99 // took out hspace="\10\", because it does not validate. don't know what to replace with.
100 $icon = "<img src=\"" . $OUTPUT->pix_url('icon', $module->name) . "\" class=\"icon\" alt=\"\" />";
101 $strmodulename = $icon.' '.get_string('modulename', $module->name);
102 $missing = false;
105 $uninstall = '';
106 if ($uninstallurl = plugin_manager::instance()->get_uninstall_url('mod_'.$module->name)) {
107 $uninstall = html_writer::link($uninstallurl, $struninstall);
110 if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") ||
111 file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) {
112 $settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
113 } else {
114 $settings = "";
117 try {
118 $count = $DB->count_records_select($module->name, "course<>0");
119 } catch (dml_exception $e) {
120 $count = -1;
122 if ($count>0) {
123 $countlink = "<a href=\"{$CFG->wwwroot}/course/search.php?modulelist=$module->name" .
124 "&amp;sesskey=".sesskey()."\" title=\"$strshowmodulecourse\">$count</a>";
125 } else if ($count < 0) {
126 $countlink = get_string('error');
127 } else {
128 $countlink = "$count";
131 if ($missing) {
132 $visible = '';
133 $class = '';
134 } else if ($module->visible) {
135 $visible = "<a href=\"modules.php?hide=$module->name&amp;sesskey=".sesskey()."\" title=\"$strhide\">".
136 "<img src=\"" . $OUTPUT->pix_url('t/hide') . "\" class=\"iconsmall\" alt=\"$strhide\" /></a>";
137 $class = '';
138 } else {
139 $visible = "<a href=\"modules.php?show=$module->name&amp;sesskey=".sesskey()."\" title=\"$strshow\">".
140 "<img src=\"" . $OUTPUT->pix_url('t/show') . "\" class=\"iconsmall\" alt=\"$strshow\" /></a>";
141 $class = ' class="dimmed_text"';
143 if ($module->name == "forum") {
144 $uninstall = "";
145 $visible = "";
146 $class = "";
150 $table->add_data(array(
151 '<span'.$class.'>'.$strmodulename.'</span>',
152 $countlink,
153 '<span'.$class.'>'.$module->version.'</span>',
154 $visible,
155 $uninstall,
156 $settings
160 $table->print_html();
162 echo $OUTPUT->footer();