~ubuntu-branches/debian/wheezy/phpldapadmin/wheezy

« back to all changes in this revision

Viewing changes to lib/TreeItem.php

  • Committer: Bazaar Package Importer
  • Author(s): Fabio Tranchitella
  • Date: 2010-04-10 10:12:22 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100410101222-3xyuhy4a7usewxla
Tags: 1.2.0.5-1
* New upstream release. (Closes: #571672, #549464)
* debian/po/ru.po: added. (Closes: #536402)
* applied patch to fix lintian warnings. (Closes: #531649)
* Removed debian/patches that have been merged upstream.
* Do not build-depend anymore on dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Classes and functions for the LDAP tree.
 
4
 *
 
5
 * @author The phpLDAPadmin development team
 
6
 * @package phpLDAPadmin
 
7
 */
 
8
 
 
9
/**
 
10
 * Represents an item in the tree.
 
11
 *
 
12
 * @package phpLDAPadmin
 
13
 * @subpackage Tree
 
14
 */
 
15
class TreeItem {
 
16
        # This entry's DN
 
17
        protected $dn;
 
18
        # The server this entry belongs to.
 
19
        private $server_id;
 
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();
 
26
        # An icon file path
 
27
        protected $icon;
 
28
        # Is the entry a leaf?
 
29
        private $leaf = false;
 
30
        # Is the node open?
 
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;
 
40
 
 
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);
 
44
 
 
45
                $this->server_id = $server_id;
 
46
                $this->dn = $dn;
 
47
        }
 
48
 
 
49
        /**
 
50
         * Get the DN of this tree item.
 
51
         *
 
52
         * @return DN The DN of this item.
 
53
         */
 
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);
 
57
 
 
58
                return $this->dn;
 
59
        }
 
60
 
 
61
        /**
 
62
         * Get the RDN of this tree items DN.
 
63
         *
 
64
         * @return RDN The RDN of this items DN.
 
65
         */
 
66
        public function getRDN() {
 
67
                if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
 
68
                        debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
 
69
 
 
70
                return get_rdn($this->getDn(),0,true);
 
71
        }
 
72
 
 
73
        /**
 
74
         * Set this item as a LDAP base DN item.
 
75
         */
 
76
        public function setBase() {
 
77
                if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
 
78
                        debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs);
 
79
 
 
80
                $this->base_entry = true;
 
81
        }
 
82
 
 
83
        /**
 
84
         * Return if this item is a base DN item.
 
85
         */
 
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);
 
89
 
 
90
                return $this->base_entry;
 
91
        }
 
92
 
 
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);
 
96
 
 
97
                $this->objectclasses = $oc;
 
98
        }
 
99
 
 
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);
 
103
 
 
104
                return $this->objectclasses;
 
105
        }
 
106
 
 
107
        public function isInLDAP() {
 
108
                if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
 
109
                        debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
 
110
 
 
111
                return count($this->objectclasses) ? true : false;
 
112
        }
 
113
 
 
114
        /**
 
115
         * Returns null if the children have never be defined
 
116
         * or an array of the dn of the children
 
117
         */
 
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);
 
121
 
 
122
                if ($this->childsort && ! $this->reading_children) {
 
123
                        usort($this->children,'pla_compare_dns');
 
124
                        $this->childsort = false;
 
125
                }
 
126
 
 
127
                return $this->children;
 
128
        }
 
129
 
 
130
        public function readingChildren($bool) {
 
131
                $this->reading_children = $bool;
 
132
        }
 
133
 
 
134
        /**
 
135
         * Do the children require resorting
 
136
         */
 
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);
 
140
 
 
141
                return $this->childsort;
 
142
        }
 
143
 
 
144
        /**
 
145
         * Mark the children as sorted
 
146
         */
 
147
        public function childSorted() {
 
148
                if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
 
149
                        debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs);
 
150
 
 
151
                $this->childsort = false;
 
152
        }
 
153
 
 
154
        /**
 
155
         * Add a child to this DN entry.
 
156
         *
 
157
         * @param DN The DN to add.
 
158
         */
 
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);
 
162
 
 
163
                if (in_array($dn,$this->children))
 
164
                        return;
 
165
 
 
166
                array_push($this->children,$dn);
 
167
                $this->childsort = true;
 
168
        }
 
169
 
 
170
        /**
 
171
         * Delete a child from this DN entry.
 
172
         *
 
173
         * @param DN The DN to add.
 
174
         */
 
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);
 
178
 
 
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);
 
182
 
 
183
                        if ($index !== false)
 
184
                                unset($this->children[$index]);
 
185
                }
 
186
        }
 
187
 
 
188
        /**
 
189
         * Rename this DN.
 
190
         *
 
191
         * @param DN The DN to rename to.
 
192
         */
 
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);
 
196
 
 
197
                $this->dn = $dn;
 
198
        }
 
199
 
 
200
        /**
 
201
         * Return if this item has been opened.
 
202
         */
 
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);
 
206
 
 
207
                return $this->open;
 
208
        }
 
209
 
 
210
        /**
 
211
         * Mark this node as closed.
 
212
         */
 
213
        public function close() {
 
214
                if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
 
215
                        debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
 
216
 
 
217
                $this->open = false;
 
218
        }
 
219
 
 
220
        /**
 
221
         * Opens the node ; the children of the node must have been defined
 
222
         */
 
223
        public function open() {
 
224
                if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
 
225
                        debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
 
226
 
 
227
                $this->open = true;
 
228
        }
 
229
 
 
230
        /**
 
231
         * Mark this node as a leaf.
 
232
         */
 
233
        public function setLeaf() {
 
234
                if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
 
235
                        debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs);
 
236
 
 
237
                $this->leaf = true;
 
238
        }
 
239
 
 
240
        /**
 
241
         * Return if this node is a leaf.
 
242
         */
 
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);
 
246
 
 
247
                return $this->leaf;
 
248
        }
 
249
 
 
250
        /**
 
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()
 
253
         */
 
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);
 
257
 
 
258
                if (! $this->icon)
 
259
                        $this->icon = get_icon($this->server_id,$this->dn,$this->objectclasses);
 
260
 
 
261
                return $this->icon;
 
262
        }
 
263
 
 
264
        /**
 
265
         * Mark this node as a size limited (it wont have all its children).
 
266
         */
 
267
        public function setSizeLimited() {
 
268
                if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
 
269
                        debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs);
 
270
 
 
271
                $this->size_limited = true;
 
272
        }
 
273
 
 
274
        /**
 
275
         * Clear the size limited flag.
 
276
         */
 
277
        public function unsetSizeLimited() {
 
278
                if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
 
279
                        debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
 
280
 
 
281
                $this->size_limited = false;
 
282
        }
 
283
 
 
284
        /**
 
285
         * Return if this node has hit an LDAP size limit (and thus doesnt have all its children).
 
286
         */
 
287
        public function isSizeLimited() {
 
288
                if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
 
289
                        debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
 
290
 
 
291
                return $this->size_limited;
 
292
        }
 
293
 
 
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);
 
297
 
 
298
                $this->template = $template;
 
299
        }
 
300
 
 
301
        public function getTemplate() {
 
302
                if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
 
303
                        debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs);
 
304
 
 
305
                return $this->template;
 
306
        }
 
307
}
 
308
?>