Merge branch 'MDL-61801-33' of git://github.com/andrewnicols/moodle into MOODLE_33_STABLE
[moodle.git] / admin / media.php
blobd6886a080fb3d84ff5e4fe289df2dfcab0fcbc7d
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 * Enrol config manipulation script.
20 * @package core
21 * @subpackage media
22 * @copyright 2016 Marina Glancy
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 define('NO_OUTPUT_BUFFERING', true);
28 require_once('../config.php');
29 require_once($CFG->libdir.'/adminlib.php');
31 $action = required_param('action', PARAM_ALPHANUMEXT);
32 $media = required_param('media', PARAM_PLUGIN);
33 $confirm = optional_param('confirm', 0, PARAM_BOOL);
35 $PAGE->set_url('/admin/media.php');
36 $PAGE->set_context(context_system::instance());
38 require_login();
39 require_capability('moodle/site:config', context_system::instance());
40 require_sesskey();
42 $plugins = core_plugin_manager::instance()->get_plugins_of_type('media');
43 $sortorder = array_values(\core\plugininfo\media::get_enabled_plugins());
45 $return = new moodle_url('/admin/settings.php', array('section' => 'managemediaplayers'));
47 if (!array_key_exists($media, $plugins)) {
48 redirect($return);
51 switch ($action) {
52 case 'disable':
53 $plugins[$media]->set_enabled(false);
54 break;
56 case 'enable':
57 $plugins[$media]->set_enabled(true);
58 break;
60 case 'up':
61 if (($pos = array_search($media, $sortorder)) > 0) {
62 $tmp = $sortorder[$pos - 1];
63 $sortorder[$pos - 1] = $sortorder[$pos];
64 $sortorder[$pos] = $tmp;
65 \core\plugininfo\media::set_enabled_plugins($sortorder);
67 break;
69 case 'down':
70 if ((($pos = array_search($media, $sortorder)) !== false) && ($pos < count($sortorder) - 1)) {
71 $tmp = $sortorder[$pos + 1];
72 $sortorder[$pos + 1] = $sortorder[$pos];
73 $sortorder[$pos] = $tmp;
74 \core\plugininfo\media::set_enabled_plugins($sortorder);
76 break;
79 redirect($return);