1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Theming functions for the LDAP authorization module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
*
|
10
|
*/
|
11
|
function theme_ldap_authorization_admin_index(&$variables) {
|
12
|
$consumers = $variables['consumers'];
|
13
|
|
14
|
$table = [
|
15
|
'header' => [t('LDAP Server ID'), t('Description'), t('Module'), t('Consumer Type'), t('Enabled'), t('Operations')],
|
16
|
'attributes' => ['id' => 'ldap_consumer_confs', 'class' => 'data'],
|
17
|
'colgroups' => [],
|
18
|
'sticky' => FALSE,
|
19
|
'empty' => '',
|
20
|
'caption' => t('LDAP Authorization Configurations'),
|
21
|
'rows' => [],
|
22
|
];
|
23
|
|
24
|
foreach ($consumers as $consumer_type => $consumer) {
|
25
|
|
26
|
if ($consumer->consumerConf->inDatabase) {
|
27
|
$admin = new LdapAuthorizationConsumerConfAdmin($consumer);
|
28
|
$actions = join(' | ', $admin->getLdapAuthorizationConsumerActions());
|
29
|
}
|
30
|
else {
|
31
|
$actions = l(t('add'), LDAP_SERVERS_MENU_BASE_PATH . '/authorization/add/' . $consumer->consumerType);
|
32
|
}
|
33
|
|
34
|
$table['rows'][] = [
|
35
|
$consumer->consumerConf->sid,
|
36
|
$consumer->name,
|
37
|
$consumer->consumerModule,
|
38
|
$consumer_type,
|
39
|
($consumer->consumerConf->status) ? t('Yes') : t('No'),
|
40
|
$actions,
|
41
|
];
|
42
|
}
|
43
|
return theme('table', $table);
|
44
|
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
*
|
49
|
*/
|
50
|
function theme_ldap_authorization_test_results($variables) {
|
51
|
|
52
|
$results = $variables['results'];
|
53
|
$consumer = $variables['consumer'];
|
54
|
$notifications = $variables['notifications'];
|
55
|
$consumer_conf_link = l($consumer->consumerType, LDAP_SERVERS_MENU_BASE_PATH . '/authorization/edit/' . $consumer->consumerType);
|
56
|
$server_link = l($consumer->consumerConf->sid, LDAP_SERVERS_MENU_BASE_PATH . '/servers/edit/' . $consumer->consumerConf->sid);
|
57
|
|
58
|
$table = [
|
59
|
'header' => [t('Drupal Username'), t('Authorization Type'), t('Authorization IDs'), t('Configuration'), t('LDAP Server Configuration')],
|
60
|
'attributes' => ['id' => 'ldap_authorization_authorizations', 'class' => 'data'],
|
61
|
'colgroups' => [],
|
62
|
'sticky' => FALSE,
|
63
|
'empty' => '',
|
64
|
'caption' => t('LDAP Authorizations Test Results for consumer %consumer', ['%consumer' => $consumer->name]),
|
65
|
'rows' => [],
|
66
|
];
|
67
|
|
68
|
if (count($results)) {
|
69
|
foreach ($results as $username => $user_results) {
|
70
|
$row = [];
|
71
|
if ($user = user_load_by_name($username)) {
|
72
|
$username_link = l($username, 'user/' . $user->uid . '/edit');
|
73
|
}
|
74
|
foreach ($user_results as $consumer_type => $authorizations) {
|
75
|
if (is_array($authorizations) && count($authorizations) > 0) {
|
76
|
$authorizations = $consumer->convertToFriendlyAuthorizationIds($authorizations);
|
77
|
$authorizations_text = theme('item_list', ['items' => array_values($authorizations), 'title' => NULL, 'type' => 'ul', 'attributes' => []]);
|
78
|
}
|
79
|
else {
|
80
|
$authorizations_text = "";
|
81
|
}
|
82
|
$row = [$username, $consumer->name, $authorizations_text, $consumer_conf_link, $server_link];
|
83
|
$table['rows'][] = $row;
|
84
|
}
|
85
|
|
86
|
foreach ($notifications[$username] as $consumer_type => $user_notifications) {
|
87
|
$authorizations_text = "";
|
88
|
if ($consumer_type == 'all') {
|
89
|
$authorizations_text = ldap_authorization_map_errors($user_notifications, $consumer_conf_link);
|
90
|
}
|
91
|
elseif (is_array($user_notifications) && count($user_notifications) > 0) {
|
92
|
foreach ($user_notifications as $i => $notification) {
|
93
|
$authorizations_text .= ldap_authorization_map_errors($notification, $consumer_conf_link);
|
94
|
}
|
95
|
}
|
96
|
$row = [$username_link, $consumer->name, $authorizations_text, $consumer_conf_link, $server_link];
|
97
|
$table['rows'][] = $row;
|
98
|
}
|
99
|
}
|
100
|
}
|
101
|
|
102
|
$output = theme('table', $table);
|
103
|
|
104
|
return $output;
|
105
|
|
106
|
}
|
107
|
|
108
|
/**
|
109
|
*
|
110
|
*/
|
111
|
function ldap_authorization_map_errors($err_id, $consumer_conf_link) {
|
112
|
|
113
|
$tokens = ['%consumer_conf_link' => $consumer_conf_link];
|
114
|
switch ($err_id) {
|
115
|
|
116
|
case LDAP_AUTHORIZATION_USER_LDAP_NOT_FOUND:
|
117
|
$authorizations_text = t('LDAP entry for drupal user not found.', $tokens);
|
118
|
break;
|
119
|
|
120
|
case LDAP_AUTHORIZATION_USER_NOT_LDAP_AUTHENTICATED:
|
121
|
$authorizations_text = t('LDAP Authorizations not applied because user is not
|
122
|
authenticated via LDAP and configuration requires is (%consumer_conf_link).', $tokens);
|
123
|
break;
|
124
|
|
125
|
case LDAP_AUTHORIZATION_MAP_NOT_CONF_FOR_LOGON:
|
126
|
$authorizations_text = t('LDAP Authorizations not configured to be executed on logon in (%consumer_conf_link).', $tokens);
|
127
|
break;
|
128
|
|
129
|
case LDAP_AUTHORIZATION_NOT_APPLY_USER_1:
|
130
|
$authorizations_text = t('LDAP Authorizations not applicable to user 1.', $tokens);
|
131
|
break;
|
132
|
|
133
|
case LDAP_AUTHORIZATION_SERVER_CONFIG_NOT_FOUND:
|
134
|
$authorizations_text = t('Enabled LDAP server configuration not found for given ldap consumer type in (%consumer_conf_link).', $tokens);
|
135
|
break;
|
136
|
|
137
|
default:
|
138
|
$authorizations_text = "Failed.";
|
139
|
}
|
140
|
|
141
|
return $authorizations_text;
|
142
|
}
|