FusionDirectory
class_SetAttribute.inc
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4  Copyright (C) 2012-2016 FusionDirectory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 
25 {
26  public $attribute;
27  protected $valueUnicity = TRUE;
28  protected $editingValue = FALSE;
29  protected $linearRendering = TRUE;
30  protected $size = 4;
31 
38  function __construct (\FusionDirectory\Core\SimplePlugin\Attribute $attribute, array $values = [], bool $valueUnicity = TRUE)
39  {
40  parent::__construct(
41  $attribute->getLabel(), $attribute->getDescription(),
42  $attribute->getLdapName(), $attribute->isRequired(),
43  $values
44  );
45  $this->attribute = $attribute;
46  $this->attribute->setRequired(TRUE);
47  $this->attribute->setIsSubAttribute(TRUE);
48  $this->valueUnicity = $valueUnicity;
49  }
50 
51  protected function getValueCount ()
52  {
53  return count($this->getValue());
54  }
55 
56  function setIsSubAttribute (bool $bool)
57  {
58  parent::setIsSubAttribute($bool);
59  $this->attribute->setIsSubAttribute($this->isSubAttribute);
60  }
61 
62  function setManagedAttributes (array $dontcare)
63  {
64  trigger_error('method setManagedAttributes is not supported for SetAttributes');
65  }
66 
67  function setLinearRendering (bool $bool)
68  {
69  $this->linearRendering = $bool;
70  }
71 
72  protected function loadAttrValue (array $attrs)
73  {
74  if (isset($attrs[$this->getLdapName()]['count'])) {
75  $this->value = [];
76  for ($i = 0; $i < $attrs[$this->getLdapName()]['count']; $i++) {
77  $this->value[] = $attrs[$this->getLdapName()][$i];
78  }
79  sort($this->value);
80  }
81  }
82 
83  function getAcl (): string
84  {
85  if ($this->attribute === FALSE) {
86  return parent::getAcl();
87  }
88  return $this->attribute->getAcl();
89  }
90 
91  function getAclInfo ()
92  {
93  if ($this->attribute === FALSE) {
94  return parent::getAclInfo();
95  }
96  return $this->attribute->getAclInfo();
97  }
98 
99  function setAcl (string $acl)
100  {
101  if ($this->attribute === FALSE) {
102  return parent::setAcl($acl);
103  }
104  $this->attribute->setAcl($acl);
105  }
106 
107  function addPostValue ($value)
108  {
109  if ($value === '') {
110  return FALSE;
111  }
112  if ($this->valueUnicity && in_array($value, $this->postValue, TRUE)) {
113  return FALSE;
114  }
115  $this->postValue[] = $value;
116  return TRUE;
117  }
118 
119  function delPostValue ($key)
120  {
121  unset($this->postValue[$key]);
122  }
123 
124  function loadPostValue ()
125  {
126  $this->editingValue = FALSE;
127  $id = $this->getHtmlId();
128  if ($this->isVisible()) {
129  $this->postValue = $this->value;
130  if (isset($_POST["add".$id])) {
131  if ($this->attribute !== FALSE) {
132  $this->attribute->loadPostValue();
133  $this->attribute->applyPostValue();
134  $this->addPostValue($this->attribute->getValue());
135  }
136  } elseif (isset($_POST["del".$id]) && isset($_POST["row".$id])) {
137  foreach ($_POST["row".$id] as $key) {
138  $this->delPostValue($key);
139  }
140  } elseif ($this->attribute !== FALSE) {
141  $this->attribute->loadPostValue();
142  $this->attribute->applyPostValue();
143  $this->editingValue = $this->attribute->getValue();
144  }
145  }
146  }
147 
148  function check ()
149  {
150  $error = parent::check();
151  if (!empty($error) || ($this->attribute === FALSE)) {
152  return $error;
153  } else {
154  $values = $this->getValue();
155  if (!is_array($values)) {
156  return new SimplePluginCheckError(
157  $this,
158  SimplePluginCheckError::invalidValue(_('Value is not an array'))
159  );
160  }
161  foreach ($values as $value) {
162  $this->attribute->setValue($value);
163  $error = $this->attribute->check();
164  if (!empty($error)) {
165  return $error;
166  }
167  }
168  }
169  }
170 
171  function renderFormInput (): string
172  {
173  $display = $this->renderOnlyFormInput();
174  $attr_display = $this->renderAttributeInput(FALSE);
175  $buttons = $this->renderButtons();
176  return $this->renderAcl($display).$attr_display.$this->renderAcl($buttons);
177  }
178 
179  function renderTemplateInput (): string
180  {
181  $display = $this->renderOnlyFormInput();
182  $attr_display = $this->renderAttributeInput(TRUE);
183  $buttons = $this->renderButtons();
184  return $this->renderAcl($display).$attr_display.$this->renderAcl($buttons);
185  }
186 
187  function renderOnlyFormInput (): string
188  {
189  if (($this->size < 15) && ($this->size < $this->getValueCount())) {
190  $this->size = min(15, $this->getValueCount());
191  }
192  $id = $this->getHtmlId();
193  $smarty = get_smarty();
194  $smarty->assign($id.'_values', $this->getDisplayValues());
195  $display = '<select multiple="multiple" name="row'.$id.'[]" id="row'.$id.'" size="'.$this->size.'"'.
196  ($this->disabled ? ' disabled="disabled"' : '').
197  ' >'."\n";
198  $display .= '{html_options options=$'.$id.'_values}';
199  $display .= '</select><br/>'."\n";
200  return $display;
201  }
202 
203  function getDisplayValues ()
204  {
205  if ($this->attribute === FALSE) {
206  return $this->getValue();
207  }
208  $attribute = $this->attribute;
209  return array_map(
210  function ($value) use ($attribute)
211  {
212  return $attribute->displayValue($value);
213  },
214  $this->getValue()
215  );
216  }
217 
218  function handleEditingValue ()
219  {
220  if ($this->editingValue === FALSE) {
221  $this->attribute->resetToDefault();
222  } else {
223  $this->attribute->setValue($this->editingValue);
224  }
225  }
226 
227  function renderAttributeInput ($template = FALSE)
228  {
229  if ($this->attribute === FALSE) {
230  return;
231  }
232  $this->handleEditingValue();
233  if ($this->valueUnicity && ($this->attribute instanceOf SelectAttribute)) {
234  $this->attribute->setHiddenChoices($this->getValue());
235  }
236  if ($template) {
237  return $this->attribute->renderTemplateInput();
238  } else {
239  return $this->attribute->renderFormInput();
240  }
241  }
242 
243  function renderAttribute (array &$attributes, bool $readOnly, bool $readable, bool $writable)
244  {
245  if ($this->attribute === FALSE) {
246  return parent::renderAttribute($attributes, $readOnly, $readable, $writable);
247  }
248  if ($this->visible) {
249  $this->attribute->setDisabled($this->disabled);
250  if ($this->linearRendering || $readOnly) {
251  parent::renderAttribute($attributes, $readOnly, $readable, $writable);
252  } else {
253  if ($this->valueUnicity && ($this->attribute instanceOf SelectAttribute)) {
254  $this->attribute->setHiddenChoices($this->getValue());
255  }
256  $attributes[$this->getLdapName()] = [
257  'htmlid' => $this->getForHtmlId(),
258  'label' => '{literal}'.htmlescape($this->getLabel()).'{/literal}',
259  'description' => ($this->isRequired() ? sprintf(_("%s (required)"), $this->getDescription()) : $this->getDescription()),
260  'input' => $this->renderAcl($this->renderOnlyFormInput()),
261  'subattribute' => $this->isSubAttribute,
262  'required' => $this->isRequired(),
263  'readable' => $readable,
264  'writable' => $writable,
265  ];
266  $this->handleEditingValue();
267  $this->attribute->renderAttribute($attributes, $readOnly, $readable, $writable);
268  $attributes[$this->getLdapName().'_buttons'] = [
269  'htmlid' => 'add'.$this->getHtmlId(),
270  'label' => '',
271  'description' => '',
272  'input' => $this->renderAcl($this->renderButtons()),
273  'subattribute' => TRUE,
274  'required' => FALSE,
275  'readable' => $readable,
276  'writable' => $writable,
277  ];
278  }
279  }
280  }
281 
282  function serializeAttribute (array &$attributes, bool $form = TRUE)
283  {
284  parent::serializeAttribute($attributes, $form);
285  if ($this->attribute === FALSE) {
286  return;
287  }
288  if ($form) {
289  return;
290  } else {
291  $subattributes = [];
292  $this->attribute->setDisabled($this->disabled);
293  $this->attribute->serializeAttribute($subattributes, $form);
294  $attributes[$this->getLdapName()]['attributes'] = $subattributes;
295  $attributes[$this->getLdapName()]['attributes_order'] = array_keys($subattributes);
296  }
297  }
298 
299  function getForHtmlId (): string
300  {
301  // Label should point to the attribute
302  if (is_object($this->attribute)) {
303  return $this->attribute->getForHtmlId();
304  } else {
305  return '';
306  }
307  }
308 
309  function renderButtons ()
310  {
311  $id = $this->getHtmlId();
312  $buttons = $this->renderInputField(
313  'submit', 'add'.$id,
314  [
315  'value' => msgPool::addButton(FALSE),
316  'formnovalidate' => 'formnovalidate',
317  'class' => 'subattribute',
318  ]
319  );
320  $buttons .= $this->renderInputField(
321  'submit', 'del'.$id,
322  [
323  'value' => msgPool::delButton(FALSE),
324  'formnovalidate' => 'formnovalidate',
325  'class' => 'subattribute',
326  ]
327  );
328  return $buttons;
329  }
330 
331  function computeLdapValue ()
332  {
333  $this->sortValues();
334  return array_values($this->getValue());
335  }
336 
337  protected function sortValues ()
338  {
339  sort($this->value);
340  }
341 
342  public function htmlIds (): array
343  {
344  $id = $this->getHtmlId();
345  return array_merge(['add'.$id,'del'.$id,'row'.$id], $this->attribute->htmlIds());
346  }
347 
352  function setParent (&$plugin)
353  {
354  parent::setParent($plugin);
355  if ($this->attribute !== FALSE) {
356  $this->attribute->setParent($plugin);
357  }
358  }
359 
360  function getArrayValues ()
361  {
362  $result = [];
363  foreach ($this->getValue() as $value) {
364  $this->attribute->setValue($value);
365  $row = [];
366  foreach ($this->attribute->getArrayValue() as $val) {
367  $row[] = $val;
368  }
369  $result[] = $row;
370  }
371  return $result;
372  }
373 
374  function foreignKeyUpdate ($oldvalue, $newvalue, array $source)
375  {
376  foreach ($this->value as $key => &$value) {
377  if (($source['FIELD'] == 'dn') && ($source['MODE'] == 'move')) {
378  if ($newvalue === NULL) {
379  if (preg_match('/'.preg_quote($oldvalue, '/').'$/', $value)) {
380  unset($this->value[$key]);
381  }
382  } else {
383  $value = preg_replace('/'.preg_quote($oldvalue, '/').'$/', $newvalue, $value);
384  }
385  } elseif ($value == $oldvalue) {
386  if ($newvalue === NULL) {
387  unset($this->value[$key]);
388  } elseif ($source['MODE'] == 'copy') {
389  $this->value[] = $newvalue;
390  } elseif ($source['MODE'] == 'move') {
391  $value = $newvalue;
392  }
393  }
394  }
395  unset($value);
396  }
397 
398  function foreignKeyCheck ($value, array $source): bool
399  {
400  return in_array($value, $this->getValue());
401  }
402 
403  function setSize ($size)
404  {
405  $this->size = $size;
406  }
407 
408  function checkValue ($value)
409  {
410  if (!is_array($value)) {
411  throw new InvalidValueException(sprintf(_('SetAttribute "%s" was set to a non-compatible value'), $this->getLabel()));
412  }
413  }
414 }
415 
420 {
421  protected $order;
422  protected $edit_enabled;
423  protected $headers = FALSE;
424 
432  function __construct ($attribute, $order = TRUE, $values = [], $edit_enabled = FALSE)
433  {
434  parent::__construct($attribute, $values);
435  $this->order = $order;
436  $this->edit_enabled = $edit_enabled;
437  }
438 
439  function setHeaders ($h)
440  {
441  $this->headers = $h;
442  }
443 
444  function readValue ($value)
445  {
446  if ($this->order) {
447  return preg_split('/:/', $value, 2);
448  } else {
449  return $value;
450  }
451  }
452 
453  function writeValue ($key, $value)
454  {
455  if ($this->order) {
456  return $key.":".$value;
457  } else {
458  return $value;
459  }
460  }
461 
462  function computeLdapValue ()
463  {
464  $this->sortValues();
465  $ldapValue = [];
466  foreach ($this->getValue() as $key => $value) {
467  $ldapValue[] = $this->writeValue($key, $value);
468  }
469  return $ldapValue;
470  }
471 
472  protected function sortValues ()
473  {
474  if (!$this->order) {
475  sort($this->value);
476  }
477  }
478 
479  protected function loadAttrValue (array $attrs)
480  {
481  if (isset($attrs[$this->getLdapName()]["count"])) {
482  $this->value = [];
483  for ($i = 0; $i < $attrs[$this->getLdapName()]["count"]; $i++) {
484  $value = $this->readValue($attrs[$this->getLdapName()][$i]);
485  if (is_array($value)) {
486  $this->value[$value[0]] = $value[1];
487  } else {
488  $this->value[] = $value;
489  }
490  }
491  }
492  if ($this->order) {
493  ksort($this->value);
494  $this->reIndexValues();
495  } else {
496  $this->sortValues();
497  }
498  }
499 
500  function renderOnlyFormInput (): string
501  {
502  if (($this->size < 15) && ($this->size < $this->getValueCount())) {
503  $this->size = min(15, $this->getValueCount());
504  }
505  $id = $this->getHtmlId();
506  $div = new divSelectBox('rows'.$id);
507  $smarty = get_smarty();
508  $height = ($this->size * 26) + 6;
509  if ($this->headers) {
510  $height += 29;
511  }
512  $div->setHeight($height);
513  $div->setHeaders($this->headers);
514  foreach ($this->getValue() as $key => $value) {
515  $fields = [];
516  foreach ($this->getAttributeArrayValue($key, $value) as $field) {
517  if (is_array($field)) {
518  $fields[] = $field;
519  } else {
520  $fields[] = ['string' => $field];
521  }
522  }
523  if (empty($fields)) {
524  continue;
525  }
526 
527  list ($img, $nbicons) = $this->genRowIcons($key, $value);
528  if ($nbicons > 0) {
529  $fields[] = ['html' => $img, 'attach' => 'style="border:0px;width:'.($nbicons * 20).'px;"'];
530  }
531  $div->addEntry($fields);
532  }
533  $smarty->assign("div_$id", $div->drawList());
534  return '{$div_'.$id.'}'."\n";
535  }
536 
537  protected function genRowIcons ($key, $value)
538  {
539  $id = $this->getHtmlId();
540 
541  $img = '';
542  $nbicons = 1;
543 
544  if ($this->order) {
545  $nbicons += 2;
546  if ($key != 0) {
547  $img .= $this->renderInputField(
548  'image', $id.'_up_'.$key,
549  [
550  'src' => 'geticon.php?context=actions&icon=view-sort-descending&size=16',
551  'title' => _('Sort up'),
552  'alt' => _('Sort up'),
553  'class' => 'center',
554  'formnovalidate' => 'formnovalidate',
555  ],
556  FALSE
557  );
558  } else {
559  $img .= '<img src="images/empty.png" alt="" style="width:16px;"/>';
560  }
561  if (($key + 1) < $this->getValueCount()) {
562  $img .= $this->renderInputField(
563  'image', $id.'_down_'.$key,
564  [
565  'src' => 'geticon.php?context=actions&icon=view-sort-ascending&size=16',
566  'title' => _('Sort down'),
567  'alt' => _('Sort down'),
568  'class' => 'center',
569  'formnovalidate' => 'formnovalidate',
570  ],
571  FALSE
572  );
573  } else {
574  $img .= '<img src="images/empty.png" alt="" style="width:16px;"/>';
575  }
576  }
577  if ($this->edit_enabled) {
578  $nbicons++;
579  $img .= $this->renderInputField(
580  'image', $id.'_edit_'.$key,
581  [
582  'src' => 'geticon.php?context=actions&icon=document-edit&size=16',
583  'title' => _('Edit'),
584  'alt' => _('Edit'),
585  'class' => 'center',
586  'formnovalidate' => 'formnovalidate',
587  ],
588  FALSE
589  );
590  }
591  $img .= $this->renderInputField(
592  'image', $id.'_del_'.$key,
593  [
594  'src' => 'geticon.php?context=actions&icon=edit-delete&size=16',
595  'title' => _('Delete'),
596  'alt' => _('Delete'),
597  'class' => 'center',
598  'formnovalidate' => 'formnovalidate',
599  ],
600  FALSE
601  );
602 
603  return [$img, $nbicons];
604  }
605 
606  protected function getAttributeArrayValue ($key, $value)
607  {
608  $this->attribute->setValue($value);
609  return $this->attribute->getArrayValue();
610  }
611 
612  protected function reIndexValues ()
613  {
614  $this->value = array_values($this->value);
615  }
616 
617  function loadPostValue ()
618  {
619  $this->editingValue = FALSE;
620  if ($this->isVisible()) {
621  $this->postValue = $this->value;
622  $id = $this->getHtmlId();
623  foreach (array_keys($_POST) as $name) {
624  if ($this->handlePostValueActions($id, $name)) {
625  break;
626  }
627  }
628  $this->handleAddAndEditValue();
629  }
630  }
631 
632  protected function handlePostValueActions ($id, $postValue)
633  {
634  if ($this->order) {
635  if (preg_match('/^'.$id.'_up_/', $postValue)) {
636  $key = preg_replace('/^'.$id.'_up_/', '', $postValue);
637  $key = (int)preg_replace('/_[xy]$/', '', $key);
638 
639  $tmp = $this->postValue[$key];
640  $this->postValue[$key] = $this->postValue[$key - 1];
641  $this->postValue[$key - 1] = $tmp;
642  return TRUE;
643  }
644  if (preg_match('/^'.$id.'_down_/', $postValue)) {
645  $key = preg_replace('/^'.$id.'_down_/', '', $postValue);
646  $key = (int)preg_replace('/_[xy]$/', '', $key);
647 
648  $tmp = $this->postValue[$key];
649  $this->postValue[$key] = $this->postValue[$key + 1];
650  $this->postValue[$key + 1] = $tmp;
651  return TRUE;
652  }
653  }
654  if ($this->edit_enabled && preg_match('/^'.$id.'_edit_/', $postValue)) {
655  $key = preg_replace('/^'.$id.'_edit_/', '', $postValue);
656  $key = preg_replace('/_[xy]$/', '', $key);
657  $this->handleEdit($key);
658  return TRUE;
659  }
660  if (preg_match('/^'.$id.'_del_/', $postValue)) {
661  $key = preg_replace('/^'.$id.'_del_/', '', $postValue);
662  $key = preg_replace('/_[xy]$/', '', $key);
663  $this->delPostValue($key);
664  return TRUE;
665  }
666  return FALSE;
667  }
668 
669  protected function handleAddAndEditValue ()
670  {
671  $id = $this->getHtmlId();
672  if ($this->attribute === FALSE) {
673  return;
674  }
675  if (isset($_POST["add$id"])) {
676  $this->attribute->loadPostValue();
677  $this->attribute->applyPostValue();
678  if ($error = $this->attribute->check()) {
679  if (is_string($error)) {
680  $error = new SimplePluginCheckError($this, $error);
681  }
682  $error->display();
683  } else {
684  $this->addPostValue($this->attribute->getValue());
685  }
686  } elseif ($this->editingValue === FALSE) {
687  $this->attribute->loadPostValue();
688  $this->attribute->applyPostValue();
689  $this->editingValue = $this->attribute->getValue();
690  }
691  }
692 
693  protected function handleEdit ($key)
694  {
695  $this->editingValue = $this->value[$key];
696  $this->delPostValue($key);
697  $this->plugin->focusedField = $this->getHtmlId();
698  }
699 
700  function applyPostValue ()
701  {
702  parent::applyPostValue();
703  if ($this->order) {
704  $this->reIndexValues();
705  }
706  }
707 
708  public function htmlIds (): array
709  {
710  $id = $this->getHtmlId();
711  $ids = ['add'.$id];
712  if ($this->attribute !== FALSE) {
713  $ids = array_merge($ids, $this->attribute->htmlIds());
714  }
715  $nb_values = $this->getValueCount();
716  for ($i = 0; $i < $nb_values; ++$i) {
717  if ($this->order) {
718  if ($i > 0) {
719  $ids[] = $id.'_up_'.$i;
720  }
721  if (($i + 1) < $nb_values) {
722  $ids[] = $id.'_down_'.$i;
723  }
724  }
725  $ids[] = $id.'_del_'.$i;
726  }
727  return $ids;
728  }
729 
730  function renderButtons ()
731  {
732  $id = $this->getHtmlId();
733  $buttons = $this->renderInputField(
734  'submit', 'add'.$id,
735  [
736  'value' => msgPool::addButton(FALSE),
737  'formnovalidate' => 'formnovalidate',
738  'class' => 'subattribute',
739  ]
740  );
741  return $buttons;
742  }
743 }
744 
749 {
750  protected $objectClass;
751  protected $objectClasses;
752 
753  function __construct ($label, $description, $ldapName, $objectClass, $attributes, $order = FALSE, $values = [], $edit_enabled = FALSE, $acl = "")
754  {
755  $attributes_keys = [];
756  foreach ($attributes as $attribute) {
757  $attributes_keys[$attribute->getLdapName()] = $attribute;
758  $attributes_keys[$attribute->getLdapName()]->htmlid_prefix = $ldapName.'_';
759  }
760  $composite = new CompositeAttribute(
761  $description, $ldapName,
762  $attributes_keys,
763  FALSE, FALSE,
764  $acl, $label
765  );
766  parent::__construct($composite, $order, $values, $edit_enabled);
767  if (is_array($objectClass)) {
768  $this->objectClass = $objectClass[0];
769  $this->objectClasses = $objectClass;
770  } else {
771  $this->objectClass = $objectClass;
772  $this->objectClasses = [$objectClass];
773  }
774  }
775 
776  protected function loadAttrValue (array $attrs)
777  {
778  global $config;
779  /* Should we take dn from attrs or plugin? */
780  if (isset($attrs['dn'])) {
781  $ldap = $config->get_ldap_link();
782  $ldap->cd($attrs['dn']);
783  $ldap->search('objectClass='.$this->objectClass, ['*'], 'one');
784  $this->value = [];
785  while ($subattrs = $ldap->fetch(TRUE)) {
786  $this->attribute->resetToDefault();
787  foreach ($this->attribute->attributes as &$attribute) {
788  $attribute->loadAttrValue($subattrs);
789  }
790  unset($attribute);
791  $this->value[] = $this->attribute->getValue();
792  }
793  sort($this->value);
794  }
795  }
796 
797  /* Not saving anything into base node */
798  function fillLdapValue (array &$attrs)
799  {
800  }
801 
802  /* Special LDAP treatment that this attribute does after plugin ldap save */
803  function postLdapSave ($ldap)
804  {
805  /* First delete all old nodes */
806  $ldap->cd($this->plugin->dn);
807  $ldap->search('objectClass='.$this->objectClass, ['dn'], 'one');
808  $delete = [];
809  while ($attrs = $ldap->fetch()) {
810  $delete[] = $attrs['dn'];
811  }
812  foreach ($delete as $dn) {
813  $ldap->rmdir($dn);
814  }
815  /* Then add our values */
816  foreach ($this->value as $val) {
817  $attrs = ['objectClass' => $this->objectClasses];
818  $this->attribute->setValue($val);
819  foreach ($this->attribute->attributes as &$attribute) {
820  $attribute->fillLdapValue($attrs);
821  }
822  unset($attribute);
823  $dn = $this->compute_attribute_dn();
824  $ldap->cd($dn);
825  foreach (array_keys($attrs) as $index) {
826  if (is_array($attrs[$index]) && (count($attrs[$index]) == 0)) {
827  unset($attrs[$index]);
828  }
829  }
830  $ldap->add($attrs);
831  if (!$ldap->success()) {
832  $error = new SimplePluginLdapError($this, $dn, LDAP_ADD, $ldap->get_error(), $ldap->get_errno());
833  $error->display();
834  }
835  }
836  }
837 
838  function compute_attribute_dn ()
839  {
840  /* Later we might want to be able to choose which attribute to use in the dn */
841  reset($this->attribute->attributes);
842  $firstAttribute = key($this->attribute->attributes);
843  return $firstAttribute.'='.$this->attribute->attributes[$firstAttribute]->computeLdapValue().','.$this->plugin->dn;
844  }
845 }
This class allow to handle easily a Select LDAP attribute with a set of choices.
fillLdapValue(array &$attrs)
Fill LDAP value in the attrs array.
Exception class which can be thrown if an attribute is set to a value with a non-compatible type...
static delButton($escape=TRUE)
Text for an delete button.
setParent(&$plugin)
Set the parent plugin for this attribute.
static addButton($escape=TRUE)
Text for an add button.
This class allow to handle easily a composite attribute.
__construct(\FusionDirectory\Core\SimplePlugin\Attribute $attribute, array $values=[], bool $valueUnicity=TRUE)
The constructor of SetAttribute.
& get_smarty()
Get global smarty object.
Definition: functions.inc:324
Error returned by an LDAP operation called from SimplePlugin.
static invalidValue(string $error)
Format error message for invalid value.
Error returned by check method of SimplePlugin.
applyPostValue()
Apply this attribute postValue in value if this attribute is enabled.
This class allow to handle easily a multi-valuated attribute.
renderAcl(string $display)
Add ACL information around display.
An OrderedArrayAttribute which stores its values in LDAP subnodes.
__construct($attribute, $order=TRUE, $values=[], $edit_enabled=FALSE)
The constructor of OrderedArrayAttribute.
This class contains all the functions to manage select box.
Multivalued attribute displayed as a columned table. May allow ordering and/or editing.
This class allow to handle easily any kind of LDAP attribute.