FusionDirectory
class_ManagementConfigurationDialog.inc
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4  Copyright (C) 2017-2018 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 
22 {
23  function __construct ($label, $description, $ldapName, $attributes, $acl = "")
24  {
25  parent::__construct($description, $ldapName, $attributes, FALSE, FALSE, $acl, $label);
26  }
27 }
28 
33 {
34  static function plInfo (): array
35  {
36  return [
37  'plShortName' => 'ManagementConfigurationDialog',
38  ];
39  }
40 
41  static function getAttributesInfo (): array
42  {
43  global $class_mapping;
44 
45  // Load column types
46  $types = [];
47  foreach (array_keys($class_mapping) as $class) {
48  if (preg_match('/Column$/', $class) && is_a($class, 'Column', TRUE)) {
49  $types[] = $class;
50  }
51  }
52  sort($types);
53 
54  return [
55  'main' => [
56  'class' => ['fullwidth'],
57  'name' => _('Management configuration'),
58  'attrs' => [
61  _('Columns'),
62  _('Columns displayed for this management list'),
63  'managementColumns',
64  [
65  new SelectAttribute(
66  _('Type'), _('Type of column'),
67  'columnType', TRUE,
68  $types, 'LinkColumn'
69  ),
70  new StringAttribute(
71  _('Attribute'), _('LDAP attributes to display, comma separated. Special values "nameAttr" and "mainAttr" also work.'),
72  'columnAttribute', FALSE
73  ),
74  new StringAttribute(
75  _('Label'), _('Column title'),
76  'columnLabel', FALSE
77  ),
78  ],
79  'ManagementConfiguration'
80  ),
81  TRUE, // ordered
82  [],
83  TRUE // edition
84  ),
85  new BooleanAttribute(
86  _('Persistent'), _('Should this configuration be saved in the LDAP as your default configuration for this management page'),
87  'saveInLdapUser', FALSE,
88  FALSE,
89  'ManagementConfiguration'
90  ),
91  new ButtonAttribute(
92  _('Forget my persistent configuration'), _('Delete the persistent configuration for this management page so that the default one is used'),
93  'resetInLdapUser', _('Forget'),
94  NULL, '',
95  'ManagementConfiguration'
96  ),
97  new BooleanAttribute(
98  _('Global default'), _('Should this configuration be saved in the LDAP as the default configuration for this management page for all users'),
99  'saveInLdap', FALSE,
100  FALSE,
101  'fdManagementConfig'
102  ),
103  new ButtonAttribute(
104  _('Forget global default'), _('Delete the global default configuration for this management page so that the default one is used'),
105  'resetInLdap', _('Forget'),
106  NULL, '',
107  'fdManagementConfig'
108  ),
109  ]
110  ],
111  ];
112  }
113 
114  function __construct (management $parent)
115  {
116  global $config;
117 
118  parent::__construct(NULL, NULL, $parent);
119 
120  $this->attributesAccess['saveInLdap']->setInLdap(FALSE);
121  $this->attributesAccess['saveInLdapUser']->setInLdap(FALSE);
122  if (!$this->attrIsWriteable('saveInLdap')) {
123  $this->attributesAccess['saveInLdap']->setVisible(FALSE);
124  }
125  $this->attributesAccess['resetInLdap']->setInLdap(FALSE);
126  $this->attributesAccess['resetInLdapUser']->setInLdap(FALSE);
127  if (!$this->attrIsWriteable('resetInLdap')) {
128  $this->attributesAccess['resetInLdap']->setVisible(FALSE);
129  }
130 
131  if (!$config->hasManagementConfig(get_class($this->parent), TRUE)) {
132  $this->attributesAccess['resetInLdapUser']->setVisible(FALSE);
133  }
134  if (!$config->hasManagementConfig(get_class($this->parent), FALSE)) {
135  $this->attributesAccess['resetInLdap']->setVisible(FALSE);
136  }
137 
138  $this->attributesAccess['managementColumns']->setInLdap(FALSE);
139  $this->attributesAccess['managementColumns']->setLinearRendering(FALSE);
140  $columnInfos = $this->parent->getColumnConfiguration();
141  $value = [];
142  foreach ($columnInfos as $column) {
143  if (!isset($column[1]['attributes'])) {
144  $column[1]['attributes'] = '';
145  } elseif (is_array($column[1]['attributes'])) {
146  $column[1]['attributes'] = json_encode($column[1]['attributes']);
147  }
148  if (!isset($column[1]['label'])) {
149  $column[1]['label'] = '';
150  }
151  $value[] = [$column[0], $column[1]['attributes'], $column[1]['label']];
152  }
153  $this->attributesAccess['managementColumns']->setValue($value);
154  }
155 
156  function attrIsReadable ($attr): bool
157  {
158  return $this->attrIsWriteable($attr);
159  }
160 
161  function attrIsWriteable ($attr): bool
162  {
163  global $config, $ui;
164 
165  $noAclAttrs = ['managementColumns', 'saveInLdapUser', 'resetInLdapUser'];
166  $configAttrs = ['saveInLdap', 'resetInLdap'];
167 
168  if ((is_object($attr) && in_array($attr->getLdapName(), $noAclAttrs)) || in_array($attr, $noAclAttrs)) {
169  return TRUE;
170  } elseif ((is_object($attr) && in_array($attr->getLdapName(), $configAttrs)) || in_array($attr, $configAttrs)) {
171  $acl = $ui->get_permissions(CONFIGRDN.$config->current['BASE'], 'configuration/configInLdap', 'fdManagementConfig', $this->readOnly());
172  return (strpos($acl, 'w') !== FALSE);
173  } else {
174  return parent::attrIsWriteable($attr);
175  }
176  }
177 
178  function handle_resetInLdapUser ()
179  {
180  global $config;
181  $errors = $config->updateManagementConfig(get_class($this->parent), NULL, TRUE);
182  msg_dialog::displayChecks($errors);
183  if (empty($errors)) {
184  $this->attributesAccess['resetInLdapUser']->setVisible(FALSE);
185  }
186  }
187 
188  function handle_resetInLdap ()
189  {
190  global $config;
191  $errors = $config->updateManagementConfig(get_class($this->parent), NULL, FALSE);
192  msg_dialog::displayChecks($errors);
193  if (empty($errors)) {
194  $this->attributesAccess['resetInLdap']->setVisible(FALSE);
195  }
196  }
197 
198  public function render (): string
199  {
200  global $config, $ui;
201 
202  $smarty = get_smarty();
203  $smarty->assign('ManagementConfigurationACL', 'rw');
204  $smarty->assign('fdManagementConfigACL', $ui->get_permissions(CONFIGRDN.$config->current['BASE'], 'configuration/configInLdap', 'fdManagementConfig', $this->readOnly()));
205  return parent::render();
206  }
207 
208  public function save (): array
209  {
210  global $config;
211  $columnInfos = [];
212  $values = $this->managementColumns;
213  foreach ($values as $value) {
214  $column = [$value[0], []];
215  if (!empty($value[1])) {
216  $jsonDecoded = json_decode($value[1], TRUE);
217  if ($jsonDecoded !== NULL) {
218  $column[1]['attributes'] = $jsonDecoded;
219  } else {
220  $column[1]['attributes'] = $value[1];
221  }
222  }
223  if (!empty($value[2])) {
224  $column[1]['label'] = $value[2];
225  }
226  $columnInfos[] = $column;
227  }
228  $this->parent->setColumnConfiguration($columnInfos);
229 
230  if ($this->saveInLdapUser) {
231  return $config->updateManagementConfig(get_class($this->parent), $columnInfos, TRUE);
232  }
233 
234  if ($this->saveInLdap) {
235  return $config->updateManagementConfig(get_class($this->parent), $columnInfos);
236  }
237 
238  return [];
239  }
240 }
This class allow to handle easily a Select LDAP attribute with a set of choices.
Attribute showing a button.
attrIsReadable($attr)
Check if logged in user have enough right to read this attribute value.
save()
Save data to the LDAP and return errors.
This class allow to handle easily a composite attribute.
const CONFIGRDN
FusionDirectory config object RDN.
render()
Render the dialog and returns the HTML code.
& get_smarty()
Get global smarty object.
Definition: functions.inc:324
attrIsWriteable($attr)
Check if logged in user have enough right to write this attribute value.
This class allow to handle easily a Boolean LDAP attribute.
Multivalued attribute displayed as a columned table. May allow ordering and/or editing.
Management base class.
This class allow to handle easily a String LDAP attribute.
Management dialog.