3
* Classes and functions for the LDAP tree.
5
* @author The phpLDAPadmin development team
6
* @package phpLDAPadmin
10
* Represents an item in the tree.
12
* @package phpLDAPadmin
18
# The server this entry belongs to.
20
# The objectclasses in LDAP, used to deterimine the icon and template
21
protected $objectclasses = array();
22
# Is this a base entry?
23
private $base_entry = false;
24
# Array of dn - the children
25
private $children = array();
28
# Is the entry a leaf?
29
private $leaf = false;
31
private $open = false;
32
# Is the size of children limited?
33
private $size_limited = true;
34
# Last template used to edit this entry
35
private $template = null;
36
# Do we need to sort the children
37
private $childsort = true;
38
# Are we reading the children
39
private $reading_children = false;
41
public function __construct($server_id,$dn) {
42
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
43
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
45
$this->server_id = $server_id;
50
* Get the DN of this tree item.
52
* @return DN The DN of this item.
54
public function getDN() {
55
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
56
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->dn);
62
* Get the RDN of this tree items DN.
64
* @return RDN The RDN of this items DN.
66
public function getRDN() {
67
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
68
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
70
return get_rdn($this->getDn(),0,true);
74
* Set this item as a LDAP base DN item.
76
public function setBase() {
77
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
78
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs);
80
$this->base_entry = true;
84
* Return if this item is a base DN item.
86
public function isBaseDN() {
87
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
88
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->base_entry);
90
return $this->base_entry;
93
public function setObjectClasses($oc) {
94
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
95
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs);
97
$this->objectclasses = $oc;
100
public function getObjectClasses() {
101
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
102
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->objectclasses);
104
return $this->objectclasses;
107
public function isInLDAP() {
108
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
109
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
111
return count($this->objectclasses) ? true : false;
115
* Returns null if the children have never be defined
116
* or an array of the dn of the children
118
public function getChildren() {
119
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
120
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->children);
122
if ($this->childsort && ! $this->reading_children) {
123
usort($this->children,'pla_compare_dns');
124
$this->childsort = false;
127
return $this->children;
130
public function readingChildren($bool) {
131
$this->reading_children = $bool;
135
* Do the children require resorting
137
public function isChildSorted() {
138
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
139
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->childsort);
141
return $this->childsort;
145
* Mark the children as sorted
147
public function childSorted() {
148
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
149
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs);
151
$this->childsort = false;
155
* Add a child to this DN entry.
157
* @param DN The DN to add.
159
public function addChild($dn) {
160
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
161
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
163
if (in_array($dn,$this->children))
166
array_push($this->children,$dn);
167
$this->childsort = true;
171
* Delete a child from this DN entry.
173
* @param DN The DN to add.
175
public function delChild($dn) {
176
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
177
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
179
if ($this->children) {
180
# If the parent hasnt been opened in the tree, then there wont be any children.
181
$index = array_search($dn,$this->children);
183
if ($index !== false)
184
unset($this->children[$index]);
191
* @param DN The DN to rename to.
193
public function rename($dn) {
194
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
195
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
201
* Return if this item has been opened.
203
public function isOpened() {
204
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
205
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->open);
211
* Mark this node as closed.
213
public function close() {
214
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
215
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
221
* Opens the node ; the children of the node must have been defined
223
public function open() {
224
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
225
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
231
* Mark this node as a leaf.
233
public function setLeaf() {
234
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
235
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs);
241
* Return if this node is a leaf.
243
public function isLeaf() {
244
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
245
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->leaf);
251
* Returns the path of the icon file used to represent this node ;
252
* If the icon hasnt been set, it will call get_icon()
254
public function getIcon() {
255
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
256
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->icon);
259
$this->icon = get_icon($this->server_id,$this->dn,$this->objectclasses);
265
* Mark this node as a size limited (it wont have all its children).
267
public function setSizeLimited() {
268
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
269
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs);
271
$this->size_limited = true;
275
* Clear the size limited flag.
277
public function unsetSizeLimited() {
278
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
279
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
281
$this->size_limited = false;
285
* Return if this node has hit an LDAP size limit (and thus doesnt have all its children).
287
public function isSizeLimited() {
288
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
289
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
291
return $this->size_limited;
294
public function setTemplate($template) {
295
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
296
debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs);
298
$this->template = $template;
301
public function getTemplate() {
302
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
303
debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
305
return $this->template;