Commit 75d1e695 authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes #3247 Using objects::open in simpleManagement, added a generic compute_dn

parent ed260777
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2013 FusionDirectory
Copyright (C) 2013-2014 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -244,35 +244,95 @@ class simpleManagement extends management
return parent::renderList();
}
// Overridden new handler - We've different types of departments to create!
function newEntry($action = '', $target = array(), $all = array(), $altTabClass = '',
$altTabType = '', $altAclCategory = '')
/*!
* \brief This method intiates the object creation.
*
* \param String $action The name of the action which was the used as trigger.
*
* \param Array $target A list of object dns, which should be affected by this method.
*
* \param Array $all A combination of both 'action' and 'target'.
*
* \param String $altTabClass Empty string.
*
* \param String $altTabType Empty string.
*
* \param String $altAclCategory Empty string.
*/
function newEntry($action = "", $target = array(), $all = array(), $altTabClass = "", $altTabType = "", $altAclCategory = "")
{
$type = strtoupper(preg_replace('/^new_/', '', $action));
$infos = $this->config->data['OBJECTS'][$type];
return management::newEntry($action, $target, $all, $infos['tabClass'],
$infos['tabGroup'], $infos['aclCategory']);
$this->displayApplyBtn = FALSE;
$this->dn = 'new';
$this->is_new = TRUE;
$this->is_single_edit = FALSE;
set_object_info($this->dn);
// Open object
$this->tabObject = objects::open($this->dn, $type);
$this->tabObject->set_acl_base($this->headpage->getBase());
$this->tabObject->parent = &$this;
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dn, "Create new entry initiated!");
}
function editEntry( $action = '', $target = array(), $all = array(), $altTabClass = '',
$altTabType = '', $altAclCategory = '')
/*!
* \brief This method opens an existing object or a list of existing objects to be edited.
*
* \param String $action The name of the action which was the used as trigger.
*
* \param Array $target A list of object dns, which should be affected by this method.
*
* \param Array $all A combination of both 'action' and 'target'.
*
* \param String $altTabClass Empty string.
*
* \param String $altTabType Empty string.
*
* \param String $altAclCategory Empty string.
*/
function editEntry($action = "", $target = array(), $all = array(), $altTabClass = "", $altTabType = "", $altAclCategory = "")
{
$type = $this->getType($target[0]);
$infos = $this->config->data['OBJECTS'][$type];
$str = management::editEntry($action, $target, $all, $infos['tabClass'],
$infos['tabGroup'], $infos['aclCategory']);
if (isset($all['subaction'])) {
$tab = preg_replace('/^tab_/', '', $all['subaction']);
if (isset($this->tabObject->by_object[$tab])) {
$this->tabObject->current = $tab;
} else {
trigger_error('Unknown tab: '.$tab);
}
// Do not create a new tabObject while there is already one opened,
// the user may have just pressed F5 to reload the page.
if (is_object($this->tabObject)) {
return;
}
if (!empty($str)) {
return $str;
$this->displayApplyBtn = (count($target) == 1);
// Single edit - we only got one object dn.
if (count($target) == 1) {
$type = $this->getType($target[0]);
$this->is_new = FALSE;
$this->is_single_edit = TRUE;
// Get the dn of the object and creates lock
$this->dn = array_pop($target);
set_object_info($this->dn);
$user = get_lock($this->dn);
if ($user != "") {
return gen_locked_message($user, $this->dn, TRUE);
}
add_lock ($this->dn, $this->ui->dn);
// Open object
$this->tabObject = objects::open($this->dn, $type);
$this->tabObject->set_acl_base($this->dn);
$this->tabObject->parent = &$this;
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dn, "Edit entry initiated!");
if (isset($all['subaction'])) {
$tab = preg_replace('/^tab_/', '', $all['subaction']);
if (isset($this->tabObject->by_object[$tab])) {
$this->tabObject->current = $tab;
} else {
trigger_error('Unknown tab: '.$tab);
}
}
}
}
......
......@@ -220,6 +220,25 @@ class simplePlugin extends plugin
return isset($this->attributesAccess[$name]);
}
/*! \brief This function returns the dn this object should have
*/
public function compute_dn()
{
if (!$this->mainTab) {
die('Only main tab can compute dn');
}
if (!isset($this->parent) || !($this->parent instanceof simpleTabs)) {
die('Could not compute dn: no parent tab class');
}
$infos = $this->parent->objectInfos();
if ($infos === FALSE) {
die('Could not compute dn: cloud not find objectType infos from tab class');
}
$attr = $infos['mainAttr'];
$ou = $infos['ou'];
return $attr.'='.$this->attributesAccess[$attr]->computeLdapValue().','.$ou.$this->base;
}
/*! \brief This function update the values of LDAP attributes as class attribute,
so that plugin code works correctly
......
......@@ -26,7 +26,8 @@
* */
class simpleTabs extends tabs
{
protected $specialTabs = TRUE;
public $objectType = FALSE;
protected $specialTabs = TRUE;
/*
* You should either call __construct($type, $dn, [$copied_object]) or __construct($config, $data, $dn, $category, [$copied_object])
......@@ -38,7 +39,7 @@ class simpleTabs extends tabs
if (is_string(func_get_arg(0))) {
$type = func_get_arg(0);
$dn = func_get_arg(1);
$infos = objects::infos($type);
$infos = objects::infos($type);
$config_object = $config;
$data = $config->data['TABS'][$infos['tabGroup']];
......@@ -46,6 +47,7 @@ class simpleTabs extends tabs
if (func_num_args() >= 3) {
$copied_object = func_get_arg(2);
}
$this->objectType = $type;
} else {
$config_object = func_get_arg(0);
$data = func_get_arg(1);
......@@ -82,6 +84,14 @@ class simpleTabs extends tabs
return parent::save();
}
function objectInfos()
{
if ($this->objectType === FALSE) {
return FALSE;
}
return objects::infos($this->objectType);
}
}
class simpleTabs_noSpecial extends simpleTabs
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment