Merge branch 'wip-mdl-41843-m25' of git://github.com/rajeshtaneja/moodle into MOODLE_...
[moodle.git] / admin / modules.php
blob33d2fbbff4e470e466046eef9237468b260df7d4
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_PLUGIN);
15 $hide = optional_param('hide', '', PARAM_PLUGIN);
16 $delete = optional_param('delete', '', PARAM_PLUGIN);
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 // Purge all caches related to activity modules administration.
33 cache::make('core', 'plugininfo_mod')->purge();
35 /// If data submitted, then process and store.
37 if (!empty($hide) and confirm_sesskey()) {
38 if (!$module = $DB->get_record("modules", array("name"=>$hide))) {
39 print_error('moduledoesnotexist', 'error');
41 $DB->set_field("modules", "visible", "0", array("id"=>$module->id)); // Hide main module
42 // Remember the visibility status in visibleold
43 // and hide...
44 $sql = "UPDATE {course_modules}
45 SET visibleold=visible, visible=0
46 WHERE module=?";
47 $DB->execute($sql, array($module->id));
48 // clear the course modinfo cache for courses
49 // where we just deleted something
50 $sql = "UPDATE {course}
51 SET modinfo=''
52 WHERE id IN (SELECT DISTINCT course
53 FROM {course_modules}
54 WHERE visibleold=1 AND module=?)";
55 $DB->execute($sql, array($module->id));
56 admin_get_root(true, false); // settings not required - only pages
59 if (!empty($show) and confirm_sesskey()) {
60 if (!$module = $DB->get_record("modules", array("name"=>$show))) {
61 print_error('moduledoesnotexist', 'error');
63 $DB->set_field("modules", "visible", "1", array("id"=>$module->id)); // Show main module
64 $DB->set_field('course_modules', 'visible', '1', array('visibleold'=>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 {course}
68 SET modinfo = ''
69 WHERE id IN (SELECT DISTINCT course
70 FROM {course_modules}
71 WHERE visible=1 AND module=?)";
72 $DB->execute($sql, array($module->id));
73 admin_get_root(true, false); // settings not required - only pages
76 if (!empty($delete) and confirm_sesskey()) {
77 echo $OUTPUT->header();
78 echo $OUTPUT->heading($stractivities);
80 if (get_string_manager()->string_exists('modulename', $delete)) {
81 $strmodulename = get_string('modulename', $delete);
82 } else {
83 $strmodulename = $delete;
86 if (!$confirm) {
87 echo $OUTPUT->confirm(get_string("moduledeleteconfirm", "", $strmodulename), "modules.php?delete=$delete&confirm=1", "modules.php");
88 echo $OUTPUT->footer();
89 exit;
91 } else { // Delete everything!!
93 if ($delete == "forum") {
94 print_error("cannotdeleteforummodule", 'forum');
97 uninstall_plugin('mod', $delete);
98 $a = new stdClass();
99 $a->module = $strmodulename;
100 $a->directory = "$CFG->dirroot/mod/$delete";
101 echo $OUTPUT->notification(get_string("moduledeletefiles", "", $a), 'notifysuccess');
102 echo $OUTPUT->continue_button("modules.php");
103 echo $OUTPUT->footer();
104 exit;
108 echo $OUTPUT->header();
109 echo $OUTPUT->heading($stractivities);
111 /// Get and sort the existing modules
113 if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
114 print_error('moduledoesnotexist', 'error');
117 /// Print the table of all modules
118 // construct the flexible table ready to display
119 $table = new flexible_table(MODULE_TABLE);
120 $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'delete', 'settings'));
121 $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strdelete, $strsettings));
122 $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php');
123 $table->set_attribute('id', 'modules');
124 $table->set_attribute('class', 'generaltable');
125 $table->setup();
127 foreach ($modules as $module) {
129 if (!file_exists("$CFG->dirroot/mod/$module->name/lib.php")) {
130 $strmodulename = '<span class="notifyproblem">'.$module->name.' ('.get_string('missingfromdisk').')</span>';
131 $missing = true;
132 } else {
133 // took out hspace="\10\", because it does not validate. don't know what to replace with.
134 $icon = "<img src=\"" . $OUTPUT->pix_url('icon', $module->name) . "\" class=\"icon\" alt=\"\" />";
135 $strmodulename = $icon.' '.get_string('modulename', $module->name);
136 $missing = false;
139 $delete = "<a href=\"modules.php?delete=$module->name&amp;sesskey=".sesskey()."\">$strdelete</a>";
141 if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") ||
142 file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) {
143 $settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
144 } else {
145 $settings = "";
148 try {
149 $count = $DB->count_records_select($module->name, "course<>0");
150 } catch (dml_exception $e) {
151 $count = -1;
153 if ($count>0) {
154 $countlink = "<a href=\"{$CFG->wwwroot}/course/search.php?modulelist=$module->name" .
155 "&amp;sesskey=".sesskey()."\" title=\"$strshowmodulecourse\">$count</a>";
156 } else if ($count < 0) {
157 $countlink = get_string('error');
158 } else {
159 $countlink = "$count";
162 if ($missing) {
163 $visible = '';
164 $class = '';
165 } else if ($module->visible) {
166 $visible = "<a href=\"modules.php?hide=$module->name&amp;sesskey=".sesskey()."\" title=\"$strhide\">".
167 "<img src=\"" . $OUTPUT->pix_url('t/hide') . "\" class=\"iconsmall\" alt=\"$strhide\" /></a>";
168 $class = '';
169 } else {
170 $visible = "<a href=\"modules.php?show=$module->name&amp;sesskey=".sesskey()."\" title=\"$strshow\">".
171 "<img src=\"" . $OUTPUT->pix_url('t/show') . "\" class=\"iconsmall\" alt=\"$strshow\" /></a>";
172 $class = ' class="dimmed_text"';
174 if ($module->name == "forum") {
175 $delete = "";
176 $visible = "";
177 $class = "";
181 $table->add_data(array(
182 '<span'.$class.'>'.$strmodulename.'</span>',
183 $countlink,
184 '<span'.$class.'>'.$module->version.'</span>',
185 $visible,
186 $delete,
187 $settings
191 $table->print_html();
193 echo $OUTPUT->footer();