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_SAFEDIR
);
15 $hide = optional_param('hide', '', PARAM_SAFEDIR
);
16 $delete = optional_param('delete', '', PARAM_SAFEDIR
);
17 $confirm = optional_param('confirm', '', PARAM_BOOL
);
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 /// If data submitted, then process and store.
34 if (!empty($hide) and confirm_sesskey()) {
35 if (!$module = $DB->get_record("modules", array("name"=>$hide))) {
36 print_error('moduledoesnotexist', 'error');
38 $DB->set_field("modules", "visible", "0", array("id"=>$module->id
)); // Hide main module
39 // Remember the visibility status in visibleold
41 $sql = "UPDATE {course_modules}
42 SET visibleold=visible, visible=0
44 $DB->execute($sql, array($module->id
));
45 // clear the course modinfo cache for courses
46 // where we just deleted something
47 $sql = "UPDATE {course}
49 WHERE id IN (SELECT DISTINCT course
51 WHERE visibleold=1 AND module=?)";
52 $DB->execute($sql, 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 // clear the course modinfo cache for courses
63 // where we just made something visible
64 $sql = "UPDATE {course}
66 WHERE id IN (SELECT DISTINCT course
68 WHERE visible=1 AND module=?)";
69 $DB->execute($sql, array($module->id
));
70 admin_get_root(true, false); // settings not required - only pages
73 if (!empty($delete) and confirm_sesskey()) {
74 echo $OUTPUT->header();
75 echo $OUTPUT->heading($stractivities);
77 if (get_string_manager()->string_exists('modulename', $delete)) {
78 $strmodulename = get_string('modulename', $delete);
80 $strmodulename = $delete;
84 echo $OUTPUT->confirm(get_string("moduledeleteconfirm", "", $strmodulename), "modules.php?delete=$delete&confirm=1", "modules.php");
85 echo $OUTPUT->footer();
88 } else { // Delete everything!!
90 if ($delete == "forum") {
91 print_error("cannotdeleteforummodule", 'forum');
94 uninstall_plugin('mod', $delete);
96 $a->module
= $strmodulename;
97 $a->directory
= "$CFG->dirroot/mod/$delete";
98 echo $OUTPUT->notification(get_string("moduledeletefiles", "", $a), 'notifysuccess');
99 echo $OUTPUT->continue_button("modules.php");
100 echo $OUTPUT->footer();
105 echo $OUTPUT->header();
106 echo $OUTPUT->heading($stractivities);
108 /// Get and sort the existing modules
110 if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
111 print_error('moduledoesnotexist', 'error');
114 /// Print the table of all modules
115 // construct the flexible table ready to display
116 $table = new flexible_table(MODULE_TABLE
);
117 $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'delete', 'settings'));
118 $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strdelete, $strsettings));
119 $table->define_baseurl($CFG->wwwroot
.'/'.$CFG->admin
.'/modules.php');
120 $table->set_attribute('id', 'modules');
121 $table->set_attribute('class', 'generaltable');
124 foreach ($modules as $module) {
126 if (!file_exists("$CFG->dirroot/mod/$module->name/lib.php")) {
127 $strmodulename = '<span class="notifyproblem">'.$module->name
.' ('.get_string('missingfromdisk').')</span>';
130 // took out hspace="\10\", because it does not validate. don't know what to replace with.
131 $icon = "<img src=\"" . $OUTPUT->pix_url('icon', $module->name
) . "\" class=\"icon\" alt=\"\" />";
132 $strmodulename = $icon.' '.get_string('modulename', $module->name
);
136 $delete = "<a href=\"modules.php?delete=$module->name&sesskey=".sesskey()."\">$strdelete</a>";
138 if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") ||
139 file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) {
140 $settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
146 $count = $DB->count_records_select($module->name
, "course<>0");
147 } catch (dml_exception
$e) {
151 $countlink = "<a href=\"{$CFG->wwwroot}/course/search.php?modulelist=$module->name" .
152 "&sesskey=".sesskey()."\" title=\"$strshowmodulecourse\">$count</a>";
153 } else if ($count < 0) {
154 $countlink = get_string('error');
156 $countlink = "$count";
162 } else if ($module->visible
) {
163 $visible = "<a href=\"modules.php?hide=$module->name&sesskey=".sesskey()."\" title=\"$strhide\">".
164 "<img src=\"" . $OUTPUT->pix_url('i/hide') . "\" class=\"icon\" alt=\"$strhide\" /></a>";
167 $visible = "<a href=\"modules.php?show=$module->name&sesskey=".sesskey()."\" title=\"$strshow\">".
168 "<img src=\"" . $OUTPUT->pix_url('i/show') . "\" class=\"icon\" alt=\"$strshow\" /></a>";
169 $class = ' class="dimmed_text"';
171 if ($module->name
== "forum") {
178 $table->add_data(array(
179 '<span'.$class.'>'.$strmodulename.'</span>',
181 '<span'.$class.'>'.$module->version
.'</span>',
188 $table->print_html();
190 echo $OUTPUT->footer();