1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Theming functions for ldap_servers module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Returns HTML for ldap servers list.
|
10
|
*
|
11
|
* @param $variables
|
12
|
* An associative array containing:
|
13
|
* - ldap_servers: an array of one or more ldap server configurations.
|
14
|
* - actions: true or false indicating include update, delete, etc. links
|
15
|
* - type: 'table', 'list', etc for style to render
|
16
|
*
|
17
|
* @ingroup themeable
|
18
|
*
|
19
|
* @return string
|
20
|
*/
|
21
|
function theme_ldap_servers_list($variables) {
|
22
|
/** @var array $ldap_servers */
|
23
|
/** @var bool $actions */
|
24
|
/** @var string $type */
|
25
|
extract($variables);
|
26
|
|
27
|
$table = [
|
28
|
'header' => [t('Name'), t('Type'), t('Enabled'), t('Server Address')],
|
29
|
'attributes' => ['id' => 'ldap_servers_servers', 'class' => 'data'],
|
30
|
'colgroups' => [],
|
31
|
'sticky' => FALSE,
|
32
|
'empty' => '',
|
33
|
'caption' => 'LDAP Server Configurations',
|
34
|
];
|
35
|
|
36
|
if ($actions) {
|
37
|
$table['header'][] = "Operations";
|
38
|
}
|
39
|
if (count($ldap_servers)) {
|
40
|
foreach ($ldap_servers as $sid => $ldap_server) {
|
41
|
$row = [
|
42
|
$ldap_server->name,
|
43
|
$ldap_server->ldap_type,
|
44
|
($ldap_server->status == 1) ? "Yes" : "No",
|
45
|
$ldap_server->address,
|
46
|
];
|
47
|
if ($actions) {
|
48
|
$admin = new LdapServerAdmin($ldap_server->sid);
|
49
|
$row[] = join(' | ', $admin->getLdapServerActions());
|
50
|
}
|
51
|
$table['rows'][] = $row;
|
52
|
}
|
53
|
}
|
54
|
else {
|
55
|
$table['rows'] = [];
|
56
|
}
|
57
|
$output = theme('table', $table);
|
58
|
|
59
|
return $output;
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* Returns HTML for ldap server.
|
64
|
*
|
65
|
* @param $variables
|
66
|
* An associative array containing:
|
67
|
* - ldap_server: an array of one or more ldap server configurations.
|
68
|
* - actions: true or false indicating include update, delete, etc. links
|
69
|
* - type: 'table', 'list', etc for style to render
|
70
|
*
|
71
|
* @ingroup themeable
|
72
|
*
|
73
|
* @return string
|
74
|
*/
|
75
|
function theme_ldap_servers_server($variables) {
|
76
|
/** @var array $ldap_server */
|
77
|
/** @var bool $actions */
|
78
|
/** @var string $type */
|
79
|
extract($variables);
|
80
|
|
81
|
ldap_servers_module_load_include('php', 'ldap_servers', 'LdapServer.class');
|
82
|
$properties = [];
|
83
|
foreach (LdapServer::field_to_properties_map() as $field_name => $property_name) {
|
84
|
$properties[] = "$field_name = " . print_r($ldap_server->$property_name, TRUE);
|
85
|
}
|
86
|
|
87
|
if ($actions) {
|
88
|
$admin = new LdapServerAdmin($ldap_server->sid);
|
89
|
$properties = join(' | ', $admin->getLdapServerActions());
|
90
|
}
|
91
|
|
92
|
$output = theme_item_list(
|
93
|
[
|
94
|
'items' => $properties,
|
95
|
'type' => 'ul',
|
96
|
'title' => 'Server Properties',
|
97
|
'attributes' => [],
|
98
|
]
|
99
|
);
|
100
|
|
101
|
return $output;
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
*
|
106
|
*/
|
107
|
function theme_ldap_server_token_table($variables) {
|
108
|
$header = [
|
109
|
['data' => 'Token', 'sort' => 'asc'],
|
110
|
['data' => 'Value'],
|
111
|
];
|
112
|
foreach ($variables['tokens'] as $token => $value) {
|
113
|
$rows[] = ['data' => [$token, $value]];
|
114
|
}
|
115
|
$token_table = '<div class="content"><h2>' . t('Available Tokens') . '</h2>' .
|
116
|
theme_table(['colgroups' => NULL, 'caption' => 'tokens', 'header' => $header, 'rows' => $rows, 'sticky' => TRUE, 'attributes' => [], 'empty' => 'No data']) .
|
117
|
'</div>';
|
118
|
|
119
|
return $token_table;
|
120
|
}
|
121
|
|
122
|
/**
|
123
|
*
|
124
|
*/
|
125
|
function theme_ldap_server_ldap_entry_table($variables) {
|
126
|
if (!isset($variables['entry']) || !is_array($variables['entry'])) {
|
127
|
return '<p>' . t('No Entry Returned.') . t('</p>');
|
128
|
}
|
129
|
|
130
|
$header = ['Attribute Name', 'Instance', 'Value', 'token'];
|
131
|
$rows = [];
|
132
|
foreach ($variables['entry'] as $key => $value) {
|
133
|
if (is_numeric($key) || $key == 'count') {
|
134
|
}
|
135
|
elseif (is_array($value) && count($value) > 1) {
|
136
|
$count = (int) $value['count'];
|
137
|
foreach ($value as $i => $value2) {
|
138
|
|
139
|
if ((string) $i == 'count') {
|
140
|
continue;
|
141
|
}
|
142
|
elseif ($i == 0 && $count == 1) {
|
143
|
$token = LDAP_SERVERS_TOKEN_PRE . $key . LDAP_SERVERS_TOKEN_POST;
|
144
|
}
|
145
|
elseif ($i == 0 && $count > 1) {
|
146
|
$token = LDAP_SERVERS_TOKEN_PRE . $key . LDAP_SERVERS_TOKEN_DEL . '0' . LDAP_SERVERS_TOKEN_POST;
|
147
|
}
|
148
|
elseif (($i == $count - 1) && $count > 1) {
|
149
|
$token = LDAP_SERVERS_TOKEN_PRE . $key . LDAP_SERVERS_TOKEN_DEL . 'last' . LDAP_SERVERS_TOKEN_POST;
|
150
|
}
|
151
|
elseif ($count > 1) {
|
152
|
$token = LDAP_SERVERS_TOKEN_PRE . $key . LDAP_SERVERS_TOKEN_DEL . $i . LDAP_SERVERS_TOKEN_POST;
|
153
|
}
|
154
|
else {
|
155
|
$token = "";
|
156
|
}
|
157
|
$rows[] = ['data' => [$key, $i, ldap_servers_string_binary_check($value2), $token]];
|
158
|
}
|
159
|
}
|
160
|
}
|
161
|
$heading = sprintf('<h2>%s</h2>', t('LDAP Entry for %username (dn: %dn)', [
|
162
|
'%dn' => $variables['dn'],
|
163
|
'%username' => $variables['username'],
|
164
|
]));
|
165
|
$table = theme('table', [
|
166
|
'colgroups' => NULL,
|
167
|
'caption' => 'ldap entry array',
|
168
|
'header' => $header,
|
169
|
'rows' => $rows,
|
170
|
'sticky' => TRUE,
|
171
|
'attributes' => [],
|
172
|
'empty' => 'No data',
|
173
|
]);
|
174
|
$entry_table = '<div class="content">' . $heading . $table . '</div>';
|
175
|
return $entry_table;
|
176
|
}
|