4 * Allows admin to edit all auth plugin settings.
6 * JH: copied and Hax0rd from admin/enrol.php and admin/filters.php
10 require_once('../config.php');
11 require_once($CFG->libdir
.'/adminlib.php');
12 require_once($CFG->libdir
.'/tablelib.php');
14 admin_externalpage_setup('userauthentication');
16 $action = optional_param('action', '', PARAM_ACTION
);
17 $auth = optional_param('auth', '', PARAM_SAFEDIR
);
19 // get currently installed and enabled auth plugins
20 $authsavailable = get_list_of_plugins('auth');
22 //revert auth_plugins_enabled
23 if (isset($CFG->auth_plugins_enabled
)) {
24 set_config('auth', $CFG->auth_plugins_enabled
);
25 delete_records('config', 'name', 'auth_plugins_enabled');
26 unset($CFG->auth_plugins_enabled
);
29 get_enabled_auth_plugins(true); // fix the list of enabled auths
30 if (empty($CFG->auth
)) {
31 $authsenabled = array();
33 $authsenabled = explode(',', $CFG->auth
);
36 if (!isset($CFG->registerauth
)) {
37 set_config('registerauth', '');
40 if (!isset($CFG->auth_instructions
)) {
41 set_config('auth_instructions', '');
44 if (!empty($auth) and !exists_auth_plugin($auth)) {
45 error(get_string('pluginnotinstalled', 'auth', $auth), $url);
49 ////////////////////////////////////////////////////////////////////////////////
57 if (data_submitted() and confirm_sesskey()) {
60 set_config('guestloginbutton', required_param('guestloginbutton', PARAM_BOOL
));
61 set_config('alternateloginurl', stripslashes(trim(required_param('alternateloginurl', PARAM_RAW
))));
62 set_config('registerauth', required_param('register', PARAM_SAFEDIR
));
63 set_config('auth_instructions', stripslashes(trim(required_param('auth_instructions', PARAM_RAW
))));
65 // enable registerauth in $CFG->auth if needed
66 if (!empty($CFG->registerauth
) and !in_array($CFG->registerauth
, $authsenabled)) {
67 $authsenabled[] = $CFG->registerauth
;
68 set_config('auth', implode(',', $authsenabled));
70 $status = get_string('changessaved');
75 // remove from enabled list
76 $key = array_search($auth, $authsenabled);
78 unset($authsenabled[$key]);
79 set_config('auth', implode(',', $authsenabled));
82 if ($auth == $CFG->registerauth
) {
83 set_config('registerauth', '');
88 // add to enabled list
89 if (!in_array($auth, $authsenabled)) {
90 $authsenabled[] = $auth;
91 $authsenabled = array_unique($authsenabled);
92 set_config('auth', implode(',', $authsenabled));
97 $key = array_search($auth, $authsenabled);
98 // check auth plugin is valid
100 error(get_string('pluginnotenabled', 'auth', $auth), $url);
102 // move down the list
103 if ($key < (count($authsenabled) - 1)) {
104 $fsave = $authsenabled[$key];
105 $authsenabled[$key] = $authsenabled[$key +
1];
106 $authsenabled[$key +
1] = $fsave;
107 set_config('auth', implode(',', $authsenabled));
112 $key = array_search($auth, $authsenabled);
113 // check auth is valid
114 if ($key === false) {
115 error(get_string('pluginnotenabled', 'auth', $auth), $url);
119 $fsave = $authsenabled[$key];
120 $authsenabled[$key] = $authsenabled[$key - 1];
121 $authsenabled[$key - 1] = $fsave;
122 set_config('auth', implode(',', $authsenabled));
131 $txt = get_strings(array('authenticationplugins', 'users', 'administration',
132 'settings', 'edit', 'name', 'enable', 'disable',
133 'up', 'down', 'none'));
134 $txt->updown
= "$txt->up/$txt->down";
136 // construct the display array, with enabled auth plugins at the top, in order
137 $displayauths = array();
138 $registrationauths = array();
139 $registrationauths[''] = $txt->disable
;
140 foreach ($authsenabled as $auth) {
141 $authplugin = get_auth_plugin($auth);
142 $displayauths[$auth] = get_string("auth_{$auth}title", 'auth');
143 if ($authplugin->can_signup()) {
144 $registrationauths[$auth] = get_string("auth_{$auth}title", 'auth');
148 foreach ($authsavailable as $auth) {
149 if (array_key_exists($auth, $displayauths)) {
150 continue; //already in the list
152 $authplugin = get_auth_plugin($auth);
153 $displayauths[$auth] = get_string("auth_{$auth}title", 'auth');
154 if ($authplugin->can_signup()) {
155 $registrationauths[$auth] = get_string("auth_{$auth}title", 'auth');
159 // build the display table
160 $table = new flexible_table('auth_admin_table');
161 $table->define_columns(array('name', 'enable', 'order', 'settings'));
162 $table->define_headers(array($txt->name
, $txt->enable
, $txt->updown
, $txt->settings
));
163 $table->define_baseurl("{$CFG->wwwroot}/{$CFG->admin}/auth.php");
164 $table->set_attribute('id', 'blocks');
165 $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
168 //add always enabled plugins first
169 $displayname = "<span>".$displayauths['manual']."</span>";
170 $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&auth=manual\">{$txt->settings}</a>";
171 $table->add_data(array($displayname, '', '', $settings));
172 $displayname = "<span>".$displayauths['nologin']."</span>";
173 $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&auth=nologin\">{$txt->settings}</a>";
174 $table->add_data(array($displayname, '', '', $settings));
177 // iterate through auth plugins and add to the display table
179 $authcount = count($authsenabled);
180 $url = "auth.php?sesskey=" . sesskey();
181 foreach ($displayauths as $auth => $name) {
182 if ($auth == 'manual' or $auth == 'nologin') {
186 if (in_array($auth, $authsenabled)) {
187 $hideshow = "<a href=\"$url&action=disable&auth=$auth\">";
188 $hideshow .= "<img src=\"{$CFG->pixpath}/i/hide.gif\" class=\"icon\" alt=\"disable\" /></a>";
189 // $hideshow = "<a href=\"$url&action=disable&auth=$auth\"><input type=\"checkbox\" checked /></a>";
191 $displayname = "<span>$name</span>";
194 $hideshow = "<a href=\"$url&action=enable&auth=$auth\">";
195 $hideshow .= "<img src=\"{$CFG->pixpath}/i/show.gif\" class=\"icon\" alt=\"enable\" /></a>";
196 // $hideshow = "<a href=\"$url&action=enable&auth=$auth\"><input type=\"checkbox\" /></a>";
198 $displayname = "<span class=\"dimmed_text\">$name</span>";
201 // up/down link (only if auth is enabled)
204 if ($updowncount > 1) {
205 $updown .= "<a href=\"$url&action=up&auth=$auth\">";
206 $updown .= "<img src=\"{$CFG->pixpath}/t/up.gif\" alt=\"up\" /></a> ";
209 $updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" /> ";
211 if ($updowncount < $authcount) {
212 $updown .= "<a href=\"$url&action=down&auth=$auth\">";
213 $updown .= "<img src=\"{$CFG->pixpath}/t/down.gif\" alt=\"down\" /></a>";
216 $updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" />";
222 $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&auth=$auth\">{$txt->settings}</a>";
224 // add a row to the table
225 $table->add_data(array($displayname, $hideshow, $updown, $settings));
229 admin_externalpage_print_header();
231 //print stus messages
232 if ($status !== '') {
233 notify($status, 'notifysuccess');
236 print_simple_box(get_string('configauthenticationplugins', 'admin'), 'center', '700');
238 $table->print_html();
240 ////////////////////////////////////////////////////////////////////////////////
242 $guestoptions = array();
243 $guestoptions[0] = get_string("hide");
244 $guestoptions[1] = get_string("show");
248 echo '<form '.$CFG->frametarget
.' id="adminsettings" method="post" action="auth.php">';
249 echo '<div class="settingsform clearfix">';
250 print_heading(get_string('auth_common_settings', 'auth'));
251 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
252 echo '<input type="hidden" name="action" value="save" />';
254 ##echo '<table cellspacing="0" cellpadding="5" border="0" style="margin-left:auto;margin-right:auto">';
256 // User self registration
257 echo '<div class="form-item" id="admin-register">';
258 echo '<label for = "menuregister">' . get_string("selfregistration", "auth");
259 echo '<span class="form-shortname">registerauth</span>';
261 choose_from_menu($registrationauths, "register", $CFG->registerauth
, "");
262 echo '<div class="description">' . get_string("selfregistration_help", "auth") . '</div>';
265 // Login as guest button enabled
266 echo '<div class="form-item" id="admin-guestloginbutton">';
267 echo '<label for = "menuguestloginbutton">' . get_string("guestloginbutton", "auth");
268 echo '<span class="form-shortname">guestloginbutton</span>';
270 choose_from_menu($guestoptions, "guestloginbutton", $CFG->guestloginbutton
, "");
271 echo '<div class="description">' . get_string("showguestlogin", "auth") . '</div>';
274 /// An alternate url for the login form. It means we can use login forms that are integrated
275 /// into non-moodle pages
276 echo '<div class="form-item" id="admin-alternateloginurl">';
277 echo '<label for = "alternateloginurl">' . get_string("alternateloginurl", "auth");
278 echo '<span class="form-shortname">alternateloginurl</span>';
280 echo '<input type="text" size="60" name="alternateloginurl" id="alternateloginurl" value="'.$CFG->alternateloginurl
."\" />\n";
281 echo '<div class="description">' . get_string("alternatelogin", "auth", htmlspecialchars($CFG->wwwroot
.'/login/index.php')) . '</div>';
284 /// Instructions about login/password
285 /// to be showed to users
286 echo '<div class="form-item" id="admin-auth_instructions">';
287 echo '<label for = "auth_instructions">' . get_string("instructions", "auth");
288 echo '<span class="form-shortname">auth_instructions</span>';
290 echo '<textarea cols="30" rows="4" name="auth_instructions" id="auth_instructions">'.s($CFG->auth_instructions
)."</textarea>\n";
291 echo '<div class="description">' . get_string("authinstructions", "auth") . '</div>';
296 ////////////////////////////////////////////////////////////////////////////////
297 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges', 'admin').'" /></div>';
300 admin_externalpage_print_footer();