1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003 Cajus Pollmeier
Copyright (C) 2011-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.
*/
class department extends simplePlugin
{
static $namingAttr = 'ou';
/* Do not append the structural object classes here, they are added dynamically in the constructor */
var $objectclasses = array("top", "gosaDepartment");
var $structuralOC = array("organizationalUnit");
static function plInfo()
{
return array(
'plShortName' => _('Department'),
'plDescription' => _('Departments'),
'plCategory' => array('department' => array('objectClass' => 'gosaDepartment', 'description' => _('Departments'))),
'plObjectType' =>
array(
'department' => array(
'name' => _('Department'),
'filter' => '(&(objectClass=organizationalUnit)(objectClass=gosaDepartment))',
'ou' => '',
'icon' => 'geticon.php?context=places&icon=folder&size=16',
'tabClass' => 'deptabs',
'mainAttr' => static::$namingAttr,
)
),
'plForeignKeys' => array(
'manager' => 'user'
),
'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo())
);
}
static function getAttributesInfo()
{
return static::getDepartmentAttributesInfo(_('department'));
}
static function getDepartmentAttributesInfo($name)
{
$attributesInfo = array(
'properties' => array(
'name' => _('Properties'),
'attrs' => array(
new BaseSelectorAttribute(''),
new StringAttribute(
sprintf(_('Name of %s'), $name), sprintf(_('A name for this %s'), $name),
static::$namingAttr, TRUE,
'', '', '/^[a-z0-9\._-]+$/i'
),
new TextAreaAttribute(
_('Description'), sprintf(_('Short description of this %s'), $name),
'description', TRUE
),
new SelectAttribute(
_('Category'), sprintf(_('Category of this %s'), $name),
'businessCategory', FALSE
),
new StringAttribute(
_('Website'), sprintf(_('Website of this %s'), $name),
'labeledURI', FALSE
),
new UserAttribute(
_('Manager'), sprintf(_('Manager of this %s'), $name),
'manager', FALSE
)
)
),
'location' => array(
'name' => _('Location'),
'attrs' => array(
new StringAttribute(
_('State'), _('State'), 'st', FALSE
),
new StringAttribute(
_('Location'), _('Location'), 'l', FALSE
),
new StringAttribute(
_('Country'), _('Country'), 'co', FALSE
),
new PostalAddressAttribute(
_('Address'), sprintf(_('A postal address for this %s'), $name),
'postalAddress', FALSE
),
new PhoneNumberAttribute(
_('Phone'), _('Telephone number'),
'telephoneNumber', FALSE
),
new PhoneNumberAttribute(
_('Fax'), _('Facsimile telephone number'),
'facsimileTelephoneNumber', FALSE
),
)
),
);
if (static::$namingAttr != 'ou') {
$attributesInfo['properties']['attrs'][] = new HiddenAttribute('ou');
}
return $attributesInfo;
}
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
{
global $config;
/* Add the default structural object class if this is a new entry */
$ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']);
if ($dn == "" || $dn == "new" || !$ldap->dn_exists($dn)) {
$this->objectclasses = array_merge($this->structuralOC, $this->objectclasses);
} else {
$ldap->cat($dn, array("structuralObjectClass"));
$attrs = $ldap->fetch();
if (isset($attrs['structuralObjectClass']['count'])) {
for ($i = 0; $i < $attrs['structuralObjectClass']['count']; $i++) {
$this->objectclasses[] = $attrs['structuralObjectClass'][$i];
}
} else {
/* Could not detect structural object class for this object, fall back to the default
*/
$this->objectclasses = array_merge($this->structuralOC, $this->objectclasses);
}
}
$this->objectclasses = array_unique($this->objectclasses);
parent::__construct($dn, $object, $parent, $mainTab);
$categoriesList = $config->get_cfg_value('DepartmentCategories', array());
/* Insert current value to possibilities */
if (isset($this->attributesAccess['businessCategory'])) {
$businessCategory = $this->attributesAccess['businessCategory']->getValue();
if (($businessCategory != "") && !in_array($businessCategory, $categoriesList)) {
$categoriesList[] = $businessCategory;
}
$this->attributesAccess['businessCategory']->setChoices($categoriesList);
}
$this->attributesAccess[static::$namingAttr]->setUnique(TRUE);
}
/* Check values */
function check()
{
/* Call common method to give check the hook */
$message = parent::check();
$namingAttr = static::$namingAttr;
if (tests::is_department_name_reserved($this->$namingAttr, $this->base)) {
$message[] = msgPool::reserved(_("Name"));
}
return $message;
}
function get_allowed_bases()
{
/* Hide all departments, that are subtrees of this department */
$bases = parent::get_allowed_bases();
if (($this->dn != "new") && ($this->dn != "")) {
foreach (array_keys($bases) as $dn) {
if (preg_match("/".preg_quote($this->dn)."/", $dn)) {
unset($bases[$dn]);
}
}
}
return $bases;
}
function prepare_save()
{
if (static::$namingAttr != 'ou') {
$this->attributesAccess['ou']->setValue($this->attributesAccess[static::$namingAttr]->getValue());
}
return parent::prepare_save();
}
}
/* Hide base selector, if this object represents the base itself
$smarty->assign("is_root_dse", FALSE);
if ($this->dn == $config->current['BASE']) {
$smarty->assign("is_root_dse", TRUE);
$nA = $this->namingAttr."ACL";
$smarty->assign($nA, $this->getacl($this->namingAttr, TRUE));
}*/
?>
|