File: PLMTree.php

package info (click to toggle)
phpldapadmin 1.1.0.5-6%2Blenny2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,008 kB
  • ctags: 3,949
  • sloc: php: 17,735; xml: 1,532; sh: 388; makefile: 46
file content (169 lines) | stat: -rw-r--r-- 5,317 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
<?php
// $Header: /cvsroot/phpldapadmin/phpldapadmin/lib/PLMTree.php,v 1.2 2007/12/15 07:50:32 wurley Exp $

require HTDOCDIR.JSDIR.'phplayersmenu/lib/PHPLIB.php';
require HTDOCDIR.JSDIR.'phplayersmenu/lib/layersmenu-common.inc.php';
require HTDOCDIR.JSDIR.'phplayersmenu/lib/treemenu.inc.php';

/**
 * @package phpLDAPadmin
 * @author The phpLDAPadmin development team
 * @author Xavier Bruyet
 */
class PLMTree extends HTMLTree {

	// no support of mass deletion form
	protected function draw_mass_deletion_start_form() {
	}

	protected function draw_mass_deletion_submit_button() {
	}
	
	protected function draw_mass_deletion_end_form() {
	}

	/**
	 * Recursively descend on the given dn and draw the tree in plm
	 *
	 * @param dn $dn Current dn.
	 * @param int $level Level to start drawing
	 * @todo: Currently draw PLM only shows the first 50 entries of the base children -
	 * possibly the childrens children too. Have disabed the size_limit on the base -
	 * need to check that it doesnt affect non PLM tree viewer and children where
	 * size > size_limit.
	 */
	protected function draw_dn($dn,$level) {
		if (DEBUG_ENABLED)
			debug_log('Entered with (%s,%s)',33,__FILE__,__LINE__,__METHOD__,$dn,$level);

		static $tm = null;

		if (! isset($tm)) {
			$tm = new TreeMenu();
			$tm->setDirroot(JSDIR.'phplayersmenu/');
			$tm->setIcondir(HTDOCDIR.'/images/');
			$tm->setIconwww('images/');
			$tm->setImgwww(JSDIR.'phplayersmenu/menuimages/');
		}

		$tree_plm = $this->to_plm($dn,$level);

		$tm->setMenuStructureString($tree_plm);
		$tm->parseStructureForMenu('pla_tree_'.$this->server_id);
		$tm->setTreeMenuTheme('');
		$tm->newTreeMenu('pla_tree_'.$this->server_id);

		echo sprintf('<tr><td class="spacer"></td><td colspan="%s">%s</td></tr>',$this->getDepth()+3-1,$tm->getTreeMenu('pla_tree_'.$this->server_id));
	}

	protected function to_plm($dn,$level) {
		if (DEBUG_ENABLED)
			debug_log('Entered with (%s,%s)',33,__FILE__,__LINE__,__METHOD__,$dn,$level);

		$ldapserver = $this->getLdapServer();

		$dnEntry = $this->getEntry($dn);
		if (!$dnEntry) {
			$this->addEntry($dn);
			$dnEntry = $this->getEntry($dn);
		}
		if (!$dnEntry) {
			if (DEBUG_ENABLED)
				debug_log('Returning (%s)',33,__FILE__,__LINE__,__METHOD__,'');
			return '';
		}

		$encoded_dn = rawurlencode($dn);
		$edit_href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s',$this->server_id,$encoded_dn);
		$rdn = get_rdn($dn);

		$dots = '';
		for ($i=0;$i<=$level+1;$i++) $dots .= '.';

		# Have we tranversed this part of the tree yet?
		if ($dnEntry->isOpened()) {
			$child_count = $this->get_children_number($dnEntry);
			$tree_plm = sprintf("%s|%s|%s|%s|%s|%s|%s\n",
				$dots,
				($this->get_formatted_dn($dnEntry, $level)).($child_count ? ' ('.$child_count.')' : ''),
				$edit_href, $this->get_formatted_title($dnEntry, $level), $dnEntry->getIcon($ldapserver), '',
				($dnEntry->isOpened() ? 1 : 0));

			$tree_plm .= $this->get_plm_before_first_child($dnEntry, $level);

			foreach ($dnEntry->getChildren() as $dn) {
				$tree_plm .= $this->to_plm($dn,$level+1);
			}

			$tree_plm .= $this->get_plm_after_last_child($dnEntry, $level);
		} else {
			$child_count = $this->get_children_number($dnEntry);

			if ($child_count) {
				$tree_plm = sprintf("%s|%s|%s|%s|%s|%s|%s|%s\n",
					$dots,
					($this->get_formatted_dn($dnEntry, $level)).($child_count ? ' ('.$child_count.')' : ''),
					$edit_href, $this->get_formatted_title($dnEntry, $level), $dnEntry->getIcon($ldapserver), '',
					($dnEntry->isOpened() ? 1 : 0),
					$child_count);
			} else {
				$tree_plm = sprintf("%s|%s|%s|%s|%s|%s|%s|%s\n",
					$dots,
					($this->get_formatted_dn($dnEntry, $level)),
					$edit_href, $this->get_formatted_title($dnEntry, $level), $dnEntry->getIcon($ldapserver), '',
					($dnEntry->isOpened() ? 1 : 0),
					$child_count === false ? 1 : 0);
			}
		}

		if (DEBUG_ENABLED)
			debug_log('Returning (%s)',33,__FILE__,__LINE__,__METHOD__,$tree_plm);

		return $tree_plm;
	}

	protected function get_formatted_title($entry, $level) {
		return $entry->getDn();
	}

	protected function get_plm_before_first_child($entry, $level) {
		$ldapserver = $this->getLdapServer();

		$plm = '';

		if (!$ldapserver->isReadOnly() && ($entry->getChildrenNumber() > 10) && ($ldapserver->isShowCreateEnabled())) {
			$encoded_dn = rawurlencode($entry->getDn());
			$create_href = sprintf('cmd.php?cmd=template_engine&server_id=%s&container=%s', $ldapserver->server_id, $encoded_dn);

			$dots = '.';
			for ($i=0;$i<=$level+1;$i++) $dots .= '.';

			$plm = sprintf("%s|%s|%s|%s|%s|%s|%s\n",
					$dots, _('Create new entry here'),
					$create_href, $entry->getDn(), 'star.png', '', 0);
		}

		return $plm;
	}

	protected function get_plm_after_last_child($entry, $level) {
		$ldapserver = $this->getLdapServer();

		$plm = '';

		if (!$ldapserver->isReadOnly() && !$entry->isLeaf() && $ldapserver->isShowCreateEnabled()) {
			$encoded_dn = rawurlencode($entry->getDn());
			$create_href = sprintf('cmd.php?cmd=template_engine&server_id=%s&container=%s', $ldapserver->server_id, $encoded_dn);

			$dots = '.';
			for ($i=0;$i<=$level+1;$i++) $dots .= '.';

			$plm = sprintf("%s|%s|%s|%s|%s|%s|%s\n",
					$dots, _('Create new entry here'),
					$create_href, $entry->getDn(), 'star.png', '', 0);
		}

		return $plm;
	}
}
?>