An error occurred while loading the file. Please try again.
-
Côme Chilliet authored
Instead of less readable func_get_args and call_user_func_array issue #5827
7e884f43
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2014-2016 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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*!
* \file class_template.inc
* Source code for the class template
*/
/*! \brief Class for applying a template */
class template
{
protected $type;
protected $dn;
protected $needed;
protected $attrs;
protected $tabObject;
protected $attributes;
protected $applied = FALSE;
static protected $uiSpecialAttributes = array('dn','cn','uid','sn','givenName');
static function plInfo()
{
return array(
'plShortName' => _('Template'),
'plDescription' => _('Object template, used to create several objects with similar values'),
/* Categories for templates are computed in config class */
'plCategory' => array(),
'plProvidedAcls' => array(
'template_cn' => _('Template name')
)
);
}
static function getTemplatedTypes()
{
$result = array();
$types = objects::types();
foreach ($types as $type) {
if (in_array($type, departmentManagement::getDepartmentTypes())) {
continue;
}
$infos = objects::infos($type);
if ($infos['templateActive']) {
$result[$type] = $infos['name'];
}
}
asort($result);
return $result;
}
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
function __construct($type, $dn, $targetdn = NULL)
{
$this->type = $type;
$this->dn = $dn;
list($this->attrs, $depends) = templateHandling::fetch($this->dn);
$this->needed = templateHandling::neededAttrs($this->attrs, $depends);
$this->needed[] = 'base';
if ($targetdn === NULL) {
$this->tabObject = objects::create($this->type);
} else {
trigger_error("This should not be used for now");
$this->tabObject = objects::open($this->dn, $this->type);
}
$tempTabObject = objects::open($this->dn, $this->type); /* Used to know which tab is activated */
$this->attributes = array();
$tempTabObject->setActiveTabs($this->tabObject);
foreach ($this->tabObject->by_object as $class => $tab) {
if ($tab->is_account || $tab->ignore_account) {
$this->attributes[$class] = array();
$attrs = array_unique(array_merge($tab->getRequiredAttributes(), $this->needed));
foreach (array_keys($tab->attributesAccess) as $attr) {
if (!$tab->showInTemplate($attr, $this->attrs)) {
continue;
}
if (in_array($attr, $attrs)) {
$this->attributes[$class][] = $attr;
}
}
}
}
}
/*! \brief Used when you need to re-apply the same template with different values */
function reset()
{
list($this->attrs, $depends) = templateHandling::fetch($this->dn);
// This is needed because it removes %askme% values from attrs
$this->needed = templateHandling::neededAttrs($this->attrs, $depends);
$this->needed[] = 'base';
$this->tabObject = objects::create($this->type);
/* Used to know which tab is activated */
$tempTabObject = objects::open($this->dn, $this->type);
foreach ($tempTabObject->by_object as $class => $plugin) {
if ($plugin->is_account || $plugin->ignore_account) {
$this->tabObject->by_object[$class]->is_account = $plugin->is_account;
}
}
$this->applied = FALSE;
}
function getDn()
{
return $this->dn;
}
function getBase()
{
if (is_object($this->tabObject)) {
return $this->tabObject->getBaseObject()->base;
} else {
$infos = objects::infos($this->type);
return dn2base($this->dn, 'ou=templates,'.$infos['ou']);
}
}
function getNeeded()
{
return $this->attributes;
}