~ubuntu-branches/ubuntu/jaunty/moodle/jaunty

« back to all changes in this revision

Viewing changes to admin/auth.php

  • Committer: Bazaar Package Importer
  • Author(s): Jordan Mantha, Matt Oquist
  • Date: 2009-02-25 15:16:22 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090225151622-0ekt1liwhv2obfza
Tags: 1.9.4.dfsg-0ubuntu1
* Merge with Debian git (Closes LP: #322961, #239481, #334611):
  - use Ubuntu's smarty lib directory for linking
  - use internal yui library 
  - add update-notifier support back in

[Matt Oquist]
  * renamed prerm script
  * significantly rewrote postinst and other maintainer scripts to improve
    user experience and package maintainability
    (Closes LP: #225662, #325450, #327843, #303078, #234609)

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
require_once($CFG->libdir.'/adminlib.php');
12
12
require_once($CFG->libdir.'/tablelib.php');
13
13
 
14
 
$adminroot = admin_get_root();
15
 
admin_externalpage_setup('userauthentication', $adminroot);
 
14
require_login();
 
15
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
 
16
 
 
17
$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageauths";
16
18
 
17
19
$action = optional_param('action', '', PARAM_ACTION);
18
20
$auth   = optional_param('auth', '', PARAM_SAFEDIR);
20
22
// get currently installed and enabled auth plugins
21
23
$authsavailable = get_list_of_plugins('auth');
22
24
 
23
 
//revert auth_plugins_enabled
24
 
if (isset($CFG->auth_plugins_enabled)) {
25
 
    set_config('auth', $CFG->auth_plugins_enabled);
26
 
    delete_records('config', 'name', 'auth_plugins_enabled');
27
 
    unset($CFG->auth_plugins_enabled);
28
 
}
29
 
 
30
25
get_enabled_auth_plugins(true); // fix the list of enabled auths
31
26
if (empty($CFG->auth)) {
32
27
    $authsenabled = array();
34
29
    $authsenabled = explode(',', $CFG->auth);
35
30
}
36
31
 
37
 
if (!isset($CFG->registerauth)) {
38
 
    set_config('registerauth', '');
39
 
}
40
 
 
41
 
if (!isset($CFG->auth_instructions)) {
42
 
    set_config('auth_instructions', '');
43
 
}
44
 
 
45
32
if (!empty($auth) and !exists_auth_plugin($auth)) {
46
 
    error(get_string('pluginnotinstalled', 'auth', $auth), $url);
 
33
    print_error('pluginnotinstalled', 'auth', $url, $auth);
47
34
}
48
35
 
49
 
 
50
36
////////////////////////////////////////////////////////////////////////////////
51
37
// process actions
52
38
 
53
 
$status = '';
 
39
if (!confirm_sesskey()) {
 
40
    redirect($returnurl);
 
41
}
54
42
 
55
43
switch ($action) {
56
 
 
57
 
    case 'save':
58
 
        if (data_submitted() and confirm_sesskey()) {
59
 
 
60
 
            // save settings
61
 
            set_config('guestloginbutton', required_param('guestloginbutton', PARAM_BOOL));
62
 
            set_config('alternateloginurl', stripslashes(trim(required_param('alternateloginurl', PARAM_RAW))));
63
 
            set_config('registerauth', required_param('register', PARAM_SAFEDIR));
64
 
            set_config('auth_instructions', stripslashes(trim(required_param('auth_instructions', PARAM_RAW))));
65
 
 
66
 
            // enable registerauth in $CFG->auth if needed
67
 
            if (!empty($CFG->registerauth) and !in_array($CFG->registerauth, $authsenabled)) {
68
 
                $authsenabled[] = $CFG->registerauth;
69
 
                set_config('auth', implode(',', $authsenabled));
70
 
            }
71
 
            $status = get_string('changessaved');
72
 
        }
73
 
        break;
74
 
 
75
44
    case 'disable':
76
45
        // remove from enabled list
77
46
        $key = array_search($auth, $authsenabled);
98
67
        $key = array_search($auth, $authsenabled);
99
68
        // check auth plugin is valid
100
69
        if ($key === false) {
101
 
            error(get_string('pluginnotenabled', 'auth', $auth), $url);
 
70
            print_error('pluginnotenabled', 'auth', $url, $auth);
102
71
        }
103
72
        // move down the list
104
73
        if ($key < (count($authsenabled) - 1)) {
113
82
        $key = array_search($auth, $authsenabled);
114
83
        // check auth is valid
115
84
        if ($key === false) {
116
 
            error(get_string('pluginnotenabled', 'auth', $auth), $url);
 
85
            print_error('pluginnotenabled', 'auth', $url, $auth);
117
86
        }
118
87
        // move up the list
119
88
        if ($key >= 1) {
128
97
        break;
129
98
}
130
99
 
131
 
// display strings
132
 
$txt = get_strings(array('authenticationplugins', 'users', 'administration',
133
 
                         'settings', 'edit', 'name', 'enable', 'disable',
134
 
                         'up', 'down', 'none'));
135
 
$txt->updown = "$txt->up/$txt->down";
136
 
 
137
 
// construct the display array, with enabled auth plugins at the top, in order
138
 
$displayauths = array();
139
 
$registrationauths = array();
140
 
$registrationauths[''] = $txt->disable;
141
 
foreach ($authsenabled as $auth) {
142
 
    $authplugin = get_auth_plugin($auth);
143
 
    $displayauths[$auth] = get_string("auth_{$auth}title", 'auth');
144
 
    if ($authplugin->can_signup()) {
145
 
        $registrationauths[$auth] = get_string("auth_{$auth}title", 'auth');
146
 
    }
147
 
}
148
 
 
149
 
foreach ($authsavailable as $auth) {
150
 
    if (array_key_exists($auth, $displayauths)) {
151
 
        continue; //already in the list
152
 
    }
153
 
    $authplugin = get_auth_plugin($auth);
154
 
    $displayauths[$auth] = get_string("auth_{$auth}title", 'auth');
155
 
    if ($authplugin->can_signup()) {
156
 
        $registrationauths[$auth] = get_string("auth_{$auth}title", 'auth');
157
 
    }
158
 
}
159
 
 
160
 
// build the display table
161
 
$table = new flexible_table('auth_admin_table');
162
 
$table->define_columns(array('name', 'enable', 'order', 'settings'));
163
 
$table->define_headers(array($txt->name, $txt->enable, $txt->updown, $txt->settings));
164
 
$table->define_baseurl("{$CFG->wwwroot}/{$CFG->admin}/auth.php");
165
 
$table->set_attribute('id', 'blocks');
166
 
$table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
167
 
$table->setup();
168
 
 
169
 
//add always enabled plugins first
170
 
$displayname = "<span>".$displayauths['manual']."</span>";
171
 
$settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&amp;auth=manual\">{$txt->settings}</a>";
172
 
$table->add_data(array($displayname, '', '', $settings));
173
 
$displayname = "<span>".$displayauths['nologin']."</span>";
174
 
$settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&amp;auth=nologin\">{$txt->settings}</a>";
175
 
$table->add_data(array($displayname, '', '', $settings));
176
 
 
177
 
 
178
 
// iterate through auth plugins and add to the display table
179
 
$updowncount = 1;
180
 
$authcount = count($authsenabled);
181
 
$url = "auth.php?sesskey=" . sesskey();
182
 
foreach ($displayauths as $auth => $name) {
183
 
    if ($auth == 'manual' or $auth == 'nologin') {
184
 
        continue;
185
 
    }
186
 
    // hide/show link
187
 
    if (in_array($auth, $authsenabled)) {
188
 
        $hideshow = "<a href=\"$url&amp;action=disable&amp;auth=$auth\">";
189
 
        $hideshow .= "<img src=\"{$CFG->pixpath}/i/hide.gif\" class=\"icon\" alt=\"disable\" /></a>";
190
 
        // $hideshow = "<a href=\"$url&amp;action=disable&amp;auth=$auth\"><input type=\"checkbox\" checked /></a>";
191
 
        $enabled = true;
192
 
        $displayname = "<span>$name</span>";
193
 
    }
194
 
    else {
195
 
        $hideshow = "<a href=\"$url&amp;action=enable&amp;auth=$auth\">";
196
 
        $hideshow .= "<img src=\"{$CFG->pixpath}/i/show.gif\" class=\"icon\" alt=\"enable\" /></a>";
197
 
        // $hideshow = "<a href=\"$url&amp;action=enable&amp;auth=$auth\"><input type=\"checkbox\" /></a>";
198
 
        $enabled = false;
199
 
        $displayname = "<span class=\"dimmed_text\">$name</span>";
200
 
    }
201
 
 
202
 
    // up/down link (only if auth is enabled)
203
 
    $updown = '';
204
 
    if ($enabled) {
205
 
        if ($updowncount > 1) {
206
 
            $updown .= "<a href=\"$url&amp;action=up&amp;auth=$auth\">";
207
 
            $updown .= "<img src=\"{$CFG->pixpath}/t/up.gif\" alt=\"up\" /></a>&nbsp;";
208
 
        }
209
 
        else {
210
 
            $updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" />&nbsp;";
211
 
        }
212
 
        if ($updowncount < $authcount) {
213
 
            $updown .= "<a href=\"$url&amp;action=down&amp;auth=$auth\">";
214
 
            $updown .= "<img src=\"{$CFG->pixpath}/t/down.gif\" alt=\"down\" /></a>";
215
 
        }
216
 
        else {
217
 
            $updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" />";
218
 
        }
219
 
        ++ $updowncount;
220
 
    }
221
 
 
222
 
    // settings link
223
 
    $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&amp;auth=$auth\">{$txt->settings}</a>";
224
 
 
225
 
    // add a row to the table
226
 
    $table->add_data(array($displayname, $hideshow, $updown, $settings));
227
 
}
228
 
 
229
 
// output form
230
 
admin_externalpage_print_header($adminroot);
231
 
 
232
 
//print stus messages
233
 
if ($status !== '') {
234
 
    notify($status, 'notifysuccess');
235
 
}
236
 
 
237
 
print_simple_box(get_string('configauthenticationplugins', 'admin'), 'center', '700');
238
 
 
239
 
$table->print_html();
240
 
 
241
 
////////////////////////////////////////////////////////////////////////////////
242
 
 
243
 
$guestoptions = array();
244
 
$guestoptions[0] = get_string("hide");
245
 
$guestoptions[1] = get_string("show");
246
 
 
247
 
echo '<hr />';
248
 
 
249
 
echo '<form '.$CFG->frametarget.' id="adminsettings" method="post" action="auth.php">';
250
 
echo '<div class="settingsform">';
251
 
print_heading(get_string('auth_common_settings', 'auth'));
252
 
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
253
 
echo '<input type="hidden" name="action" value="save" />';
254
 
echo '<fieldset>';
255
 
##echo '<table cellspacing="0" cellpadding="5" border="0" style="margin-left:auto;margin-right:auto">';
256
 
 
257
 
// User self registration
258
 
echo '<div class="form-item" id="admin-register">';
259
 
echo '<label for = "menuregister">' . get_string("selfregistration", "auth");
260
 
echo '<span class="form-shortname">registerauth</span>';
261
 
echo '</label>';
262
 
choose_from_menu($registrationauths, "register", $CFG->registerauth, "");
263
 
echo '<div class="description">' . get_string("selfregistration_help", "auth") . '</div>';
264
 
echo '</div>';
265
 
 
266
 
// Login as guest button enabled
267
 
echo '<div class="form-item" id="admin-guestloginbutton">';
268
 
echo '<label for = "menuguestloginbutton">' . get_string("guestloginbutton", "auth");
269
 
echo '<span class="form-shortname">guestloginbutton</span>';
270
 
echo '</label>';
271
 
choose_from_menu($guestoptions, "guestloginbutton", $CFG->guestloginbutton, "");
272
 
echo '<div class="description">' . get_string("showguestlogin", "auth") . '</div>';
273
 
echo '</div>';
274
 
 
275
 
/// An alternate url for the login form. It means we can use login forms that are integrated
276
 
/// into non-moodle pages
277
 
echo '<div class="form-item" id="admin-alternateloginurl">';
278
 
echo '<label for = "alternateloginurl">' . get_string("alternateloginurl", "auth");
279
 
echo '<span class="form-shortname">alternateloginurl</span>';
280
 
echo '</label>';
281
 
echo '<input type="text" size="60" name="alternateloginurl" id="alternateloginurl" value="'.$CFG->alternateloginurl."\" />\n";
282
 
echo '<div class="description">' . get_string("alternatelogin", "auth", htmlspecialchars($CFG->wwwroot.'/login/index.php')) . '</div>';
283
 
echo '</div>';
284
 
 
285
 
/// Instructions about login/password
286
 
/// to be showed to users
287
 
echo '<div class="form-item" id="admin-auth_instructions">';
288
 
echo '<label for = "auth_instructions">' . get_string("instructions", "auth");
289
 
echo '<span class="form-shortname">auth_instructions</span>';
290
 
echo '</label>';
291
 
echo '<textarea cols="30" rows="4" name="auth_instructions" id="auth_instructions">'.s($CFG->auth_instructions)."</textarea>\n";
292
 
echo '<div class="description">' . get_string("authinstructions", "auth") . '</div>';
293
 
echo '</div>';
294
 
 
295
 
echo '</fieldset>';
296
 
 
297
 
////////////////////////////////////////////////////////////////////////////////
298
 
echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges', 'admin').'" /></div>';
299
 
echo '</div>';
300
 
echo '</form>';
301
 
admin_externalpage_print_footer($adminroot);
 
100
redirect ($returnurl);
302
101
 
303
102
?>