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');
8 require_once($CFG->libdir
.'/ddllib.php');
11 define('MODULE_TABLE','module_administration_table');
13 admin_externalpage_setup('managemodules');
15 $show = optional_param('show', '', PARAM_SAFEDIR
);
16 $hide = optional_param('hide', '', PARAM_SAFEDIR
);
17 $delete = optional_param('delete', '', PARAM_SAFEDIR
);
18 $confirm = optional_param('confirm', '', PARAM_BOOL
);
23 $stractivities = get_string("activities");
24 $strdelete = get_string("delete");
25 $strversion = get_string("version");
26 $strhide = get_string("hide");
27 $strshow = get_string("show");
28 $strsettings = get_string("settings");
29 $stractivities = get_string("activities");
30 $stractivitymodule = get_string("activitymodule");
31 $strshowmodulecourse = get_string('showmodulecourse');
33 /// If data submitted, then process and store.
35 if (!empty($hide) and confirm_sesskey()) {
36 if (!$module = get_record("modules", "name", $hide)) {
37 error("Module doesn't exist!");
39 set_field("modules", "visible", "0", "id", $module->id
); // Hide main module
40 // Remember the visibility status in visibleold
42 $sql = "UPDATE {$CFG->prefix}course_modules
43 SET visibleold=visible,
45 WHERE module={$module->id}";
46 execute_sql($sql, false);
47 // clear the course modinfo cache for courses
48 // where we just deleted something
49 $sql = "UPDATE {$CFG->prefix}course
51 WHERE id IN (SELECT DISTINCT course
52 FROM {$CFG->prefix}course_modules
53 WHERE visibleold=1 AND module={$module->id})";
54 execute_sql($sql, false);
55 admin_get_root(true, false); // settings not required - only pages
58 if (!empty($show) and confirm_sesskey()) {
59 if (!$module = get_record("modules", "name", $show)) {
60 error("Module doesn't exist!");
62 set_field("modules", "visible", "1", "id", $module->id
); // Show main module
63 set_field('course_modules', 'visible', '1', 'visibleold',
64 '1', 'module', $module->id
); // Get the previous saved visible state for the course module.
65 // clear the course modinfo cache for courses
66 // where we just made something visible
67 $sql = "UPDATE {$CFG->prefix}course
69 WHERE id IN (SELECT DISTINCT course
70 FROM {$CFG->prefix}course_modules
71 WHERE visible=1 AND module={$module->id})";
72 execute_sql($sql, false);
73 admin_get_root(true, false); // settings not required - only pages
76 if (!empty($delete) and confirm_sesskey()) {
77 admin_externalpage_print_header();
78 print_heading($stractivities);
80 $strmodulename = get_string("modulename", "$delete");
83 notice_yesno(get_string("moduledeleteconfirm", "", $strmodulename),
84 "modules.php?delete=$delete&confirm=1&sesskey=$USER->sesskey",
86 admin_externalpage_print_footer();
89 } else { // Delete everything!!
91 if ($delete == "forum") {
92 error("You can not delete the forum module!!");
95 if (!$module = get_record("modules", "name", $delete)) {
96 error("Module doesn't exist!");
99 // OK, first delete all the relevant instances from all course sections
100 if ($coursemods = get_records("course_modules", "module", $module->id
)) {
101 foreach ($coursemods as $coursemod) {
102 if (! delete_mod_from_section($coursemod->id
, $coursemod->section
)) {
103 notify("Could not delete the $strmodulename with id = $coursemod->id from section $coursemod->section");
108 // delete calendar events
109 if (!delete_records("event", "modulename", $delete)) {
110 notify("Error occurred while deleting all $strmodulename records in calendar event table");
113 // clear course.modinfo for courses
114 // that used this module...
115 $sql = "UPDATE {$CFG->prefix}course
117 WHERE id IN (SELECT DISTINCT course
118 FROM {$CFG->prefix}course_modules
119 WHERE module={$module->id})";
120 execute_sql($sql, false);
122 // Now delete all the course module records
123 if (!delete_records("course_modules", "module", $module->id
)) {
124 notify("Error occurred while deleting all $strmodulename records in course_modules table");
127 // Then delete all the logs
128 if (!delete_records("log", "module", $module->name
)) {
129 notify("Error occurred while deleting all $strmodulename records in log table");
132 // And log_display information
133 if (!delete_records("log_display", "module", $module->name
)) {
134 notify("Error occurred while deleting all $strmodulename records in log_display table");
137 // And the module entry itself
138 if (!delete_records("modules", "name", $module->name
)) {
139 notify("Error occurred while deleting the $strmodulename record from modules table");
142 // And the module configuration records
143 if (!execute_sql("DELETE FROM {$CFG->prefix}config WHERE name LIKE '{$module->name}_%'")) {
144 notify("Error occurred while deleting the $strmodulename records from the config table");
147 // cleanup the gradebook
148 require_once($CFG->libdir
.'/gradelib.php');
149 grade_uninstalled_module($module->name
);
151 // Then the tables themselves
152 drop_plugin_tables($module->name
, "$CFG->dirroot/mod/$module->name/db/install.xml", false);
154 // Delete the capabilities that were defined by this module
155 capabilities_cleanup('mod/'.$module->name
);
157 // remove entent handlers and dequeue pending events
158 events_uninstall('mod/'.$module->name
);
160 // Perform any custom uninstall tasks
161 if (file_exists($CFG->dirroot
. '/mod/' . $module->name
. '/lib.php')) {
162 require_once($CFG->dirroot
. '/mod/' . $module->name
. '/lib.php');
163 $uninstallfunction = $module->name
. '_uninstall';
164 if (function_exists($uninstallfunction)) {
165 if (! $uninstallfunction() ) {
166 notify('Encountered a problem running uninstall function for '. $module->name
.'!');
171 $a->module
= $strmodulename;
172 $a->directory
= "$CFG->dirroot/mod/$delete";
173 notice(get_string("moduledeletefiles", "", $a), "modules.php");
177 admin_externalpage_print_header();
178 print_heading($stractivities);
180 /// Get and sort the existing modules
182 if (!$modules = get_records("modules")) {
183 error("No modules found!!"); // Should never happen
186 foreach ($modules as $module) {
187 $strmodulename = get_string("modulename", "$module->name");
188 // Deal with modules which are lacking the language string
189 if ($strmodulename == '[[modulename]]') {
190 $strmodulename = $module->name
;
192 $modulebyname[$strmodulename] = $module;
194 ksort($modulebyname, SORT_LOCALE_STRING
);
196 /// Print the table of all modules
197 // construct the flexible table ready to display
198 $table = new flexible_table(MODULE_TABLE
);
199 $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'delete', 'settings'));
200 $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strdelete, $strsettings));
201 $table->define_baseurl($CFG->wwwroot
.'/'.$CFG->admin
.'/modules.php');
202 $table->set_attribute('id', 'modules');
203 $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
206 foreach ($modulebyname as $modulename => $module) {
208 // took out hspace="\10\", because it does not validate. don't know what to replace with.
209 $icon = "<img src=\"$CFG->modpixpath/$module->name/icon.gif\" class=\"icon\" alt=\"\" />";
211 $delete = "<a href=\"modules.php?delete=$module->name&sesskey=$USER->sesskey\">$strdelete</a>";
213 if (file_exists("$CFG->dirroot/mod/$module->name/settings.php")) {
214 $settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
215 } else if (file_exists("$CFG->dirroot/mod/$module->name/config.html")) {
216 $settings = "<a href=\"module.php?module=$module->name\">$strsettings</a>";
221 $count = count_records_select("$module->name",'course<>0');
223 $countlink = "<a href=\"{$CFG->wwwroot}/course/search.php?modulelist=$module->name" .
224 "&sesskey={$USER->sesskey}\" title=\"$strshowmodulecourse\">$count</a>";
227 $countlink = "$count";
230 if ($module->visible
) {
231 $visible = "<a href=\"modules.php?hide=$module->name&sesskey=$USER->sesskey\" title=\"$strhide\">".
232 "<img src=\"$CFG->pixpath/i/hide.gif\" class=\"icon\" alt=\"$strhide\" /></a>";
235 $visible = "<a href=\"modules.php?show=$module->name&sesskey=$USER->sesskey\" title=\"$strshow\">".
236 "<img src=\"$CFG->pixpath/i/show.gif\" class=\"icon\" alt=\"$strshow\" /></a>";
237 $class = " class=\"dimmed_text\"";
239 if ($module->name
== "forum") {
246 if (!file_exists("$CFG->dirroot/mod/$module->name/lib.php")) {
247 $extra = ' <span class="notifyproblem">('.get_string('missingfromdisk').')</span>';
250 $table->add_data(array(
251 '<span'.$class.'>'.$icon.' '.$modulename.$extra.'</span>',
253 '<span'.$class.'>'.$module->version
.'</span>',
260 $table->print_html();
262 admin_externalpage_print_footer();