~ubuntu-branches/ubuntu/trusty/phpldapadmin/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/Entry.php

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Lesicnik
  • Date: 2010-05-10 06:15:32 UTC
  • mfrom: (1.1.9 upstream) (3.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100510061532-s4m6ytom0eb7oam1
Tags: 1.2.0.5-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Merged call to dh_install to install debian/additional-templates/*
  - added groupOfNames.xml
  - Adds php_value memory_limit 32M to the apache.conf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
// $Header: /cvsroot/phpldapadmin/phpldapadmin/lib/Entry.php,v 1.2.2.5 2009/03/20 07:33:34 wurley Exp $
3
 
 
4
 
define('TMPDEBUG',0);
5
 
 
6
 
/**
7
 
 * @package phpLDAPadmin
8
 
 * @author The phpLDAPadmin development team
9
 
 * @author Xavier Bruyet
10
 
 *
11
 
 * Represent a tree node
12
 
 */
13
 
abstract class Entry {
14
 
        protected $dn;
15
 
 
16
 
        # the server_id to which the entry belongs
17
 
        protected $server_id;
18
 
 
19
 
        # is the entry a leaf ?
20
 
        private $leaf;
21
 
 
22
 
        # is the node open ?
23
 
        private $open;
24
 
 
25
 
        # array of dn
26
 
        private $children;
27
 
 
28
 
        # allow to test if addChild() is called by readChildren()
29
 
        private $reading_children;
30
 
 
31
 
        # is the size of children limited ?
32
 
        private $size_limited;
33
 
 
34
 
        # is the entry modifiable ?
35
 
        private $readonly;
36
 
 
37
 
        # an icon file path
38
 
        protected $icon;
39
 
 
40
 
        protected $properties;
41
 
 
42
 
        public function __construct($dn) {
43
 
                $this->dn = $dn;
44
 
                $this->leaf = false;
45
 
                $this->open = false;
46
 
                $this->children = array();
47
 
                $this->reading_children = false;
48
 
                $this->size_limited = true;
49
 
                $this->readonly = false;
50
 
                $this->icon = '';
51
 
                $this->properties = array();
52
 
        }
53
 
 
54
 
        public function getDn() {
55
 
                return $this->dn;
56
 
        }
57
 
 
58
 
        public function getRdn() {
59
 
                return get_rdn($this->getDn(), 0, true);
60
 
        }
61
 
 
62
 
        public function getRdnAttributeName() {
63
 
                $attr = array();
64
 
                if ($this->dn) {
65
 
                        $i = strpos($this->dn, ',');
66
 
                        if ($i !== false) {
67
 
                                $attrs = split('\+',substr($this->dn, 0, $i));
68
 
                                foreach ($attrs as $id => $attr) {
69
 
                                        list ($name,$value) = split('=',$attr);
70
 
                                        $attrs[$id] = $name;
71
 
                                }
72
 
                                $attr = array_unique($attrs);
73
 
                        }
74
 
                }
75
 
                return $attr;
76
 
        }
77
 
 
78
 
        public function setTree($index) {
79
 
                $this->server_id = $index;
80
 
        }
81
 
 
82
 
        private function readChildren($nolimit=false) {
83
 
                if (DEBUG_ENABLED)
84
 
                        debug_log('Entered with ()',1,__FILE__,__LINE__,__METHOD__);
85
 
 
86
 
                $ldapserver = (isset($this->server_id) ? $_SESSION[APPCONFIG]->ldapservers->Instance($this->server_id) : null);
87
 
                if (DEBUG_ENABLED)
88
 
                        debug_log('LdapServer (%s)',1,__FILE__,__LINE__,__METHOD__, $ldapserver ? $ldapserver->server_id : -1);
89
 
 
90
 
                $ldap['child_limit'] = $nolimit ? 0 : $_SESSION[APPCONFIG]->GetValue('search','size_limit');
91
 
                $ldap['filter'] = $_SESSION[APPCONFIG]->GetValue('appearance','tree_filter');
92
 
                $ldap['deref'] = $_SESSION[APPCONFIG]->GetValue('deref','view');
93
 
                $ldap['children'] = $ldapserver->getContainerContents($this->getDn(),$ldap['child_limit'],$ldap['filter'],$ldap['deref']);
94
 
 
95
 
                if (DEBUG_ENABLED)
96
 
                        debug_log('Children of (%s) are (%s)',64,__FILE__,__LINE__,__METHOD__,$this->getDn(),$ldap['children']);
97
 
 
98
 
                if (isset($this->server_id)) {
99
 
                        $this->reading_children = true;
100
 
                        $tree = get_cached_item($ldapserver->server_id,'tree');
101
 
 
102
 
                        foreach ($ldap['children'] as $dn) {
103
 
                                if (DEBUG_ENABLED)
104
 
                                        debug_log('Adding (%s)',64,__FILE__,__LINE__,__METHOD__,$dn);
105
 
 
106
 
                                if (! $tree->getEntry($dn))
107
 
                                        $tree->addEntry($dn);
108
 
                        }
109
 
                        set_cached_item($ldapserver->server_id,'tree','null',$tree);
110
 
                        usort($this->children,'pla_compare_dns');
111
 
                        $this->reading_children = false;
112
 
                }
113
 
 
114
 
                if (count($this->children) == $ldap['child_limit'])
115
 
                        $this->size_limited = true;
116
 
                else
117
 
                        $this->size_limited = false;
118
 
 
119
 
                if (DEBUG_ENABLED)
120
 
                        debug_log('Entered with (), Returning ()',1,__FILE__,__LINE__,__METHOD__);
121
 
        }
122
 
 
123
 
        /**
124
 
         * Returns null if the children have never be defined
125
 
         * or an array of the dn of the children
126
 
         */
127
 
        public function getChildren() {
128
 
                if (! $this->children)
129
 
                        $this->readChildren();
130
 
 
131
 
                return $this->children;
132
 
        }
133
 
 
134
 
        public function getChildrenNumber() {
135
 
                if (! $this->children)
136
 
                        $this->readChildren();
137
 
 
138
 
                if ($this->children)
139
 
                        return count($this->children);
140
 
                else
141
 
                        return 0;
142
 
        }
143
 
 
144
 
        /**
145
 
         * Called by Tree::addEntry() only
146
 
         */
147
 
        public function addChild($dn) {
148
 
                if (DEBUG_ENABLED)
149
 
                        debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$dn);
150
 
 
151
 
                if (! $this->children) {
152
 
                        if (DEBUG_ENABLED)
153
 
                                debug_log('this->children is FALSE',64,__FILE__,__LINE__,__METHOD__);
154
 
 
155
 
                        if (! $this->reading_children) {
156
 
                                if (DEBUG_ENABLED)
157
 
                                        debug_log('this->reading_children is FALSE',64,__FILE__,__LINE__,__METHOD__,$dn);
158
 
 
159
 
                                $this->readChildren();
160
 
                        }else {
161
 
                                $this->children = array();
162
 
                        }
163
 
                }
164
 
 
165
 
                $index = array_search($dn,$this->children);
166
 
                if (DEBUG_ENABLED)
167
 
                        debug_log('array_search of (%s) in (%s) returned (%s)',64,__FILE__,__LINE__,__METHOD__,$dn,$this->children,$index);
168
 
 
169
 
                if ($index === false) {
170
 
                        $this->children[] = $dn;
171
 
                        if (! $this->reading_children) usort($this->children,'pla_compare_dns');
172
 
                }
173
 
 
174
 
                if (DEBUG_ENABLED)
175
 
                        debug_log('Entered with (%s), Leaving ()',1,__FILE__,__LINE__,__METHOD__,$dn);
176
 
        }
177
 
 
178
 
        /**
179
 
         * Called by Tree::delEntry() only
180
 
         */
181
 
        public function delChild($dn) {
182
 
                if (DEBUG_ENABLED)
183
 
                        debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$dn);
184
 
 
185
 
                if ($this->children) {
186
 
                        # If the parent hasnt been opened in the tree, then there wont be any children.
187
 
                        $index = array_search($dn,$this->children);
188
 
                        if ($index !== false) unset($this->children[$index]);
189
 
                }
190
 
        }
191
 
 
192
 
        public function rename($newDn) {
193
 
                if (DEBUG_ENABLED)
194
 
                        debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$newDn);
195
 
                $this->dn = $newDn;
196
 
        }
197
 
 
198
 
        public function isOpened() {
199
 
                return $this->open;
200
 
        }
201
 
 
202
 
        public function close() {
203
 
                if (DEBUG_ENABLED)
204
 
                        debug_log('Entered with ()',1,__FILE__,__LINE__,__METHOD__);
205
 
 
206
 
                $this->open = false;
207
 
        }
208
 
 
209
 
        /**
210
 
         * Opens the node ; the children of the node must have been defined
211
 
         */
212
 
        public function open() {
213
 
                if (DEBUG_ENABLED)
214
 
                        debug_log('Entered with ()',1,__FILE__,__LINE__,__METHOD__);
215
 
 
216
 
                $this->open = true;
217
 
 
218
 
                if ($this->isSizeLimited()) {
219
 
                        $this->readChildren(true);
220
 
                }
221
 
        }
222
 
 
223
 
        public function setLeaf($is_leaf) {
224
 
                $this->leaf = $is_leaf;
225
 
        }
226
 
 
227
 
        public function isLeaf() {
228
 
                return $this->leaf;
229
 
        }
230
 
 
231
 
        public function isReadOnly() {
232
 
                return $this->readonly;
233
 
        }
234
 
 
235
 
        public function setReadOnly() {
236
 
                $this->readonly = true;
237
 
        }
238
 
 
239
 
        public function setReadWrite() {
240
 
                $this->readonly = false;
241
 
        }
242
 
 
243
 
        /**
244
 
         * Returns the path of the icon file used to represent this node ;
245
 
         * returns the result of get_icon() function
246
 
         */
247
 
        public function getIcon($ldapserver) {
248
 
                if ($this->icon) return $this->icon;
249
 
                else return get_icon($ldapserver,$this->dn);
250
 
        }
251
 
 
252
 
        public function isSizeLimited() {
253
 
                return $this->size_limited;
254
 
        }
255
 
 
256
 
        public function setProperty($name, $value) {
257
 
                $this->properties[$name] = $value;
258
 
        }
259
 
 
260
 
        public function delProperty($name) {
261
 
                if ($this->hasProperty($name)) unset($this->properties[$name]);
262
 
        }
263
 
 
264
 
        public function hasProperty($name) {
265
 
                return isset($this->properties[$name]);
266
 
        }
267
 
 
268
 
        public function getProperty($name) {
269
 
                if ($this->hasProperty($name)) return $this->properties[$name];
270
 
                else return null;
271
 
        }
272
 
 
273
 
        public function getTemplateName() {
274
 
                if (isset($this->selected_template))
275
 
                        return $this->selected_template;
276
 
                else
277
 
                        return '';
278
 
        }
279
 
 
280
 
        public function getTemplateTitle() {
281
 
                if (isset($this->selected_template['title']))
282
 
                        return $this->templates[$this->selected_template]['title'];
283
 
                else
284
 
                        return _('No Template');
285
 
        }
286
 
 
287
 
        /**
288
 
         * Visit the entry and its attributes
289
 
         *
290
 
         * The visitor must implement these methods :
291
 
         * - visit<Entry>Start($entry)
292
 
         * - visit<Entry>End($entry)
293
 
         * where <Entry> is the entry class name.
294
 
         */
295
 
        public function accept($visitor) {
296
 
                $visitor->visit('Start', $this);
297
 
                $attrs = $this->getAttributes();
298
 
                foreach ($attrs as $attribute) {
299
 
                        $attribute->accept($visitor);
300
 
                }
301
 
                $visitor->visit('End', $this);
302
 
        }
303
 
 
304
 
        public function getAttribute($name) {
305
 
                foreach ($this->getAttributes() as $attr) {
306
 
                        if ($attr->getName() == $name) return $attr;
307
 
                }
308
 
                return null;
309
 
        }
310
 
 
311
 
        /**
312
 
         * Return an array of Attribute objects
313
 
         */
314
 
        abstract public function getAttributes();
315
 
}
316
 
?>