FusionDirectory
 All Data Structures Files Functions Variables
class_BaseSelectorAttribute.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  private $baseSelector = NULL;
27  private $orig_dn = NULL;
28  private $ou = NULL;
29 
34  function __construct ($ou, $label = NULL, $desc = NULL)
35  {
36  if ($label === NULL) {
37  $label = _('Base');
38  }
39  if ($desc === NULL) {
40  $desc = _('Object base');
41  }
42  parent::__construct($label, $desc, 'base', FALSE, '', 'base');
43  $this->setInLdap(FALSE);
44  $this->ou = $ou;
45  }
46 
47  function setManagedAttributes ($dontcare)
48  {
49  trigger_error('method setManagedAttributes is not supported for BaseSelectorAttribute');
50  }
51 
52  function setParent (&$plugin)
53  {
54  parent::setParent($plugin);
55  if (is_object($this->plugin)) {
56  /* Do base conversation */
57  if ($this->plugin->is_template) {
58  $this->ou = 'ou=templates,'.$this->ou;
59  }
60  if ($this->plugin->dn == "new") {
61  $ui = get_userinfo();
62  $this->setValue(dn2base(session::global_is_set("CurrentMainBase")?"cn=dummy,".session::global_get("CurrentMainBase"):$ui->dn));
63  } else {
64  $this->setValue(dn2base($this->plugin->dn, $this->ou));
65  }
66  $this->orig_dn = $this->plugin->dn;
67  /* Instanciate base selector */
68  $this->initialValue = $this->value;
69  $this->baseSelector = new baseSelector($this->plugin->get_allowed_bases(), $this->value);
70  $this->baseSelector->setSubmitButton(FALSE);
71  $this->baseSelector->setHeight(300);
72  $this->baseSelector->update(TRUE);
73  }
74  }
75 
76  function loadPostValue ()
77  {
78  }
79 
80  function applyPostValue ()
81  {
82  if (!$this->disabled && $this->isVisible()) {
83  /* Refresh base */
84  if ($this->plugin->acl_is_moveable($this->value) || ($this->plugin->dn == 'new')) {
85  if (!$this->baseSelector->update()) {
86  if ($this->plugin->dn == 'new') {
87  msg_dialog::display(_('Error'), msgPool::permCreate(), ERROR_DIALOG);
88  } else {
89  msg_dialog::display(_('Error'), msgPool::permMove($this->plugin->dn), ERROR_DIALOG);
90  }
91  }
92  if ($this->value != $this->baseSelector->getBase()) {
93  $this->setValue($this->baseSelector->getBase());
94  }
95  }
96  }
97  }
98 
99  function check ()
100  {
101  $error = parent::check();
102  if (!empty($error)) {
103  return $error;
104  } else {
105  /* Check if we are allowed to create/move this user */
106  if (($this->orig_dn == 'new') && !$this->plugin->acl_is_createable($this->value)) {
107  return msgPool::permCreate();
108  } elseif (
109  ($this->orig_dn != 'new') &&
110  ($this->plugin->dn != $this->orig_dn) &&
111  !$this->plugin->acl_is_moveable($this->value)) {
112  return msgPool::permMove($this->plugin->dn);
113  }
114  // Check if a wrong base was supplied
115  if (!$this->baseSelector->checkLastBaseUpdate()) {
116  return msgPool::check_base();
117  }
118  }
119  }
120 
121  function checkValue($value)
122  {
123  if (!is_string($value) && (!is_object($value) || !method_exists($value, '__toString' ))) {
124  throw new InvalidValueException(_('Base field value should always be a string'));
125  }
126  }
127 
128  function setValue ($value)
129  {
130  parent::setValue($value);
131  if (is_object($this->plugin)) {
132  /* Set the new acl base */
133  if ($this->plugin->dn == 'new') {
134  $this->plugin->set_acl_base($this->value);
135  $this->plugin->parent->set_acl_base();
136  }
137 
138  if (($this->baseSelector !== NULL) && ($this->baseSelector->getBase() !== $this->value)) {
139  $this->baseSelector->setBase($this->value);
140  }
141  }
142  }
143 
144  function getValue ()
145  {
146  return $this->value;
147  }
148 
149  function renderFormInput ()
150  {
151  $smarty = get_smarty();
152  $smarty->assign('usePrototype', 'true');
153  if ($this->disabled) {
154  $display = $this->renderInputField(
155  'text', '',
156  array(
157  'value' => '{literal}'.htmlentities($this->getValue(), ENT_COMPAT, 'UTF-8').'{/literal}'
158  )
159  );
160  } else {
161  $display = '{literal}'.$this->baseSelector->render().'{/literal}';
162  }
163  return $this->renderAcl($display);
164  }
165 
166  function getHtmlId()
167  {
168  if (isset($this->baseSelector)) {
169  return $this->baseSelector->getInputHtmlId();
170  } else {
171  return '';
172  }
173  }
174 
175  function serializeAttribute(&$attributes, $form = TRUE)
176  {
177  if (!$form || $this->visible) {
178  parent::serializeAttribute($attributes, $form);
179 
180  $attributes[$this->getLdapName()]['choices'] = $this->baseSelector->getBases();
181  }
182  }
183 }
renderAcl($display)
Add ACL information around display.
setSubmitButton($flag)
Set a new flag to the submit button.
Exception class which can be thrown if an attribute is set to a value with a non-compatible type...
This class allow to handle easily any kind of LDAP attribute.
update($force=FALSE)
Update the base.
__construct($ou, $label=NULL, $desc=NULL)
The constructor of BaseSelectorAttribute.
setBase($base)
Set a new value of the member base.
& get_userinfo()
Return the current userinfo object.
Definition: functions.inc:941
Class Base Selector.
checkLastBaseUpdate()
Check the last base value updated.
& get_smarty()
Get global smarty object.
Definition: functions.inc:953
static permMove($name="")
Display that we have no permission to move an object.
static check_base()
Display error when checking the base.
dn2base($dn, $ou=NULL)
Return the base of a given DN.
Definition: functions.inc:1314
setHeight($value)
Set a new value of the member height.
getBase()
Accessor of the base.
This class allow to handle easily an Base selector attribute.
static permCreate($name="")
Display that we have no permission to create an object.
static global_get($name)
Accessor of a session var.
static display($s_title, $s_message, $i_type=INFO_DIALOG)
Display a message dialog.
getInputHtmlId()
Returns id of the html field.
getBases()
Accessor of the bases.
static global_is_set($name)
Check if a session is defined.