Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dropdown list to advanced search criteria #42

Closed
vlepetit opened this issue Apr 11, 2018 · 8 comments
Closed

add dropdown list to advanced search criteria #42

vlepetit opened this issue Apr 11, 2018 · 8 comments
Assignees
Milestone

Comments

@vlepetit
Copy link

Hi,

it's possible to add dropdown list to advanced for some search criteria like team. The list may be contain in ldap or just right in hard list in config files ?

This functionality to help users who don't know the name of all team in organisation and want to know members of differents teams or services..

Regards,
vlepetit

@coudot coudot added this to the future milestone Apr 11, 2018
@coudot
Copy link
Member

coudot commented Apr 11, 2018

Interesting feature, but will not be in 0.2 which should be released soon.

@vlepetit
Copy link
Author

Can you give me advice to implement this feature in your code.

In which file can i works ?
the best way or approach ?

And maybe i can propose code...

Regards,
vlepetit

@coudot
Copy link
Member

coudot commented Apr 13, 2018

You new to create a new type and define how it will appear in search form in templates/search_displayer.tpl

There is already a select box for boolean values, you can use the same idea.

@vlepetit
Copy link
Author

vlepetit commented Jul 26, 2018

hi,

so i tried that but i had some problems

1 - I had copy already existing function 'get_attribute' and created an adapt to a new smarty function in smarty.inc.php to return an array ->

function get_attributes_entity($params, $smarty) {

    $return = "";
    $dn = $params["dn"];
    $attributes = $params["attributes"];
    $ldap_url = $params["ldap_url"];
    $ldap_starttls = $params["ldap_starttls"];
    $ldap_binddn = $params["ldap_binddn"];
    $ldap_bindpw = $params["ldap_bindpw"];
    $ldap_user_filter = $params["ldap_user_filter"];

    # 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) {

        # Search entry
        $search = ldap_search($ldap, $dn, $ldap_user_filter, array($attributes));

        $errno = ldap_errno($ldap);

        if ( $errno ) {
            error_log("LDAP - Search error $errno  (".ldap_error($ldap).")");
        } else {
            $entry = ldap_get_entries($ldap, $search);

            //$return = $entry[0][$attribute][0];
            $return = $entry;
        }
    }

    $template->assign($params['entitys'], $return);
    /*return $return;*/
}

2 - i had register this new plugin in index.php ->

# Register plugins
require_once("../lib/smarty.inc.php");
$smarty->registerPlugin("function", "get_attribute", "get_attribute");
$smarty->registerPlugin("function", "convert_ldap_date", "convert_ldap_date");
$smarty->registerPlugin("function", "get_attributes_entity", "get_attributes_entity");

3 - and i tried to called this function and manipulate the retrurned array values in search_displayer.tpl ->

{elseif {$item} eq 'organizationalunit' and $type eq 'entity'}
			{get_attributes_entity entitys="entitysValues" dn="ou=structures,dc=univ-psl,dc=fr" attributes="supanncodeentite,ou" ldap_url="{$ldap_params.ldap_url}" ldap_starttls="{$ldap_params.ldap_starttls}" ldap_binddn="{$ldap_params.ldap_binddn}" ldap_bindpw="{$ldap_params.ldap_bindpw}" ldap_user_filter="ou=*"}
			
			<select class="form-control" id="{$item}" name="{$item}" placeholder="{$label}">
			{foreach from=$entitysValues key=supanncodeentite item=ou}
			{*<option value="{$entity.supanncodeentite[0]}">{$entity.ou}</option>*}
			{$supanncodeentite} : {$ou}<br/>
			{$entitys|@print_r}
			{/foreach}
                        </select>
            {else}....

But at this moment i can not take values inside returned array.

Ans i don't now if my function/plugin return something...

Maybe you can help me ?

Regards,
vlepetit

@coudot
Copy link
Member

coudot commented Aug 29, 2018

You must not assign to template inside the smarty function. You need to call the function in the template.

@coudot
Copy link
Member

coudot commented Jul 23, 2019

Seems a plugin cannot return an array: smarty-php/smarty#228

The only solution I see is to search for values in php code and assign the result to a template var. It is not as clean as calling directly the plugin in smarty template, but this should work. I will give a try.

@coudot coudot self-assigned this Jul 23, 2019
@coudot coudot modified the milestones: future, 0.3 Jul 23, 2019
coudot added a commit to Worteks/white-pages that referenced this issue Jul 23, 2019
coudot added a commit to Worteks/white-pages that referenced this issue Jul 23, 2019
@coudot
Copy link
Member

coudot commented Jul 23, 2019

Code done in #74

@coudot
Copy link
Member

coudot commented Jul 23, 2019

@coudot coudot closed this as completed Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants