adding current groupid to grade_export class - soon to be used in plugins
[moodle-pu.git] / admin / modules.php
blob7e5e32a35eb964d86b11bb22db094709b60f677c
1 <?PHP // $Id$
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_SAFEDIR);
15 $hide = optional_param('hide', '', PARAM_SAFEDIR);
16 $delete = optional_param('delete', '', PARAM_SAFEDIR);
17 $confirm = optional_param('confirm', '', PARAM_BOOL);
20 /// Print headings
22 $stractivities = get_string("activities");
23 $strdelete = get_string("delete");
24 $strversion = get_string("version");
25 $strhide = get_string("hide");
26 $strshow = get_string("show");
27 $strsettings = get_string("settings");
28 $stractivities = get_string("activities");
29 $stractivitymodule = get_string("activitymodule");
30 $strshowmodulecourse = get_string('showmodulecourse');
32 admin_externalpage_print_header();
34 print_heading($stractivities);
36 $coursesaffected = false;
39 /// If data submitted, then process and store.
41 if (!empty($hide) and confirm_sesskey()) {
42 if (!$module = get_record("modules", "name", $hide)) {
43 error("Module doesn't exist!");
45 set_field("modules", "visible", "0", "id", $module->id); // Hide main module
46 set_field('course_modules', 'visibleold', '1', 'visible' ,'1', 'module', $module->id); // Remember the previous visible state so we can toggle this back if the module is unhidden.
47 set_field('course_modules', 'visibleold', '0', 'visible' ,'0', 'module', $module->id);
48 set_field("course_modules", "visible", "0", "module", $module->id); // Hide all related activity modules
49 $coursesaffected = true;
52 if (!empty($show) and confirm_sesskey()) {
53 if (!$module = get_record("modules", "name", $show)) {
54 error("Module doesn't exist!");
56 set_field("modules", "visible", "1", "id", $module->id); // Show main module
57 set_field('course_modules', 'visible', '1', 'visibleold', '1', 'module', $module->id); // Get the previous saved visible state for the course module.
58 $coursesaffected = true;
61 if (!empty($delete) and confirm_sesskey()) {
63 $strmodulename = get_string("modulename", "$delete");
65 if (!$confirm) {
66 notice_yesno(get_string("moduledeleteconfirm", "", $strmodulename),
67 "modules.php?delete=$delete&amp;confirm=1&amp;sesskey=$USER->sesskey",
68 "modules.php");
69 admin_externalpage_print_footer();
70 exit;
72 } else { // Delete everything!!
74 if ($delete == "forum") {
75 error("You can not delete the forum module!!");
78 if (!$module = get_record("modules", "name", $delete)) {
79 error("Module doesn't exist!");
82 // OK, first delete all the relevant instances from all course sections
83 if ($coursemods = get_records("course_modules", "module", $module->id)) {
84 foreach ($coursemods as $coursemod) {
85 if (! delete_mod_from_section($coursemod->id, $coursemod->section)) {
86 notify("Could not delete the $strmodulename with id = $coursemod->id from section $coursemod->section");
91 // Now delete all the course module records
92 if (!delete_records("course_modules", "module", $module->id)) {
93 notify("Error occurred while deleting all $strmodulename records in course_modules table");
96 // Then delete all the logs
97 if (!delete_records("log", "module", $module->name)) {
98 notify("Error occurred while deleting all $strmodulename records in log table");
101 // And log_display information
102 if (!delete_records("log_display", "module", $module->name)) {
103 notify("Error occurred while deleting all $strmodulename records in log_display table");
106 // And the module entry itself
107 if (!delete_records("modules", "name", $module->name)) {
108 notify("Error occurred while deleting the $strmodulename record from modules table");
111 // And the module configuration records
112 if (!execute_sql("DELETE FROM {$CFG->prefix}config WHERE name LIKE '{$module->name}_%'")) {
113 notify("Error occurred while deleting the $strmodulename records from the config table");
116 // Then the tables themselves
118 if ($tables = $db->Metatables()) {
119 $prefix = $CFG->prefix.$module->name;
120 foreach ($tables as $table) {
121 if (strpos($table, $prefix) === 0) {
122 if (!execute_sql("DROP TABLE $table", false)) {
123 notify("ERROR: while trying to drop table $table");
128 // Delete the capabilities that were defined by this module
129 capabilities_cleanup('mod/'.$module->name);
131 // remove entent handlers and dequeue pending events
132 events_uninstall('mod/'.$module->name);
134 // rebuild_course_cache(); // Because things have changed
135 $coursesaffected = true;
137 $a->module = $strmodulename;
138 $a->directory = "$CFG->dirroot/mod/$delete";
139 notice(get_string("moduledeletefiles", "", $a), "modules.php");
143 if ($coursesaffected) {
144 rebuild_course_cache(); // Because things have changed
148 /// Get and sort the existing modules
150 if (!$modules = get_records("modules")) {
151 error("No modules found!!"); // Should never happen
154 foreach ($modules as $module) {
155 $strmodulename = get_string("modulename", "$module->name");
156 // Deal with modules which are lacking the language string
157 if ($strmodulename == '[[modulename]]') {
158 $strmodulename = $module->name;
160 $modulebyname[$strmodulename] = $module;
162 ksort($modulebyname);
164 /// Print the table of all modules
165 // construct the flexible table ready to display
166 $table = new flexible_table(MODULE_TABLE);
167 $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'delete', 'settings'));
168 $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strdelete, $strsettings));
169 $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php');
170 $table->set_attribute('id', 'modules');
171 $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
172 $table->setup();
174 foreach ($modulebyname as $modulename => $module) {
176 // took out hspace="\10\", because it does not validate. don't know what to replace with.
177 $icon = "<img src=\"$CFG->modpixpath/$module->name/icon.gif\" class=\"icon\" alt=\"\" />";
179 $delete = "<a href=\"modules.php?delete=$module->name&amp;sesskey=$USER->sesskey\">$strdelete</a>";
181 if (file_exists("$CFG->dirroot/mod/$module->name/config.html")) {
182 $settings = "<a href=\"module.php?module=$module->name\">$strsettings</a>";
183 } else {
184 $settings = "";
187 $count = count_records_select("$module->name",'course<>0');
188 if ($count>0) {
189 $countlink = "<a href=\"{$CFG->wwwroot}/course/search.php?modulelist=$module->name" .
190 "&amp;sesskey={$USER->sesskey}\" title=\"$strshowmodulecourse\">$count</a>";
192 else {
193 $countlink = "$count";
196 if ($module->visible) {
197 $visible = "<a href=\"modules.php?hide=$module->name&amp;sesskey=$USER->sesskey\" title=\"$strhide\">".
198 "<img src=\"$CFG->pixpath/i/hide.gif\" class=\"icon\" alt=\"$strhide\" /></a>";
199 $class = "";
200 } else {
201 $visible = "<a href=\"modules.php?show=$module->name&amp;sesskey=$USER->sesskey\" title=\"$strshow\">".
202 "<img src=\"$CFG->pixpath/i/show.gif\" class=\"icon\" alt=\"$strshow\" /></a>";
203 $class = " class=\"dimmed_text\"";
205 if ($module->name == "forum") {
206 $delete = "";
207 $visible = "";
208 $class = "";
211 $table->add_data(array(
212 '<span'.$class.'>'.$icon.' '.$modulename.'</span>',
213 $countlink,
214 '<span'.$class.'>'.$module->version.'</span>',
215 $visible,
216 $delete,
217 $settings
221 $table->print_html();
223 admin_externalpage_print_footer();