diff --git a/conf/config.inc.php b/conf/config.inc.php index 85bc431..2e78612 100644 --- a/conf/config.inc.php +++ b/conf/config.inc.php @@ -71,6 +71,8 @@ 'uniquemember' => array( 'attribute' => 'uniquemember', 'faclass' => 'user', 'type' => 'usergroup_dn_link' ), ); +$attributes_list = array(); + # Quick search $use_quick_search = true; $quick_search_attributes = array('uid', 'cn', 'mail'); diff --git a/htdocs/advancedsearch.php b/htdocs/advancedsearch.php index ebabe8c..82acd0b 100644 --- a/htdocs/advancedsearch.php +++ b/htdocs/advancedsearch.php @@ -15,6 +15,26 @@ if (!isset($_POST["submit"])) { $smarty->assign('advanced_search_criteria', $advanced_search_criteria); $smarty->assign('advanded_search_display_search_objects', $advanded_search_display_search_objects); + + # Check if an attribute is a list type and prepare the list + require_once("../lib/ldap.inc.php"); + + # Connect to LDAP + $ldap_connection = wp_ldap_connect($ldap_url, $ldap_starttls, $ldap_binddn, $ldap_bindpw); + + $ldap = $ldap_connection[0]; + $result = $ldap_connection[1]; + + if ($ldap) { + $item_list = array(); + foreach ( $advanced_search_criteria as $criteria ) { + if ( $attributes_map[$criteria]["type"] === "list" ) { + $item_list[$criteria] = wp_ldap_get_list( $ldap, $attributes_list[$criteria]["base"], $attributes_list[$criteria]["filter"], $attributes_list[$criteria]["key"], $attributes_list[$criteria]["value"] ); + } + } + $smarty->assign('item_list', $item_list); + } + $result = "displayform"; } diff --git a/lib/ldap.inc.php b/lib/ldap.inc.php index 211bed1..13caaac 100644 --- a/lib/ldap.inc.php +++ b/lib/ldap.inc.php @@ -33,4 +33,29 @@ function wp_ldap_connect($ldap_url, $ldap_starttls, $ldap_binddn, $ldap_bindpw) return array($ldap, false); } +function wp_ldap_get_list($ldap, $ldap_base, $ldap_filter, $key, $value) { + + $return = array(); + + if ($ldap) { + + # Search entry + $search = ldap_search($ldap, $ldap_base, $ldap_filter, array($key, $value) ); + + $errno = ldap_errno($ldap); + + if ( $errno ) { + error_log("LDAP - Search error $errno (".ldap_error($ldap).")"); + } else { + $entries = ldap_get_entries($ldap, $search); + for ($i=0; $i<$entries["count"]; $i++) { + if(isset($entries[$i][$key][0])) { + $return[$entries[$i][$key][0]] = isset($entries[$i][$value][0]) ? $entries[$i][$value][0] : $entries[$i][$key][0]; + } + } + } + } + + return $return; +} ?> diff --git a/templates/advancedsearch.tpl b/templates/advancedsearch.tpl index bfdbd91..4f98fa9 100644 --- a/templates/advancedsearch.tpl +++ b/templates/advancedsearch.tpl @@ -20,7 +20,7 @@ {foreach $advanced_search_criteria as $item} {$type=$attributes_map.{$item}.type} {$faclass=$attributes_map.{$item}.faclass} - {include 'search_displayer.tpl' label="{$msg_label_{$item}}" item=$item type=$type faclass=$faclass ldap_params=$ldap_params} + {include 'search_displayer.tpl' label="{$msg_label_{$item}}" item=$item type=$type faclass=$faclass ldap_params=$ldap_params list=$item_list.{$item}} {/foreach}
diff --git a/templates/search_displayer.tpl b/templates/search_displayer.tpl index a1e9c36..5445621 100644 --- a/templates/search_displayer.tpl +++ b/templates/search_displayer.tpl @@ -16,6 +16,14 @@ {elseif $type eq 'guid' or $type eq 'dn_link' or $type eq 'group_dn_link' or $type eq 'usergroup_dn_link' } + {elseif $type eq 'list'} + + {else} diff --git a/templates/value_displayer.tpl b/templates/value_displayer.tpl index aafe695..1c4e1ed 100644 --- a/templates/value_displayer.tpl +++ b/templates/value_displayer.tpl @@ -43,3 +43,7 @@ {if $type eq 'guid'} {convert_guid_value($value)|truncate:{$truncate_value_after}}
{/if} + +{if $type eq 'list'} + {$value|truncate:{$truncate_value_after}}
+{/if}