2
// $Header: /cvsroot/phpldapadmin/phpldapadmin/lib/Entry.php,v 1.2.2.5 2009/03/20 07:33:34 wurley Exp $
7
* @package phpLDAPadmin
8
* @author The phpLDAPadmin development team
9
* @author Xavier Bruyet
11
* Represent a tree node
13
abstract class Entry {
16
# the server_id to which the entry belongs
19
# is the entry a leaf ?
28
# allow to test if addChild() is called by readChildren()
29
private $reading_children;
31
# is the size of children limited ?
32
private $size_limited;
34
# is the entry modifiable ?
40
protected $properties;
42
public function __construct($dn) {
46
$this->children = array();
47
$this->reading_children = false;
48
$this->size_limited = true;
49
$this->readonly = false;
51
$this->properties = array();
54
public function getDn() {
58
public function getRdn() {
59
return get_rdn($this->getDn(), 0, true);
62
public function getRdnAttributeName() {
65
$i = strpos($this->dn, ',');
67
$attrs = split('\+',substr($this->dn, 0, $i));
68
foreach ($attrs as $id => $attr) {
69
list ($name,$value) = split('=',$attr);
72
$attr = array_unique($attrs);
78
public function setTree($index) {
79
$this->server_id = $index;
82
private function readChildren($nolimit=false) {
84
debug_log('Entered with ()',1,__FILE__,__LINE__,__METHOD__);
86
$ldapserver = (isset($this->server_id) ? $_SESSION[APPCONFIG]->ldapservers->Instance($this->server_id) : null);
88
debug_log('LdapServer (%s)',1,__FILE__,__LINE__,__METHOD__, $ldapserver ? $ldapserver->server_id : -1);
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']);
96
debug_log('Children of (%s) are (%s)',64,__FILE__,__LINE__,__METHOD__,$this->getDn(),$ldap['children']);
98
if (isset($this->server_id)) {
99
$this->reading_children = true;
100
$tree = get_cached_item($ldapserver->server_id,'tree');
102
foreach ($ldap['children'] as $dn) {
104
debug_log('Adding (%s)',64,__FILE__,__LINE__,__METHOD__,$dn);
106
if (! $tree->getEntry($dn))
107
$tree->addEntry($dn);
109
set_cached_item($ldapserver->server_id,'tree','null',$tree);
110
usort($this->children,'pla_compare_dns');
111
$this->reading_children = false;
114
if (count($this->children) == $ldap['child_limit'])
115
$this->size_limited = true;
117
$this->size_limited = false;
120
debug_log('Entered with (), Returning ()',1,__FILE__,__LINE__,__METHOD__);
124
* Returns null if the children have never be defined
125
* or an array of the dn of the children
127
public function getChildren() {
128
if (! $this->children)
129
$this->readChildren();
131
return $this->children;
134
public function getChildrenNumber() {
135
if (! $this->children)
136
$this->readChildren();
139
return count($this->children);
145
* Called by Tree::addEntry() only
147
public function addChild($dn) {
149
debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$dn);
151
if (! $this->children) {
153
debug_log('this->children is FALSE',64,__FILE__,__LINE__,__METHOD__);
155
if (! $this->reading_children) {
157
debug_log('this->reading_children is FALSE',64,__FILE__,__LINE__,__METHOD__,$dn);
159
$this->readChildren();
161
$this->children = array();
165
$index = array_search($dn,$this->children);
167
debug_log('array_search of (%s) in (%s) returned (%s)',64,__FILE__,__LINE__,__METHOD__,$dn,$this->children,$index);
169
if ($index === false) {
170
$this->children[] = $dn;
171
if (! $this->reading_children) usort($this->children,'pla_compare_dns');
175
debug_log('Entered with (%s), Leaving ()',1,__FILE__,__LINE__,__METHOD__,$dn);
179
* Called by Tree::delEntry() only
181
public function delChild($dn) {
183
debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$dn);
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]);
192
public function rename($newDn) {
194
debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$newDn);
198
public function isOpened() {
202
public function close() {
204
debug_log('Entered with ()',1,__FILE__,__LINE__,__METHOD__);
210
* Opens the node ; the children of the node must have been defined
212
public function open() {
214
debug_log('Entered with ()',1,__FILE__,__LINE__,__METHOD__);
218
if ($this->isSizeLimited()) {
219
$this->readChildren(true);
223
public function setLeaf($is_leaf) {
224
$this->leaf = $is_leaf;
227
public function isLeaf() {
231
public function isReadOnly() {
232
return $this->readonly;
235
public function setReadOnly() {
236
$this->readonly = true;
239
public function setReadWrite() {
240
$this->readonly = false;
244
* Returns the path of the icon file used to represent this node ;
245
* returns the result of get_icon() function
247
public function getIcon($ldapserver) {
248
if ($this->icon) return $this->icon;
249
else return get_icon($ldapserver,$this->dn);
252
public function isSizeLimited() {
253
return $this->size_limited;
256
public function setProperty($name, $value) {
257
$this->properties[$name] = $value;
260
public function delProperty($name) {
261
if ($this->hasProperty($name)) unset($this->properties[$name]);
264
public function hasProperty($name) {
265
return isset($this->properties[$name]);
268
public function getProperty($name) {
269
if ($this->hasProperty($name)) return $this->properties[$name];
273
public function getTemplateName() {
274
if (isset($this->selected_template))
275
return $this->selected_template;
280
public function getTemplateTitle() {
281
if (isset($this->selected_template['title']))
282
return $this->templates[$this->selected_template]['title'];
284
return _('No Template');
288
* Visit the entry and its attributes
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.
295
public function accept($visitor) {
296
$visitor->visit('Start', $this);
297
$attrs = $this->getAttributes();
298
foreach ($attrs as $attribute) {
299
$attribute->accept($visitor);
301
$visitor->visit('End', $this);
304
public function getAttribute($name) {
305
foreach ($this->getAttributes() as $attr) {
306
if ($attr->getName() == $name) return $attr;
312
* Return an array of Attribute objects
314
abstract public function getAttributes();