Merge branch 'MDL-70327-310' of git://github.com/cescobedo/moodle into MOODLE_310_STABLE
[moodle.git] / admin / editors.php
blob649d2f5bbed70f178b2707ab97c4e1e8c0d6f643
1 <?php
3 /**
4 * Allows admin to configure editors.
5 */
7 require_once('../config.php');
8 require_once($CFG->libdir.'/adminlib.php');
9 require_once($CFG->libdir.'/tablelib.php');
11 $action = required_param('action', PARAM_ALPHANUMEXT);
12 $editor = required_param('editor', PARAM_PLUGIN);
13 $confirm = optional_param('confirm', 0, PARAM_BOOL);
15 $PAGE->set_url('/admin/editors.php', array('action'=>$action, 'editor'=>$editor));
16 $PAGE->set_context(context_system::instance());
18 require_admin();
20 $returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageeditors";
22 // get currently installed and enabled auth plugins
23 $available_editors = editors_get_available();
24 if (!empty($editor) and empty($available_editors[$editor])) {
25 redirect ($returnurl);
28 $active_editors = explode(',', $CFG->texteditors);
29 foreach ($active_editors as $key=>$active) {
30 if (empty($available_editors[$active])) {
31 unset($active_editors[$key]);
35 ////////////////////////////////////////////////////////////////////////////////
36 // process actions
38 if (!confirm_sesskey()) {
39 redirect($returnurl);
43 $return = true;
44 switch ($action) {
45 case 'disable':
46 // remove from enabled list
47 $key = array_search($editor, $active_editors);
48 unset($active_editors[$key]);
49 add_to_config_log('editor_visibility', '1', '0', $editor);
50 break;
52 case 'enable':
53 // add to enabled list
54 if (!in_array($editor, $active_editors)) {
55 $active_editors[] = $editor;
56 $active_editors = array_unique($active_editors);
57 add_to_config_log('editor_visibility', '0', '1', $editor);
59 break;
61 case 'down':
62 $key = array_search($editor, $active_editors);
63 // check auth plugin is valid
64 if ($key !== false) {
65 // move down the list
66 if ($key < (count($active_editors) - 1)) {
67 $fsave = $active_editors[$key];
68 $active_editors[$key] = $active_editors[$key + 1];
69 $active_editors[$key + 1] = $fsave;
70 add_to_config_log('editor_position', $key, $key + 1, $editor);
73 break;
75 case 'up':
76 $key = array_search($editor, $active_editors);
77 // check auth is valid
78 if ($key !== false) {
79 // move up the list
80 if ($key >= 1) {
81 $fsave = $active_editors[$key];
82 $active_editors[$key] = $active_editors[$key - 1];
83 $active_editors[$key - 1] = $fsave;
84 add_to_config_log('editor_position', $key, $key - 1, $editor);
87 break;
89 default:
90 break;
93 // at least one editor must be active
94 if (empty($active_editors)) {
95 $active_editors = array('textarea');
98 set_config('texteditors', implode(',', $active_editors));
99 core_plugin_manager::reset_caches();
101 if ($return) {
102 redirect ($returnurl);