28 protected $templatable = TRUE;
41 function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = FALSE, $acl =
"", $trueValue =
"TRUE", $falseValue =
"FALSE")
43 parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
44 $this->trueValue = $trueValue;
45 $this->falseValue = $falseValue;
48 function setTemplatable ($bool)
50 $this->templatable = $bool;
53 protected function isTemplatable ()
56 return (!$this->submitForm && empty($this->managedAttributes) && $this->templatable);
59 function inputValue ($value)
61 if ($this->isTemplate() && $this->isTemplatable() && ($value ===
'%askme%')) {
64 return ($value == $this->trueValue);
67 function loadPostValue ()
69 if ($this->isVisible()) {
70 if ($this->isTemplate() && $this->isTemplatable()) {
71 if (!isset($_POST[$this->getHtmlId()])) {
73 } elseif ($_POST[$this->getHtmlId()] ===
'%askme%') {
76 $this->
setPostValue($_POST[$this->getHtmlId()] ==
'TRUE');
84 function computeLdapValue ()
86 if ($this->isTemplate() && $this->isTemplatable() && ($this->value ===
'%askme%')) {
89 return ($this->value ? $this->trueValue : $this->falseValue);
93 function displayValue ($value):
string 95 if ($this->isTemplate() && $this->isTemplatable() && ($value ===
'%askme%')) {
98 return ($value ? _(
'yes') : _(
'no'));
102 function renderFormInput ():
string 104 $id = $this->getHtmlId();
105 $attributes = ($this->value ? [
'checked' =>
'checked'] : []);
106 if ($this->submitForm) {
107 $js =
'document.mainform.submit();';
108 $attributes[
'onChange'] =
'javascript:'.$js;
109 } elseif (!empty($this->managedAttributes)) {
110 $js = $this->managedAttributesJS();
111 $attributes[
'onChange'] =
'javascript:'.$js;
113 $display = $this->renderInputField(
'checkbox', $id, $attributes);
117 function renderTemplateInput ():
string 119 if ($this->isTemplatable()) {
120 $id = $this->getHtmlId();
121 if ($this->getValue() ===
'%askme%') {
122 $selected =
'%askme%';
123 } elseif ($this->getValue()) {
128 $display =
'<select name="'.$id.
'" id="'.$id.
'" ';
129 if ($this->disabled) {
130 $display .=
'disabled="disabled" ';
133 $display .=
'{html_options values=array("FALSE","TRUE","%askme%") output=array("FALSE","TRUE","%askme%") selected="'.$selected.
'"}';
134 $display .=
'</select>';
137 return $this->renderFormInput();
141 protected function managedAttributesJS ():
string 144 $id = $this->getHtmlId();
145 foreach ($this->managedAttributes as $array) {
146 foreach ($array as $value => $attributes) {
147 if (isset($this->managedAttributesMultipleValues[$value])) {
148 trigger_error(
'Multiple values are not available for boolean attributes');
150 $js .=
'disableAttributes = (document.getElementById('.json_encode($id).
').checked == '.($value ?
'true' :
'false').
');'.
"\n";
152 foreach ($attributes as $attribute) {
153 foreach ($this->plugin->attributesAccess[$attribute]->htmlIds() as $htmlId) {
154 $js .=
'if (document.getElementById('.json_encode($htmlId).
')) { document.getElementById('.json_encode($htmlId).
').disabled = disableAttributes; }'.
"\n";
168 if ($this->disabled) {
171 htmlescape(sprintf(_(
'Attribute %s is disabled, its value could not be set'), $this->getLdapName()))
174 if ($value === $this->trueValue) {
175 $this->setValue(TRUE);
176 } elseif ($value === $this->falseValue) {
177 $this->setValue(FALSE);
178 } elseif (is_bool($value)) {
179 $this->setValue($value);
180 } elseif ($value === 1) {
181 $this->setValue(TRUE);
182 } elseif ($value === 0) {
183 $this->setValue(FALSE);
187 htmlescape(sprintf(_(
'"%s" is not a valid value, should be "%s" or "%s"'), $value, $this->getLdapName(), $this->trueValue, $this->falseValue))
195 function serializeAttribute (array &$attributes,
bool $form = TRUE)
197 if (!$form || $this->visible) {
198 parent::serializeAttribute($attributes, $form);
199 $attributes[$this->getLdapName()][
'choices'] = [
200 $this->trueValue =>
'True',
201 $this->falseValue =>
'False',
212 private $objectclasses;
225 function __construct ($label, $description, $ldapName, $required, $objectclasses, $defaultValue = FALSE, $acl =
"")
227 if (is_array($objectclasses)) {
228 $this->objectclasses = $objectclasses;
230 $this->objectclasses = [$objectclasses];
232 parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
233 $this->setInLdap(FALSE);
238 if (isset($attrs[
'objectClass'])) {
239 $missing_oc = array_udiff($this->objectclasses, $attrs[
'objectClass'],
'strcasecmp');
240 $this->setValue(empty($missing_oc));
244 $this->initialValue = $this->value;
249 if ($this->getValue()) {
250 $attrs[
'objectClass'] =
array_merge_unique($this->objectclasses, $attrs[
'objectClass']);
htmlescape(string $str)
Escape string for HTML output.
fillLdapValue(array &$attrs)
Fill LDAP value in the attrs array.
loadValue(array $attrs)
If in LDAP, loads this attribute value from the attrs array.
Error returned by any method of SimplePlugin.
deserializeValue($value)
Apply value from RPC requests.
setPostValue($value)
Set the postValue.
This class allow to handle easily a Boolean LDAP attribute.
renderAcl(string $display)
Add ACL information around display.
array_merge_unique(array $ar1, array $ar2)
resetToDefault()
Reset this attribute to its default value.
array_remove_entries(array $needles, array $haystack)
__construct($label, $description, $ldapName, $required, $objectclasses, $defaultValue=FALSE, $acl="")
The constructor of ObjectClassBooleanAttribute.
This class allow to handle easily any kind of LDAP attribute.
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.