class_subscriptionInfo.inc 4.70 KiB
<?php
/*
  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
  Copyright (C) 2020-2021  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 subscriptionInfo extends simplePlugin
  /* ldap attribute => ini variable */
  public static $subscriptionAttributes = [
    'fdSubscriptionName'        => 'Name',
    'fdSubscriptionType'        => 'Type',
    'fdSubscriptionContractId'  => 'Contract',
    'fdSubscriptionStartDate'   => 'StartDate',
    'fdSubscriptionEndDate'     => 'EndDate',
  public static function plInfo (): array
    return [
      'plShortName'   => _('Subscription'),
      'plTitle'       => _('Subscription information'),
      'plDescription' => _('Information about your FusionDirectory subscription'),
      'plIcon'        => 'geticon.php?context=applications&icon=fusiondirectory&size=48',
      'plObjectClass' => ['fdSubscriptionInformation'],
      'plObjectType'  => [
        'subscriptionInfo' => [
          'name'      => _('Subscription information'),
      'plSection'     => 'conf',
      'plPriority'    => 1,
      'plProvidedAcls'  => parent::generatePlProvidedAcls(static::getAttributesInfo()),
  public static function getAttributesInfo (): array
    return [
      'stats' => [
        'name'  => _('Subscription information'),
        'attrs' => [
          new HiddenAttribute(
            'cn', TRUE, 'subscription'
          new DisplayLDAPAttribute(
            _('Name'), _('Subscription name'),
            'fdSubscriptionName', TRUE
          new DisplayLDAPAttribute(
            _('Type'), _('Subscription type'),
            'fdSubscriptionType', TRUE
          new DisplayLDAPAttribute(
            _('Contract'), _('Contract reference'),
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
'fdSubscriptionContractId', TRUE ), new GeneralizedTimeDisplayAttribute( _('Start date'), _('Start date of this subscription'), 'fdSubscriptionStartDate', TRUE, '' ), new GeneralizedTimeDisplayAttribute( _('End date'), _('End date of this subscription'), 'fdSubscriptionEndDate', TRUE, '' ), new FileAttribute( _('Import'), _('Import subscription'), 'import_file', FALSE ), new ButtonAttribute( '', '', 'import', _('Import'), NULL, '', 'import_file' ), ], ], ]; } public function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE) { parent::__construct($dn, $object, $parent, $mainTab); $this->attributesAccess['import_file']->setInLdap(FALSE); $this->attributesAccess['import']->setInLdap(FALSE); } public function handle_import () { $data = $this->import_file; if (empty($data)) { /* No file or empty file */ $error = new SimplePluginError( $this->attributesAccess['import_file'], htmlescape(_('No data. Did you forgot to upload a file?')) ); $error->display(); } elseif (($data = parse_ini_string($data)) === FALSE) { /* Import of INI failed */ $error = new SimplePluginError( $this->attributesAccess['import_file'], htmlescape(_('Failed to parse imported file')) ); $error->display(); } else { /* Import data and save it to the LDAP */ foreach (static::$subscriptionAttributes as $attr => $iniVar) { $this->attributesAccess[$attr]->setValue($data[$iniVar] ?? ''); } $errors = $this->parent->save(); msg_dialog::displayChecks($errors); } /* Avoid double import */ $this->import_file = ''; } public static function mainInc ($classname = NULL, $entry_dn = NULL, $tabs = FALSE, $edit_mode = FALSE, $objectType = FALSE) { global $config; if ($entry_dn === NULL) {
141142143144145146147
$entry_dn = 'cn=subscription,'.get_ou('fusiondirectoryRDN').$config->current['BASE']; } parent::mainInc($classname, $entry_dn, $tabs, $edit_mode, $objectType); } }