class_supannConfig.inc 5.69 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

  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
    );
  }
168
}