MDL-28471 Further tweaks to the question flag code.
[moodle.git] / admin / modules.php
blob71e22bdb4881260d9f8e2df94bc003c352a97a64
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_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 /// 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
40 // and hide...
41 $sql = "UPDATE {course_modules}
42 SET visibleold=visible, visible=0
43 WHERE module=?";
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}
48 SET modinfo=''
49 WHERE id IN (SELECT DISTINCT course
50 FROM {course_modules}
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}
65 SET modinfo = ''
66 WHERE id IN (SELECT DISTINCT course
67 FROM {course_modules}
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);
79 } else {
80 $strmodulename = $delete;
83 if (!$confirm) {
84 echo $OUTPUT->confirm(get_string("moduledeleteconfirm", "", $strmodulename), "modules.php?delete=$delete&confirm=1", "modules.php");
85 echo $OUTPUT->footer();
86 exit;
88 } else { // Delete everything!!
90 if ($delete == "forum") {
91 print_error("cannotdeleteforummodule", 'forum');
94 uninstall_plugin('mod', $delete);
95 $a->module = $strmodulename;
96 $a->directory = "$CFG->dirroot/mod/$delete";
97 echo $OUTPUT->notification(get_string("moduledeletefiles", "", $a), 'notifysuccess');
98 echo $OUTPUT->continue_button("modules.php");
99 echo $OUTPUT->footer();
100 exit;
104 echo $OUTPUT->header();
105 echo $OUTPUT->heading($stractivities);
107 /// Get and sort the existing modules
109 if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
110 print_error('moduledoesnotexist', 'error');
113 /// Print the table of all modules
114 // construct the flexible table ready to display
115 $table = new flexible_table(MODULE_TABLE);
116 $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'delete', 'settings'));
117 $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strdelete, $strsettings));
118 $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php');
119 $table->set_attribute('id', 'modules');
120 $table->set_attribute('class', 'generaltable');
121 $table->setup();
123 foreach ($modules as $module) {
125 if (!file_exists("$CFG->dirroot/mod/$module->name/lib.php")) {
126 $strmodulename = '<span class="notifyproblem">'.$module->name.' ('.get_string('missingfromdisk').')</span>';
127 $missing = true;
128 } else {
129 // took out hspace="\10\", because it does not validate. don't know what to replace with.
130 $icon = "<img src=\"" . $OUTPUT->pix_url('icon', $module->name) . "\" class=\"icon\" alt=\"\" />";
131 $strmodulename = $icon.' '.get_string('modulename', $module->name);
132 $missing = false;
135 $delete = "<a href=\"modules.php?delete=$module->name&amp;sesskey=".sesskey()."\">$strdelete</a>";
137 if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") ||
138 file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) {
139 $settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
140 } else {
141 $settings = "";
144 try {
145 $count = $DB->count_records_select($module->name, "course<>0");
146 } catch (dml_exception $e) {
147 $count = -1;
149 if ($count>0) {
150 $countlink = "<a href=\"{$CFG->wwwroot}/course/search.php?modulelist=$module->name" .
151 "&amp;sesskey=".sesskey()."\" title=\"$strshowmodulecourse\">$count</a>";
152 } else if ($count < 0) {
153 $countlink = get_string('error');
154 } else {
155 $countlink = "$count";
158 if ($missing) {
159 $visible = '';
160 $class = '';
161 } else if ($module->visible) {
162 $visible = "<a href=\"modules.php?hide=$module->name&amp;sesskey=".sesskey()."\" title=\"$strhide\">".
163 "<img src=\"" . $OUTPUT->pix_url('i/hide') . "\" class=\"icon\" alt=\"$strhide\" /></a>";
164 $class = '';
165 } else {
166 $visible = "<a href=\"modules.php?show=$module->name&amp;sesskey=".sesskey()."\" title=\"$strshow\">".
167 "<img src=\"" . $OUTPUT->pix_url('i/show') . "\" class=\"icon\" alt=\"$strshow\" /></a>";
168 $class = ' class="dimmed_text"';
170 if ($module->name == "forum") {
171 $delete = "";
172 $visible = "";
173 $class = "";
177 $table->add_data(array(
178 '<span'.$class.'>'.$strmodulename.'</span>',
179 $countlink,
180 '<span'.$class.'>'.$module->version.'</span>',
181 $visible,
182 $delete,
183 $settings
187 $table->print_html();
189 echo $OUTPUT->footer();