Skip to content

Commit

Permalink
Merge pull request #74 from Worteks/issue-42
Browse files Browse the repository at this point in the history
Provide a new type (list)
  • Loading branch information
coudot authored Jul 23, 2019
2 parents a02d54f + 056ee22 commit 3959bb7
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
2 changes: 2 additions & 0 deletions conf/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
20 changes: 20 additions & 0 deletions htdocs/advancedsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down
25 changes: 25 additions & 0 deletions lib/ldap.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
?>
2 changes: 1 addition & 1 deletion templates/advancedsearch.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
Expand Down
8 changes: 8 additions & 0 deletions templates/search_displayer.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
<input type="text" class="form-control" id="{$item}to" name="{$item}to" data-provide="datepicker" data-date-language="{$lang}">
{elseif $type eq 'guid' or $type eq 'dn_link' or $type eq 'group_dn_link' or $type eq 'usergroup_dn_link' }
<input type="text" class="form-control" id="{$item}" name="{$item}" placeholder="{$label}">
{elseif $type eq 'list'}
<select class="form-control" id="{$item}" name="{$item}" placeholder="{$label}">
<option></option>
{foreach $list as $value}
<option value="{$value@key}">{$value}</option>
{/foreach}
</select>
<span class="input-group-addon"><input type="checkbox" name="{$item}match" value="exact" data-toggle="popover" data-content="{$msg_exactmatch}"></span>
{else}
<input type="text" class="form-control" id="{$item}" name="{$item}" placeholder="{$label}">
<span class="input-group-addon"><input type="checkbox" name="{$item}match" value="exact" data-toggle="popover" data-content="{$msg_exactmatch}"></span>
Expand Down
4 changes: 4 additions & 0 deletions templates/value_displayer.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@
{if $type eq 'guid'}
{convert_guid_value($value)|truncate:{$truncate_value_after}}<br />
{/if}

{if $type eq 'list'}
{$value|truncate:{$truncate_value_after}}<br />
{/if}

0 comments on commit 3959bb7

Please # to comment.