An error occurred while loading the file. Please try again.
-
Côme Chilliet authored
This avoids problems with templates not behaving like LDAP data. I tried to use the option in all cases where the array is stored for futur use, and of course especially for simplePlugin. issue #6080
Unverified00122031
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
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.
*/
/*!
* \file class_templateHandling.inc
* Source code for the class templateHandling
*/
/*! \brief this class stores static methods used to parse templates LDAP data
*/
class templateHandling
{
/*! \brief Fetch a template from LDAP and returns its attributes and dependencies information */
public static function fetch ($dn)
{
global $config;
$ldap = $config->get_ldap_link();
$ldap->cat($dn);
$attrs = $ldap->fetch(TRUE);
$attrs = static::fieldsFromLDAP($attrs);
list($depends, $errors) = static::attributesDependencies($attrs);
msg_dialog::displayChecks($errors);
$attrs = static::sortAttributes($attrs, $depends);
return [$attrs, $depends];
}
/*! \brief Translate template attrs into $attrs as if taken from LDAP */
public static function fieldsFromLDAP (array $template_attrs)
{
$attrs = [];
if (isset($template_attrs['fdTemplateField'])) {
unset($template_attrs['fdTemplateField']['count']);
sort($template_attrs['fdTemplateField']);
foreach ($template_attrs['fdTemplateField'] as $field) {
if (!preg_match('/^([^:]+):(.*)$/s', $field, $m)) {
throw new FusionDirectoryException('Template field does not match format');
}
if (isset($attrs[$m[1]])) {
$attrs[$m[1]][] = $m[2];
$attrs[$m[1]]['count']++;
} else {
$attrs[$m[1]] = [$m[2]];
$attrs[$m[1]]['count'] = 1;
}
}
}
return $attrs;
}
/*! \brief Translate $attrs into template attrs */
public static function fieldsToLDAP (array $template_attrs, array $attrs)
{