MDL-22015 fixed more string_manager encapsulation issues
[moodle.git] / admin / modules.php
CommitLineData
20207b82 1<?php
7f30d941 2 // Allows the admin to manage activity modules
5867bfb5 3
636c2c08 4 require_once('../config.php');
778951f8 5 require_once('../course/lib.php');
6e4dc10f 6 require_once($CFG->libdir.'/adminlib.php');
778951f8 7 require_once($CFG->libdir.'/tablelib.php');
8
9 // defines
10 define('MODULE_TABLE','module_administration_table');
11
1ae083e4 12 admin_externalpage_setup('managemodules');
5867bfb5 13
636c2c08 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);
5867bfb5 18
5867bfb5 19
20/// Print headings
21
bee4702d 22 $stractivities = get_string("activities");
5867bfb5 23 $strdelete = get_string("delete");
1e169427 24 $strversion = get_string("version");
5867bfb5 25 $strhide = get_string("hide");
26 $strshow = get_string("show");
4e299145 27 $strsettings = get_string("settings");
9bf45e00 28 $stractivities = get_string("activities");
5867bfb5 29 $stractivitymodule = get_string("activitymodule");
616ad119 30 $strshowmodulecourse = get_string('showmodulecourse');
5867bfb5 31
5867bfb5 32/// If data submitted, then process and store.
33
5ba7f1b7 34 if (!empty($hide) and confirm_sesskey()) {
b9a66360 35 if (!$module = $DB->get_record("modules", array("name"=>$hide))) {
4fd532ea 36 print_error('moduledoesnotexist', 'error');
5867bfb5 37 }
b9a66360 38 $DB->set_field("modules", "visible", "0", array("id"=>$module->id)); // Hide main module
6b6eea55 39 // Remember the visibility status in visibleold
40 // and hide...
b9a66360 41 $sql = "UPDATE {course_modules}
42 SET visibleold=visible, visible=0
43 WHERE module=?";
44 $DB->execute($sql, array($module->id));
6b6eea55 45 // clear the course modinfo cache for courses
46 // where we just deleted something
b9a66360 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));
220a90c5 53 admin_get_root(true, false); // settings not required - only pages
5867bfb5 54 }
55
5ba7f1b7 56 if (!empty($show) and confirm_sesskey()) {
b9a66360 57 if (!$module = $DB->get_record("modules", array("name"=>$show))) {
4fd532ea 58 print_error('moduledoesnotexist', 'error');
5867bfb5 59 }
b9a66360 60 $DB->set_field("modules", "visible", "1", array("id"=>$module->id)); // Show main module
73f27e16 61 $DB->set_field('course_modules', 'visible', '1', array('visibleold'=>1, 'module'=>$module->id)); // Get the previous saved visible state for the course module.
6b6eea55 62 // clear the course modinfo cache for courses
63 // where we just made something visible
b9a66360 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));
220a90c5 70 admin_get_root(true, false); // settings not required - only pages
5867bfb5 71 }
72
5ba7f1b7 73 if (!empty($delete) and confirm_sesskey()) {
61ef8f9f 74 echo $OUTPUT->header();
2fff8846 75 echo $OUTPUT->heading($stractivities);
eef868d1 76
ecd7978c
PS
77 if (get_string_manager()->string_exists('modulename', $delete)) {
78 $strmodulename = get_string('modulename', $delete);
d9a8e12d
PS
79 } else {
80 $strmodulename = $delete;
81 }
5867bfb5 82
636c2c08 83 if (!$confirm) {
414a4a91 84 echo $OUTPUT->confirm(get_string("moduledeleteconfirm", "", $strmodulename), "modules.php?delete=$delete&confirm=1", "modules.php");
73d6f52f 85 echo $OUTPUT->footer();
5867bfb5 86 exit;
87
88 } else { // Delete everything!!
89
90 if ($delete == "forum") {
e6b6b2bb 91 print_error("cannotdeleteforummodule", 'forum');
5867bfb5 92 }
93
ed996ede 94 uninstall_plugin('mod', $delete);
5867bfb5 95 $a->module = $strmodulename;
96 $a->directory = "$CFG->dirroot/mod/$delete";
e4e03fa6
PS
97 echo $OUTPUT->notification(get_string("moduledeletefiles", "", $a), 'notifysuccess');
98 echo $OUTPUT->continue_button("modules.php");
99 echo $OUTPUT->footer();
100 exit;
5867bfb5 101 }
102 }
eef868d1 103
61ef8f9f 104 echo $OUTPUT->header();
2fff8846 105 echo $OUTPUT->heading($stractivities);
220a90c5 106
5867bfb5 107/// Get and sort the existing modules
108
d9a8e12d 109 if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
4fd532ea 110 print_error('moduledoesnotexist', 'error');
5867bfb5 111 }
112
5867bfb5 113/// Print the table of all modules
778951f8 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'));
778951f8 117 $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strdelete, $strsettings));
e12d37df 118 $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php');
119 $table->set_attribute('id', 'modules');
90ea86e9 120 $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
778951f8 121 $table->setup();
5867bfb5 122
d9a8e12d 123 foreach ($modules as $module) {
5867bfb5 124
d9a8e12d
PS
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;
133 }
5867bfb5 134
973d2660 135 $delete = "<a href=\"modules.php?delete=$module->name&amp;sesskey=".sesskey()."\">$strdelete</a>";
5867bfb5 136
0a82a1bb 137 if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") ||
138 file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) {
220a90c5 139 $settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
4e299145 140 } else {
141 $settings = "";
142 }
143
b9a66360 144 $count = $DB->count_records_select($module->name, "course<>0");
616ad119 145 if ($count>0) {
146 $countlink = "<a href=\"{$CFG->wwwroot}/course/search.php?modulelist=$module->name" .
34a2faed 147 "&amp;sesskey=".sesskey()."\" title=\"$strshowmodulecourse\">$count</a>";
616ad119 148 }
149 else {
150 $countlink = "$count";
151 }
9bf45e00 152
d9a8e12d
PS
153 if ($missing) {
154 $visible = '';
155 $class = '';
156 } else if ($module->visible) {
973d2660 157 $visible = "<a href=\"modules.php?hide=$module->name&amp;sesskey=".sesskey()."\" title=\"$strhide\">".
b5d0cafc 158 "<img src=\"" . $OUTPUT->pix_url('i/hide') . "\" class=\"icon\" alt=\"$strhide\" /></a>";
d9a8e12d 159 $class = '';
5867bfb5 160 } else {
973d2660 161 $visible = "<a href=\"modules.php?show=$module->name&amp;sesskey=".sesskey()."\" title=\"$strshow\">".
b5d0cafc 162 "<img src=\"" . $OUTPUT->pix_url('i/show') . "\" class=\"icon\" alt=\"$strshow\" /></a>";
d9a8e12d 163 $class = ' class="dimmed_text"';
5867bfb5 164 }
165 if ($module->name == "forum") {
166 $delete = "";
167 $visible = "";
168 $class = "";
169 }
778951f8 170
ac42d5c6 171
778951f8 172 $table->add_data(array(
d9a8e12d 173 '<span'.$class.'>'.$strmodulename.'</span>',
220a90c5 174 $countlink,
175 '<span'.$class.'>'.$module->version.'</span>',
176 $visible,
177 $delete,
778951f8 178 $settings
179 ));
5867bfb5 180 }
5867bfb5 181
778951f8 182 $table->print_html();
5867bfb5 183
73d6f52f 184 echo $OUTPUT->footer();
5867bfb5 185
20207b82 186