1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
<?php
/**
* Incoming variables (among others)
* $results: The result of ldap_search(), ldap_list(), or ldap_read().
* $ds: LDAP connection resource.
* $start_entry: The index of the entry at which to begin displaying
* $end_entry: The index of the entry at which to end displaying
*/
$friendly_attrs = process_friendly_attr_table();
$entry_id = ldap_first_entry( $ds, $results );
$all_attrs = array( '' => 1,
'dn' => 1 );
// 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 ) {
$entry_id = ldap_next_entry( $ds, $entry_id );
continue;
}
if( $i >= $end_entry )
break;
$dn = ldap_get_dn( $ds, $entry_id );
$dn_display = strlen( $dn ) > 40 ? "<acronym title=\"" . htmlspecialchars( $dn ) . "\">" .
htmlspecialchars( substr( $dn, 0, 40 ) . '...' ) .
"</acronym>"
: htmlspecialchars( $dn );
$encoded_dn = rawurlencode( $dn );
$rdn = get_rdn( $dn );
$icon = get_icon_use_cache( $server_id, $dn );
$attrs = ldap_get_attributes( $ds, $entry_id );
$attr = ldap_first_attribute( $ds, $entry_id, $attrs );
$attrs_display = array();
$edit_url = "edit.php?server_id=$server_id&dn=$encoded_dn";
$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 ) ] ) )
$attr_display = "<acronym title=\"Alias for $attr\">" .
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 = '';
if( is_jpeg_photo( $server_id, $attr ) ) {
ob_start();
draw_jpeg_photos( $server_id, $dn, $attr, false, false, 'align="center"' );
$display = ob_get_contents();
ob_end_clean();
} elseif( is_attr_binary( $server_id, $attr ) ) {
$display = array( "(binary)" );
} else {
$values = @ldap_get_values( $ds, $entry_id, $attr );
if( ! is_array( $values ) ) {
$display = 'Error';
} else {
if( isset( $values['count'] ) )
unset( $values['count'] );
foreach( $values as $value )
$display .= str_replace( ' ', ' ',
htmlspecialchars( $value ) ) . "<br />\n";
}
}
$attrs_display[ $attr_display ] = $display;
$attr = ldap_next_attribute( $ds, $entry_id, $attrs );
} // end while( $attr )
$entries_display[] = $attrs_display;
//echo '<pre>';
//print_r( $attrs_display );
//echo "\n\n";
$entry_id = ldap_next_entry( $ds, $entry_id );
} // 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";
}
echo "</table>";
echo "</center>";
|