MDL-42551 timezone info: updated to 2013h
[moodle.git] / admin / courseformats.php
blobfddcdda750fd40a47da93243442225ae73727521
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * Allows the admin to enable, disable and uninstall course formats
20 * @package core_admin
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);
37 require_login();
38 require_capability('moodle/site:config', $syscontext);
39 require_sesskey();
41 $return = new moodle_url('/admin/settings.php', array('section' => 'manageformats'));
43 $formatplugins = plugin_manager::instance()->get_plugins_of_type('format');
44 $sortorder = array_flip(array_keys($formatplugins));
46 if (!isset($formatplugins[$formatname])) {
47 print_error('courseformatnotfound', 'error', $return, $formatname);
50 switch ($action) {
51 case 'disable':
52 if ($formatplugins[$formatname]->is_enabled()) {
53 if (get_config('moodlecourse', 'format') === $formatname) {
54 print_error('cannotdisableformat', 'error', $return);
56 set_config('disabled', 1, 'format_'. $formatname);
58 break;
59 case 'enable':
60 if (!$formatplugins[$formatname]->is_enabled()) {
61 unset_config('disabled', 'format_'. $formatname);
63 break;
64 case 'up':
65 if ($sortorder[$formatname]) {
66 $currentindex = $sortorder[$formatname];
67 $seq = array_keys($formatplugins);
68 $seq[$currentindex] = $seq[$currentindex-1];
69 $seq[$currentindex-1] = $formatname;
70 set_config('format_plugins_sortorder', implode(',', $seq));
72 break;
73 case 'down':
74 if ($sortorder[$formatname] < count($sortorder)-1) {
75 $currentindex = $sortorder[$formatname];
76 $seq = array_keys($formatplugins);
77 $seq[$currentindex] = $seq[$currentindex+1];
78 $seq[$currentindex+1] = $formatname;
79 set_config('format_plugins_sortorder', implode(',', $seq));
81 break;
82 case 'uninstall':
83 echo $OUTPUT->header();
84 echo $OUTPUT->heading(get_string('courseformats', 'moodle'));
86 $coursecount = $DB->count_records('course', array('format' => $formatname));
87 if ($coursecount) {
88 // Check that default format is set. It will be used to convert courses
89 // using this format
90 $defaultformat = get_config('moodlecourse', 'format');
91 $defaultformat = $formatplugins[get_config('moodlecourse', 'format')];
92 if (!$defaultformat) {
93 echo $OUTPUT->error_text(get_string('defaultformatnotset', 'admin'));
94 echo $OUTPUT->footer();
95 exit;
99 $format = $formatplugins[$formatname];
100 $deleteurl = $format->get_uninstall_url();
101 if (!$deleteurl) {
102 // somebody was trying to cheat and type non-existing link
103 echo $OUTPUT->error_text(get_string('cannotuninstall', 'admin', $format->displayname));
104 echo $OUTPUT->footer();
105 exit;
108 if (!$confirm) {
109 if ($coursecount) {
110 $message = get_string('formatuninstallwithcourses', 'admin',
111 (object)array('count' => $coursecount, 'format' => $format->displayname,
112 'defaultformat' => $defaultformat->displayname));
113 } else {
114 $message = get_string('formatuninstallconfirm', 'admin', $format->displayname);
116 $deleteurl->param('confirm', 1);
117 echo $OUTPUT->confirm($message, $deleteurl, $return);
118 } else {
119 $a = new stdClass();
120 $a->plugin = $format->displayname;
121 $a->directory = $format->rootdir;
122 uninstall_plugin('format', $formatname);
123 echo $OUTPUT->notification(get_string('formatuninstalled', 'admin', $a), 'notifysuccess');
124 echo $OUTPUT->continue_button($return);
127 echo $OUTPUT->footer();
128 exit;
130 redirect($return);