FusionDirectory
 All Data Structures Files Functions Variables
class_BooleanAttribute.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 $trueValue;
27  public $falseValue;
28 
40  function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = FALSE, $acl = "", $trueValue = "TRUE", $falseValue = "FALSE")
41  {
42  parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
43  $this->trueValue = $trueValue;
44  $this->falseValue = $falseValue;
45  }
46 
47  function inputValue ($value)
48  {
49  return ($value == $this->trueValue);
50  }
51 
52  function loadPostValue ()
53  {
54  if ($this->isVisible()) {
55  $this->setPostValue(isset($_POST[$this->getHtmlId()]));
56  }
57  }
58 
59  function computeLdapValue ()
60  {
61  return ($this->value?$this->trueValue:$this->falseValue);
62  }
63 
64  function renderFormInput ()
65  {
66  $id = $this->getHtmlId();
67  $attributes = ($this->value?array('checked' => 'checked'): array());
68  if ($this->submitForm) {
69  $js = 'document.mainform.submit();';
70  $attributes['onChange'] = 'javascript:'.htmlentities($js, ENT_COMPAT, 'UTF-8');
71  } elseif (!empty($this->managedAttributes)) {
72  $js = $this->managedAttributesJS();
73  $attributes['onChange'] = 'javascript:'.htmlentities($js, ENT_COMPAT, 'UTF-8');
74  }
75  $display = $this->renderInputField('checkbox', $id, $attributes);
76  return $this->renderAcl($display);
77  }
78 
79  protected function managedAttributesJS ()
80  {
81  $js = '';
82  $id = $this->getHtmlId();
83  foreach ($this->managedAttributes as $array) {
84  foreach ($array as $value => $attributes) {
85  if (isset($this->managedAttributesMultipleValues[$value])) {
86  trigger_error('Multiple values are not available for boolean attributes');
87  } else {
88  $js .= 'disableAttributes = (document.getElementById('.json_encode($id).').checked == '.($value?'true':'false').');'."\n";
89  }
90  foreach ($attributes as $attribute) {
91  foreach ($this->plugin->attributesAccess[$attribute]->htmlIds() as $htmlId) {
92  $js .= 'if (document.getElementById('.json_encode($htmlId).')) { document.getElementById('.json_encode($htmlId).').disabled = disableAttributes; }'."\n";
93  }
94  }
95  }
96  }
97  return $js;
98  }
99 }
100 
105 {
106  private $objectclasses;
107 
108 
119  function __construct ($label, $description, $ldapName, $required, $objectclasses, $defaultValue = FALSE, $acl = "")
120  {
121  if (is_array($objectclasses)) {
122  $this->objectclasses = $objectclasses;
123  } else {
124  $this->objectclasses = array($objectclasses);
125  }
126  parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
127  $this->setInLdap(FALSE);
128  }
129 
130  function loadValue ($attrs)
131  {
132  if (isset($attrs['objectClass'])) {
133  $missing_oc = array_udiff($this->objectclasses, $attrs['objectClass'], 'strcasecmp');
134  $this->setValue(empty($missing_oc));
135  } else {
136  $this->resetToDefault();
137  }
138  $this->initialValue = $this->value;
139  }
140 
141  function fillLdapValue (&$attrs)
142  {
143  if ($this->getValue()) {
144  $attrs['objectClass'] = array_merge_unique($this->objectclasses, $attrs['objectClass']);
145  } else {
146  $attrs['objectClass'] = array_remove_entries($this->objectclasses, $attrs['objectClass']);
147  }
148  }
149 }
150 
renderAcl($display)
Add ACL information around display.
setPostValue($value)
Set the postValue.
This class allow to handle easily any kind of LDAP attribute.
array_merge_unique($ar1, $ar2)
Merge to array but remove duplicate entries (case-insensitive)
Definition: functions.inc:393
This class allow to handle easily a Boolean LDAP attribute.
resetToDefault()
Reset this attribute to its default value.
array_remove_entries(array $needles, array $haystack)
Remove multiple entries from an array.
Definition: functions.inc:359
__construct($label, $description, $ldapName, $required, $objectclasses, $defaultValue=FALSE, $acl="")
The constructor of ObjectClassBooleanAttribute.
This class allow to handle easily a Boolean LDAP attribute that triggers a set of objectclasses...
__construct($label, $description, $ldapName, $required=FALSE, $defaultValue=FALSE, $acl="", $trueValue="TRUE", $falseValue="FALSE")
The constructor of BooleanAttribute.