FusionDirectory
class_DisplayAttribute.inc
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4 
5  Copyright (C) 2012-2021 FusionDirectory
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21 
28 {
29  protected $allowHTML = FALSE;
30  protected $allowSmarty = FALSE;
31 
32  function renderFormInput (): string
33  {
34  if ($this->allowHTML) {
35  $value = $this->getValue();
36  } else {
37  $value = htmlescape($this->getValue());
38  }
39  if ($this->allowSmarty) {
40  return $value;
41  } else {
42  return '{literal}'.$value.'{/literal}';
43  }
44  }
45 
46  function setAllowHTML (bool $allowHTML)
47  {
48  $this->allowHTML = $allowHTML;
49  }
50 
51  function setAllowSmarty (bool $allowSmarty)
52  {
53  $this->allowSmarty = $allowSmarty;
54  }
55 }
56 
62 {
63  function fillLdapValue (array &$attrs)
64  {
65  }
66 }
67 
73 {
74  protected function loadAttrValue (array $attrs)
75  {
76  if (isset($attrs[$this->getLdapName()]['count'])) {
77  $this->value = [];
78  for ($i = 0; $i < $attrs[$this->getLdapName()]['count']; $i++) {
79  $this->value[] = $attrs[$this->getLdapName()][$i];
80  }
81  }
82  }
83 
84  function renderFormInput (): string
85  {
86  $value = $this->getValue();
87  if (is_array($value)) {
88  $value = join(', ', $value);
89  }
90  return '{literal}'.htmlescape($value).'{/literal}';
91  }
92 }
93 
99 {
100  function __construct (string $label, string $description, string $ldapName, bool $required = FALSE, $defaultValue = '', string $acl = '')
101  {
102  parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
103  $this->setInLdap(FALSE);
104  }
105 }
106 
110 {
111  protected $type;
112 
113  function __construct (string $label, string $description, string $ldapName, bool $required, string $type, $defaultValue = '', string $acl = '')
114  {
115  parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
116  $this->type = $type;
117  }
118 
119  function renderFormInput (): string
120  {
121  if (empty($this->value)) {
122  return '';
123  }
124 
125  try {
126  return objects::link($this->value, $this->type);
127  } catch (NonExistingLdapNodeException $e) {
128  return '<a><img src="geticon.php?context=status&amp;icon=dialog-warning&amp;size=16" alt="warning" class="center"/>&nbsp;'.sprintf(_('Invalid: %s'), $this->value).'</a>';
129  }
130  }
131 }
htmlescape(string $str)
Escape string for HTML output.
Definition: php_setup.inc:32
fillLdapValue(array &$attrs)
Fill LDAP value in the attrs array.
This class allow to display an attribute.
loadAttrValue(array $attrs)
Loads this attribute value from the attrs array if present.
This class allow to display an attribute.
This class allow to display a link to an object which dn is stored in the attribute.
This class allow to display a text in front of an attribute.
This class allow to display an attribute.
static link(string $dn, string $type, string $subaction='', $text=NULL, bool $icon=TRUE, bool $link=TRUE)
This class allow to handle easily any kind of LDAP attribute.
__construct(string $label, string $description, string $ldapName, bool $required=FALSE, $defaultValue='', string $acl='')
The constructor of Attribute.