class_SupannCMSAffectationAttribute.inc 3.86 KB
Newer Older
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
<?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 = '')
  {
27
    global $config;
28
29
30
31
32
33
34
    $types      = [];
    $typeLabels = [];
    foreach ($config->get_cfg_value('SupannCMSTypes', []) as $supannCMSType) {
      list($type, $label) = explode(';', $supannCMSType);
      $types[]      = $type;
      $typeLabels[] = $label;
    }
35
36
37
38
39
40
41
    $formats      = [];
    $formatLabels = [];
    foreach ($config->get_cfg_value('SupannCMSFormats', ['MIFARE:XLSB;Mifare XLSB']) as $supannCMSFormat) {
      list($format, $label) = explode(';', $supannCMSFormat);
      $formats[]      = $format;
      $formatLabels[] = $label;
    }
42
43
44
    $attributes = [
      new SelectAttribute(
        _('Type'), _('supannCMSType - Card type'),
45
        'supannCMSType_type_'.$ldapName, TRUE,
46
47
48
49
        $types, '', $typeLabels
      ),
      new SelectAttribute(
        _('Format'), _('Card format'),
50
        'none_format_'.$ldapName, TRUE,
51
52
53
54
        $formats, '', $formatLabels
      ),
      new StringAttribute(
        _('Id'), _('Card id'),
55
        'none_id_'.$ldapName, TRUE
56
57
58
      ),
      new BooleanAttribute(
        _('Valid'), _('Card validity'),
59
        'none_valide_'.$ldapName, TRUE,
60
61
        TRUE, '',
        'vrai', 'faux'
62
63
64
      ),
      new SelectAttribute(
        _('Source'), _('Card managing system and establishment'),
65
        'supannCMSSource_source_'.$ldapName, FALSE,
66
        $config->get_cfg_value('supannCMSSources', [])
67
68
69
      ),
      new GeneralizedTimeDateAttribute(
        _('End date'), _('End of validity date, if any'),
70
        'supannCMSDateFin_datefin_'.$ldapName, FALSE,
71
72
73
74
75
76
        ''
      ),
    ];
    parent::__construct($description, $ldapName, $attributes, $acl, $label);
  }

77
78
79
80
81
  protected function isValid (): bool
  {
    return ($this->attributes[3]->getValue() === TRUE);
  }

82
83
84
  function supannGetValues (&$values)
  {
    foreach ($this->attributes as &$attribute) {
85
86
      list($attrname, ) = explode('_', $attribute->getLdapName());
      if ($attrname == 'none') {
87
88
        continue;
      }
89
90
      if (!isset($values[$attrname])) {
        $values[$attrname] = [];
91
      }
92
93
94
95
96
97
98
99
      if (!$this->isTemplate()) {
        $value = $attribute->getValue();
        if ($value == '') {
          continue;
        }
        if ($this->isValid()) {
          $values[$attrname][$value] = $value;
        }
100
      }
101
102
    }
    unset($attribute);
103
    if ($this->isValid() && !$this->isTemplate()) {
104
105
106
107
108
109
110
111
112
113
114
115
116
117
      $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'] = [];
      }
    }
118
119
  }
}