class_hooksConfig.inc 3.24 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) 2012-2019 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 hooksConfig extends simplePlugin
{
  static function plInfo (): array
  {
    return [
27 28
      'plShortName'     => _('Triggers'),
      'plTitle'         => _('Triggers configuration'),
29 30 31 32 33 34 35 36 37 38 39 40
      'plPriority'      => 1,
      'plObjectType'    => ['configuration'],

      'plProvidedAcls'  => parent::generatePlProvidedAcls(static::getAttributesInfo())
    ];
  }

  static function getAttributesInfo (): array
  {
    global $config;

    $plugins = [];
41
    if (session::is_set('plist')) {
42
      $plugins = array_keys(session::get('plist')->info);
43 44 45 46
    }
    sort($plugins);

    return [
47 48
      'triggers' => [
        'name'  => _('Triggers'),
49 50 51
        'class' => ['fullwidth'],
        'attrs' => [
          new BooleanAttribute(
52 53
            _('Display trigger output'),
            _('When enabled successful trigger execution output is displayed to the user using a dialog.'),
54 55 56 57
            'fdDisplayHookOutput'
          ),
          new OrderedArrayAttribute(
            new CompositeAttribute(
58
              _('Triggers that are called when specific actions happens'),
59 60 61
              'fdTabHook',
              [
                new SelectAttribute(
62 63
                  _('Tab'), _('The tab that this trigger concerns'),
                  'triggerTab', TRUE,
64 65 66 67
                  $plugins
                ),
                new SelectAttribute(
                  _('Mode'), _('When to call this command'),
68
                  'triggerMode', TRUE,
69 70 71 72 73 74
                  ['postcreate', 'postremove', 'postmodify',
                        'precreate', 'preremove', 'premodify', 'check',
                        'prelock', 'postlock', 'preunlock', 'postunlock']
                ),
                new TextAreaAttribute(
                  _('Command'), _('The command that will be called'),
75
                  'triggerCmd', TRUE
76 77 78 79 80
                )
              ],
              '/^([^\\|]+)\\|([^\\|]+)\\|(.*)$/',
              '%s|%s|%s',
              '', // acl
81
              _('Triggers')
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
            ),
            FALSE, // non-ordered
            [],
            TRUE // edition
          ),
        ]
      ],
    ];
  }

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

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

    $this->attributesAccess['fdTabHook']->setLinearRendering(FALSE);
99 100 101 102 103 104
    $this->attributesAccess['fdTabHook']->setHeaders([
      _('Tab'),
      _('Mode'),
      _('Command'),
      '',
    ]);
105 106
  }
}