FusionDirectory
class_DialogAttribute.inc
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4  Copyright (C) 2012-2020 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 
27 abstract class DialogAttribute extends SetAttribute
28 {
29  protected $dialogClass = NULL;
30 
40  function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = [], $acl = "")
41  {
42  \FusionDirectory\Core\SimplePlugin\Attribute::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
43  $this->attribute = FALSE;
44  }
45 
46  function addPostValue ($value)
47  {
48  $this->addValue($value, NULL);
49  }
50 
51  function delPostValue ($key)
52  {
53  $this->removeValue($key);
54  }
55 
56  abstract function addValue (string $dn, $attrs = NULL);
57 
58  function searchAndRemove ($value)
59  {
60  $row = array_search($value, $this->value);
61  if ($row !== FALSE) {
62  $this->removeValue($row);
63  }
64  }
65 
66  protected function removeValue ($row)
67  {
68  unset($this->value[$row]);
69  }
70 
71  abstract function getFilterBlackList ();
72 
73  function getFilterWhiteList ()
74  {
75  return [];
76  }
77 
78  function loadPostValue ()
79  {
80  parent::loadPostValue();
81  if ($this->isVisible()) {
82  $id = $this->getHtmlId();
83  if (isset($_POST['add'.$id.'_dialog'])) {
84  $this->plugin->openDialog(new $this->dialogClass($this->plugin, $this));
85  } elseif (isset($_POST['add'.$id]) && isset($_POST[$id]) && $this->isTemplate()) {
86  $this->addPostValue($_POST[$id]);
87  }
88  }
89  }
90 
91  function applyPostValue ()
92  {
93  }
94 
95  function renderButtons ()
96  {
97  $id = $this->getHtmlId();
98  $buttons = '';
99  $dialogButtonValue = msgPool::addButton(FALSE);
100  if ($this->isTemplate()) {
101  $buttons .= $this->renderInputField(
102  'text', $id,
103  ['value' => $this->editingValue, 'class' => 'subattribute']
104  );
105  $buttons .= $this->renderInputField(
106  'submit', 'add'.$id,
107  [
108  'value' => msgPool::addButton(FALSE),
109  'formnovalidate' => 'formnovalidate',
110  'class' => 'subattribute',
111  ]
112  );
113  $dialogButtonValue = _('Add (dialog)');
114  }
115  $buttons .= $this->renderInputField(
116  'submit', 'add'.$id.'_dialog',
117  [
118  'class' => 'dialog subattribute',
119  'value' => $dialogButtonValue,
120  'formnovalidate' => 'formnovalidate',
121  ]
122  );
123  $buttons .= $this->renderInputField(
124  'submit', 'del'.$id,
125  [
126  'value' => msgPool::delButton(FALSE),
127  'formnovalidate' => 'formnovalidate',
128  'class' => 'subattribute',
129  ]
130  );
131  return $buttons;
132  }
133 
134  public function htmlIds (): array
135  {
136  $id = $this->getHtmlId();
137  $ids = ['add'.$id.'_dialog','del'.$id,'row'.$id];
138  if ($this->isTemplate()) {
139  $ids[] = $id;
140  $ids[] = 'add'.$id;
141  }
142  return $ids;
143  }
144 }
static delButton($escape=TRUE)
Text for an delete button.
static addButton($escape=TRUE)
Text for an add button.
This class allows to handle an attribute with a popup for selection.
This class allow to handle easily a multi-valuated attribute.
__construct($label, $description, $ldapName, $required=FALSE, $defaultValue=[], $acl="")
The constructor of DialogAttribute.
__construct(string $label, string $description, string $ldapName, bool $required=FALSE, $defaultValue='', string $acl='')
The constructor of Attribute.