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. |
---|
13 | // |
---|
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/>. |
---|
16 | |
---|
17 | /** |
---|
18 | * Enrol config manipulation script. |
---|
19 | * |
---|
20 | * @package core |
---|
21 | * @subpackage enrol |
---|
22 | * @copyright 2010 Petr Skoda {@link http://skodak.org} |
---|
23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
---|
24 | */ |
---|
25 | |
---|
26 | define('NO_OUTPUT_BUFFERING', true); |
---|
27 | |
---|
28 | require_once('../config.php'); |
---|
29 | require_once($CFG->libdir.'/adminlib.php'); |
---|
30 | |
---|
31 | $action = required_param('action', PARAM_ALPHANUMEXT); |
---|
32 | $enrol = required_param('enrol', PARAM_PLUGIN); |
---|
33 | $confirm = optional_param('confirm', 0, PARAM_BOOL); |
---|
34 | |
---|
35 | $PAGE->set_url('/admin/enrol.php'); |
---|
36 | $PAGE->set_context(context_system::instance()); |
---|
37 | |
---|
38 | require_login(); |
---|
39 | require_capability('moodle/site:config', context_system::instance()); |
---|
40 | require_sesskey(); |
---|
41 | |
---|
42 | $enabled = enrol_get_plugins(true); |
---|
43 | $all = enrol_get_plugins(false); |
---|
44 | |
---|
45 | $return = new moodle_url('/admin/settings.php', array('section'=>'manageenrols')); |
---|
46 | |
---|
47 | $syscontext = context_system::instance(); |
---|
48 | |
---|
49 | switch ($action) { |
---|
50 | case 'disable': |
---|
51 | unset($enabled[$enrol]); |
---|
52 | set_config('enrol_plugins_enabled', implode(',', array_keys($enabled))); |
---|
53 | core_plugin_manager::reset_caches(); |
---|
54 | $syscontext->mark_dirty(); // resets all enrol caches |
---|
55 | break; |
---|
56 | |
---|
57 | case 'enable': |
---|
58 | if (!isset($all[$enrol])) { |
---|
59 | break; |
---|
60 | } |
---|
61 | $enabled = array_keys($enabled); |
---|
62 | $enabled[] = $enrol; |
---|
63 | set_config('enrol_plugins_enabled', implode(',', $enabled)); |
---|
64 | core_plugin_manager::reset_caches(); |
---|
65 | $syscontext->mark_dirty(); // resets all enrol caches |
---|
66 | break; |
---|
67 | |
---|
68 | case 'up': |
---|
69 | if (!isset($enabled[$enrol])) { |
---|
70 | break; |
---|
71 | } |
---|
72 | $enabled = array_keys($enabled); |
---|
73 | $enabled = array_flip($enabled); |
---|
74 | $current = $enabled[$enrol]; |
---|
75 | if ($current == 0) { |
---|
76 | break; //already at the top |
---|
77 | } |
---|
78 | $enabled = array_flip($enabled); |
---|
79 | $enabled[$current] = $enabled[$current - 1]; |
---|
80 | $enabled[$current - 1] = $enrol; |
---|
81 | set_config('enrol_plugins_enabled', implode(',', $enabled)); |
---|
82 | break; |
---|
83 | |
---|
84 | case 'down': |
---|
85 | if (!isset($enabled[$enrol])) { |
---|
86 | break; |
---|
87 | } |
---|
88 | $enabled = array_keys($enabled); |
---|
89 | $enabled = array_flip($enabled); |
---|
90 | $current = $enabled[$enrol]; |
---|
91 | if ($current == count($enabled) - 1) { |
---|
92 | break; //already at the end |
---|
93 | } |
---|
94 | $enabled = array_flip($enabled); |
---|
95 | $enabled[$current] = $enabled[$current + 1]; |
---|
96 | $enabled[$current + 1] = $enrol; |
---|
97 | set_config('enrol_plugins_enabled', implode(',', $enabled)); |
---|
98 | break; |
---|
99 | |
---|
100 | case 'migrate': |
---|
101 | if (get_string_manager()->string_exists('pluginname', 'enrol_'.$enrol)) { |
---|
102 | $strplugin = get_string('pluginname', 'enrol_'.$enrol); |
---|
103 | } else { |
---|
104 | $strplugin = $enrol; |
---|
105 | } |
---|
106 | |
---|
107 | $PAGE->set_title($strplugin); |
---|
108 | echo $OUTPUT->header(); |
---|
109 | |
---|
110 | // This may take a long time. |
---|
111 | core_php_time_limit::raise(); |
---|
112 | |
---|
113 | // Disable plugin to prevent concurrent cron execution. |
---|
114 | unset($enabled[$enrol]); |
---|
115 | set_config('enrol_plugins_enabled', implode(',', array_keys($enabled))); |
---|
116 | |
---|
117 | echo $OUTPUT->heading(get_string('uninstallmigrating', 'enrol', 'enrol_'.$enrol)); |
---|
118 | |
---|
119 | require_once("$CFG->dirroot/enrol/manual/locallib.php"); |
---|
120 | enrol_manual_migrate_plugin_enrolments($enrol); |
---|
121 | |
---|
122 | echo $OUTPUT->notification(get_string('success'), 'notifysuccess'); |
---|
123 | |
---|
124 | if (!$return = core_plugin_manager::instance()->get_uninstall_url('enrol_'.$enrol, 'manage')) { |
---|
125 | $return = new moodle_url('/admin/plugins.php'); |
---|
126 | } |
---|
127 | echo $OUTPUT->continue_button($return); |
---|
128 | echo $OUTPUT->footer(); |
---|
129 | exit; |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | redirect($return); |
---|