2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Allows the admin to enable, disable and uninstall course formats
21 * @copyright 2012 Marina Glancy
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once('../config.php');
26 require_once($CFG->libdir
.'/adminlib.php');
27 require_once($CFG->libdir
.'/pluginlib.php');
29 $action = required_param('action', PARAM_ALPHANUMEXT
);
30 $formatname = required_param('format', PARAM_PLUGIN
);
31 $confirm = optional_param('confirm', 0, PARAM_BOOL
);
33 $syscontext = context_system
::instance();
34 $PAGE->set_url('/admin/courseformats.php');
35 $PAGE->set_context($syscontext);
38 require_capability('moodle/site:config', $syscontext);
41 $return = new moodle_url('/admin/settings.php', array('section' => 'manageformats'));
43 $allplugins = plugin_manager
::instance()->get_plugins();
44 $formatplugins = $allplugins['format'];
45 $sortorder = array_flip(array_keys($formatplugins));
47 if (!isset($formatplugins[$formatname])) {
48 print_error('courseformatnotfound', 'error', $return, $formatname);
53 if ($formatplugins[$formatname]->is_enabled()) {
54 if (get_config('moodlecourse', 'format') === $formatname) {
55 print_error('cannotdisableformat', 'error', $return);
57 set_config('disabled', 1, 'format_'. $formatname);
61 if (!$formatplugins[$formatname]->is_enabled()) {
62 unset_config('disabled', 'format_'. $formatname);
66 if ($sortorder[$formatname]) {
67 $currentindex = $sortorder[$formatname];
68 $seq = array_keys($formatplugins);
69 $seq[$currentindex] = $seq[$currentindex-1];
70 $seq[$currentindex-1] = $formatname;
71 set_config('format_plugins_sortorder', implode(',', $seq));
75 if ($sortorder[$formatname] < count($sortorder)-1) {
76 $currentindex = $sortorder[$formatname];
77 $seq = array_keys($formatplugins);
78 $seq[$currentindex] = $seq[$currentindex+
1];
79 $seq[$currentindex+
1] = $formatname;
80 set_config('format_plugins_sortorder', implode(',', $seq));
84 echo $OUTPUT->header();
85 echo $OUTPUT->heading(get_string('courseformats', 'moodle'));
87 $coursecount = $DB->count_records('course', array('format' => $formatname));
89 // Check that default format is set. It will be used to convert courses
91 $defaultformat = get_config('moodlecourse', 'format');
92 $defaultformat = $formatplugins[get_config('moodlecourse', 'format')];
93 if (!$defaultformat) {
94 echo $OUTPUT->error_text(get_string('defaultformatnotset', 'admin'));
95 echo $OUTPUT->footer();
100 $format = $formatplugins[$formatname];
101 $deleteurl = $format->get_uninstall_url();
103 // somebody was trying to cheat and type non-existing link
104 echo $OUTPUT->error_text(get_string('cannotuninstall', 'admin', $format->displayname
));
105 echo $OUTPUT->footer();
111 $message = get_string('formatuninstallwithcourses', 'admin',
112 (object)array('count' => $coursecount, 'format' => $format->displayname
,
113 'defaultformat' => $defaultformat->displayname
));
115 $message = get_string('formatuninstallconfirm', 'admin', $format->displayname
);
117 $deleteurl->param('confirm', 1);
118 echo $OUTPUT->confirm($message, $deleteurl, $return);
121 $a->plugin
= $format->displayname
;
122 $a->directory
= $format->rootdir
;
123 uninstall_plugin('format', $formatname);
124 echo $OUTPUT->notification(get_string('formatuninstalled', 'admin', $a), 'notifysuccess');
125 echo $OUTPUT->continue_button($return);
128 echo $OUTPUT->footer();