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