class_supannConfig.inc 7.65 KB
Newer Older
1
2
3
<?php
/*
  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4
5

  Copyright (C) 2013-2019 FusionDirectory
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

  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 supannConfig extends simplePlugin
{
24
25
  protected $officialSubstates;

26
  static function plInfo (): array
27
  {
28
    return [
29
30
      'plShortName'     => _('SupAnn'),
      'plTitle'         => _('SupAnn configuration'),
31
      'plDescription'   => _('FusionDirectory SupAnn plugin configuration'),
32
      'plObjectClass'   => ['fdSupannPluginConf'],
33
      'plPriority'      => 10,
34
      'plObjectType'    => ['configuration'],
35

36
      'plProvidedAcls'  => parent::generatePlProvidedAcls(static::getAttributesInfo())
37
    ];
38
39
  }

40
  static function getAttributesInfo (): array
41
  {
42
43
44
45
46
47
48
    $officialStates = supannAccountStatus::getOfficialSubstates();
    $defaultStates  = [];
    foreach ($officialStates as $state => $substates) {
      foreach (array_keys($substates) as $substate) {
        $defaultStates[] = $state.':'.$substate;
      }
    }
49
50
    return [
      'main' => [
51
        'name'  => _('SupAnn'),
52
        'class' => ['fullwidth'],
53
        'attrs' => [
54
          new StringAttribute(
55
            _('SupAnn RDN'), _('Branch in which SupAnn structures will be stored'),
56
57
58
            'fdSupannStructuresRDN', TRUE,
            'ou=structures'
          ),
59
          new BooleanAttribute(
60
            _('SupAnn mail for recovery'), _('Allow the use of mail addresses from the personal mail address field from SupAnn account for password recovery'),
61
62
63
            'fdSupannPasswordRecovery', FALSE,
            TRUE
          ),
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
          new OrderedArrayAttribute(
            new CharSeparatedCompositeAttribute(
              _('Custom resources and their labels'),
              'fdSupannRessourceLabels',
              [
                new StringAttribute(
                  _('Resource'), _('String that will be stored between {} in supannRessourceEtatDate'),
                  'fdSupannRessourceLabels_resource', TRUE
                ),
                new StringAttribute(
                  _('Label'), _('Label shown for this resource'),
                  'fdSupannRessourceLabels_label', TRUE
                ),
              ],
              ':',
              '',
              _('Custom resources')
            ),
            FALSE,
            [],
            TRUE
          ),
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
          new OrderedArrayAttribute(
            new CharSeparatedCompositeAttribute(
              _('Allowed substates for an account'),
              'fdSupannRessourceSubStates',
              [
                new SelectAttribute(
                  _('Status'), _('Active status this substatus is tied to'),
                  'fdSupannRessourceSubStates_status', TRUE,
                  ['A','I','S'], 'A',
                  [_('Active'), _('Inactive'), _('Suspended')]
                ),
                new StringAttribute(
                  _('Substatus'), _('LDAP value for this substatus'),
                  'fdSupannRessourceSubStates_substatus', TRUE
                ),
              ],
              ':',
              '',
              _('Substates')
            ),
            TRUE,
            $defaultStates
          ),
          new OrderedArrayAttribute(
            new CharSeparatedCompositeAttribute(
              _('Labels for custom substates'),
              'fdSupannRessourceSubStatesLabels',
              [
                new SelectAttribute(
                  _('Substatus'), _('LDAP value for this substatus'),
                  'fdSupannRessourceSubStatesLabels_substatus', TRUE
                ),
                new StringAttribute(
                  _('Label'), _('Label shown for this substatus'),
                  'fdSupannRessourceSubStatesLabels_label', TRUE
                ),
              ],
              ':',
              '',
              _('Custom labels')
            ),
            FALSE,
            [],
            TRUE
          ),
131
132
133
134
135
136
137
138
          new SetAttribute(
            new StringAttribute(
              _('Card sources'), _('Multi service card possible sources, with format system@domain'),
              'fdSupannCMSSources', FALSE,
              '', '',
              '/^.+@.+$/', 'unicampus@univ.example.com'
            )
          ),
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
          new OrderedArrayAttribute(
            new CompositeAttribute(
              _('Allowed formats for multiservice cards'),
              'fdSupannCMSFormats',
              [
                new StringAttribute(
                  _('Technology'), _('Technology name in uppercase'),
                  'fdSupannCMSFormats_techno', TRUE,
                  '', '',
                  '/^[A-Z]+$/', 'MIFARE'
                ),
                new StringAttribute(
                  _('Encoding'), _('Encoding name in uppercase'),
                  'fdSupannCMSFormats_encoding', TRUE,
                  '', '',
                  '/^[A-Z]+$/', 'XLSB'
                ),
                new StringAttribute(
                  _('Label'), _('Format label'),
                  'fdSupannCMSFormats_label', TRUE,
                  '', '',
                  '', 'Mifare XLSB'
                ),
              ],
              '/^([A-Z]*):([A-Z]*);(.*)$/',
              '%s:%s;%s',
              '',
              _('Card formats')
            ),
            FALSE,
            ['MIFARE:XLSB;Mifare XLSB'],
            TRUE
          ),
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
          new OrderedArrayAttribute(
            new CharSeparatedCompositeAttribute(
              _('Domains for card applications'),
              'fdSupannCMSAppDomains',
              [
                new StringAttribute(
                  _('Option'), _('Attribute option to use, starting with x-'),
                  'fdSupannCMSAppDomains_option', TRUE,
                  '', '',
                  '/^x-.+$/', 'x-biblio-xlsb'
                ),
                new StringAttribute(
                  _('Domain'), _('Domain to use'),
                  'fdSupannCMSAppDomains_domain', TRUE,
                  '', '',
                  '', 'xlsb.biblio.univ.example.com'
                ),
              ],
              ';',
              '',
              _('Card application domains')
            ),
            FALSE,
            [],
            TRUE
          ),
198
199
200
        ]
      ],
    ];
201
  }
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226

  function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
  {
    global $config;

    parent::__construct($dn, $object, $parent, $mainTab);

    $this->attributesAccess['fdSupannRessourceSubStates']->setSubmitForm('updateFieldsChoices');
    $this->officialSubstates = array_merge(...array_values(array_map('array_keys', supannAccountStatus::getOfficialSubstates())));
    $this->updateFieldsChoices();
  }

  function updateFieldsChoices ()
  {
    $substateChoices = [];
    foreach ($this->fdSupannRessourceSubStates as $line) {
      list($state, $substate) = explode(':', $line, 2);
      if (!in_array($substate, $this->officialSubstates)) {
        $substateChoices[] = $substate;
      }
    }
    $this->attributesAccess['fdSupannRessourceSubStatesLabels']->attribute->attributes[0]->setChoices(
      $substateChoices
    );
  }
227
}