File: Attribute.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 (272 lines) | stat: -rw-r--r-- 5,296 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php
// $Header: /cvsroot/phpldapadmin/phpldapadmin/lib/Attribute.php,v 1.2.2.2 2007/12/26 09:26:32 wurley Exp $

/**
 * @package phpLDAPadmin
 * @author Xavier Bruyet
 *
 * Represents an attribute of a entry
 */
class Attribute {
	private $name;
	private $values;

	# min/max number of values
	protected $min_value_count;
	protected $max_value_count;

	# The entry in which the attribute is
	protected $entry;

	# Is the attribute internal
	protected $internal;

	# Has the attribute been modified
	protected $modified;

	# Is the attribute visible
	protected $visible;

	# Is the attribute modifiable
	protected $readonly;

	# Display parameters
	protected $friendly_name;
	protected $description;
	protected $icon;
	protected $hint;

	protected $size;	# Component size
	protected $maxlength;	# Value max length

	protected $properties;
	
	public function __construct($name, $values) {
		$this->name = $name;

		if (is_string($values) && (strlen($values) > 0)) $this->values = array($values);
		elseif (is_array($values)) $this->values = $values;
		else $this->values = array();

		$this->min_value_count = -1;
		$this->max_value_count = -1;

		$this->entry = null;
		$this->internal = false;
		$this->modified = false;
		$this->visible = true;
		$this->readonly = false;

		$this->friendly_name = '';
		$this->description = '';
		$this->icon = '';
		$this->hint = '';

		$this->size = 0;
		$this->maxlength = 0;

		$this->properties = array();
	}

	public function getName() {
		return $this->name;
	}

	public function getValues() {
		return $this->values;
	}

	public function getValueCount() {
		return count($this->values);
	}

	public function addValue($new_val, $i = -1) {
		if ($i < 0) $i = $this->getValueCount();
		$old_val = $this->getValue($i);
		if (is_null($old_val) || ($old_val != $new_val)) $this->justModified();
		$this->values[$i] = $new_val;
	}

	public function getValue($i) {
		if (isset($this->values[$i])) return ''.$this->values[$i];
		else return null;
	}

	public function getMinValueCount() {
		return $this->min_value_count;
	}

	public function setMinValueCount($min) {
		$this->min_value_count = $min;
	}

	public function getMaxValueCount() {
		return $this->max_value_count;
	}

	public function setMaxValueCount($max) {
		$this->max_value_count = $max;
	}

	public function getEntry() {
		return $this->entry;
	}

	public function setEntry($entry) {
		$this->entry = $entry;

		global $ldapserver;
		$schema_attr = null;
		if ($entry) {
			$schema_attr = $ldapserver->getSchemaAttribute($this->getName(), $entry->getDn());
		}
		if ($schema_attr && $schema_attr->getIsSingleValue()) {
			$this->setMaxValueCount(1);
		}
	}

	public function justModified() {
		$this->modified = true;
	}

	public function hasBeenModified() {
		return $this->modified;
	}

	public function isInternal() {
		return $this->internal;
	}

	public function setInternal() {
		$this->internal = true;
	}

	public function isRequired() {
		if ($this->getMinValueCount() > 0) {
			return true;
		} elseif ($this->isRdn()) {
			return true;
		} else {
			return false;
		}
	}

	public function setRequired() {
		if ($this->getMinValueCount() <= 0) {
			$this->setMinValueCount(1);
		}
	}

	public function setOptional() {
		$this->setMinValueCount(0);
	}

	public function isReadOnly() {
		return $this->readonly;
	}

	public function setReadOnly() {
		$this->readonly = true;
	}

	public function isVisible() {
		return $this->visible;
	}

	public function hide() {
		$this->visible = false;
	}

	public function show() {
		$this->visible = true;
	}

	public function setFriendlyName($name) {
		if ($name != $this->name) {
			$this->friendly_name = $name;
		}
	}

	public function getFriendlyName() {
		if ($this->friendly_name)
			return $this->friendly_name;
		else
			return $_SESSION[APPCONFIG]->getFriendlyName(real_attr_name($this->name));
	}

	public function setDescription($description) {
		$this->description = $description;
	}

	public function getDescription() {
		return $this->description;
	}

	public function setIcon($icon) {
		$this->icon = $icon;
	}

	public function getIcon() {
		return $this->icon;
	}

	public function getHint() {
		return $this->hint;
	}

	public function setHint($hint) {
		$this->hint = $hint;
	}

	public function getMaxLength() {
		return $this->maxlength;
	}

	public function setMaxLength($maxlength) {
		$this->maxlength = $maxlength;
	}

	public function getSize() {
		return $this->size;
	}

	public function setSize($size) {
		$this->size = $size;
	}

	public function setProperty($name, $value) {
		$this->properties[$name] = $value;
	}

	public function delProperty($name) {
		if ($this->hasProperty($name)) unset($this->properties[$name]);
	}

	public function hasProperty($name) {
		return isset($this->properties[$name]);
	}

	public function getProperty($name) {
		if ($this->hasProperty($name)) return $this->properties[$name];
		else return null;
	}

	public function isRdn() {
		if ($this->entry) {
			//$rdn = get_rdn($this->entry->getDn());
    			//$attr = $this->name;
			//return preg_match("/^${attr}=/", $rdn);
			return ($this->name == $this->entry->getRdnAttributeName());
		} else {
			return false;
		}
	}

	/**
	 * Visit the attribute
	 */
	public function accept($visitor) {
		$visitor->visit('', $this);
	}
}
?>