auth_config.php 6.66 KB
Newer Older
1
2
3
4
<?php
/**
 * Edit configuration for an individual auth plugin
 */
skodak's avatar
skodak committed
5

6
7
8
require_once '../config.php';
require_once $CFG->libdir.'/adminlib.php';

skodak's avatar
skodak committed
9
$auth = required_param('auth', PARAM_SAFEDIR);
10
$PAGE->set_pagetype('admin-auth-' . $auth);
11

12
13
admin_externalpage_setup('authsetting'.$auth);

14
15
16
$authplugin = get_auth_plugin($auth);
$err = array();

17
$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageauths";
18

19
// save configuration changes
20
if ($frm = data_submitted() and confirm_sesskey()) {
21

22
    $authplugin->validate_form($frm, $err);
23
24
25
26
27
28
29
30
31
32
33

    if (count($err) == 0) {

        // save plugin config
        if ($authplugin->process_config($frm)) {

            // save field lock configuration
            foreach ($frm as $name => $value) {
                if (preg_match('/^lockconfig_(.+?)$/', $name, $matches)) {
                    $plugin = "auth/$auth";
                    $name   = $matches[1];
skodak's avatar
skodak committed
34
                    set_config($name, $value, $plugin);
35
36
                }
            }
37
            redirect($returnurl);
38
39
40
41
42
43
            exit;
        }
    } else {
        foreach ($err as $key => $value) {
            $focus = "form.$key";
        }
skodak's avatar
skodak committed
44
    }
45
46
47
48
} else {
    $frm = get_config("auth/$auth");
}

49
50
$user_fields = $authplugin->userfields;
//$user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "institution", "department", "address", "city", "country", "description", "idnumber", "lang");
51

52
/// Get the auth title (from core or own auth lang files)
53
    $authtitle = $authplugin->get_title();
54
/// Get the auth descriptions (from core or own auth lang files)
55
    $authdescription = $authplugin->get_description();
56
57

// output configuration form
58
admin_externalpage_print_header();
59
60

// choose an authentication method
61
echo "<form $CFG->frametarget id=\"authmenu\" method=\"post\" action=\"auth_config.php\">\n";
nicolasconnault's avatar
nicolasconnault committed
62
echo "<div>\n";
skodak's avatar
skodak committed
63
echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />\n";
64
echo "<input type=\"hidden\" name=\"auth\" value=\"".$auth."\" />\n";
65
66
67

// auth plugin description
print_simple_box_start('center', '80%');
68
echo $OUTPUT->heading($authtitle);
69
70
print_simple_box_start('center', '80%', '', 5, 'informationbox');
echo $authdescription;
71
72
print_simple_box_end();
echo "<hr />\n";
skodak's avatar
skodak committed
73
$authplugin->config_form($frm, $err, $user_fields);
74
print_simple_box_end();
nicolasconnault's avatar
nicolasconnault committed
75
76
echo '<p style="text-align: center"><input type="submit" value="' . get_string("savechanges") . "\" /></p>\n";
echo "</div>\n";
77
78
echo "</form>\n";

79
echo $OUTPUT->footer();
80
81
82
83
84
85
86
exit;

/// Functions /////////////////////////////////////////////////////////////////

// Good enough for most auth plugins
// but some may want a custom one if they are offering
// other options
skodak's avatar
skodak committed
87
// Note: lockconfig_ fields have special handling.
88
89
90
91
function print_auth_lock_options ($auth, $user_fields, $helptext, $retrieveopts, $updateopts) {

    echo '<tr><td colspan="3">';
    if ($retrieveopts) {
92
        echo $OUTPUT->heading(get_string('auth_data_mapping', 'auth'));
93
    } else {
94
        echo $OUTPUT->heading(get_string('auth_fieldlocks', 'auth'));
95
96
97
98
99
100
101
102
103
104
    }
    echo '</td></tr>';

    $lockoptions = array ('unlocked'        => get_string('unlocked', 'auth'),
                          'unlockedifempty' => get_string('unlockedifempty', 'auth'),
                          'locked'          => get_string('locked', 'auth'));
    $updatelocaloptions = array('oncreate'  => get_string('update_oncreate', 'auth'),
                                'onlogin'   => get_string('update_onlogin', 'auth'));
    $updateextoptions = array('0'  => get_string('update_never', 'auth'),
                              '1'   => get_string('update_onupdate', 'auth'));
skodak's avatar
skodak committed
105

106
    $pluginconfig = get_config("auth/$auth");
107

108
109
110
111
112
113
114
115
    // helptext is on a field with rowspan
    if (empty($helptext)) {
                $helptext = '&nbsp;';
    }

    foreach ($user_fields as $field) {

        // Define some vars we'll work with
116
        if (!isset($pluginconfig->{"field_map_$field"})) {
117
118
            $pluginconfig->{"field_map_$field"} = '';
        }
119
        if (!isset($pluginconfig->{"field_updatelocal_$field"})) {
120
121
            $pluginconfig->{"field_updatelocal_$field"} = '';
        }
122
        if (!isset($pluginconfig->{"field_updateremote_$field"})) {
123
124
            $pluginconfig->{"field_updateremote_$field"} = '';
        }
125
        if (!isset($pluginconfig->{"field_lock_$field"})) {
126
127
            $pluginconfig->{"field_lock_$field"} = '';
        }
128
129
130
131
132
133
134

        // define the fieldname we display to the  user
        $fieldname = $field;
        if ($fieldname === 'lang') {
            $fieldname = get_string('language');
        } elseif (preg_match('/^(.+?)(\d+)$/', $fieldname, $matches)) {
            $fieldname =  get_string($matches[1]) . ' ' . $matches[2];
135
136
        } elseif ($fieldname == 'url') {
            $fieldname = get_string('webpage');
137
138
        } else {
            $fieldname = get_string($fieldname);
139
        } 
140
141
142
        if ($retrieveopts) {
            $varname = 'field_map_' . $field;

skodak's avatar
skodak committed
143
144
145
146
147
            echo '<tr valign="top"><td align="right">';
            echo '<label for="lockconfig_'.$varname.'">'.$fieldname.'</label>';
            echo '</td><td>';

            echo "<input id=\"lockconfig_{$varname}\" name=\"lockconfig_{$varname}\" type=\"text\" size=\"30\" value=\"{$pluginconfig->$varname}\" />";
nicolasconnault's avatar
nicolasconnault committed
148
            echo '<div style="text-align: right">';
skodak's avatar
skodak committed
149
            echo '<label for="menulockconfig_field_updatelocal_'.$field.'">'.get_string('auth_updatelocal', 'auth') . '</label>&nbsp;';
150
151
152
            choose_from_menu($updatelocaloptions, "lockconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, "");
            echo '<br />';
            if ($updateopts) {
skodak's avatar
skodak committed
153
                echo '<label for="menulockconfig_field_updateremote_'.$field.'">'.get_string('auth_updateremote', 'auth') . '</label>&nbsp;';
154
155
156
157
158
                choose_from_menu($updateextoptions, "lockconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, "");
                echo '<br />';


            }
skodak's avatar
skodak committed
159
            echo '<label for="menulockconfig_field_lock_'.$field.'">'.get_string('auth_fieldlock', 'auth') . '</label>&nbsp;';
160
161
162
            choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
            echo '</div>';
        } else {
skodak's avatar
skodak committed
163
164
165
            echo '<tr valign="top"><td align="right">';
            echo '<label for="menulockconfig_field_lock_'.$field.'">'.$fieldname.'</label>';
            echo '</td><td>';
166
167
168
169
170
171
172
173
174
175
176
177
            choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
        }
        echo '</td>';
        if (!empty($helptext)) {
            echo '<td rowspan="' . count($user_fields) . '">' . $helptext . '</td>';
            $helptext = '';
        }
        echo '</tr>';
    }
}

?>