36 public $objectType = FALSE;
37 protected $specialTabs = TRUE;
38 protected $plNotify = [];
55 public $ignoreAcls = FALSE;
60 function __construct (
string $type, $dn, $attrs_object = NULL)
64 $infos = objects::infos($type);
65 $data = $config->data[
'TABS'][$infos[
'tabGroup']];
66 $this->acl_category = $infos[
'aclCategory'];
67 $this->objectType = $type;
73 _(
'No plugin definitions found to initialize "%s", please check your configuration file.'),
79 $this->baseclass = NULL;
80 foreach ($data as $tab) {
84 if (!is_a($tab[
'CLASS'],
'SimpleTab', TRUE)) {
88 $this->by_name[$tab[
'CLASS']] = $tab[
'NAME'];
89 $this->plNotify[$tab[
'CLASS']] = FALSE;
91 if ($this->baseclass === NULL) {
92 $this->by_object[$tab[
'CLASS']] =
new $tab[
'CLASS']($this->dn, $attrs_object, $this, TRUE);
93 $this->baseclass = $tab[
'CLASS'];
95 $this->by_object[$tab[
'CLASS']] =
new $tab[
'CLASS']($this->dn, $this->by_object[$this->baseclass], $this, FALSE);
98 $this->by_object[$tab[
'CLASS']]->set_acl_category($this->acl_category);
102 $this->current = $this->baseclass;
104 if ($infos[
'mainAttr']) {
105 $baseobject = $this->getBaseObject();
108 ($baseobject->attributesAccess[$infos[
'mainAttr']]->getUnique() === FALSE)
110 $baseobject->attributesAccess[$infos[
'mainAttr']]->setUnique(
'one');
114 if ($this->specialTabs) {
128 foreach ($this->by_object as $name => $object) {
129 $class = get_class($object);
130 if (in_array($class, [
"reference",
"acl"])) {
133 if ($baseobject === NULL) {
134 $baseobject =
new $class($this->dn, NULL, $this, TRUE);
135 $this->by_object[$name] = $baseobject;
137 $this->by_object[$name] =
new $class($this->dn, $baseobject, $this, FALSE);
139 $this->by_object[$name]->set_acl_category($this->acl_category);
150 return $config->data[
'TABS'][$infos[
'tabGroup']];
158 foreach ($this->by_object as $class => $plugin) {
159 if ($plugin->isActive()) {
160 $tabObject->by_object[$class]->is_account = $plugin->is_account;
165 function resetCopyInfos ()
168 foreach ($this->by_object as &$obj) {
169 $obj->resetCopyInfos();
174 function resetBase ()
177 $baseobject = $this->getBaseObject();
178 if (isset($baseobject->base)) {
179 logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $baseobject->base,
'Fixing base');
180 $baseobject->base = $ui->getCurrentBase();
181 logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $baseobject->base,
'Fixed base');
183 logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
'',
'no base');
189 return $this->by_object[$this->baseclass];
195 return $this->getBaseObject()->readOnly();
203 trigger_error(
'obsolete');
207 public function readPostTabChange ()
210 foreach (array_keys($this->by_object) as $class) {
211 if (isset($_POST[$class]) || (isset($_POST[
'arg']) && ($_POST[
'arg'] == $class))) {
212 $this->current = $class;
221 if (!isset($this->by_name[$this->current])) {
222 $this->current = key($this->by_name);
226 $this->last = $this->current;
229 if ($this->last !=
'') {
230 logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->last,
'Reading POST');
232 $this->by_object[$this->last]->readPost();
235 $this->readPostTabChange();
240 trigger_error(
'obsolete');
248 foreach ($this->by_object as $key => $obj) {
260 $tabContent = $this->by_object[$this->current]->render();
266 $display .=
'<div class="tab-content">'.
"\n";
267 $display .= $tabContent;
268 $display .=
'</div>';
289 $display .=
'<input type="hidden" name="arg" value=""/>';
291 $display .=
'<table class="tabs-header"><tbody><tr>';
293 $style = [
'tab-left',
'tab-active',
'tab-right'];
294 foreach ($this->by_name as $class => $name) {
295 $obj = $this->by_object[$class];
299 if (($index == 1) || ($class == $this->current)) {
304 if ($obj->aclHasPermissions() && empty($obj->aclGetPermissions(
''))) {
305 $display .=
'<td class="nonreadable">';
312 if (mb_strlen($title,
'UTF-8') > 28) {
313 $title = mb_substr($title, 0, 25,
'UTF-8').
"...";
316 $cssClasses = $style[$index];
319 if ($this->plNotify[$class] && $obj->isActive()) {
320 $cssClasses .=
' tab-notify';
323 $cssClasses .=
' tab-disabled';
325 if (!$obj->isActive()) {
326 $cssClasses .=
' tab-inactive';
330 $display .=
'<div class="'.$cssClasses.
'">';
335 'id="tab_'.$class.
'" '.
336 'onclick="return true;" '.
337 'href="'.
"javascript:document.mainform.arg.value='$class';document.mainform.submit();".
'">';
339 $display .=
htmlescape($title).
'</a></div></td>';
342 $display .=
"<td>\n";
343 $display .=
'<div class="tab-border"> </div></td></tr></tbody></table>';
353 public function delete (
bool $checkAcl = TRUE): array
355 if ($checkAcl && !$this->getBaseObject()->acl_is_removeable()) {
360 foreach (array_reverse($this->by_object) as $obj) {
361 $errors = $obj->remove(TRUE);
362 if (!empty($errors)) {
378 if ($this->getBaseObject()->is_template) {
379 $ldap = $config->get_ldap_link();
380 $ldap->cd($config->current[
'BASE']);
381 $filter =
'(&(objectClass=fdTemplate)(cn='.ldap_escape_f($this->getBaseObject()->_template_cn).
'))';
382 $ldap->search($filter, [
'dn']);
383 while ($attrs = $ldap->fetch()) {
384 if ($attrs[
'dn'] != $this->getBaseObject()->dn) {
386 $this->getBaseObject()->attributesAccess[
'_template_cn'],
387 msgPool::duplicated($this->getBaseObject()->attributesAccess[
'_template_cn']->getLabel(), $attrs[
'dn'])
394 $current_set = FALSE;
397 foreach ($this->by_object as $key => $obj) {
398 $this->plNotify[$key] = FALSE;
399 if ($obj->isActive() && (!$obj->is_template)) {
400 logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $key,
"Checking");
402 $msg = $obj->check();
405 $this->plNotify[$key] = TRUE;
408 $this->current = $key;
424 $messages = $this->
check();
425 if (!empty($messages)) {
429 $baseobject = $this->getBaseObject();
432 $new_dn = $baseobject->compute_dn();
433 logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $new_dn,
'Saving');
438 htmlescape(sprintf(_(
'Failed to compute DN for object: %s'), $e->getMessage())),
446 $creation = ($this->dn ==
'new');
449 if ($this->dn != $new_dn) {
455 if (($error = $baseobject->move($this->dn, $new_dn)) === TRUE) {
460 htmlescape(sprintf(_(
'Move from "%s" to "%s" failed: %s'), $this->dn, $new_dn, $error))
469 foreach ($this->by_object as $key => $obj) {
470 logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $key,
'Saving');
472 $obj->dn = $this->dn;
474 if ($obj->isActive()) {
475 $result = $obj->save();
477 $result = $obj->remove(FALSE);
479 if (!empty($result)) {
480 if ($creation && $first) {
483 $obj->dn = $this->dn;
486 $errors = array_merge($errors, $result);
493 if (empty($errors) && isset($ui->dn) && ($this->dn == $ui->dn)) {
498 if (!empty($errors)) {
500 foreach ($this->by_object as $obj) {
501 $obj->dn = $this->dn;
516 foreach ($this->by_object as $key => &$obj) {
517 logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $key,
"Adapting");
518 $obj->parent = &$this;
519 $obj->adapt_from_template($attrs, $skip);
530 $baseobject = $this->getBaseObject();
531 foreach ($config->data[
'TABS'][
'SPECIALTABS'] as $tab) {
536 $this->by_name[$tab[
'CLASS']] = $tab[
'NAME'];
537 $this->plNotify[$tab[
'CLASS']] = FALSE;
538 $this->by_object[$tab[
'CLASS']] =
new $tab[
'CLASS']($this->dn, $baseobject, $this, FALSE);
539 $this->by_object[$tab[
'CLASS']]->set_acl_category($this->acl_category);
548 return $this->getBaseObject()->getAclBase(FALSE);
551 function setTemplateMode ($cn)
553 $this->getBaseObject()->_template_cn = $cn;
555 foreach ($this->by_object as &$obj) {
556 $obj->setTemplate(TRUE);
561 public function setNeedEditMode ($bool)
563 foreach ($this->by_object as &$obj) {
564 $obj->setNeedEditMode($bool);
569 public function setIgnoreAcls ($bool)
571 $this->ignoreAcls = $bool;
574 public function dialogOpened ():
bool 576 return $this->by_object[$this->current]->is_modal_dialog();
579 function objectInfos ()
581 if ($this->objectType === FALSE) {
584 return objects::infos($this->objectType);
588 function getTabOrServiceObject ($tab)
590 if (isset($this->by_object[$tab]) && $this->by_object[$tab]->isActive()) {
591 return $this->by_object[$tab];
592 } elseif (is_subclass_of($tab,
'simpleService') && isset($this->by_object[
'servicesManagement'])) {
593 return $this->by_object[
'servicesManagement']->getServiceObject($tab);
605 protected $specialTabs = FALSE;
renderTabList(bool $disabled=FALSE)
Generate the tab classes.
htmlescape(string $str)
Escape string for HTML output.
This class is made for easy plugin creation for editing LDAP attributes.
render()
This function display the plugin and return the html code.
readOnly()
Indicates if this tab class is read-only (because of locks)
readPost()
Interpret POST content.
This interface should be implemented by all dialog classes in FusionDirectory.
__construct(string $type, $dn, $attrs_object=NULL)
Tabs classes constructor.
This class contains all function to manage tabs classes.
static getPotentialTabList(string $type, array $infos)
Returns the list of tabs which may appear for a given object type.
re_init()
Reinitializes the tab classes with fresh ldap values.
adapt_from_template(array $attrs, array $skip=[])
Adapt from template.
Error returned by any method of SimplePlugin.
save_object()
Save a tabs object.
setActiveTabs(&$tabObject)
Sets the active tabs from this instance to an other one. Used by templates.
For objects which does not support special tabs such as LDAP and references.
static debug(int $level, int $line, string $function, string $file, $data, string $info='')
Debug output method.
Error returned by check method of SimplePlugin.
Parent class for all exceptions thrown in FusionDirectory.
static permDelete($name='')
Display that we have no permission to delete an object.
getAclBase()
Get LDAP base to use for ACL checks.
static duplicated($name, $dn=NULL)
Display error about existing entry in the system.
loadTabs()
Load tab list if needed.
update()
Update state and return FALSE if the dialog was closed.
addSpecialTabs()
Add special Tabs.
plugin_available($plugin)
Check if plugin is available.