1
1
<?php
2
- // enrol.php - allows admin to edit all enrollment variables
3
- // Yes, enrol is correct English spelling.
4
-
5
- require_once ('../config.php ' );
6
- require_once ($ CFG ->libdir .'/adminlib.php ' );
7
-
8
- $ enrol = optional_param ('enrol ' , $ CFG ->enrol , PARAM_SAFEDIR );
9
- $ savesettings = optional_param ('savesettings ' , 0 , PARAM_BOOL );
10
-
11
- admin_externalpage_setup ('enrolment ' );
12
-
13
- if (!isset ($ CFG ->sendcoursewelcomemessage )) {
14
- set_config ('sendcoursewelcomemessage ' , 1 );
15
- }
16
-
17
-
18
- require_once ("$ CFG ->dirroot /enrol/enrol.class.php " ); /// Open the factory class
19
-
20
- /// Save settings
21
-
22
- if ($ frm = data_submitted () and !$ savesettings ) {
23
- if (!confirm_sesskey ()) {
24
- print_error ('confirmsesskeybad ' , 'error ' );
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
+ require_once ('../config.php ' );
27
+ require_once ($ CFG ->libdir .'/adminlib.php ' );
28
+
29
+ $ action = required_param ('action ' , PARAM_ACTION );
30
+ $ enrol = required_param ('enrol ' , PARAM_SAFEDIR );
31
+ $ confirm = optional_param ('confirm ' , 0 , PARAM_BOOL );
32
+
33
+ $ PAGE ->set_url ('/admin/enrol.php ' );
34
+
35
+ require_login ();
36
+ require_capability ('moodle/site:config ' , get_context_instance (CONTEXT_SYSTEM ));
37
+ require_sesskey ();
38
+
39
+ $ enabled = enrol_get_plugins (true );
40
+ $ all = enrol_get_plugins (false );
41
+
42
+ $ return = new moodle_url ('/admin/settings.php ' , array ('section ' =>'manageenrols ' ));
43
+
44
+ switch ($ action ) {
45
+ case 'disable ' :
46
+ unset($ enabled [$ enrol ]);
47
+ set_config ('enrol_plugins_enabled ' , implode (', ' , array_keys ($ enabled )));
48
+ break ;
49
+
50
+ case 'enable ' :
51
+ if (!isset ($ all [$ enrol ])) {
52
+ break ;
25
53
}
26
- if (empty ($ frm ->enable )) {
27
- $ frm ->enable = array ();
54
+ $ enabled = array_keys ($ enabled );
55
+ $ enabled [] = $ enrol ;
56
+ set_config ('enrol_plugins_enabled ' , implode (', ' , $ enabled ));
57
+ break ;
58
+
59
+ case 'up ' :
60
+ if (!isset ($ enabled [$ enrol ])) {
61
+ break ;
28
62
}
29
- if (empty ($ frm ->default )) {
30
- $ frm ->default = '' ;
31
- }
32
- if ($ frm ->default && $ frm ->default != 'manual ' && !in_array ($ frm ->default , $ frm ->enable )) {
33
- $ frm ->enable [] = $ frm ->default ;
34
- }
35
- asort ($ frm ->enable );
36
- $ frm ->enable = array_merge (array ('manual ' ), $ frm ->enable ); // make sure manual plugin is called first
37
- set_config ('enrol_plugins_enabled ' , implode (', ' , $ frm ->enable ));
38
- set_config ('enrol ' , $ frm ->default );
39
- redirect ("enrol.php " , get_string ("changessaved " ), 1 );
40
-
41
- } else if ($ frm = data_submitted () and $ savesettings ) {
42
- if (!confirm_sesskey ()) {
43
- print_error ('confirmsesskeybad ' , 'error ' );
44
- }
45
- set_config ('sendcoursewelcomemessage ' , required_param ('sendcoursewelcomemessage ' , PARAM_BOOL ));
46
- }
47
-
48
- /// Print the form
49
-
50
- $ str = get_strings (array ('enrolmentplugins ' , 'users ' , 'administration ' , 'settings ' , 'edit ' ));
51
-
52
- echo $ OUTPUT ->header ();
53
-
54
- $ modules = get_plugin_list ('enrol ' );
55
- $ options = array ();
56
- foreach ($ modules as $ module => $ moduledir ) {
57
- $ options [$ module ] = get_string ("enrolname " , "enrol_ $ module " );
58
- }
59
- asort ($ options );
60
-
61
- echo $ OUTPUT ->box (get_string ('configenrolmentplugins ' , 'admin ' ));
62
-
63
- echo "<form id= \"enrolmenu \" method= \"post \" action= \"enrol.php \"> " ;
64
- echo "<div> " ;
65
- echo "<input type= \"hidden \" name= \"sesskey \" value= \"" .sesskey ()."\" /> " ;
66
-
67
- $ table = new html_table ();
68
- $ table ->head = array (get_string ('name ' ), get_string ('enable ' ), get_string ('default ' ), $ str ->settings );
69
- $ table ->align = array ('left ' , 'center ' , 'center ' , 'center ' );
70
- $ table ->size = array ('60% ' , '' , '' , '15% ' );
71
- $ table ->attributes ['class ' ] = 'generaltable enrolplugintable ' ;
72
- $ table ->data = array ();
73
-
74
- $ enabledplugins = explode (', ' , $ CFG ->enrol_plugins_enabled );
75
- foreach ($ modules as $ module => $ moduledir ) {
76
-
77
- // skip if directory is empty
78
- if (!file_exists ("$ moduledir/enrol.php " )) {
79
- continue ;
63
+ $ enabled = array_keys ($ enabled );
64
+ $ enabled = array_flip ($ enabled );
65
+ $ current = $ enabled [$ enrol ];
66
+ if ($ current == 0 ) {
67
+ break ; //already at the top
80
68
}
81
-
82
- $ name = get_string ("enrolname " , "enrol_ $ module " );
83
- $ plugin = enrolment_factory::factory ($ module );
84
- $ enable = '<input type="checkbox" name="enable[]" value=" ' .$ module .'" ' ;
85
- if (in_array ($ module , $ enabledplugins )) {
86
- $ enable .= ' checked="checked" ' ;
69
+ $ enabled = array_flip ($ enabled );
70
+ $ enabled [$ current ] = $ enabled [$ current - 1 ];
71
+ $ enabled [$ current - 1 ] = $ enrol ;
72
+ set_config ('enrol_plugins_enabled ' , implode (', ' , $ enabled ));
73
+ break ;
74
+
75
+ case 'down ' :
76
+ if (!isset ($ enabled [$ enrol ])) {
77
+ break ;
87
78
}
88
- if ($ module == 'manual ' ) {
89
- $ enable .= ' disabled="disabled" ' ;
79
+ $ enabled = array_keys ($ enabled );
80
+ $ enabled = array_flip ($ enabled );
81
+ $ current = $ enabled [$ enrol ];
82
+ if ($ current == count ($ enabled ) - 1 ) {
83
+ break ; //already at the end
90
84
}
91
- $ enable .= ' /> ' ;
92
- if (method_exists ($ plugin , 'print_entry ' )) {
93
- $ default = '<input type="radio" name="default" value=" ' .$ module .'" ' ;
94
- if ($ CFG ->enrol == $ module ) {
95
- $ default .= ' checked="checked" ' ;
96
- }
97
- $ default .= ' /> ' ;
85
+ $ enabled = array_flip ($ enabled );
86
+ $ enabled [$ current ] = $ enabled [$ current + 1 ];
87
+ $ enabled [$ current + 1 ] = $ enrol ;
88
+ set_config ('enrol_plugins_enabled ' , implode (', ' , $ enabled ));
89
+ break ;
90
+
91
+ case 'uninstall ' :
92
+ echo $ OUTPUT ->header ();
93
+ echo $ OUTPUT ->heading (get_string ('enrolments ' , 'enrol ' ));
94
+
95
+ if (get_string_manager ()->string_exists ('pluginname ' , 'enrol_ ' .$ enrol )) {
96
+ $ strplugin = get_string ('pluginname ' , 'enrol_ ' .$ enrol );
98
97
} else {
99
- $ default = '' ;
98
+ $ strplugin = $ enrol ;
100
99
}
101
- $ table ->data [$ name ] = array ($ name , $ enable , $ default ,
102
- '<a href="enrol_config.php?enrol= ' .$ module .'"> ' .$ str ->edit .'</a> ' );
103
- }
104
- asort ($ table ->data );
105
-
106
- echo html_writer::table ($ table );
107
-
108
- echo "<div style= \"text-align:center \"><input type= \"submit \" value= \"" .get_string ("savechanges " )."\" /></div> \n" ;
109
- echo "</div> " ;
110
- echo "</form> " ;
111
100
112
- echo '<hr /> ' ;
113
-
114
- $ yesnooptions = array (0 =>get_string ('no ' ), 1 =>get_string ('yes ' ));
115
-
116
- echo '<form id="adminsettings" method="post" action="enrol.php"> ' ;
117
- echo '<div class="settingsform clearfix"> ' ;
118
- echo $ OUTPUT ->heading (get_string ('commonsettings ' , 'admin ' ));
119
- echo '<input type="hidden" name="sesskey" value=" ' .sesskey ().'" /> ' ;
120
- echo '<input type="hidden" name="savesettings" value="1" /> ' ;
121
- echo '<fieldset> ' ;
122
- echo '<div class="form-item clearfix" id="admin-sendcoursewelcomemessage"> ' ;
123
-
124
- echo '<div class="form-label"><label for = "menusendcoursewelcomemessage"> ' . get_string ('sendcoursewelcomemessage ' , 'admin ' );
125
- echo '<span class="form-shortname">sendcoursewelcomemessage</span> ' ;
126
- echo '</label></div> ' ;
127
- echo '<div class="form-setting"><div class="form-checkbox defaultsnext"> ' ;
128
- echo html_writer::select ($ yesnooptions , 'sendcoursewelcomemessage ' , $ CFG ->sendcoursewelcomemessage , false );
129
- echo '</div><div class="form-defaultinfo"> ' .get_string ('defaultsettinginfo ' , 'admin ' , get_string ('yes ' )).'</div></div> ' ;
130
- echo '<div class="form-description"> ' . get_string ('configsendcoursewelcomemessage ' , 'admin ' ) . '</div> ' ;
131
- echo '</div> ' ;
132
-
133
- echo '</fieldset> ' ;
134
-
135
- echo '<div class="form-buttons"><input class="form-submit" type="submit" value=" ' .get_string ('savechanges ' , 'admin ' ).'" /></div> ' ;
136
- echo '</div> ' ;
137
- echo '</form> ' ;
138
-
139
- echo $ OUTPUT ->footer ();
101
+ if (!$ confirm ) {
102
+ $ uurl = new moodle_url ('/admin/enrol.php ' , array ('action ' =>'uninstall ' , 'enrol ' =>$ enrol , 'sesskey ' =>sesskey (), 'confirm ' =>1 ));
103
+ echo $ OUTPUT ->confirm (get_string ('uninstallconfirm ' , 'enrol ' , $ strplugin ), $ uurl , $ return );
104
+ echo $ OUTPUT ->footer ();
105
+ exit ;
106
+
107
+ } else { // Delete everything!!
108
+ uninstall_plugin ('enrol ' , $ enrol );
109
+
110
+ $ a ->plugin = $ strplugin ;
111
+ $ a ->directory = "$ CFG ->dirroot /enrol/ $ enrol " ;
112
+ echo $ OUTPUT ->notification (get_string ('uninstalldeletefiles ' , 'enrol ' , $ a ), 'notifysuccess ' );
113
+ echo $ OUTPUT ->continue_button ($ return );
114
+ echo $ OUTPUT ->footer ();
115
+ exit ;
116
+ }
117
+ }
140
118
141
119
120
+ redirect ($ return );
0 commit comments