Unverified Commit 95ce0118 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:sparkles: feat(core) Add subscription page

issue #6152
Showing with 135 additions and 0 deletions
+135 -0
<?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
{
public static $subscriptionAttributes = ['fdSubscriptionType', 'fdSubscriptionContractId', 'fdSubscriptionStartDate', 'fdSubscriptionEndDate'];
public static function plInfo (): array
{
return [
'plShortName' => _('Subscription'),
'plTitle' => _('Subscription information'),
'plDescription' => _('Information about your subscription to FusionDirectory, if any'),
'plIcon' => 'geticon.php?context=applications&icon=fusiondirectory&size=48',
'plObjectClass' => ['fdSubscriptionInfo'],
'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(
_('Type'), _('Subscription type'),
'fdSubscriptionType', TRUE
),
new DisplayLDAPAttribute(
_('Contract'), _('Contract identifier from Dolibarr'),
'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) {
$this->attributesAccess[$attr]->setValue($data[$attr] ?? '');
}
$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) {
$entry_dn = 'cn=subscription,'.get_ou('fusiondirectoryRDN').$config->current['BASE'];
}
parent::mainInc($classname, $entry_dn, $tabs, $edit_mode, $objectType);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment