Skip to content

Commit

Permalink
Add buttons in directory page to switch between users and groups (ltb…
Browse files Browse the repository at this point in the history
  • Loading branch information
coudot committed Jun 23, 2019
1 parent 4ae23b0 commit 1ede1e9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
4 changes: 4 additions & 0 deletions conf/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@
# Directory
$use_directory = true;
$directory_items = array('firstname', 'lastname', 'mail', 'organization');
$directory_group_items = array('fullname', 'description');
$directory_linkto = array('firstname', 'lastname');
$directory_group_linkto = array('fullname');
$directory_sortby = "lastname";
$directory_group_sortby = "fullname";
$directory_show_undefined = false;
$directory_truncate_value_after = 30;
$directory_display_search_objects = true;

# CSV
$use_csv = true;
Expand Down
39 changes: 32 additions & 7 deletions htdocs/directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,35 @@
$ldap = $ldap_connection[0];
$result = $ldap_connection[1];

if (isset($_GET["type"])) {
$type = $_GET["type"];
} else {
$type = "user";
}

if ( $type === "user" ) {
$ldap_search_base = $ldap_user_base;
$ldap_search_filter = $ldap_user_filter;
$result_items = $directory_items;
$result_sortby = $directory_sortby;
$result_linkto = $directory_linkto;
}

if ( $type === "group" ) {
$ldap_search_base = $ldap_group_base;
$ldap_search_filter = $ldap_group_filter;
$result_items = $directory_group_items;
$result_sortby = $directory_group_sortby;
$result_linkto = $directory_group_linkto;
}

if ($ldap) {

# Search attributes
foreach ($directory_items as $item) $attributes[] = $attributes_map[$item]['attribute'];
foreach ($result_items as $item) $attributes[] = $attributes_map[$item]['attribute'];

# Search for users
$search = ldap_search($ldap, $ldap_user_base, $ldap_user_filter, $attributes, 0, $ldap_size_limit);
# Search for entries
$search = ldap_search($ldap, $ldap_search_base, $ldap_search_filter, $attributes, 0, $ldap_size_limit);

$errno = ldap_errno($ldap);

Expand All @@ -37,7 +59,7 @@

# Sort entries
if (isset($search_result_sortby)) {
$sortby = $attributes_map[$directory_sortby]['attribute'];
$sortby = $attributes_map[$result_sortby]['attribute'];
ldap_sort($ldap, $search, $sortby);
}

Expand All @@ -57,10 +79,13 @@
$smarty->assign("entries", $entries);
$smarty->assign("size_limit_reached", $size_limit_reached);

$smarty->assign("listing_columns", $directory_items);
$smarty->assign("listing_linkto", $directory_linkto);
$smarty->assign("listing_sortby", array_search($directory_sortby, $directory_items));
$smarty->assign("listing_columns", $result_items);
$smarty->assign("listing_linkto", $result_linkto);
$smarty->assign("listing_sortby", array_search($result_sortby, $result_items));

$smarty->assign("show_undef", $directory_show_undefined);
$smarty->assign("truncate_value_after", $directory_truncate_value_after);

$smarty->assign("type", $type);
$smarty->assign("directory_display_search_objects", $directory_display_search_objects)
?>
6 changes: 6 additions & 0 deletions templates/directory.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<div class="alert alert-warning"><i class="fa fa-fw fa-exclamation-triangle"></i> {$msg_sizelimit}</div>
{/if}

{if {$directory_display_search_objects}}
<div class="btn-group" role="group">
<a type="button" href="index.php?page=directory&type=user" class="btn btn-default{if {$type}==="user"} active{/if}"><i class="fa fa-user"></i> {$msg_user_object}</a>
<a type="button" href="index.php?page=directory&type=group" class="btn btn-default{if {$type}==="group"} active{/if}"><i class="fa fa-group"></i> {$msg_group_object}</a>
</div>
{/if}

<table id="directory-listing" class="table table-striped table-hover table-condensed dataTable">
{include 'listing_table.tpl'}
Expand Down

0 comments on commit 1ede1e9

Please sign in to comment.