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 /// Get the auth title (from core or own auth lang files)
143 $authtitle = get_string("auth_{$auth}title", "auth");
144 if ($authtitle == "[[auth_{$auth}title]]") {
145 $authtitle = get_string("auth_{$auth}title", "auth_{$auth}");
148 $displayauths[$auth] = $authtitle;
149 if ($authplugin->can_signup()) {
150 $registrationauths[$auth] = $authtitle;
154 foreach ($authsavailable as $auth) {
155 if (array_key_exists($auth, $displayauths)) {
156 continue; //already in the list
158 $authplugin = get_auth_plugin($auth);
159 /// Get the auth title (from core or own auth lang files)
160 $authtitle = get_string("auth_{$auth}title", "auth");
161 if ($authtitle == "[[auth_{$auth}title]]") {
162 $authtitle = get_string("auth_{$auth}title", "auth_{$auth}");
165 $displayauths[$auth] = $authtitle;
166 if ($authplugin->can_signup()) {
167 $registrationauths[$auth] = $authtitle;
171 // build the display table
172 $table = new flexible_table('auth_admin_table');
173 $table->define_columns(array('name', 'enable', 'order', 'settings'));
174 $table->define_headers(array($txt->name
, $txt->enable
, $txt->updown
, $txt->settings
));
175 $table->define_baseurl("{$CFG->wwwroot}/{$CFG->admin}/auth.php");
176 $table->set_attribute('id', 'blocks');
177 $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
180 //add always enabled plugins first
181 $displayname = "<span>".$displayauths['manual']."</span>";
182 $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&auth=manual\">{$txt->settings}</a>";
183 $table->add_data(array($displayname, '', '', $settings));
184 $displayname = "<span>".$displayauths['nologin']."</span>";
185 $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&auth=nologin\">{$txt->settings}</a>";
186 $table->add_data(array($displayname, '', '', $settings));
189 // iterate through auth plugins and add to the display table
191 $authcount = count($authsenabled);
192 $url = "auth.php?sesskey=" . sesskey();
193 foreach ($displayauths as $auth => $name) {
194 if ($auth == 'manual' or $auth == 'nologin') {
198 if (in_array($auth, $authsenabled)) {
199 $hideshow = "<a href=\"$url&action=disable&auth=$auth\">";
200 $hideshow .= "<img src=\"{$CFG->pixpath}/i/hide.gif\" class=\"icon\" alt=\"disable\" /></a>";
201 // $hideshow = "<a href=\"$url&action=disable&auth=$auth\"><input type=\"checkbox\" checked /></a>";
203 $displayname = "<span>$name</span>";
206 $hideshow = "<a href=\"$url&action=enable&auth=$auth\">";
207 $hideshow .= "<img src=\"{$CFG->pixpath}/i/show.gif\" class=\"icon\" alt=\"enable\" /></a>";
208 // $hideshow = "<a href=\"$url&action=enable&auth=$auth\"><input type=\"checkbox\" /></a>";
210 $displayname = "<span class=\"dimmed_text\">$name</span>";
213 // up/down link (only if auth is enabled)
216 if ($updowncount > 1) {
217 $updown .= "<a href=\"$url&action=up&auth=$auth\">";
218 $updown .= "<img src=\"{$CFG->pixpath}/t/up.gif\" alt=\"up\" /></a> ";
221 $updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" /> ";
223 if ($updowncount < $authcount) {
224 $updown .= "<a href=\"$url&action=down&auth=$auth\">";
225 $updown .= "<img src=\"{$CFG->pixpath}/t/down.gif\" alt=\"down\" /></a>";
228 $updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" />";
234 $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&auth=$auth\">{$txt->settings}</a>";
236 // add a row to the table
237 $table->add_data(array($displayname, $hideshow, $updown, $settings));
241 admin_externalpage_print_header();
243 //print stus messages
244 if ($status !== '') {
245 notify($status, 'notifysuccess');
248 print_simple_box(get_string('configauthenticationplugins', 'admin'), 'center', '700');
250 $table->print_html();
252 ////////////////////////////////////////////////////////////////////////////////
254 $guestoptions = array();
255 $guestoptions[0] = get_string("hide");
256 $guestoptions[1] = get_string("show");
260 echo '<form '.$CFG->frametarget
.' id="adminsettings" method="post" action="auth.php">';
261 echo '<div class="settingsform clearfix">';
262 print_heading(get_string('auth_common_settings', 'auth'));
263 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
264 echo '<input type="hidden" name="action" value="save" />';
266 ##echo '<table cellspacing="0" cellpadding="5" border="0" style="margin-left:auto;margin-right:auto">';
268 // User self registration
269 echo '<div class="form-item" id="admin-register">';
270 echo '<label for = "menuregister">' . get_string("selfregistration", "auth");
271 echo '<span class="form-shortname">registerauth</span>';
273 choose_from_menu($registrationauths, "register", $CFG->registerauth
, "");
274 echo '<div class="description">' . get_string("selfregistration_help", "auth") . '</div>';
277 // Login as guest button enabled
278 echo '<div class="form-item" id="admin-guestloginbutton">';
279 echo '<label for = "menuguestloginbutton">' . get_string("guestloginbutton", "auth");
280 echo '<span class="form-shortname">guestloginbutton</span>';
282 choose_from_menu($guestoptions, "guestloginbutton", $CFG->guestloginbutton
, "");
283 echo '<div class="description">' . get_string("showguestlogin", "auth") . '</div>';
286 /// An alternate url for the login form. It means we can use login forms that are integrated
287 /// into non-moodle pages
288 echo '<div class="form-item" id="admin-alternateloginurl">';
289 echo '<label for = "alternateloginurl">' . get_string("alternateloginurl", "auth");
290 echo '<span class="form-shortname">alternateloginurl</span>';
292 echo '<input type="text" size="60" name="alternateloginurl" id="alternateloginurl" value="'.$CFG->alternateloginurl
."\" />\n";
293 echo '<div class="description">' . get_string("alternatelogin", "auth", htmlspecialchars($CFG->wwwroot
.'/login/index.php')) . '</div>';
296 /// Instructions about login/password
297 /// to be showed to users
298 echo '<div class="form-item" id="admin-auth_instructions">';
299 echo '<label for = "auth_instructions">' . get_string("instructions", "auth");
300 echo '<span class="form-shortname">auth_instructions</span>';
302 echo '<textarea cols="30" rows="4" name="auth_instructions" id="auth_instructions">'.s($CFG->auth_instructions
)."</textarea>\n";
303 echo '<div class="description">' . get_string("authinstructions", "auth") . '</div>';
308 ////////////////////////////////////////////////////////////////////////////////
309 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges', 'admin').'" /></div>';
312 admin_externalpage_print_footer();