phpldapadmin/lib/search_results_table.php

134 lines
4.6 KiB
PHP
Raw Normal View History

2009-06-30 09:29:51 +00:00
<?php
2009-06-30 09:40:37 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/lib/search_results_table.php,v 1.7 2005/04/29 11:24:15 wurley Exp $
2009-06-30 09:22:30 +00:00
/**
* Incoming variables (among others)
* $results: The result of ldap_search(), ldap_list(), or ldap_read().
2009-06-30 09:29:51 +00:00
* $ldapserver: LDAP Server Object.
2009-06-30 09:22:30 +00:00
* $start_entry: The index of the entry at which to begin displaying
* $end_entry: The index of the entry at which to end displaying
2009-06-30 09:29:51 +00:00
* @package phpLDAPadmin
2009-06-30 09:22:30 +00:00
*/
2009-06-30 09:29:51 +00:00
2009-06-30 09:22:30 +00:00
$friendly_attrs = process_friendly_attr_table();
2009-06-30 09:29:51 +00:00
$entry_id = ldap_first_entry( $ldapserver->connect(), $results );
$all_attrs = array( '' => 1, 'dn' => 1 );
2009-06-30 09:22:30 +00:00
// Iterate over each entry and store the whole dang thing in memory (necessary to extract
// all attribute names and display in table format in a single pass)
$i = 0;
$entries = array();
$entries_display = array();
while( $entry_id ) {
$i++;
if( $i <= $start_entry ) {
2009-06-30 09:29:51 +00:00
$entry_id = ldap_next_entry( $ldapserver->connect(), $entry_id );
2009-06-30 09:22:30 +00:00
continue;
}
if( $i >= $end_entry )
break;
2009-06-30 09:29:51 +00:00
$dn = ldap_get_dn( $ldapserver->connect(), $entry_id );
$dn_display = strlen( $dn ) > 40 ? "<acronym title=\"" . htmlspecialchars( $dn ) . "\">" .
2009-06-30 09:22:30 +00:00
htmlspecialchars( substr( $dn, 0, 40 ) . '...' ) .
"</acronym>"
: htmlspecialchars( $dn );
$encoded_dn = rawurlencode( $dn );
$rdn = get_rdn( $dn );
2009-06-30 09:29:51 +00:00
$icon = get_icon_use_cache( $ldapserver, $dn );
$attrs = ldap_get_attributes( $ldapserver->connect(), $entry_id );
$attr = ldap_first_attribute( $ldapserver->connect(), $entry_id, $attrs );
2009-06-30 09:22:30 +00:00
$attrs_display = array();
2009-06-30 09:29:51 +00:00
$edit_url = sprintf("edit.php?server_id=%s&amp;dn=%s",$ldapserver->server_id,$encoded_dn);
2009-06-30 09:22:30 +00:00
$attrs_display[''] = "<center><a href=\"$edit_url\"><img src=\"images/$icon\" /></a><center>";
$attrs_display['dn'] = "<a href=\"$edit_url\">$dn_display</a>";
// Iterate over each attribute for this entry and store in associative array $attrs_display
while( $attr ) {
//echo "getting values for dn $dn, attr $attr\n";
// Clean up the attr name
if( isset( $friendly_attrs[ strtolower( $attr ) ] ) )
2009-06-30 09:29:51 +00:00
$attr_display = "<acronym title=\"Alias for $attr\">" .
2009-06-30 09:22:30 +00:00
htmlspecialchars( $friendly_attrs[ strtolower($attr) ] ) .
"</acronym>";
else
$attr_display = htmlspecialchars( $attr );
if( ! isset( $all_attrs[ $attr_display ] ) )
$all_attrs[ $attr_display ] = 1;
// Get the values
$display = '';
2009-06-30 09:29:51 +00:00
if( is_jpeg_photo( $ldapserver, $attr ) ) {
2009-06-30 09:22:30 +00:00
ob_start();
2009-06-30 09:29:51 +00:00
draw_jpeg_photos( $ldapserver, $dn, $attr, false, false, 'align="center"' );
2009-06-30 09:22:30 +00:00
$display = ob_get_contents();
ob_end_clean();
2009-06-30 09:29:51 +00:00
} elseif( is_attr_binary( $ldapserver, $attr ) ) {
2009-06-30 09:22:30 +00:00
$display = array( "(binary)" );
} else {
2009-06-30 09:29:51 +00:00
$values = @ldap_get_values( $ldapserver->connect(), $entry_id, $attr );
2009-06-30 09:22:30 +00:00
if( ! is_array( $values ) ) {
$display = 'Error';
} else {
if( isset( $values['count'] ) )
unset( $values['count'] );
foreach( $values as $value )
$display .= str_replace( ' ', '&nbsp;',
htmlspecialchars( $value ) ) . "<br />\n";
}
}
$attrs_display[ $attr_display ] = $display;
2009-06-30 09:29:51 +00:00
$attr = ldap_next_attribute( $ldapserver->connect(), $entry_id, $attrs );
2009-06-30 09:22:30 +00:00
} // end while( $attr )
$entries_display[] = $attrs_display;
//echo '<pre>';
//print_r( $attrs_display );
//echo "\n\n";
2009-06-30 09:29:51 +00:00
$entry_id = ldap_next_entry( $ldapserver->connect(), $entry_id );
2009-06-30 09:22:30 +00:00
} // end while( $entry_id )
$all_attrs = array_keys( $all_attrs );
/*
echo "<pre>";
print_r( $all_attrs );
print_r( $entries_display );
echo "</pre>";
*/
// Store the header row so it can be repeated later
$header_row = "<tr>";
foreach( $all_attrs as $attr )
$header_row .= "<th>$attr</th>";
$header_row .= "</tr>\n";
// begin drawing table
echo "<br />";
echo "<center>";
echo "<table class=\"search_result_table\">\n";
for( $i=0; $i<count($entries_display); $i++ ) {
$entry = $entries_display[$i];
if( $i %10 == 0 )
echo $header_row;
if( $i % 2 == 0 )
echo "<tr class=\"highlight\">";
else
echo "<tr>";
foreach( $all_attrs as $attr ) {
echo "<td>";
if( isset( $entry[ $attr ] ) )
echo $entry[ $attr ];
echo "</td>\n";
}
echo "</tr>\n";
}
2009-06-30 09:29:51 +00:00
2009-06-30 09:22:30 +00:00
echo "</table>";
echo "</center>";
2009-06-30 09:29:51 +00:00
?>