1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Provides settings pages for the CAS Attributes module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Administrative settings form.
|
10
|
*/
|
11
|
function cas_attributes_admin_settings() {
|
12
|
|
13
|
$form['cas_attributes_sync_every_login'] = array(
|
14
|
'#type' => 'radios',
|
15
|
'#title' => t('Fetch CAS Attributes'),
|
16
|
'#default_value' => variable_get('cas_attributes_sync_every_login', NULL),
|
17
|
'#options' => array(
|
18
|
0 => 'only when a CAS account is created (i.e., the first login of a CAS user).',
|
19
|
1 => 'every time a CAS user logs in.'
|
20
|
),
|
21
|
'#weight' => -10,
|
22
|
);
|
23
|
|
24
|
$form['cas_attributes_overwrite'] = array(
|
25
|
'#type' => 'radios',
|
26
|
'#title' => t('Overwrite existing values'),
|
27
|
'#default_value' => variable_get('cas_attributes_overwrite', TRUE),
|
28
|
'#options' => array(
|
29
|
0 => 'only store data from attributes for fields that are empty (don\'t overwrite user fields that already have data).',
|
30
|
1 => 'always store data from attributes (overwrite user fields that already have data).',
|
31
|
),
|
32
|
'#weight' => -9,
|
33
|
);
|
34
|
|
35
|
$relations = variable_get('cas_attributes_relations', array());
|
36
|
$form['cas_attributes_relations'] = array(
|
37
|
'#tree' => TRUE,
|
38
|
'#type' => 'fieldset',
|
39
|
'#title' => t('CAS attribute mappings'),
|
40
|
);
|
41
|
|
42
|
$form['cas_attributes_relations']['help'] = array(
|
43
|
'#markup' => t('Token replacement strings used to populate each <a href="@url">user field</a>? Only text fields are eligible to be populated. Entries left blank will be ignored.', array('@url' => url('admin/config/people/accounts/fields'))),
|
44
|
);
|
45
|
|
46
|
// Provide fields for username and e-mail address.
|
47
|
$form['cas_attributes_relations']['name'] = array(
|
48
|
'#type' => 'textfield',
|
49
|
'#title' => t('Username'),
|
50
|
'#default_value' => isset($relations['name']) ? $relations['name'] : '',
|
51
|
'#size' => 50,
|
52
|
'#description' => t('The account username.'),
|
53
|
);
|
54
|
$form['cas_attributes_relations']['mail'] = array(
|
55
|
'#type' => 'textfield',
|
56
|
'#title' => t('E-mail address'),
|
57
|
'#default_value' => isset($relations['mail']) ? $relations['mail'] : '',
|
58
|
'#size' => 50,
|
59
|
'#description' => t('The account e-mail address.'),
|
60
|
);
|
61
|
|
62
|
// Provide fields for fields attached to the user bundle.
|
63
|
foreach (field_info_instances('user', 'user') as $name => $instance) {
|
64
|
$field = field_info_field($instance['field_name']);
|
65
|
if ($field['type'] == 'text') {
|
66
|
$form['cas_attributes_relations'][$name] = array(
|
67
|
'#type' => 'textfield',
|
68
|
'#title' => t($instance['label']),
|
69
|
'#default_value' => isset($relations[$name]) ? $relations[$name] : '',
|
70
|
'#size' => 50,
|
71
|
'#description' => t('The account field with name %field_name.', array('%field_name' => $instance['field_name'])),
|
72
|
);
|
73
|
}
|
74
|
}
|
75
|
|
76
|
// Role Management
|
77
|
$form['cas_attributes_roles'] = array(
|
78
|
'#type' => 'fieldset',
|
79
|
'#title' => t('Role Mapping'),
|
80
|
'#access' => user_access('administer permissions'),
|
81
|
'#description' => t('You may choose to manage assignment of one or more of the roles on this Drupal site based on the values of certain CAS attributes. ' .
|
82
|
'Only the roles you select to manage will be affected. Managed roles will be assigned or revoked whenever a user logs in thru CAS (regardless of how you set the ' .
|
83
|
'"Overwrite existing values" setting above).<br>' .
|
84
|
'For each managed role: if the role name is present in at least one of the attributes you specify, ' .
|
85
|
'the role will be granted to the user. If the role name is not present in any of the attributes, it will be removed from the user.<br>' .
|
86
|
'Roles must be specified by name (not by numeric ID, since that is site specific).<br>'),
|
87
|
);
|
88
|
|
89
|
$roles = user_roles(TRUE);
|
90
|
unset($roles[DRUPAL_AUTHENTICATED_RID]);
|
91
|
asort($roles);
|
92
|
|
93
|
$form['cas_attributes_roles']['cas_attributes_roles_manage'] = array(
|
94
|
'#type' => 'checkboxes',
|
95
|
'#title' => t('Roles to manage'),
|
96
|
'#description' => t('Which roles should be managed by these attributes.'),
|
97
|
'#default_value' => variable_get('cas_attributes_roles_manage', array()),
|
98
|
'#options' => $roles,
|
99
|
);
|
100
|
|
101
|
$form['cas_attributes_roles']['cas_attributes_roles_mapping'] = array(
|
102
|
'#type' => 'textarea',
|
103
|
'#title' => t('Attributes'),
|
104
|
'#description' => t('List the names of the CAS attributes which may ' .
|
105
|
'contain names of the managed roles. List one attribute per line - ' .
|
106
|
'for example, <strong>department</strong> or <strong>affiliations' .
|
107
|
'</strong>. Do not use token syntax, as it will not be processed. ' .
|
108
|
'If the name of a managed role is present in at least one of these ' .
|
109
|
'attributes, that role will be given to the user; otherwise, it will ' .
|
110
|
'be taken away.'),
|
111
|
'#default_value' => variable_get('cas_attributes_roles_mapping', ''),
|
112
|
);
|
113
|
|
114
|
$form['token_tree'] = array(
|
115
|
'#theme' => 'token_tree',
|
116
|
'#token_types' => array('cas'),
|
117
|
'#global_types' => FALSE,
|
118
|
);
|
119
|
|
120
|
return system_settings_form($form);
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
* Lists available CAS Attributes.
|
125
|
*/
|
126
|
function cas_attributes_list() {
|
127
|
cas_phpcas_load();
|
128
|
cas_phpcas_init();
|
129
|
|
130
|
phpCAS::forceAuthentication();
|
131
|
$attributes = phpCAS::getAttributes();
|
132
|
|
133
|
$header = array('Token', 'Value');
|
134
|
$rows = array();
|
135
|
|
136
|
foreach ($attributes as $attribute => $value) {
|
137
|
if (is_array($value)) {
|
138
|
$value = $value[0];
|
139
|
}
|
140
|
$rows[] = array(
|
141
|
t('[cas:attribute:@attribute]', array('@attribute' => drupal_strtolower($attribute))),
|
142
|
check_plain($value),
|
143
|
);
|
144
|
}
|
145
|
|
146
|
if (empty($rows)) {
|
147
|
$rows[] = array(
|
148
|
'data' => array(
|
149
|
array(
|
150
|
'data' => t('No CAS attributes were returned by the CAS server.'),
|
151
|
'colspan' => 2,
|
152
|
),
|
153
|
),
|
154
|
);
|
155
|
}
|
156
|
|
157
|
return theme('table', array('header' => $header, 'rows' => $rows));
|
158
|
}
|