File: tree.php

package info (click to toggle)
phpldapadmin 0.9.5-3sarge3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,052 kB
  • ctags: 2,526
  • sloc: php: 21,258; sh: 262; makefile: 132; xml: 42
file content (220 lines) | stat: -rw-r--r-- 7,508 bytes parent folder | download
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
// $Header: /cvsroot/phpldapadmin/phpldapadmin/tree.php,v 1.75 2004/12/18 22:07:46 uugdave Exp $

/* 
 * 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
 */

require './common.php';

// 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");

// This allows us to display large sub-trees without running out of time.
@set_time_limit( 0 );

// do we not have a tree and tree icons yet? Build a new ones.
initialize_session_tree();

// get the tree and tree icons.
$tree = $_SESSION['tree'];
$tree_icons = $_SESSION['tree_icons'];

// Close the session for faster page loading (we're done with session data anyway).
pla_session_close();

include './header.php';
?>

<body>

<?php
	$bug_href = get_href( 'add_bug' );
	$feature_href = get_href( 'add_rfe' );
	$donate_href = get_href( 'donate' );
?>

<h3 class="subtitle" style="margin:0px">phpLDAPadmin - <?php echo pla_version(); ?></h3>

<!-- Links at the top of the tree viewer -->
<table class="edit_dn_menu">
<?php if ( ! hide_configuration_management() ) { ?>
<tr>
	<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>
</tr>
<tr>	
	<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>
</tr>
</table>

<table class="tree" cellspacing="0">

<?php 

// We want the std tree function as a fallback
require_once( 'tree_functions.php' );

// For each of the configured servers
foreach( $servers as $server_id => $server_tree ) { 

	$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' );
	}
}

?>

</table>
<?php 
//	echo "<pre>"; print_r( $tree ); 
?>

</body>
</html>

<?php
exit;

/**
 * Recursively descend on the given dn and draw the tree in html
 */
function draw_tree_html( $dn, $server_id, $level = 0 )
{
	global $servers, $tree, $tree_icons, $lang, $search_result_size_limit;
	$id = $server_id;

	$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 ];

	$rdn = get_rdn( $dn );

	echo '<tr>';

	for( $i=0; $i<=$level; $i++ ) {
		echo '<td class="spacer"></td>' . "\n";
	}

	// 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";
	}

	// is this node expanded? (deciding whether to draw "+" or "-")
	if( isset( $tree[$server_id][$dn] ) ) { ?>
		<td class="expander">
			<nobr>
			<a href="<?php echo $collapse_href; ?>"><img src="images/minus.png" alt="-" /></a>
			</nobr>
		</td>
		<?php  $child_count = number_format( count( $tree[$server_id][$dn] ) );
	} else { ?>	
		<td class="expander">
			<nobr>
			<a href="<?php echo $expand_href; ?>"><img src="images/plus.png" alt="+" /></a>
			</nobr>
		</td>
		<?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 . '+';
            }
	} ?>	

	<td class="icon">
		<a href="<?php echo $edit_href; ?>"
		   target="right_frame"
		   name="<?php echo $server_id; ?>_<?php echo $encoded_dn; ?>"><img src="<?php echo $img_src; ?>" alt="img" /></a>
	</td>
	<td class="rdn" colspan="<?php echo (97-$level); ?>">
		<nobr>
			<a href="<?php echo $edit_href; ?>"
				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 } ?>
		</nobr>
	</td>
	</tr>

	<?php 

	if( isset( $tree[$server_id][$dn] ) && is_array( $tree[$server_id][$dn] ) )	{
        // 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 )
			draw_tree_html( $dn, $server_id, $level+1 );
        // 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 );
	}
}

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;
}

?>