1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* theming functions for ldap_query module
|
6 |
|
|
*
|
7 |
|
|
*/
|
8 |
|
|
|
9 |
|
|
/**
|
10 |
|
|
* Returns HTML for ldap servers list.
|
11 |
|
|
*
|
12 |
|
|
* @param $variables
|
13 |
|
|
* An associative array containing:
|
14 |
|
|
* - ldap_query: an array of one or more ldap server configurations.
|
15 |
|
|
* - actions: true or false indicating include update, delete, etc. links
|
16 |
|
|
* - type: 'table', 'list', etc for style to render
|
17 |
|
|
*
|
18 |
|
|
* @ingroup themeable
|
19 |
|
|
*/
|
20 |
|
|
function theme_ldap_query_list($variables) {
|
21 |
|
|
extract($variables);
|
22 |
|
|
|
23 |
|
|
$table = array(
|
24 |
|
|
'header' => array(t('Name'), t('Base DN'), t('Filter'), t('Attributes'), t('Enabled')),
|
25 |
|
|
'attributes' => array('id' => 'ldap_queries', 'class' => 'data'),
|
26 |
|
|
'colgroups' => array(),
|
27 |
|
|
'sticky' => FALSE,
|
28 |
|
|
'empty' => '',
|
29 |
|
|
'caption' => 'LDAP Queries',
|
30 |
|
|
);
|
31 |
|
|
|
32 |
|
|
if ($actions) {
|
33 |
|
|
$table['header'][] = "Operations";
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
if (count($ldap_queries)) {
|
37 |
|
|
foreach ($ldap_queries as $qid => $ldap_query ) {
|
38 |
|
|
$row = array(
|
39 |
|
|
$ldap_query->name,
|
40 |
|
|
$ldap_query->base_dn_str,
|
41 |
|
|
$ldap_query->filter,
|
42 |
|
|
$ldap_query->attributes_str,
|
43 |
|
|
($ldap_query->status == 1) ? "Yes" : "No",
|
44 |
|
|
);
|
45 |
|
|
if ($actions) {
|
46 |
|
|
$admin = new LdapQueryAdmin($ldap_query->qid);
|
47 |
|
|
$row[] = join(' | ', $admin->getActions());
|
48 |
|
|
}
|
49 |
|
|
$table['rows'][] = $row;
|
50 |
|
|
}
|
51 |
|
|
}
|
52 |
|
|
else {
|
53 |
|
|
$table['rows'] = array();
|
54 |
|
|
}
|
55 |
|
|
$output = theme('table', $table);
|
56 |
|
|
|
57 |
|
|
return $output;
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
/**
|
61 |
|
|
* Returns HTML for ldap server.
|
62 |
|
|
*
|
63 |
|
|
* @param $variables
|
64 |
|
|
* An associative array containing:
|
65 |
|
|
* - ldap_query_config: an array of one or more ldap server configurations.
|
66 |
|
|
* - actions: true or false indicating include update, delete, etc. links
|
67 |
|
|
* - type: 'table', 'list', etc for style to render
|
68 |
|
|
*
|
69 |
|
|
* @ingroup themeable
|
70 |
|
|
*/
|
71 |
|
|
|
72 |
|
|
function theme_ldap_query($variables) {
|
73 |
|
|
|
74 |
|
|
extract($variables); // $ldap_query, $actions, $type (see above)
|
75 |
|
|
|
76 |
|
|
ldap_servers_module_load_include('php', 'ldap_query', 'LdapQuery.class');
|
77 |
|
|
$properties = array();
|
78 |
|
|
foreach (LdapQuery::fields() as $field_id => $field) {
|
79 |
|
|
$value = $ldap_query->{$field['property_name']};
|
80 |
|
|
if (is_scalar($value)) {
|
81 |
|
|
$properties[] = $field_id . " = " . $value; // $value";
|
82 |
|
|
}
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
if ($actions) {
|
86 |
|
|
$admin = new LdapQueryAdmin($ldap_query->sid);
|
87 |
|
|
$properties = join(' | ', $admin->getActions());
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
$output = theme_item_list(
|
91 |
|
|
array(
|
92 |
|
|
'items' => $properties,
|
93 |
|
|
'type' => 'ul',
|
94 |
|
|
'title' => 'Query Properties',
|
95 |
|
|
'attributes' => array()
|
96 |
|
|
)
|
97 |
|
|
);
|
98 |
|
|
|
99 |
|
|
return $output;
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
function theme_ldap_query_results($variables) {
|
103 |
|
|
extract($variables); // $ldap_query, $results, $show_query
|
104 |
|
|
|
105 |
|
|
$query = theme('ldap_query', array('ldap_query' => $ldap_query));
|
106 |
|
|
$results_text = t('LDAP Query Results: count=%count', array('%count' => $results['count']));
|
107 |
|
|
|
108 |
|
|
if (!$results['count']) {
|
109 |
|
|
return $query . '<br/>' . $results_text;
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
$table = array(
|
113 |
|
|
'header' => array('DN'),
|
114 |
|
|
'attributes' => array('id' => 'ldap_query_resultset', 'class' => 'data'),
|
115 |
|
|
'colgroups' => array(),
|
116 |
|
|
'sticky' => FALSE,
|
117 |
|
|
'empty' => '',
|
118 |
|
|
'caption' => $results_text,
|
119 |
|
|
);
|
120 |
|
|
unset($results['count']);
|
121 |
|
|
|
122 |
|
|
$attributes_display = array();
|
123 |
|
|
if (isset($results[0]) && $results[0]) { // searching on all attributes
|
124 |
|
|
foreach ($results[0] as $k => $v) {
|
125 |
|
|
if (is_numeric($k)) {
|
126 |
|
|
$attributes_display[] = $v;
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
foreach ($attributes_display as $attr) {
|
133 |
|
|
$table['header'][] = $attr;
|
134 |
|
|
}
|
135 |
|
|
|
136 |
|
|
foreach ($results as $i => $entry) {
|
137 |
|
|
$row = array($entry['dn']);
|
138 |
|
|
foreach ($attributes_display as $i => $attr_name) {
|
139 |
|
|
$attr_name = ldap_server_massage_text($attr_name, 'attr_name', LDAP_SERVER_MASSAGE_QUERY_ARRAY); // drupal_strtolower($attr_name);
|
140 |
|
|
if (!isset($entry[$attr_name])) {
|
141 |
|
|
$row[] = 'no data';
|
142 |
|
|
}
|
143 |
|
|
elseif (is_array($entry[$attr_name])) {
|
144 |
|
|
unset($entry[$attr_name]['count']);
|
145 |
|
|
$row[] = join("<br/>", $entry[$attr_name]);
|
146 |
|
|
}
|
147 |
|
|
else {
|
148 |
|
|
$row[] = $entry[$attr_name];
|
149 |
|
|
}
|
150 |
|
|
// unset($attr_data['count']);
|
151 |
|
|
|
152 |
|
|
}
|
153 |
|
|
unset($entry['count']);
|
154 |
|
|
$table['rows'][] = $row;
|
155 |
|
|
}
|
156 |
|
|
return $query . '<br/>' . theme_table($table);
|
157 |
|
|
|
158 |
|
|
} |