phpldapadmin/tree.php

224 lines
7.5 KiB
PHP
Raw Normal View History

2009-06-30 08:09:20 +00:00
<?php
2009-06-30 09:22:30 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/tree.php,v 1.76 2004/12/22 14:12:15 uugdave Exp $
2009-06-30 08:05:37 +00:00
/*
* tree.php
* This script displays the LDAP tree for all the servers that you have
* in config.php. We read the session variable 'tree' to know which
* dns are expanded or collapsed. No query string parameters are expected,
* however, you can use a '#' offset to scroll to a given dn. The syntax is
* tree.php#<server_id>_<rawurlencoded dn>, so if I wanted to scroll to
* dc=example,dc=com for server 3, the URL would be:
* tree.php#3_dc%3Dexample%2Cdc%3Dcom
*/
2009-06-30 09:22:30 +00:00
require './common.php';
2009-06-30 08:05:37 +00:00
// no expire header stuff
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
2009-06-30 09:22:30 +00:00
// This allows us to display large sub-trees without running out of time.
@set_time_limit( 0 );
2009-06-30 08:05:37 +00:00
2009-06-30 09:22:30 +00:00
// do we not have a tree and tree icons yet? Build a new ones.
initialize_session_tree();
2009-06-30 08:05:37 +00:00
2009-06-30 09:22:30 +00:00
// get the tree and tree icons.
2009-06-30 08:05:37 +00:00
$tree = $_SESSION['tree'];
$tree_icons = $_SESSION['tree_icons'];
2009-06-30 09:22:30 +00:00
// Close the session for faster page loading (we're done with session data anyway).
pla_session_close();
include './header.php';
?>
2009-06-30 08:05:37 +00:00
<body>
2009-06-30 09:22:30 +00:00
<?php
2009-06-30 08:07:14 +00:00
$bug_href = get_href( 'add_bug' );
$feature_href = get_href( 'add_rfe' );
2009-06-30 09:22:30 +00:00
$donate_href = get_href( 'donate' );
$help_href = get_href( 'help' );
2009-06-30 08:05:37 +00:00
?>
2009-06-30 08:07:14 +00:00
<h3 class="subtitle" style="margin:0px">phpLDAPadmin - <?php echo pla_version(); ?></h3>
2009-06-30 09:22:30 +00:00
<!-- Links at the top of the tree viewer -->
2009-06-30 08:05:37 +00:00
<table class="edit_dn_menu">
2009-06-30 09:22:30 +00:00
<?php if ( ! hide_configuration_management() ) { ?>
2009-06-30 08:05:37 +00:00
<tr>
2009-06-30 09:22:30 +00:00
<td><img src="images/light.png" alt="<?php echo $lang['light']; ?>" /></td>
<td><nobr><a href="<?php echo $feature_href; ?>" target="new"><?php echo $lang['request_new_feature']; ?></a></nobr></td>
<td><img src="images/bug.png" alt="<?php echo $lang['bug']; ?>" /></td>
<td><nobr><a href="<?php echo $bug_href; ?>" target="new"><?php echo $lang['report_bug']; ?></a></nobr></td>
</tr>
<?php } ?>
<tr>
<td><img src="images/smile.png" alt="<?php echo $lang['donate']; ?>" /></td>
<td><nobr><a href="<?php echo $donate_href; ?>" target="right_frame"><?php echo $lang['donate']; ?></a></nobr></td>
<td><img src="images/trash.png" alt="<?php echo $lang['purge_cache']; ?>" /></td>
<td><nobr><a href="purge_cache.php" target="right_frame" title="<?php echo $lang['purge_cache_tooltip']; ?>"><?php echo $lang['purge_cache']; ?></a></nobr></td>
2009-06-30 08:05:37 +00:00
</tr>
<tr>
2009-06-30 09:22:30 +00:00
<td><img src="images/home.png" alt="<?php echo $lang['home']; ?>" /></td>
<td><nobr><a href="welcome.php" target="right_frame"><?php echo $lang['home']; ?></a></nobr></td>
<td><img src="images/help.png" alt="<?php echo $lang['help']; ?>" /></td>
<td><nobr><a href="help.php" target="right_frame"><?php echo $lang['help']; ?></a></nobr></td>
2009-06-30 08:05:37 +00:00
</tr>
</table>
2009-06-30 08:07:14 +00:00
2009-06-30 08:05:37 +00:00
<table class="tree" cellspacing="0">
<?php
2009-06-30 09:22:30 +00:00
// We want the std tree function as a fallback
require_once( 'tree_functions.php' );
// For each of the configured servers
2009-06-30 08:05:37 +00:00
foreach( $servers as $server_id => $server_tree ) {
2009-06-30 09:22:30 +00:00
$is_visible = ( ! isset( $servers[ $server_id ][ 'visible' ] )
|| ( $servers[ $server_id ][ 'visible' ] === true ) );
if( isset( $servers[ $server_id ] )
&& trim( $servers[ $server_id ][ 'host' ] ) != ''
&& $is_visible )
{
$filename = get_custom_file( $server_id, 'tree_functions.php' );
require_once( $filename );
call_custom_function( $server_id, 'draw_server_tree' );
2009-06-30 08:05:37 +00:00
}
}
?>
</table>
2009-06-30 08:07:14 +00:00
<?php
2009-06-30 09:22:30 +00:00
// echo "<pre>"; print_r( $tree );
2009-06-30 08:07:14 +00:00
?>
2009-06-30 08:05:37 +00:00
</body>
</html>
2009-06-30 09:22:30 +00:00
<?php
2009-06-30 08:05:37 +00:00
exit;
/**
* Recursively descend on the given dn and draw the tree in html
*/
2009-06-30 09:22:30 +00:00
function draw_tree_html( $dn, $server_id, $level = 0 )
2009-06-30 08:05:37 +00:00
{
2009-06-30 09:22:30 +00:00
global $servers, $tree, $tree_icons, $lang, $search_result_size_limit;
2009-06-30 08:05:37 +00:00
$id = $server_id;
2009-06-30 09:22:30 +00:00
2009-06-30 08:05:37 +00:00
$encoded_dn = rawurlencode( $dn );
$expand_href = "expand.php?server_id=$id&amp;dn=$encoded_dn";
$collapse_href = "collapse.php?server_id=$id&amp;dn=$encoded_dn";
$edit_href = "edit.php?server_id=$id&amp;dn=$encoded_dn";
// should never happen, but just in case
if( ! isset( $tree_icons[ $server_id ][ $dn ] ) )
$tree_icons[ $server_id ][ $dn ] = get_icon( $server_id, $dn );
$img_src = 'images/' . $tree_icons[ $server_id ][ $dn ];
2009-06-30 08:10:17 +00:00
$rdn = get_rdn( $dn );
2009-06-30 08:05:37 +00:00
echo '<tr>';
for( $i=0; $i<=$level; $i++ ) {
2009-06-30 08:07:14 +00:00
echo '<td class="spacer"></td>' . "\n";
2009-06-30 08:05:37 +00:00
}
2009-06-30 08:09:20 +00:00
// Shall we draw the "mass-delete" checkbox?
if( mass_delete_enabled( $server_id ) ) {
echo "<td>
<input
type=\"checkbox\"
name=\"mass_delete[" . htmlspecialchars($dn) . "]\" />
</td>\n";
}
2009-06-30 08:07:14 +00:00
// is this node expanded? (deciding whether to draw "+" or "-")
2009-06-30 08:05:37 +00:00
if( isset( $tree[$server_id][$dn] ) ) { ?>
<td class="expander">
<nobr>
2009-06-30 09:22:30 +00:00
<a href="<?php echo $collapse_href; ?>"><img src="images/minus.png" alt="-" /></a>
2009-06-30 08:05:37 +00:00
</nobr>
</td>
2009-06-30 09:22:30 +00:00
<?php $child_count = number_format( count( $tree[$server_id][$dn] ) );
2009-06-30 08:07:14 +00:00
} else { ?>
2009-06-30 08:05:37 +00:00
<td class="expander">
<nobr>
2009-06-30 09:22:30 +00:00
<a href="<?php echo $expand_href; ?>"><img src="images/plus.png" alt="+" /></a>
2009-06-30 08:05:37 +00:00
</nobr>
</td>
2009-06-30 09:22:30 +00:00
<?php $limit = isset( $search_result_size_limit ) ? $search_result_size_limit : 50;
if( is_server_low_bandwidth( $server_id ) ) {
$child_count = null;
} else {
$child_count = count( get_container_contents( $server_id, $dn, $limit+1,
'(objectClass=*)', get_tree_deref_setting() ) );
if( $child_count > $limit )
$child_count = $limit . '+';
}
2009-06-30 08:07:14 +00:00
} ?>
2009-06-30 08:05:37 +00:00
<td class="icon">
<a href="<?php echo $edit_href; ?>"
target="right_frame"
2009-06-30 09:22:30 +00:00
name="<?php echo $server_id; ?>_<?php echo $encoded_dn; ?>"><img src="<?php echo $img_src; ?>" alt="img" /></a>
2009-06-30 08:05:37 +00:00
</td>
2009-06-30 08:07:14 +00:00
<td class="rdn" colspan="<?php echo (97-$level); ?>">
2009-06-30 08:05:37 +00:00
<nobr>
<a href="<?php echo $edit_href; ?>"
2009-06-30 09:22:30 +00:00
target="right_frame"><?php echo ( draw_formatted_dn( $server_id, $dn ) ); /*pretty_print_dn( $rdn ) );*/ ?></a>
<?php if( $child_count ) { ?>
<span class="count">(<?php echo $child_count; ?>)</span>
<?php } ?>
2009-06-30 08:05:37 +00:00
</nobr>
</td>
</tr>
<?php
if( isset( $tree[$server_id][$dn] ) && is_array( $tree[$server_id][$dn] ) ) {
2009-06-30 09:22:30 +00:00
// Draw the "create new" link at the top of the tree list if there are more than 10
// entries in the listing for this node.
if( count( $tree[$server_id][$dn] ) > 10 )
if( show_create_enabled( $server_id ) )
draw_create_link( $server_id, $rdn, $level, $encoded_dn );
foreach( $tree[$server_id][$dn] as $dn )
2009-06-30 08:05:37 +00:00
draw_tree_html( $dn, $server_id, $level+1 );
2009-06-30 09:22:30 +00:00
// Always draw the "create new" link at the bottom of the listing
if( show_create_enabled( $server_id ) )
draw_create_link( $server_id, $rdn, $level, $encoded_dn );
2009-06-30 08:05:37 +00:00
}
2009-06-30 09:22:30 +00:00
}
2009-06-30 08:05:37 +00:00
2009-06-30 09:22:30 +00:00
function draw_create_link( $server_id, $rdn, $level, $encoded_dn )
{
global $lang;
// print the "Create New object" link.
$create_html = "";
$create_href = "create_form.php?server_id=$server_id&amp;container=$encoded_dn";
$create_html .= '<tr>';
for( $i=0; $i<=$level; $i++ ) {
$create_html .= '<td class="spacer"></td>';
}
$create_html .= '<td class="spacer"></td>';
$create_html .= '<td class="icon"><a href="' . $create_href .
'" target="right_frame"><img src="images/star.png" alt="' . $lang['new'] . '" /></a></td>';
$create_html .= '<td class="create" colspan="' . (97-$level) . '"><a href="' . $create_href .
'" target="right_frame" title="' . $lang['create_new_entry_in'] . ' ' . $rdn.'">' .
$lang['create_new'] . '</a></td>';
$create_html .= '</tr>';
echo $create_html;
2009-06-30 08:05:37 +00:00
}
?>