Commit 80bf781c authored by Côme Chilliet's avatar Côme Chilliet

Merge branch '6015-add-support-for-supann-cms-carte-multi-service' into '1.4-dev'

Resolve "Add support for SupAnn CMS (Carte Multi Service)"

See merge request fusiondirectory/fd-plugins!688
parents f8601e00 18ea0a06
......@@ -128,6 +128,14 @@ class supannConfig extends simplePlugin
[],
TRUE
),
new SetAttribute(
new StringAttribute(
_('Card sources'), _('Multi service card possible sources, with format system@domain'),
'fdSupannCMSSources', FALSE,
'', '',
'/^.+@.+$/', 'unicampus@univ.example.com'
)
),
]
],
];
......
# Formats
# TECHONOLOGY:ENCODING;label
MIFARE:XLSB;Mifare XLSB
# Nomenclature SupAnn
etudiant;étudiant
personnel;professionnelle
visiteur;visiteur, anonyme
invite;invité, nominative
lecteur;lecteur de bibliothèque
prestataire;prestataire de services
vehicule;véhicule
externe;externe
# Ajouter ici les types locaux étiqueté si besoin
# {ORIGINE}type_local;Type de carte défini localement par l'établissement ORIGINE
......@@ -34,6 +34,12 @@ attributetype ( 1.3.6.1.4.1.38414.17.1.5 NAME 'fdSupannRessourceLabels'
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15)
attributetype ( 1.3.6.1.4.1.38414.17.1.6 NAME 'fdSupannCMSSources'
DESC 'FusionDirectory - SupAnn possible values for supannCMSSource'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15)
# Object Class
objectclass ( 1.3.6.1.4.1.38414.17.2.1 NAME 'fdSupannPluginConf'
DESC 'FusionDirectory SupAnn plugin configuration'
......@@ -41,5 +47,6 @@ objectclass ( 1.3.6.1.4.1.38414.17.2.1 NAME 'fdSupannPluginConf'
MUST ( cn )
MAY (
fdSupannStructuresRDN $ fdSupannPasswordRecovery $
fdSupannRessourceSubStates $ fdSupannRessourceSubStatesLabels $ fdSupannRessourceLabels
fdSupannRessourceSubStates $ fdSupannRessourceSubStatesLabels $ fdSupannRessourceLabels $
fdSupannCMSSources
) )
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 2010-2012 Antoine Gallavardin
Copyright (C) 2013-2020 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 SupannCMSAffectationAttribute extends SupannCompositeAttribute
{
function __construct ($label, $description, $ldapName, $acl = '')
{
global $config;
list($types, $typeLabels) = supann::get_choices_for('cmstype');
list($formats, $formatLabels) = supann::get_choices_for('cmsformat');
$attributes = [
new SelectAttribute(
_('Type'), _('supannCMSType - Card type'),
'supannCMSType_type', TRUE,
$types, '', $typeLabels
),
new SelectAttribute(
_('Format'), _('Card format'),
'none_format', TRUE,
$formats, '', $formatLabels
),
new StringAttribute(
_('Id'), _('Card id'),
'none_id', TRUE
),
new BooleanAttribute(
_('Valid'), _('Card validity'),
'none_valid', TRUE,
TRUE
),
new SelectAttribute(
_('Source'), _('Card managing system and establishment'),
'supannCMSSource_source', FALSE,
$config->get_cfg_value('supannCMSSources', [])
),
new GeneralizedTimeDateAttribute(
_('End date'), _('End of validity date, if any'),
'supannCMSDateFin_datefin', FALSE,
''
),
];
parent::__construct($description, $ldapName, $attributes, $acl, $label);
}
function supannGetValues (&$values)
{
foreach ($this->attributes as &$attribute) {
$shortname = preg_replace('/^([^_]+)_.*$/', '\\1', $attribute->getLdapName());
if ($shortname == 'none') {
continue;
}
$value = $attribute->getValue();
if (!isset($values[$shortname])) {
$values[$shortname] = [];
}
if ($value == '') {
continue;
}
if ($this->attributes[3]->getValue() === TRUE) {
/* Card is valid */
$values[$shortname][$value] = $value;
}
}
unset($attribute);
if ($this->attributes[3]->getValue() === TRUE) {
/* Card is valid */
$format = $this->attributes[1]->getValue();
$id = $this->attributes[2]->getValue();
$supannCMSIdEtiquette = '{'.$format.'}'.$id;
$supannCMSId = 'x-'.strtolower(str_replace(':', '-', $format)).';'.$id;
$values['supannCMSIdEtiquette'][$supannCMSIdEtiquette] = $supannCMSIdEtiquette;
$values['supannCMSId'][$supannCMSId] = $supannCMSId;
} else {
if (!isset($values['supannCMSIdEtiquette'])) {
$values['supannCMSIdEtiquette'] = [];
}
if (!isset($values['supannCMSId'])) {
$values['supannCMSId'] = [];
}
}
}
}
......@@ -55,6 +55,6 @@ class SupannCursusAnneeAttribute extends SupannPrefixedSelectAttribute
protected function supannUpdateSelect ()
{
$prefix = $this->attributes[0]->getValue();
$this->attributes[1]->setChoices($this->prefixedChoices[$prefix][0], $this->prefixedChoices[$prefix][1]);
$this->attributes[1]->setChoices($this->prefixedChoices[$prefix][0] ?? [], $this->prefixedChoices[$prefix][1] ?? []);
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 2019-2020 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 TaggedAttribute extends SetAttribute
{
function __construct (Attribute $attribute, array $values = [], bool $valueUnicity = TRUE)
{
parent::__construct($attribute, $values, $valueUnicity);
}
protected function loadAttrValue (array $attrs)
{
$this->value = [];
$pattern = '/^'.preg_quote($this->getLdapName(), '/').';(.+)$/';
for ($i = 0; $i < $attrs['count']; $i++) {
if ($attrs[$i] == $this->getLdapName()) {
for ($j = 0; $j < $attrs[$attrs[$i]]['count']; $j++) {
$this->value[] = ';'.$attrs[$attrs[$i]][$j];
}
} elseif (preg_match($pattern, $attrs[$i], $m)) {
for ($j = 0; $j < $attrs[$attrs[$i]]['count']; $j++) {
$this->value[] = $m[1].';'.$attrs[$attrs[$i]][$j];
}
}
}
$this->sortValues();
}
function computeLdapValue ()
{
throw new FusionDirectoryException('nope');
}
/*! \brief Fill LDAP value in the attrs array
*/
function fillLdapValue (array &$attrs)
{
if ($this->isInLdap()) {
$initialValues = $this->getInitialValue();
foreach ($initialValues as $value) {
list($tag, $tagvalue) = explode(';', $value, 2);
if (empty($tag)) {
$attrs[$this->getLdapName()] = [];
} else {
$attrs[$this->getLdapName().';'.$tag] = [];
}
}
if (!empty($this->value)) {
foreach ($this->value as $value) {
list($tag, $tagvalue) = explode(';', $value, 2);
if (empty($tag)) {
$attrs[$this->getLdapName()][] = $tagvalue;
} else {
$attrs[$this->getLdapName().';'.$tag][] = $tagvalue;
}
}
}
}
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 2018-2020 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 supannCMS extends simplePlugin
{
protected $displayHeader = TRUE;
static function plInfo (): array
{
return [
'plShortName' => _('Multiservice card'),
'plDescription' => _('SupAnn CMS management'),
'plIcon' => 'geticon.php?context=applications&icon=supann&size=48',
'plSmallIcon' => 'geticon.php?context=applications&icon=supann&size=16',
'plSelfModify' => TRUE,
'plPriority' => 16,
'plObjectClass' => ['supannCMS'],
'plObjectType' => ['user'],
'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo())
];
}
static function getAttributesInfo (): array
{
return [
'status' => [
'name' => _('Cards'),
'class' => ['fullwidth'],
'attrs' => [
new HiddenArrayAttribute('supannCMSType', FALSE, []),
new TaggedAttribute(new StringAttribute('', '', 'supannCMSId', FALSE)),
new HiddenArrayAttribute('supannCMSIdEtiquette', FALSE, []),
new HiddenArrayAttribute('supannCMSSource', FALSE, []),
new HiddenArrayAttribute('supannCMSDateFin', FALSE, []),
new SupannOrderedArrayAttribute(
new SupannCMSAffectationAttribute(
_('Cards'), _('SupAnn CMS Affectation'),
'supannCMSAffectation'
),
// no order
FALSE,
[],
// edit button
TRUE
),
]
],
];
}
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
{
global $config;
parent::__construct($dn, $object, $parent, $mainTab);
$this->attributesAccess['supannCMSId']->setVisible(FALSE);
$this->attributesAccess['supannCMSAffectation']->setLinearRendering(FALSE);
$this->attributesAccess['supannCMSAffectation']->setHeaders([
_('Type'),
_('Format'),
_('Id'),
_('Valid'),
_('Source'),
_('End date'),
''
]);
}
protected function prepare_save (): array
{
$this->attributesAccess['supannCMSAffectation']->supannPrepareSave();
return parent::prepare_save();
}
}
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