init III
This commit is contained in:
539
Perl OTRS/Kernel/System/SysConfig/Base/Framework.pm
Normal file
539
Perl OTRS/Kernel/System/SysConfig/Base/Framework.pm
Normal file
@@ -0,0 +1,539 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::Base::Framework;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Main',
|
||||
'Kernel::System::Storable',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::Base::Framework - Base class for system configuration.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 SettingModifiedXMLContentParsedGet()
|
||||
|
||||
Returns perl structure for modified setting.
|
||||
|
||||
my $Result = $SysConfigObject->SettingModifiedXMLContentParsedGet(
|
||||
ModifiedSetting => {
|
||||
EffectiveValue => 'Scalar value updated'
|
||||
},
|
||||
DefaultSetting => {
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => "Scalar value",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Result = [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => "Scalar value updated",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingModifiedXMLContentParsedGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(DefaultSetting ModifiedSetting)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $Result = $Param{DefaultSetting}->{XMLContentParsed};
|
||||
|
||||
$Result = $Self->_ModifiedValueCalculate(
|
||||
Value => $Result->{Value},
|
||||
EffectiveValue => $Param{ModifiedSetting}->{EffectiveValue},
|
||||
);
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
=head1 PRIVATE INTERFACE
|
||||
|
||||
=head2 _ModifiedValueCalculate()
|
||||
|
||||
Recursive helper for SettingModifiedXMLContentParsedGet().
|
||||
|
||||
my $Result = $SysConfigObject->_ModifiedValueCalculate(
|
||||
'EffectiveValue' => 'Scalar value updated', # (optional) new effective value
|
||||
'Value' => [ # (required) the XMLContentParsed value from Defaults
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => 'Scalar value',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Result = [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => 'Scalar value updated'
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
=cut
|
||||
|
||||
sub _ModifiedValueCalculate {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(Value)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Objects;
|
||||
if ( $Param{Objects} ) {
|
||||
%Objects = %{ $Param{Objects} };
|
||||
}
|
||||
|
||||
my @SkipParameters = (
|
||||
'Hash',
|
||||
'Array',
|
||||
'Item',
|
||||
'Content',
|
||||
'Key',
|
||||
);
|
||||
|
||||
my $Result;
|
||||
|
||||
my $ValueType;
|
||||
|
||||
# Check if additional parameters are provided.
|
||||
if ( IsHashRefWithData( $Param{Parameters} ) && $Param{Value}->[0]->{Item} ) {
|
||||
for my $Parameter ( sort keys %{ $Param{Parameters} } ) {
|
||||
$Result->[0]->{Item}->[0]->{$Parameter} = $Param{Parameters}->{$Parameter};
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
$Param{Value}->[0]->{Item}
|
||||
&& $Param{Value}->[0]->{Item}->[0]->{ValueType}
|
||||
)
|
||||
{
|
||||
$ValueType = $Param{Value}->[0]->{Item}->[0]->{ValueType};
|
||||
}
|
||||
if ( $Param{ValueType} ) {
|
||||
$ValueType = $Param{ValueType};
|
||||
}
|
||||
|
||||
if ($ValueType) {
|
||||
|
||||
if ( !$Objects{$ValueType} ) {
|
||||
|
||||
# Make sure the ValueType backed is present and is syntactically correct.
|
||||
my $Loaded = $Kernel::OM->Get('Kernel::System::Main')->Require(
|
||||
"Kernel::System::SysConfig::ValueType::$ValueType",
|
||||
);
|
||||
|
||||
return $Result if !$Loaded;
|
||||
|
||||
# Create object instance.
|
||||
$Objects{$ValueType} = $Kernel::OM->Get(
|
||||
"Kernel::System::SysConfig::ValueType::$ValueType",
|
||||
);
|
||||
}
|
||||
|
||||
$Result = $Objects{$ValueType}->ModifiedValueGet(%Param);
|
||||
|
||||
# Get all additional parameters (defined as attributes in XML).
|
||||
if ( IsHashRefWithData( $Param{Value}->[0]->{Item}->[0] ) ) {
|
||||
PARAMETER:
|
||||
for my $Parameter ( sort keys %{ $Param{Value}->[0]->{Item}->[0] } ) {
|
||||
next PARAMETER if grep { $_ eq $Parameter } @SkipParameters;
|
||||
|
||||
# Skip already defined values.
|
||||
next PARAMETER if $Result->[0]->{Item}->[0]->{$Parameter};
|
||||
|
||||
$Result->[0]->{Item}->[0]->{$Parameter} =
|
||||
$Param{Value}->[0]->{Item}->[0]->{$Parameter};
|
||||
}
|
||||
}
|
||||
}
|
||||
elsif ( ref $Param{EffectiveValue} eq 'ARRAY' ) {
|
||||
|
||||
# Create basic structure.
|
||||
$Result = [
|
||||
{
|
||||
'Array' => [
|
||||
{
|
||||
'Item' => [],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
my $DefaultItem = $Param{Value}->[0]->{Array}->[0]->{DefaultItem};
|
||||
|
||||
if ( $Param{Value}->[0]->{Array}->[0]->{MinItems} ) {
|
||||
$Result->[0]->{Array}->[0]->{MinItems} = $Param{Value}->[0]->{Array}->[0]->{MinItems};
|
||||
}
|
||||
|
||||
if ( $Param{Value}->[0]->{Array}->[0]->{MaxItems} ) {
|
||||
$Result->[0]->{Array}->[0]->{MaxItems} = $Param{Value}->[0]->{Array}->[0]->{MaxItems};
|
||||
}
|
||||
|
||||
my %Attributes;
|
||||
|
||||
if (
|
||||
$DefaultItem
|
||||
&& ref $DefaultItem eq 'ARRAY'
|
||||
&& scalar @{$DefaultItem}
|
||||
&& ref $DefaultItem->[0] eq 'HASH'
|
||||
)
|
||||
{
|
||||
# Get additional attributes
|
||||
ATTRIBUTE:
|
||||
for my $Attribute ( sort keys %{ $DefaultItem->[0] } ) {
|
||||
next ATTRIBUTE if grep { $Attribute eq $_ } qw(Hash Array Item Content);
|
||||
|
||||
$Attributes{$Attribute} = $DefaultItem->[0]->{$Attribute};
|
||||
}
|
||||
}
|
||||
|
||||
for my $Index ( 0 .. scalar @{ $Param{EffectiveValue} } - 1 ) {
|
||||
|
||||
if (
|
||||
$DefaultItem
|
||||
&& $DefaultItem->[0]->{ValueType}
|
||||
&& $Param{Value}->[0]->{Array}->[0]->{Item}
|
||||
)
|
||||
{
|
||||
|
||||
# It's Item with defined ValueType.
|
||||
|
||||
my $ItemData = $Kernel::OM->Get('Kernel::System::Storable')->Clone(
|
||||
Data => $DefaultItem,
|
||||
);
|
||||
|
||||
my $Value = $Self->_ModifiedValueCalculate(
|
||||
Value => [
|
||||
{
|
||||
Item => $ItemData,
|
||||
},
|
||||
],
|
||||
EffectiveValue => $Param{EffectiveValue}->[$Index],
|
||||
ValueType => $Param{Value}->[0]->{Array}->[0]->{ValueType},
|
||||
Objects => \%Objects,
|
||||
);
|
||||
|
||||
push @{ $Result->[0]->{Array}->[0]->{Item} }, $Value->[0];
|
||||
}
|
||||
elsif (
|
||||
$DefaultItem
|
||||
&& ( $DefaultItem->[0]->{Array} || $DefaultItem->[0]->{Hash} )
|
||||
)
|
||||
{
|
||||
# It's complex structure (AoA or AoH), continue recursion.
|
||||
my $StructureType = $DefaultItem->[0]->{Array} ? 'Array' : 'Hash';
|
||||
|
||||
$Param{Value}->[0]->{Array}->[0]->{Item}->[0]->{$StructureType}->[0]->{DefaultItem} =
|
||||
$DefaultItem->[0]->{$StructureType}->[0]->{DefaultItem};
|
||||
|
||||
my $Value = $Self->_ModifiedValueCalculate(
|
||||
Value => $Param{Value}->[0]->{Array}->[0]->{Item},
|
||||
EffectiveValue => $Param{EffectiveValue}->[$Index],
|
||||
Objects => \%Objects,
|
||||
);
|
||||
|
||||
push @{ $Result->[0]->{Array}->[0]->{Item} }, $Value->[0];
|
||||
}
|
||||
else {
|
||||
|
||||
if ( IsArrayRefWithData( $Param{EffectiveValue}->[$Index] ) ) {
|
||||
for my $ArrayItem ( @{ $Param{EffectiveValue}->[$Index] } ) {
|
||||
push @{ $Result->[0]->{Array}->[0]->{Item} }, {
|
||||
%Attributes,
|
||||
Content => $ArrayItem,
|
||||
};
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
# This is a string value.
|
||||
push @{ $Result->[0]->{Array}->[0]->{Item} }, {
|
||||
%Attributes,
|
||||
Content => $Param{EffectiveValue}->[$Index],
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elsif ( ref $Param{EffectiveValue} eq 'HASH' ) {
|
||||
|
||||
# Create basic structure.
|
||||
$Result = [
|
||||
{
|
||||
'Hash' => [
|
||||
{
|
||||
'Item' => [],
|
||||
},
|
||||
],
|
||||
}
|
||||
];
|
||||
|
||||
if ( $Param{Value}->[0]->{Hash}->[0]->{MinItems} ) {
|
||||
$Result->[0]->{Hash}->[0]->{MinItems} = $Param{Value}->[0]->{Hash}->[0]->{MinItems};
|
||||
}
|
||||
|
||||
if ( $Param{Value}->[0]->{Hash}->[0]->{MaxItems} ) {
|
||||
$Result->[0]->{Hash}->[0]->{MaxItems} = $Param{Value}->[0]->{Hash}->[0]->{MaxItems};
|
||||
}
|
||||
|
||||
my $DefaultItem;
|
||||
|
||||
my %Attributes;
|
||||
|
||||
for my $Key ( sort keys %{ $Param{EffectiveValue} } ) {
|
||||
%Attributes = ();
|
||||
|
||||
$DefaultItem = $Param{Value}->[0]->{Hash}->[0]->{DefaultItem};
|
||||
|
||||
if ( $Param{Value}->[0]->{Hash}->[0]->{Item} ) {
|
||||
my @ItemWithSameKey = grep { $Key eq ( $Param{Value}->[0]->{Hash}->[0]->{Item}->[$_]->{Key} || '' ) }
|
||||
0 .. scalar @{ $Param{Value}->[0]->{Hash}->[0]->{Item} } - 1;
|
||||
if ( scalar @ItemWithSameKey ) {
|
||||
|
||||
if (
|
||||
$DefaultItem
|
||||
&& !$Param{Value}->[0]->{Hash}->[0]->{Item}->[ $ItemWithSameKey[0] ]->{ValueType}
|
||||
&& $DefaultItem->[0]->{ValueType}
|
||||
)
|
||||
{
|
||||
# update hash
|
||||
for my $DefaultKey (
|
||||
sort keys %{ $Param{Value}->[0]->{Hash}->[0]->{Item}->[ $ItemWithSameKey[0] ] }
|
||||
)
|
||||
{
|
||||
$DefaultItem->[0]->{$DefaultKey}
|
||||
= $Param{Value}->[0]->{Hash}->[0]->{Item}->[ $ItemWithSameKey[0] ]->{$DefaultKey};
|
||||
}
|
||||
}
|
||||
else {
|
||||
$DefaultItem = [
|
||||
$Param{Value}->[0]->{Hash}->[0]->{Item}->[ $ItemWithSameKey[0] ],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
$DefaultItem
|
||||
&& ref $DefaultItem eq 'ARRAY'
|
||||
&& scalar @{$DefaultItem}
|
||||
&& ref $DefaultItem->[0] eq 'HASH'
|
||||
)
|
||||
{
|
||||
# Get additional attributes
|
||||
ATTRIBUTE:
|
||||
for my $Attribute ( sort keys %{ $DefaultItem->[0] } ) {
|
||||
next ATTRIBUTE if grep { $Attribute eq $_ } qw(Hash Array Content Key);
|
||||
|
||||
if ( $Attribute eq 'Item' ) {
|
||||
if (
|
||||
!$DefaultItem->[0]->{Item}->[0]->{ValueType}
|
||||
|| $DefaultItem->[0]->{Item}->[0]->{ValueType} ne 'Option'
|
||||
)
|
||||
{
|
||||
next ATTRIBUTE;
|
||||
}
|
||||
}
|
||||
$Attributes{$Attribute} = $DefaultItem->[0]->{$Attribute};
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
$DefaultItem
|
||||
&& !$DefaultItem->[0]->{Content}
|
||||
&& $Param{Value}->[0]->{Hash}->[0]->{Item}
|
||||
&& scalar @{ $Param{Value}->[0]->{Hash}->[0]->{Item} }
|
||||
&& $Param{Value}->[0]->{Hash}->[0]->{Item}->[0]->{Item}
|
||||
)
|
||||
{
|
||||
# It's Item with defined ValueType.
|
||||
my $ItemData = $Kernel::OM->Get('Kernel::System::Storable')->Clone(
|
||||
Data => $DefaultItem,
|
||||
);
|
||||
|
||||
ATTRIBUTE:
|
||||
for my $Attribute ( sort keys %Attributes ) {
|
||||
next ATTRIBUTE if defined $ItemData->[0]->{$Attribute};
|
||||
|
||||
$ItemData->[0]->{$Attribute} = $Attributes{$Attribute};
|
||||
}
|
||||
|
||||
if (
|
||||
!$ItemData->[0]->{Item}
|
||||
|| ( $ItemData->[0]->{Item} && !$ItemData->[0]->{Item}->[0]->{ValueType} )
|
||||
)
|
||||
{
|
||||
$ItemData->[0]->{ValueType} //= 'String';
|
||||
}
|
||||
|
||||
my $Value = $Self->_ModifiedValueCalculate(
|
||||
Value => $ItemData,
|
||||
EffectiveValue => $Param{EffectiveValue}->{$Key},
|
||||
ValueType => $DefaultItem->[0]->{ValueType},
|
||||
Objects => \%Objects,
|
||||
);
|
||||
|
||||
$Value->[0]->{Key} = $Key;
|
||||
|
||||
push @{ $Result->[0]->{Hash}->[0]->{Item} }, $Value->[0];
|
||||
}
|
||||
elsif (
|
||||
$DefaultItem
|
||||
&& ( $DefaultItem->[0]->{Array} || $DefaultItem->[0]->{Hash} )
|
||||
)
|
||||
{
|
||||
# It's complex structure (HoA or HoH), continue recursion.
|
||||
my $StructureType = $DefaultItem->[0]->{Array} ? 'Array' : 'Hash';
|
||||
|
||||
my ($SubValue)
|
||||
= grep { defined $_->{Key} && $_->{Key} eq $Key } @{ $Param{Value}->[0]->{Hash}->[0]->{Item} };
|
||||
|
||||
if (
|
||||
$Param{Value}->[0]->{Hash}->[0]->{DefaultItem}
|
||||
&& $Param{Value}->[0]->{Hash}->[0]->{DefaultItem}->[0]->{$StructureType}
|
||||
)
|
||||
{
|
||||
$SubValue->{$StructureType}->[0]->{DefaultItem} =
|
||||
$Param{Value}->[0]->{Hash}->[0]->{DefaultItem}->[0]->{$StructureType}->[0]->{DefaultItem};
|
||||
}
|
||||
|
||||
my $Value = $Self->_ModifiedValueCalculate(
|
||||
Value => [$SubValue],
|
||||
EffectiveValue => $Param{EffectiveValue}->{$Key},
|
||||
Objects => \%Objects,
|
||||
);
|
||||
$Value->[0]->{Key} = $Key;
|
||||
|
||||
if ( $SubValue->{$StructureType}->[0]->{DefaultItem} ) {
|
||||
$Value->[0]->{$StructureType}->[0]->{DefaultItem} = $SubValue->{$StructureType}->[0]->{DefaultItem};
|
||||
}
|
||||
|
||||
push @{ $Result->[0]->{Hash}->[0]->{Item} }, $Value->[0];
|
||||
}
|
||||
else {
|
||||
# This is a scaler value.
|
||||
|
||||
my $ValueAttribute = "Content"; # by default
|
||||
|
||||
my $ValueType = $Attributes{ValueType};
|
||||
|
||||
if ($ValueType) {
|
||||
if ( !$Objects{$ValueType} ) {
|
||||
|
||||
# Make sure the ValueType backed is present and is syntactically correct.
|
||||
my $Loaded = $Kernel::OM->Get('Kernel::System::Main')->Require(
|
||||
"Kernel::System::SysConfig::ValueType::$ValueType",
|
||||
);
|
||||
|
||||
if ($Loaded) {
|
||||
|
||||
# Create object instance.
|
||||
$Objects{$ValueType} = $Kernel::OM->Get(
|
||||
"Kernel::System::SysConfig::ValueType::$ValueType",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$ValueAttribute = $Objects{$ValueType}->ValueAttributeGet();
|
||||
}
|
||||
|
||||
push @{ $Result->[0]->{Hash}->[0]->{Item} }, {
|
||||
%Attributes,
|
||||
Key => $Key,
|
||||
$ValueAttribute => $Param{EffectiveValue}->{$Key},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
# This is a scaler value.
|
||||
$Result = [
|
||||
{
|
||||
Item => [
|
||||
{
|
||||
Content => $Param{EffectiveValue},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
# Get all additional parameters (defined as attributes in XML).
|
||||
if ( IsHashRefWithData( $Param{Value}->[0]->{Item}->[0] ) ) {
|
||||
PARAMETER:
|
||||
for my $Parameter ( sort keys %{ $Param{Value}->[0]->{Item}->[0] } ) {
|
||||
next PARAMETER if grep { $_ eq $Parameter } @SkipParameters;
|
||||
|
||||
$Result->[0]->{Item}->[0]->{$Parameter} =
|
||||
$Param{Value}->[0]->{Item}->[0]->{$Parameter};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
508
Perl OTRS/Kernel/System/SysConfig/BaseValueType.pm
Normal file
508
Perl OTRS/Kernel/System/SysConfig/BaseValueType.pm
Normal file
@@ -0,0 +1,508 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::BaseValueType;
|
||||
## nofilter(TidyAll::Plugin::OTRS::Perl::LayoutObject)
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Language',
|
||||
'Kernel::Output::HTML::Layout',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::BaseValueType - Common system configuration value type backend functions.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 SettingEffectiveValueCheck()
|
||||
|
||||
Check if provided EffectiveValue matches structure defined in XMLContentParsed.
|
||||
|
||||
my %Result = $ValueTypeObject->SettingEffectiveValueCheck(
|
||||
EffectiveValue => 'open',
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => "Scalar value",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
Result:
|
||||
$Result = (
|
||||
EffectiveValue => 'open', # Note for common ValueTypes EffectiveValue is not changed.
|
||||
Success => 1,
|
||||
Error => undef,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingEffectiveValueCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(XMLContentParsed)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Result = (
|
||||
Success => 0,
|
||||
);
|
||||
|
||||
my $Value = $Param{XMLContentParsed}->{Value};
|
||||
|
||||
for my $Parameter ( sort keys %{ $Param{Parameters} } ) {
|
||||
if ( !defined $Value->[0]->{Item}->[0]->{$Parameter} ) {
|
||||
$Value->[0]->{Item}->[0]->{$Parameter} = $Param{Parameters}->{$Parameter};
|
||||
}
|
||||
}
|
||||
|
||||
# Data should be scalar.
|
||||
if ( ref $Param{EffectiveValue} ) {
|
||||
$Result{Error} = 'EffectiveValue must be a scalar!';
|
||||
return %Result;
|
||||
}
|
||||
|
||||
my $Regex = $Value->[0]->{Item}->[0]->{ValueRegex};
|
||||
|
||||
# RegEx check - do not use any modifiers for compatibility reasons.
|
||||
if ( $Regex && $Param{EffectiveValue} !~ m{$Regex} ) {
|
||||
$Result{Error} = "EffectiveValue not valid - regex '$Regex'!";
|
||||
return %Result;
|
||||
}
|
||||
|
||||
$Result{Success} = 1;
|
||||
$Result{EffectiveValue} = $Param{EffectiveValue};
|
||||
|
||||
return %Result;
|
||||
}
|
||||
|
||||
=head2 EffectiveValueGet()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $EffectiveValue = $ValueTypeObject->EffectiveValueGet(
|
||||
Value => [
|
||||
{
|
||||
ValueRegex => '', # (optional)
|
||||
Content => 'TheEffectiveValue',
|
||||
ValueType => 'AValueType', # (optional)
|
||||
# ...
|
||||
}
|
||||
],
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$EffectiveValue = 'TheEffectiveValue';
|
||||
|
||||
=cut
|
||||
|
||||
sub EffectiveValueGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !IsArrayRefWithData( $Param{Value} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Value is missing or invalid!",
|
||||
);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( scalar @{ $Param{Value} } > 1 ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Value must be a single element!",
|
||||
);
|
||||
return '';
|
||||
}
|
||||
|
||||
$Param{Translate} = 0; # common ValueTypes are never translated
|
||||
|
||||
my $Result = $Param{Value}->[0]->{Content} // '';
|
||||
|
||||
if (
|
||||
$Result
|
||||
&& $Param{Translate}
|
||||
&& $Param{Value}->[0]->{Translatable}
|
||||
)
|
||||
{
|
||||
$Result = $Kernel::OM->Get('Kernel::Language')->Translate($Result);
|
||||
}
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
=head2 ModifiedValueGet()
|
||||
|
||||
Returns parsed value with updated content(according to EffectiveValue).
|
||||
|
||||
my $ModifiedValue = $ValueTypeObject->ModifiedValueGet(
|
||||
'EffectiveValue' => 'Item 1',
|
||||
'Value' => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => 'Default value',
|
||||
'ValueType' => 'String',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$ModifiedValue = [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => 'Item 1',
|
||||
'ValueType' => 'String',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
=cut
|
||||
|
||||
sub ModifiedValueGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(Value)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $Result = $Param{Value};
|
||||
|
||||
# Update Content
|
||||
$Result->[0]->{Item}->[0]->{Content} = $Param{EffectiveValue} || '';
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
=head2 SettingRender()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $SettingHTML = $ValueTypeObject->SettingRender(
|
||||
Name => 'SettingName',
|
||||
EffectiveValue => 'Product 6', # (optional)
|
||||
DefaultValue => 'Product 5', # (optional)
|
||||
Class => 'My class' # (optional)
|
||||
Item => [ # (optional) XML parsed item
|
||||
{
|
||||
'ValueType' => 'String',
|
||||
'Content' => 'admin@example.com',
|
||||
'ValueRegex' => '',
|
||||
},
|
||||
],
|
||||
RW => 1, # (optional) Allow editing. Default 0.
|
||||
IsArray => 1, # (optional) Item is part of the array
|
||||
IsHash => 1, # (optional) Item is part of the hash
|
||||
IDSuffix => 1, # (optional) Suffix will be added to the element ID
|
||||
SkipEffectiveValueCheck => 1, # (optional) If enabled, system will not perform effective value check.
|
||||
# Default: 1.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$SettingHTML = '<div class "Field"...</div>';
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingRender {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !defined $Param{Name} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need Name",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$Param{EffectiveValue} //= '';
|
||||
$Param{Class} //= '';
|
||||
$Param{DefaultValue} //= '';
|
||||
my $IDSuffix = $Param{IDSuffix} || '';
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
|
||||
my $EffectiveValue = $Param{EffectiveValue};
|
||||
if (
|
||||
!defined $EffectiveValue
|
||||
&& $Param{Item}
|
||||
&& $Param{Item}->[0]->{Content}
|
||||
)
|
||||
{
|
||||
$EffectiveValue = $Param{Item}->[0]->{Content};
|
||||
}
|
||||
|
||||
my $Regex;
|
||||
if ( $Param{Item}->[0]->{ValueRegex} ) {
|
||||
$Regex = $Param{Item}->[0]->{ValueRegex};
|
||||
$Param{Class} .= ' Validate_Regex ';
|
||||
}
|
||||
|
||||
my $DefaultValueStrg = $LanguageObject->Translate('Default');
|
||||
|
||||
my %EffectiveValueCheck = (
|
||||
Success => 1,
|
||||
);
|
||||
|
||||
if ( !$Param{SkipEffectiveValueCheck} ) {
|
||||
%EffectiveValueCheck = $Self->SettingEffectiveValueCheck(
|
||||
EffectiveValue => $EffectiveValue,
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
Item => $Param{Item},
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
my $HTML = '<div class="SettingContent">';
|
||||
$HTML .= "<input class=\"$Param{Class}\" type=\"text\" name=\"$Param{Name}\" id=\"$Param{Name}$IDSuffix\" ";
|
||||
|
||||
my $HTMLValue = $Kernel::OM->Get('Kernel::Output::HTML::Layout')->Ascii2Html(
|
||||
Text => $EffectiveValue,
|
||||
Type => 'Normal',
|
||||
);
|
||||
$HTML .= "value=\"$HTMLValue\" ";
|
||||
|
||||
if ($Regex) {
|
||||
$HTML .= "data-regex=\"$Regex\" ";
|
||||
}
|
||||
|
||||
if ( !$Param{RW} ) {
|
||||
$HTML .= "disabled='disabled' ";
|
||||
}
|
||||
|
||||
$HTML .= " />\n";
|
||||
|
||||
if ( !$EffectiveValueCheck{Success} ) {
|
||||
my $Message = $LanguageObject->Translate("Value is not correct! Please, consider updating this field.");
|
||||
|
||||
$HTML .= $Param{IsValid} ? "<div class='BadEffectiveValue'>\n" : "<div>\n";
|
||||
$HTML .= "<p>* $Message</p>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
if ($Regex) {
|
||||
my $Message = $LanguageObject->Translate(
|
||||
"Value doesn't satisfy regex (%s).", $Regex,
|
||||
);
|
||||
|
||||
$HTML .= "<div class='TooltipErrorMessage' id=\"$Param{Name}$IDSuffix" . "Error\">\n";
|
||||
$HTML .= "<p>$Message</p>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
$HTML .= "</div>";
|
||||
|
||||
if ( !$Param{IsArray} && !$Param{IsHash} ) {
|
||||
$HTML .= <<"EOF";
|
||||
<div class=\"WidgetMessage Bottom\">
|
||||
$DefaultValueStrg: $Param{DefaultValue}
|
||||
</div>
|
||||
EOF
|
||||
}
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
sub EffectiveValueCalculate {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check needed stuff.
|
||||
for my $Needed (qw(Name)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $Result = '';
|
||||
|
||||
if ( $Param{ $Param{Name} } ) {
|
||||
$Result = $Param{ $Param{Name} };
|
||||
}
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
=head2 AddItem()
|
||||
|
||||
Generate HTML for new array/hash item.
|
||||
|
||||
my $HTML = $ValueTypeObject->AddItem(
|
||||
Name => 'SettingName', (required) Name
|
||||
DefaultItem => { (optional) DefaultItem hash, if available
|
||||
Item => {
|
||||
Content => 'Value',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$HTML = "<input type='text' id='Setting_ExampleArray'
|
||||
value='Value' name='ExampleArray' class='Entry'/>";
|
||||
|
||||
=cut
|
||||
|
||||
sub AddItem {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check needed stuff.
|
||||
for my $Needed (qw(Name)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $IDSuffix = $Param{IDSuffix} || '';
|
||||
my $Class = $Param{Class} || '';
|
||||
|
||||
my $Name = $Param{Name} . $IDSuffix;
|
||||
|
||||
my $DefaultValue = '';
|
||||
|
||||
if ( $Param{DefaultItem} && $Param{DefaultItem}->{Item} ) {
|
||||
$DefaultValue = $Param{DefaultItem} && $Param{DefaultItem}->{Item}->{Content} || '';
|
||||
}
|
||||
elsif ( $Param{DefaultItem} ) {
|
||||
$DefaultValue = $Param{DefaultItem} && $Param{DefaultItem}->{Content} || '';
|
||||
}
|
||||
|
||||
my $RemoveThisEntry = $Kernel::OM->Get('Kernel::Language')->Translate("Remove this entry");
|
||||
|
||||
my $Result = "<input type='text' id='$Name'
|
||||
value='$DefaultValue' name='$Param{Name}' class='$Class Entry'/>";
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
=head2 ValueAttributeGet()
|
||||
|
||||
Returns attribute name in the parsed XML that contains Value.
|
||||
|
||||
my $Result = $ValueTypeObject->ValueAttributeGet();
|
||||
|
||||
Result:
|
||||
$Result = 'Content';
|
||||
|
||||
=cut
|
||||
|
||||
sub ValueAttributeGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
return 'Content';
|
||||
}
|
||||
|
||||
=head2 DefaultItemAdd()
|
||||
|
||||
Return structure of the DefaultItem in case it's not inside of Array or Hash.
|
||||
|
||||
my $DefaultItem = $ValueTypeObject->DefaultItemAdd();
|
||||
|
||||
Returns:
|
||||
|
||||
$DefaultItem = undef;
|
||||
# or
|
||||
$DefaultItem = {
|
||||
Item => {
|
||||
Content => '',
|
||||
},
|
||||
ValueType => 'VacationDaysOneTime',
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub DefaultItemAdd {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# For most ValueTypes there is no such case, so return undef.
|
||||
return;
|
||||
}
|
||||
|
||||
=head2 ForbiddenValueTypes()
|
||||
|
||||
Return array of value types that are not allowed inside this value type.
|
||||
|
||||
my @ForbiddenValueTypes = $ValueTypeObject->ForbiddenValueTypes();
|
||||
|
||||
Returns:
|
||||
|
||||
@ForbiddenValueTypes = (
|
||||
'Option',
|
||||
...
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ForbiddenValueTypes {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
return ();
|
||||
}
|
||||
|
||||
=head2 AddSettingContent()
|
||||
|
||||
Checks if a div with class 'SettingContent' should be added when adding new item to an array/hash in some special cases.
|
||||
|
||||
my $AddSettingContent = $ValueTypeObject->AddSettingContent();
|
||||
|
||||
Returns:
|
||||
|
||||
my $AddSettingContent = 1;
|
||||
|
||||
=cut
|
||||
|
||||
sub AddSettingContent {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
5652
Perl OTRS/Kernel/System/SysConfig/DB.pm
Normal file
5652
Perl OTRS/Kernel/System/SysConfig/DB.pm
Normal file
File diff suppressed because it is too large
Load Diff
2922
Perl OTRS/Kernel/System/SysConfig/Migration.pm
Normal file
2922
Perl OTRS/Kernel/System/SysConfig/Migration.pm
Normal file
File diff suppressed because it is too large
Load Diff
345
Perl OTRS/Kernel/System/SysConfig/ValueType/Checkbox.pm
Normal file
345
Perl OTRS/Kernel/System/SysConfig/ValueType/Checkbox.pm
Normal file
@@ -0,0 +1,345 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::Checkbox;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Language',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::Checkbox - System configuration check-box value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::Checkbox');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingEffectiveValueCheck()
|
||||
|
||||
Check if provided EffectiveValue matches structure defined in XMLContentParsed.
|
||||
|
||||
my %Result = $ValueTypeObject->SettingEffectiveValueCheck(
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => '1',
|
||||
'ValueType' => 'Checkbox',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
EffectiveValue => '1',
|
||||
);
|
||||
|
||||
Result:
|
||||
%Result = (
|
||||
EffectiveValue => 'open', # Note for Checkbox ValueTypes EffectiveValue is not changed.
|
||||
Success => 1,
|
||||
Error => undef,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingEffectiveValueCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(XMLContentParsed)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Result = (
|
||||
Success => 0,
|
||||
);
|
||||
|
||||
# Data should be scalar.
|
||||
if ( ref $Param{EffectiveValue} ) {
|
||||
$Result{Error} = 'EffectiveValue for Checkbox must be a scalar!';
|
||||
return %Result;
|
||||
}
|
||||
|
||||
if ( $Param{EffectiveValue} && $Param{EffectiveValue} ne '1' ) {
|
||||
$Result{Error} = 'EffectiveValue must be 0 or 1 for Checkbox!';
|
||||
return %Result;
|
||||
}
|
||||
|
||||
$Result{Success} = 1;
|
||||
$Result{EffectiveValue} = $Param{EffectiveValue};
|
||||
|
||||
return %Result;
|
||||
}
|
||||
|
||||
=head2 SettingRender()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $SettingHTML = $ValueTypeObject->SettingRender(
|
||||
Name => 'SettingName',
|
||||
DefaultID => 123, # (required)
|
||||
EffectiveValue => 'Product 6',
|
||||
DefaultValue => 'Product 5', # (optional)
|
||||
Class => 'My class' # (optional)
|
||||
RW => 1, # (optional) Allow editing. Default 0.
|
||||
Item => [ # (optional) XML parsed item
|
||||
{
|
||||
'ValueType' => 'Checkbox',
|
||||
'Content' => '1',
|
||||
'ValueRegex' => '',
|
||||
},
|
||||
],
|
||||
IsArray => 1, # (optional) Item is part of the array
|
||||
IsHash => 1, # (optional) Item is part of the hash
|
||||
IDSuffix => 1, # (optional) Suffix will be added to the element ID
|
||||
SkipEffectiveValueCheck => 1, # (optional) If enabled, system will not perform effective value check.
|
||||
# Default: 1.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$SettingHTML = '<div class "Field"...</div>';
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingRender {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(Name EffectiveValue)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{DefaultValue} //= '';
|
||||
|
||||
my $IDSuffix = $Param{IDSuffix} || '';
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
|
||||
my $EffectiveValue = $Param{EffectiveValue};
|
||||
|
||||
if (
|
||||
!defined $Param{EffectiveValue}
|
||||
&& $Param{Item}->[0]->{Content}
|
||||
)
|
||||
{
|
||||
$EffectiveValue = $Param{Item}->[0]->{Content};
|
||||
}
|
||||
|
||||
my %EffectiveValueCheck = (
|
||||
Success => 1,
|
||||
);
|
||||
|
||||
if ( !$Param{SkipEffectiveValueCheck} ) {
|
||||
%EffectiveValueCheck = $Self->SettingEffectiveValueCheck(
|
||||
EffectiveValue => $EffectiveValue,
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
Item => $Param{Item},
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
my $HTML = "<div class='SettingContent'>\n";
|
||||
$HTML
|
||||
.= "<input class=\"$Param{Class}\" type=\"checkbox\" id=\"Checkbox_$Param{Name}$IDSuffix\" ";
|
||||
$HTML .= "value=\"1\" ";
|
||||
|
||||
if ($EffectiveValue) {
|
||||
$HTML .= "checked='checked' ";
|
||||
}
|
||||
|
||||
if ( !$Param{RW} ) {
|
||||
$HTML .= "disabled='disabled' ";
|
||||
}
|
||||
$HTML .= ">";
|
||||
|
||||
# Add hidden input field with checkbox value
|
||||
$HTML .= "<input type='hidden' name='$Param{Name}' id=\"$Param{Name}$IDSuffix\" ";
|
||||
if ($EffectiveValue) {
|
||||
$HTML .= "value='1' ";
|
||||
}
|
||||
else {
|
||||
$HTML .= "value='0' ";
|
||||
}
|
||||
$HTML .= "/>\n";
|
||||
|
||||
$HTML .= "<label for='Checkbox_$Param{Name}$IDSuffix' class='CheckboxLabel'>"
|
||||
. $LanguageObject->Translate('Enabled')
|
||||
. "</label>\n";
|
||||
|
||||
if ( !$EffectiveValueCheck{Success} ) {
|
||||
my $Message = $LanguageObject->Translate("Value is not correct! Please, consider updating this field.");
|
||||
|
||||
$HTML .= $Param{IsValid} ? "<div class='BadEffectiveValue'>\n" : "<div>\n";
|
||||
$HTML .= "<p>* $Message</p>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
$HTML .= "</div>\n";
|
||||
|
||||
if ( !$Param{IsArray} && !$Param{IsHash} ) {
|
||||
my $DefaultText = $Kernel::OM->Get('Kernel::Language')->Translate('Default');
|
||||
my $DefaultValueText = $Param{DefaultValue}
|
||||
?
|
||||
$LanguageObject->Translate('Enabled')
|
||||
:
|
||||
$LanguageObject->Translate('Disabled');
|
||||
|
||||
$HTML .= <<"EOF";
|
||||
<div class=\"WidgetMessage Bottom\">
|
||||
$DefaultText: $DefaultValueText
|
||||
</div>
|
||||
EOF
|
||||
}
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
sub EffectiveValueCalculate {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check needed stuff.
|
||||
for my $Needed (qw(Name)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $Result = '0';
|
||||
|
||||
if ( $Param{ $Param{Name} } ) {
|
||||
$Result = $Param{ $Param{Name} };
|
||||
}
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
=head2 AddItem()
|
||||
|
||||
Generate HTML for new array/hash item.
|
||||
|
||||
my $HTML = $ValueTypeObject->AddItem(
|
||||
Name => 'SettingName', (required) Name
|
||||
DefaultItem => { (optional) DefaultItem hash, if available
|
||||
Content => 'Value',
|
||||
ValueType => 'Checkbox',
|
||||
},
|
||||
IDSuffix => '_Array1', (optional) IDSuffix is needed for arrays and hashes.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$HTML = "<input type="checkbox" checked="checked" name="SettingName" value="1" id="SettingName_Array1">
|
||||
<input type="hidden" value="1" name="SettingName">
|
||||
<label for="SettingName_Array1" class='CheckboxLabel'>
|
||||
Enabled
|
||||
</label>";
|
||||
|
||||
=cut
|
||||
|
||||
sub AddItem {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check needed stuff.
|
||||
for my $Needed (qw(Name)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $IDSuffix = $Param{IDSuffix} || '';
|
||||
my $Checked;
|
||||
if ( $Param{DefaultItem} ) {
|
||||
$Checked = $Param{DefaultItem}->{Content};
|
||||
}
|
||||
|
||||
my $Enabled = $Kernel::OM->Get('Kernel::Language')->Translate('Enabled');
|
||||
|
||||
my $Result = "<input type=\"checkbox\" id=\"Checkbox_$Param{Name}$IDSuffix\" value=\"1\" ";
|
||||
|
||||
if ($Checked) {
|
||||
$Result .= "checked='checked' ";
|
||||
}
|
||||
|
||||
$Result .= "/><input type=\"hidden\" class=\"Entry\" id=\"$Param{Name}$IDSuffix\" name=\"$Param{Name}\" value=\"";
|
||||
|
||||
if ($Checked) {
|
||||
$Result .= "1";
|
||||
}
|
||||
else {
|
||||
$Result .= "0";
|
||||
}
|
||||
|
||||
$Result .= "\" /><label for='Checkbox_$Param{Name}$IDSuffix' class='CheckboxLabel'>$Enabled</label>";
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
500
Perl OTRS/Kernel/System/SysConfig/ValueType/Date.pm
Normal file
500
Perl OTRS/Kernel/System/SysConfig/ValueType/Date.pm
Normal file
@@ -0,0 +1,500 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
## nofilter(TidyAll::Plugin::OTRS::Perl::LayoutObject)
|
||||
package Kernel::System::SysConfig::ValueType::Date;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::Language',
|
||||
'Kernel::Output::HTML::Layout',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::JSON',
|
||||
'Kernel::System::User',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::Date - System configuration date value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::Date');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingEffectiveValueCheck()
|
||||
|
||||
Check if provided EffectiveValue matches structure defined in XMLContentParsed.
|
||||
|
||||
my %Result = $ValueTypeObject->SettingEffectiveValueCheck(
|
||||
XMLContentParsed => { # (required)
|
||||
Value => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => '2016-01-01',
|
||||
'ValueType' => 'Date',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
EffectiveValue => '2016-02-02', # (optional)
|
||||
UserID => 1, # (required)
|
||||
);
|
||||
|
||||
Result:
|
||||
%Result = (
|
||||
EffectiveValue => '2016-02-03', # Note that EffectiveValue can be modified
|
||||
Success => 1,
|
||||
Error => undef,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingEffectiveValueCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(XMLContentParsed UserID)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Result = (
|
||||
Success => 0,
|
||||
);
|
||||
|
||||
# Data should be scalar.
|
||||
if ( ref $Param{EffectiveValue} ) {
|
||||
$Result{Error} = 'EffectiveValue for Date must be a scalar!';
|
||||
return %Result;
|
||||
}
|
||||
|
||||
if ( $Param{EffectiveValue} !~ m{\d{4}-\d{2}-\d{2}} ) {
|
||||
$Result{Error} = "EffectiveValue for Date($Param{EffectiveValue}) must be in format YYYY-MM-DD!";
|
||||
return %Result;
|
||||
}
|
||||
|
||||
my %Preferences = $Kernel::OM->Get('Kernel::System::User')->GetPreferences(
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
my $OTRSTimeZone = $Kernel::OM->Get('Kernel::Config')->Get("OTRSTimeZone");
|
||||
my $DateTimeObject;
|
||||
|
||||
if ( !$Preferences{UserTimeZone} || $Preferences{UserTimeZone} eq $OTRSTimeZone ) {
|
||||
$DateTimeObject = $Kernel::OM->Create(
|
||||
'Kernel::System::DateTime',
|
||||
ObjectParams => {
|
||||
TimeZone => $OTRSTimeZone,
|
||||
},
|
||||
);
|
||||
|
||||
my $SetSuccess = $DateTimeObject->Set( String => $Param{EffectiveValue} );
|
||||
|
||||
if ( !$SetSuccess ) {
|
||||
$Result{Error} = $Kernel::OM->Get('Kernel::Language')->Translate(
|
||||
"EffectiveValue for Date($Param{EffectiveValue}) must be in format YYYY-MM-DD!",
|
||||
);
|
||||
return %Result;
|
||||
}
|
||||
|
||||
$Result{EffectiveValue} = $Param{EffectiveValue};
|
||||
}
|
||||
else {
|
||||
$DateTimeObject = $Kernel::OM->Create(
|
||||
'Kernel::System::DateTime',
|
||||
ObjectParams => {
|
||||
TimeZone => $Preferences{UserTimeZone},
|
||||
},
|
||||
);
|
||||
|
||||
my $SetSuccess = $DateTimeObject->Set( String => $Param{EffectiveValue} );
|
||||
|
||||
if ( !$SetSuccess ) {
|
||||
$Result{Error} = $Kernel::OM->Get('Kernel::Language')->Translate(
|
||||
"EffectiveValue for Date($Param{EffectiveValue}) must be in format YYYY-MM-DD!",
|
||||
);
|
||||
return %Result;
|
||||
}
|
||||
|
||||
my $Success = $DateTimeObject->ToTimeZone(
|
||||
TimeZone => $OTRSTimeZone,
|
||||
);
|
||||
|
||||
if ($Success) {
|
||||
$Result{EffectiveValue} = $DateTimeObject->ToString();
|
||||
}
|
||||
else {
|
||||
$Result{Error} = $Kernel::OM->Get('Kernel::Language')->Translate(
|
||||
"System was not able to calculate user Date in OTRSTimeZone!"
|
||||
);
|
||||
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "System was not able to calculate user Date in OTRSTimeZone!"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$DateTimeObject ) {
|
||||
$Result{Error} = $Kernel::OM->Get('Kernel::Language')->Translate(
|
||||
"EffectiveValue for Date($Param{EffectiveValue}) must be in format YYYY-MM-DD!",
|
||||
);
|
||||
return %Result;
|
||||
}
|
||||
|
||||
$Result{Success} = 1;
|
||||
|
||||
return %Result;
|
||||
}
|
||||
|
||||
=head2 SettingRender()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $SettingHTML = $ValueTypeObject->SettingRender(
|
||||
Name => 'SettingName',
|
||||
EffectiveValue => '2016-02-02', # (optional)
|
||||
DefaultValue => 'Product 5', # (optional)
|
||||
Class => 'My class' # (optional)
|
||||
RW => 1, # (optional) Allow editing. Default 0.
|
||||
Item => [ # (optional) XML parsed item
|
||||
{
|
||||
'ValueType' => 'Date',
|
||||
'Content' => '2016-02-02',
|
||||
'ValueRegex' => '',
|
||||
},
|
||||
],
|
||||
IsArray => 1, # (optional) Item is part of the array
|
||||
IsHash => 1, # (optional) Item is part of the hash
|
||||
IDSuffix => 1, # (optional) Suffix will be added to the element ID
|
||||
SkipEffectiveValueCheck => 1, # (optional) If enabled, system will not perform effective value check.
|
||||
# Default: 1.
|
||||
UserID => 1, # (required) UserID
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$SettingHTML = '<div class "Field"...</div>';
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingRender {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(Name UserID)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{Class} .= ' Date';
|
||||
$Param{DefaultValue} //= '';
|
||||
|
||||
my $IDSuffix = $Param{IDSuffix} || '';
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
|
||||
my $EffectiveValue = $Param{EffectiveValue};
|
||||
if (
|
||||
!defined $EffectiveValue
|
||||
&& $Param{Item}
|
||||
&& $Param{Item}->[0]->{Content}
|
||||
)
|
||||
{
|
||||
$EffectiveValue = $Param{Item}->[0]->{Content};
|
||||
}
|
||||
|
||||
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
|
||||
|
||||
# Check if there is Datepicker before we add it.
|
||||
my $HasDatepicker = $LayoutObject->{HasDatepicker};
|
||||
|
||||
my $Name = $Param{Name} . $IDSuffix;
|
||||
|
||||
my %EffectiveValueCheck = (
|
||||
Success => 1,
|
||||
);
|
||||
|
||||
if ( !$Param{SkipEffectiveValueCheck} ) {
|
||||
%EffectiveValueCheck = $Self->SettingEffectiveValueCheck(
|
||||
EffectiveValue => $EffectiveValue,
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
Item => $Param{Item},
|
||||
},
|
||||
],
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
|
||||
my $TimeZone = $Kernel::OM->Get('Kernel::Config')->Get("OTRSTimeZone");
|
||||
|
||||
my $DateTimeObject = $Kernel::OM->Create(
|
||||
'Kernel::System::DateTime',
|
||||
ObjectParams => {
|
||||
String => $EffectiveValue,
|
||||
TimeZone => $TimeZone,
|
||||
},
|
||||
);
|
||||
|
||||
my %Preferences = $Kernel::OM->Get('Kernel::System::User')->GetPreferences(
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( $Preferences{UserTimeZone} ) {
|
||||
my $Success = $DateTimeObject->ToTimeZone(
|
||||
TimeZone => $Preferences{UserTimeZone},
|
||||
);
|
||||
|
||||
$TimeZone = $Preferences{UserTimeZone};
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "System was not able to calculate DateTime in user timezone!"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
my @Date = split m{-|\s|:}, $DateTimeObject->ToString();
|
||||
|
||||
my $HTML = "<div class='SettingContent'>\n";
|
||||
$HTML .= $LayoutObject->BuildDateSelection(
|
||||
Prefix => $Name,
|
||||
$Name . "Class" => $Param{Class},
|
||||
$Name . "Year" => $Date[0],
|
||||
$Name . "Month" => $Date[1],
|
||||
$Name . "Day" => $Date[2],
|
||||
YearDiff => 10,
|
||||
Format => 'DateInputFormat',
|
||||
Validate => 1,
|
||||
Disabled => $Param{RW} ? 0 : 1,
|
||||
OverrideTimeZone => 1,
|
||||
);
|
||||
|
||||
my $TimeZoneText = $Kernel::OM->Get('Kernel::Language')->Translate("Time Zone");
|
||||
$HTML .= "<span class='TimeZoneText'>$TimeZoneText: $TimeZone</span>\n";
|
||||
|
||||
if ( !$EffectiveValueCheck{Success} ) {
|
||||
my $Message = $LanguageObject->Translate("Value is not correct! Please, consider updating this field.");
|
||||
|
||||
$HTML .= $Param{IsValid} ? "<div class='BadEffectiveValue'>\n" : "<div>\n";
|
||||
$HTML .= "<p>* $Message</p>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
$HTML .= "</div>\n";
|
||||
|
||||
if ( !$Param{IsArray} && !$Param{IsHash} ) {
|
||||
my $DefaultText = $LanguageObject->Translate('Default');
|
||||
|
||||
$HTML .= <<"EOF";
|
||||
<div class=\"WidgetMessage Bottom\">
|
||||
$DefaultText: $Param{DefaultValue}
|
||||
</div>
|
||||
EOF
|
||||
}
|
||||
|
||||
if ( $Param{IsAjax} && $LayoutObject->{_JSOnDocumentComplete} && $Param{RW} ) {
|
||||
for my $JS ( @{ $LayoutObject->{_JSOnDocumentComplete} } ) {
|
||||
$HTML .= "<script>$JS</script>";
|
||||
}
|
||||
}
|
||||
|
||||
if ( $Param{IsAjax} ) {
|
||||
|
||||
# Remove JS generated in BuildDateSelection() call (setting is disabled or it's already sent together with HTML).
|
||||
# It also prevents multiple Datepicker initializations (if there are several on the page).
|
||||
pop @{ $LayoutObject->{_JSOnDocumentComplete} };
|
||||
|
||||
if ( !$HasDatepicker ) {
|
||||
my $VacationDays = $LayoutObject->DatepickerGetVacationDays();
|
||||
my $TextDirection = $LanguageObject->{TextDirection} || '';
|
||||
|
||||
my $JSONString = $Kernel::OM->Get('Kernel::System::JSON')->Encode(
|
||||
Data => {
|
||||
VacationDays => $VacationDays,
|
||||
IsRTL => ( $TextDirection eq 'rtl' ) ? 1 : 0,
|
||||
},
|
||||
);
|
||||
|
||||
$HTML .= "<script>
|
||||
Core.Config.Set('Datepicker', $JSONString);
|
||||
</script>";
|
||||
|
||||
# If there are several DateTime settings, don't run this block again.
|
||||
$LayoutObject->{HasDatepicker} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
=head2 AddItem()
|
||||
|
||||
Generate HTML for new array/hash item.
|
||||
|
||||
my $HTML = $ValueTypeObject->AddItem(
|
||||
Name => 'SettingName', (required) Name
|
||||
DefaultItem => { (optional) DefaultItem hash, if available
|
||||
Content => '2017-01-01',
|
||||
ValueType => 'Date',
|
||||
},
|
||||
IDSuffix => '_Array1', (optional) IDSuffix is needed for arrays and hashes.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$HTML = '<select class="Validate_DateMonth Date" id="SettingName_Array1Month" ...';
|
||||
|
||||
=cut
|
||||
|
||||
sub AddItem {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check needed stuff.
|
||||
for my $Needed (qw(Name)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $IDSuffix = $Param{IDSuffix} || '';
|
||||
my $Class = $Param{Class} || '';
|
||||
$Class .= ' Date Entry';
|
||||
|
||||
my $Name = $Param{Name} . $IDSuffix;
|
||||
|
||||
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
|
||||
my $TimeZone = $Kernel::OM->Get('Kernel::Config')->Get("OTRSTimeZone");
|
||||
|
||||
my %Preferences = $Kernel::OM->Get('Kernel::System::User')->GetPreferences(
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
my $DefaultValue;
|
||||
if ( $Param{DefaultItem} ) {
|
||||
my $DateTimeObject = $Kernel::OM->Create(
|
||||
'Kernel::System::DateTime',
|
||||
ObjectParams => {
|
||||
String => $Param{DefaultItem}->{Content},
|
||||
TimeZone => $TimeZone,
|
||||
},
|
||||
);
|
||||
|
||||
if ( $Preferences{UserTimeZone} ) {
|
||||
my $Success = $DateTimeObject->ToTimeZone(
|
||||
TimeZone => $Preferences{UserTimeZone},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "System was not able to calculate DateTime in user timezone!"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$DefaultValue = $DateTimeObject->ToString();
|
||||
}
|
||||
|
||||
if ( $Preferences{UserTimeZone} ) {
|
||||
$TimeZone = $Preferences{UserTimeZone};
|
||||
}
|
||||
|
||||
my $Result;
|
||||
|
||||
if ($DefaultValue) {
|
||||
my @Date = split m{-|\s|:}, $DefaultValue;
|
||||
|
||||
$Result = $LayoutObject->BuildDateSelection(
|
||||
Prefix => $Name,
|
||||
$Name . "Year" => $Date[0],
|
||||
$Name . "Month" => $Date[1],
|
||||
$Name . "Day" => $Date[2],
|
||||
$Name . "Class" => $Class,
|
||||
YearDiff => 10,
|
||||
Format => 'DateInputFormat',
|
||||
Validate => 1,
|
||||
OverrideTimeZone => 1,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$Result = $LayoutObject->BuildDateSelection(
|
||||
Prefix => $Name,
|
||||
$Name . "Class" => $Class,
|
||||
YearDiff => 10,
|
||||
Format => 'DateInputFormat',
|
||||
Validate => 1,
|
||||
OverrideTimeZone => 1,
|
||||
);
|
||||
}
|
||||
|
||||
my $TimeZoneText = $Kernel::OM->Get('Kernel::Language')->Translate("Time Zone");
|
||||
$Result .= "<span class='TimeZoneText'>$TimeZoneText: $TimeZone</span>\n";
|
||||
|
||||
for my $JS ( @{ $LayoutObject->{_JSOnDocumentComplete} } ) {
|
||||
$Result .= "<script>$JS</script>";
|
||||
}
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
506
Perl OTRS/Kernel/System/SysConfig/ValueType/DateTime.pm
Normal file
506
Perl OTRS/Kernel/System/SysConfig/ValueType/DateTime.pm
Normal file
@@ -0,0 +1,506 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
## nofilter(TidyAll::Plugin::OTRS::Perl::LayoutObject)
|
||||
package Kernel::System::SysConfig::ValueType::DateTime;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::Language',
|
||||
'Kernel::Output::HTML::Layout',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::JSON',
|
||||
'Kernel::System::User',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::DateTime - System configuration date-time value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::DateTime');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingEffectiveValueCheck()
|
||||
|
||||
Check if provided EffectiveValue matches structure defined in XMLContentParsed.
|
||||
|
||||
my %Result = $ValueTypeObject->SettingEffectiveValueCheck(
|
||||
XMLContentParsed => { # (required)
|
||||
Value => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => '2016-01-01 00:00:00',
|
||||
'ValueType' => 'DateTime',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
EffectiveValue => '2016-02-02 01:12:22', # (optional)
|
||||
UserID => 1, # (required)
|
||||
);
|
||||
|
||||
Result:
|
||||
%Result = (
|
||||
EffectiveValue => '2016-02-02 03:12:22', # Note that EffectiveValue can be modified
|
||||
Success => 1,
|
||||
Error => undef,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingEffectiveValueCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(XMLContentParsed UserID)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Result = (
|
||||
Success => 0,
|
||||
);
|
||||
|
||||
# Data should be scalar.
|
||||
if ( ref $Param{EffectiveValue} ) {
|
||||
$Result{Error} = 'EffectiveValue for DateTime must be a scalar!';
|
||||
return %Result;
|
||||
}
|
||||
|
||||
if ( $Param{EffectiveValue} !~ m{\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}} ) {
|
||||
$Result{Error} = 'EffectiveValue for DateTime must be in format YYYY-MM-DD hh:mm:ss!';
|
||||
return %Result;
|
||||
}
|
||||
|
||||
my %Preferences = $Kernel::OM->Get('Kernel::System::User')->GetPreferences(
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
my $OTRSTimeZone = $Kernel::OM->Get('Kernel::Config')->Get("OTRSTimeZone");
|
||||
my $DateTimeObject;
|
||||
|
||||
if ( !$Preferences{UserTimeZone} || $Preferences{UserTimeZone} eq $OTRSTimeZone ) {
|
||||
$DateTimeObject = $Kernel::OM->Create(
|
||||
'Kernel::System::DateTime',
|
||||
ObjectParams => {
|
||||
TimeZone => $OTRSTimeZone,
|
||||
},
|
||||
);
|
||||
|
||||
my $SetSuccess = $DateTimeObject->Set( String => $Param{EffectiveValue} );
|
||||
|
||||
if ( !$SetSuccess ) {
|
||||
$Result{Error} = $Kernel::OM->Get('Kernel::Language')->Translate(
|
||||
"EffectiveValue for DateTime($Param{EffectiveValue}) must be in format YYYY-MM-DD hh:mm:ss!",
|
||||
);
|
||||
return %Result;
|
||||
}
|
||||
|
||||
$Result{EffectiveValue} = $Param{EffectiveValue};
|
||||
}
|
||||
else {
|
||||
$DateTimeObject = $Kernel::OM->Create(
|
||||
'Kernel::System::DateTime',
|
||||
ObjectParams => {
|
||||
TimeZone => $Preferences{UserTimeZone},
|
||||
},
|
||||
);
|
||||
|
||||
my $SetSuccess = $DateTimeObject->Set( String => $Param{EffectiveValue} );
|
||||
|
||||
if ( !$SetSuccess ) {
|
||||
$Result{Error} = $Kernel::OM->Get('Kernel::Language')->Translate(
|
||||
"EffectiveValue for DateTime($Param{EffectiveValue}) must be in format YYYY-MM-DD hh:mm:ss!",
|
||||
);
|
||||
return %Result;
|
||||
}
|
||||
|
||||
my $Success = $DateTimeObject->ToTimeZone(
|
||||
TimeZone => $OTRSTimeZone,
|
||||
);
|
||||
|
||||
if ($Success) {
|
||||
$Result{EffectiveValue} = $DateTimeObject->ToString();
|
||||
}
|
||||
else {
|
||||
$Result{Error} = $Kernel::OM->Get('Kernel::Language')->Translate(
|
||||
"System was not able to calculate user DateTime in OTRSTimeZone!"
|
||||
);
|
||||
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "System was not able to calculate user DateTime in OTRSTimeZone!"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$DateTimeObject ) {
|
||||
$Result{Error} = $Kernel::OM->Get('Kernel::Language')->Translate(
|
||||
"EffectiveValue for DateTime($Param{EffectiveValue}) must be in format YYYY-MM-DD hh:mm:ss!",
|
||||
);
|
||||
return %Result;
|
||||
}
|
||||
|
||||
$Result{Success} = 1;
|
||||
|
||||
return %Result;
|
||||
}
|
||||
|
||||
=head2 SettingRender()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $SettingHTML = $ValueTypeObject->SettingRender(
|
||||
Name => 'SettingName',
|
||||
EffectiveValue => '2016-02-02 01:00:59', # (optional)
|
||||
DefaultValue => 'Product 5', # (optional)
|
||||
Class => 'My class' # (optional)
|
||||
RW => 1, # (optional) Allow editing. Default 0.
|
||||
Item => [ # (optional) XML parsed item
|
||||
{
|
||||
'ValueType' => 'Date',
|
||||
'Content' => '2016-02-02 01:00:59',
|
||||
'ValueRegex' => '',
|
||||
},
|
||||
],
|
||||
IsArray => 1, # (optional) Item is part of the array
|
||||
IsHash => 1, # (optional) Item is part of the hash
|
||||
SkipEffectiveValueCheck => 1, # (optional) If enabled, system will not perform effective value check.
|
||||
# Default: 1.
|
||||
UserID => 1, # (required) UserID
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$SettingHTML = '<div class "Field"...</div>';
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingRender {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(Name UserID)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{Class} .= ' DateTime';
|
||||
$Param{DefaultValue} //= '';
|
||||
|
||||
my $IDSuffix = $Param{IDSuffix} || '';
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
|
||||
my $EffectiveValue = $Param{EffectiveValue};
|
||||
if (
|
||||
!defined $EffectiveValue
|
||||
&& $Param{Item}
|
||||
&& $Param{Item}->[0]->{Content}
|
||||
)
|
||||
{
|
||||
$EffectiveValue = $Param{Item}->[0]->{Content};
|
||||
}
|
||||
|
||||
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
|
||||
|
||||
# Check if there is Datepicker before we add it.
|
||||
my $HasDatepicker = $LayoutObject->{HasDatepicker};
|
||||
|
||||
my $Name = $Param{Name} . $IDSuffix;
|
||||
|
||||
my %EffectiveValueCheck = (
|
||||
Success => 1,
|
||||
);
|
||||
|
||||
if ( !$Param{SkipEffectiveValueCheck} ) {
|
||||
%EffectiveValueCheck = $Self->SettingEffectiveValueCheck(
|
||||
EffectiveValue => $EffectiveValue,
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
Item => $Param{Item},
|
||||
},
|
||||
],
|
||||
},
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
}
|
||||
|
||||
my $TimeZone = $Kernel::OM->Get('Kernel::Config')->Get("OTRSTimeZone");
|
||||
|
||||
my $DateTimeObject = $Kernel::OM->Create(
|
||||
'Kernel::System::DateTime',
|
||||
ObjectParams => {
|
||||
String => $EffectiveValue,
|
||||
TimeZone => $TimeZone,
|
||||
},
|
||||
);
|
||||
|
||||
my %Preferences = $Kernel::OM->Get('Kernel::System::User')->GetPreferences(
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
if ( $Preferences{UserTimeZone} ) {
|
||||
my $Success = $DateTimeObject->ToTimeZone(
|
||||
TimeZone => $Preferences{UserTimeZone},
|
||||
);
|
||||
$TimeZone = $Preferences{UserTimeZone};
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "System was not able to calculate DateTime in user timezone!"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
my @Date = split m{-|\s|:}, $DateTimeObject->ToString();
|
||||
|
||||
my $HTML = "<div class='SettingContent'>\n";
|
||||
$HTML .= $LayoutObject->BuildDateSelection(
|
||||
Prefix => $Name,
|
||||
$Name . "Class" => $Param{Class},
|
||||
$Name . "Year" => $Date[0],
|
||||
$Name . "Month" => $Date[1],
|
||||
$Name . "Day" => $Date[2],
|
||||
$Name . "Hour" => $Date[3],
|
||||
$Name . "Minute" => $Date[4],
|
||||
$Name . "Second" => $Date[5],
|
||||
YearDiff => 10,
|
||||
Format => 'DateInputFormatLong',
|
||||
Validate => 1,
|
||||
Disabled => $Param{RW} ? 0 : 1,
|
||||
OverrideTimeZone => 1,
|
||||
);
|
||||
|
||||
my $TimeZoneText = $Kernel::OM->Get('Kernel::Language')->Translate("Time Zone");
|
||||
$HTML .= "<span class='TimeZoneText'>$TimeZoneText: $TimeZone</span>\n";
|
||||
|
||||
if ( !$EffectiveValueCheck{Success} ) {
|
||||
my $Message = $LanguageObject->Translate("Value is not correct! Please, consider updating this field.");
|
||||
|
||||
$HTML .= $Param{IsValid} ? "<div class='BadEffectiveValue'>\n" : "<div>\n";
|
||||
$HTML .= "<p>* $Message</p>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
$HTML .= "</div>\n";
|
||||
|
||||
if ( !$Param{IsArray} && !$Param{IsHash} ) {
|
||||
my $DefaultText = $Kernel::OM->Get('Kernel::Language')->Translate('Default');
|
||||
|
||||
$HTML .= <<"EOF";
|
||||
<div class=\"WidgetMessage Bottom\">
|
||||
$DefaultText: $Param{DefaultValue}
|
||||
</div>
|
||||
EOF
|
||||
}
|
||||
|
||||
if ( $Param{IsAjax} && $LayoutObject->{_JSOnDocumentComplete} && $Param{RW} ) {
|
||||
for my $JS ( @{ $LayoutObject->{_JSOnDocumentComplete} } ) {
|
||||
|
||||
$HTML .= "<script>$JS</script>";
|
||||
}
|
||||
}
|
||||
|
||||
if ( $Param{IsAjax} ) {
|
||||
|
||||
# Remove JS generated in BuildDateSelection() call (setting is disabled or it's already sent together with HTML).
|
||||
# It also prevents multiple Datepicker initializations (if there are several on the page).
|
||||
pop @{ $LayoutObject->{_JSOnDocumentComplete} };
|
||||
|
||||
if ( !$HasDatepicker ) {
|
||||
my $VacationDays = $LayoutObject->DatepickerGetVacationDays();
|
||||
my $TextDirection = $LanguageObject->{TextDirection} || '';
|
||||
|
||||
my $JSONString = $Kernel::OM->Get('Kernel::System::JSON')->Encode(
|
||||
Data => {
|
||||
VacationDays => $VacationDays,
|
||||
IsRTL => ( $TextDirection eq 'rtl' ) ? 1 : 0,
|
||||
},
|
||||
);
|
||||
|
||||
$HTML .= "<script>
|
||||
Core.Config.Set('Datepicker', $JSONString);
|
||||
</script>";
|
||||
|
||||
# If there are several DateTime settings, don't run this block again.
|
||||
$LayoutObject->{HasDatepicker} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
=head2 AddItem()
|
||||
|
||||
Generate HTML for new array/hash item.
|
||||
|
||||
my $HTML = $ValueTypeObject->AddItem(
|
||||
Name => 'SettingName', (required) Name
|
||||
DefaultItem => { (optional) DefaultItem hash, if available
|
||||
Content => '2017-01-01 01:45:00',
|
||||
ValueType => 'DateTime',
|
||||
},
|
||||
IDSuffix => '_Array1', (optional) IDSuffix is needed for arrays and hashes.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$HTML = '<select class="Validate_DateMonth Date" id="SettingName_Array1Month" ...';
|
||||
|
||||
=cut
|
||||
|
||||
sub AddItem {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check needed stuff.
|
||||
for my $Needed (qw(Name)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $IDSuffix = $Param{IDSuffix} || '';
|
||||
my $Class = $Param{Class} || '';
|
||||
$Class .= ' DateTime Entry';
|
||||
|
||||
my $Name = $Param{Name} . $IDSuffix;
|
||||
|
||||
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
|
||||
my $TimeZone = $Kernel::OM->Get('Kernel::Config')->Get("OTRSTimeZone");
|
||||
|
||||
my %Preferences = $Kernel::OM->Get('Kernel::System::User')->GetPreferences(
|
||||
UserID => $Param{UserID},
|
||||
);
|
||||
|
||||
my $DefaultValue;
|
||||
if ( $Param{DefaultItem} ) {
|
||||
|
||||
my $DateTimeObject = $Kernel::OM->Create(
|
||||
'Kernel::System::DateTime',
|
||||
ObjectParams => {
|
||||
String => $Param{DefaultItem}->{Content},
|
||||
TimeZone => $TimeZone,
|
||||
},
|
||||
);
|
||||
|
||||
if ( $Preferences{UserTimeZone} ) {
|
||||
my $Success = $DateTimeObject->ToTimeZone(
|
||||
TimeZone => $Preferences{UserTimeZone},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "System was not able to calculate DateTime in user timezone!"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$DefaultValue = $DateTimeObject->ToString();
|
||||
}
|
||||
|
||||
if ( $Preferences{UserTimeZone} ) {
|
||||
$TimeZone = $Preferences{UserTimeZone};
|
||||
}
|
||||
|
||||
my $Result;
|
||||
|
||||
if ($DefaultValue) {
|
||||
$DefaultValue =~ m{(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2}):(\d{2})};
|
||||
|
||||
$Result = $LayoutObject->BuildDateSelection(
|
||||
Prefix => $Name,
|
||||
$Name . "Year" => $1,
|
||||
$Name . "Month" => $2,
|
||||
$Name . "Day" => $3,
|
||||
$Name . "Hour" => $4,
|
||||
$Name . "Minute" => $5,
|
||||
$Name . "Second" => $6,
|
||||
$Name . "Class" => $Class,
|
||||
YearDiff => 10,
|
||||
Format => 'DateInputFormatLong',
|
||||
Validate => 1,
|
||||
OverrideTimeZone => 1,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$Result = $LayoutObject->BuildDateSelection(
|
||||
Prefix => $Name,
|
||||
$Name . "Class" => $Class,
|
||||
YearDiff => 10,
|
||||
Format => 'DateInputFormatLong',
|
||||
Validate => 1,
|
||||
OverrideTimeZone => 1,
|
||||
);
|
||||
}
|
||||
|
||||
my $TimeZoneText = $Kernel::OM->Get('Kernel::Language')->Translate("Time Zone");
|
||||
$Result .= "<span class='TimeZoneText'>$TimeZoneText: $TimeZone</span>\n";
|
||||
|
||||
for my $JS ( @{ $LayoutObject->{_JSOnDocumentComplete} } ) {
|
||||
$Result .= "<script>$JS</script>";
|
||||
}
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
137
Perl OTRS/Kernel/System/SysConfig/ValueType/Directory.pm
Normal file
137
Perl OTRS/Kernel/System/SysConfig/ValueType/Directory.pm
Normal file
@@ -0,0 +1,137 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::Directory;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::Directory - System configuration directory value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::Directory');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingEffectiveValueCheck()
|
||||
|
||||
Check if provided EffectiveValue matches structure defined in XMLContentParsed.
|
||||
|
||||
my %Result = $ValueTypeObject->SettingEffectiveValueCheck(
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => '/etc',
|
||||
'ValueType' => 'Directory',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
EffectiveValue => '/etc',
|
||||
);
|
||||
|
||||
Result:
|
||||
%Result = (
|
||||
EffectiveValue => '/etc', # Note for Directory ValueTypes EffectiveValue is not changed.
|
||||
Success => 1,
|
||||
Error => undef,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingEffectiveValueCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(XMLContentParsed)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Result = (
|
||||
Success => 0,
|
||||
);
|
||||
|
||||
my $Value = $Param{XMLContentParsed}->{Value};
|
||||
|
||||
for my $Parameter ( sort keys %{ $Param{Parameters} } ) {
|
||||
if ( !defined $Value->[0]->{Item}->[0]->{$Parameter} ) {
|
||||
$Value->[0]->{Item}->[0]->{$Parameter} = $Param{Parameters}->{$Parameter};
|
||||
}
|
||||
}
|
||||
|
||||
# Data should be scalar.
|
||||
if ( ref $Param{EffectiveValue} ) {
|
||||
$Result{Error} = 'EffectiveValue for Directory must be a scalar!';
|
||||
return %Result;
|
||||
}
|
||||
|
||||
if ( !-e $Param{EffectiveValue} ) {
|
||||
$Result{Error} = "$Param{EffectiveValue} not exists!";
|
||||
return %Result;
|
||||
}
|
||||
|
||||
my $IsDirectory = -d $Param{EffectiveValue};
|
||||
|
||||
if ( !$IsDirectory ) {
|
||||
$Result{Error} = "$Param{EffectiveValue} is not directory!";
|
||||
return %Result;
|
||||
}
|
||||
|
||||
$Result{Success} = 1;
|
||||
$Result{EffectiveValue} = $Param{EffectiveValue};
|
||||
|
||||
return %Result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
471
Perl OTRS/Kernel/System/SysConfig/ValueType/Entity.pm
Normal file
471
Perl OTRS/Kernel/System/SysConfig/ValueType/Entity.pm
Normal file
@@ -0,0 +1,471 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::Entity;
|
||||
## nofilter(TidyAll::Plugin::OTRS::Perl::LayoutObject)
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Language',
|
||||
'Kernel::Output::HTML::Layout',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Main',
|
||||
'Kernel::System::SysConfig::EntityType',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::Entity - System configuration entity value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::Entity');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingEffectiveValueCheck()
|
||||
|
||||
Check if provided EffectiveValue matches structure defined in XMLContentParsed.
|
||||
|
||||
my %Result = $ValueTypeObject->SettingEffectiveValueCheck(
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => '3 - normal',
|
||||
'ValueEntityType' => 'Priority',
|
||||
'ValueEntitySubType' => 'SomeSubType',
|
||||
'ValueType' => 'Entity',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
EffectiveValue => '2 - low',
|
||||
);
|
||||
|
||||
Result:
|
||||
$Result = (
|
||||
EffectiveValue => '2 - low', # Note for Entity ValueTypes EffectiveValue is not changed.
|
||||
Success => 1,
|
||||
Error => undef,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingEffectiveValueCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for (qw(XMLContentParsed)) {
|
||||
if ( !$Param{$_} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $_!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Result = (
|
||||
Success => 0,
|
||||
);
|
||||
|
||||
# Data should be scalar.
|
||||
if ( ref $Param{EffectiveValue} ) {
|
||||
$Result{Error} = 'EffectiveValue for Entity must be scalar!';
|
||||
return %Result;
|
||||
}
|
||||
|
||||
my $Value = $Param{XMLContentParsed}->{Value};
|
||||
|
||||
for my $Parameter ( sort keys %{ $Param{Parameters} } ) {
|
||||
if ( !defined $Value->[0]->{Item}->[0]->{$Parameter} ) {
|
||||
$Value->[0]->{Item}->[0]->{$Parameter} = $Param{Parameters}->{$Parameter};
|
||||
}
|
||||
}
|
||||
|
||||
my $EntityType = $Value->[0]->{Item}->[0]->{ValueEntityType};
|
||||
|
||||
if ( !$EntityType ) {
|
||||
$Result{Error} = 'ValueEntityType not provided!';
|
||||
return %Result;
|
||||
}
|
||||
|
||||
my $EntitySubType = $Value->[0]->{Item}->[0]->{ValueEntitySubType} || '';
|
||||
|
||||
my @ValidValues = $Self->EntityValueList(
|
||||
EntityType => $EntityType,
|
||||
EntitySubType => $EntitySubType,
|
||||
);
|
||||
|
||||
if ( !grep { $_ eq $Param{EffectiveValue} } @ValidValues ) {
|
||||
$Result{Error} = "Entity value is invalid($Param{EffectiveValue})!";
|
||||
return %Result;
|
||||
}
|
||||
|
||||
$Result{Success} = 1;
|
||||
$Result{EffectiveValue} = $Param{EffectiveValue};
|
||||
|
||||
return %Result;
|
||||
}
|
||||
|
||||
=head2 EntityValueList()
|
||||
|
||||
Returns a list of valid values for provided EntityType.
|
||||
|
||||
my $Result = $ValueTypeObject->EntityValueList(
|
||||
EntityType => 'Priority',
|
||||
EntitySubType => 'SomeSubtype', # optional e.g. the ObjectType for DynamicField entities
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Result = [
|
||||
'1 very low',
|
||||
'2 low',
|
||||
'3 medium',
|
||||
'4 high',
|
||||
'5 very high',
|
||||
];
|
||||
|
||||
=cut
|
||||
|
||||
sub EntityValueList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(EntityType)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $Loaded = $Kernel::OM->Get('Kernel::System::Main')->Require(
|
||||
"Kernel::System::SysConfig::ValueType::Entity::$Param{EntityType}",
|
||||
);
|
||||
|
||||
return [] if !$Loaded;
|
||||
|
||||
my $BackendObject = $Kernel::OM->Get(
|
||||
"Kernel::System::SysConfig::ValueType::Entity::$Param{EntityType}",
|
||||
);
|
||||
|
||||
return $BackendObject->EntityValueList(%Param);
|
||||
}
|
||||
|
||||
=head2 SettingRender()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $SettingHTML = $ValueTypeObject->SettingRender(
|
||||
Name => 'SettingName',
|
||||
EffectiveValue => '3 medium', # (optional)
|
||||
DefaultValue => '3 medium', # (optional)
|
||||
Class => 'My class' # (optional)
|
||||
RW => 1, # (optional) Allow editing. Default 0.
|
||||
Item => [ # (optional) XML parsed item
|
||||
{
|
||||
'ValueType' => 'Entity',
|
||||
'ValueEntityType' => 'Priority',
|
||||
'ValueEntitySubType' => 'SomeSubType',
|
||||
'Content' => '2 low',
|
||||
},
|
||||
],
|
||||
IsArray => 1, # (optional) Item is part of the array
|
||||
IsHash => 1, # (optional) Item is part of the hash
|
||||
SkipEffectiveValueCheck => 1, # (optional) If enabled, system will not perform effective value check.
|
||||
# Default: 1.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$SettingHTML = '<div class "Field"...</div>';
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingRender {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !defined $Param{Name} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need Name",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{DefaultValue} //= '';
|
||||
$Param{IDSuffix} //= '';
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
|
||||
my $Value = $Param{Value};
|
||||
|
||||
my $EntityType;
|
||||
my $EntitySubType;
|
||||
|
||||
my $EffectiveValue = $Param{EffectiveValue};
|
||||
if (
|
||||
!defined $EffectiveValue
|
||||
&& $Param{Item}->[0]->{Content}
|
||||
)
|
||||
{
|
||||
$EffectiveValue = $Param{Item}->[0]->{Content};
|
||||
}
|
||||
|
||||
if (
|
||||
$Param{Item}
|
||||
&& $Param{Item}->[0]->{ValueEntityType}
|
||||
)
|
||||
{
|
||||
$EntityType = $Param{Item}->[0]->{ValueEntityType};
|
||||
$EntitySubType = $Param{Item}->[0]->{ValueEntitySubType} || '';
|
||||
}
|
||||
elsif (
|
||||
$Value->[0]->{Item}
|
||||
&& $Value->[0]->{Item}->[0]->{ValueEntityType}
|
||||
)
|
||||
{
|
||||
$EntityType = $Value->[0]->{Item}->[0]->{ValueEntityType};
|
||||
$EntitySubType = $Value->[0]->{Item}->[0]->{ValueEntitySubType} || '';
|
||||
}
|
||||
elsif ( $Value->[0]->{Array} ) {
|
||||
$EntityType = $Value->[0]->{Array}->[0]->{DefaultItem}->[0]->{ValueEntityType};
|
||||
$EntitySubType = $Value->[0]->{Array}->[0]->{DefaultItem}->[0]->{ValueEntitySubType} || '';
|
||||
}
|
||||
elsif ( $Value->[0]->{Hash} ) {
|
||||
if (
|
||||
$Value->[0]->{Hash}->[0]->{DefaultItem}
|
||||
&& $Value->[0]->{Hash}->[0]->{DefaultItem}->[0]->{ValueEntityType}
|
||||
)
|
||||
{
|
||||
|
||||
# take ValueEntityType from DefaultItem
|
||||
$EntityType = $Value->[0]->{Hash}->[0]->{DefaultItem}->[0]->{ValueEntityType};
|
||||
$EntitySubType = $Value->[0]->{Hash}->[0]->{DefaultItem}->[0]->{ValueEntitySubType} || '';
|
||||
}
|
||||
else {
|
||||
# check if there is definition for certain key
|
||||
ITEM:
|
||||
for my $Item ( @{ $Value->[0]->{Hash}->[0]->{Item} } ) {
|
||||
if ( $Item->{Key} eq $Param{Key} ) {
|
||||
$EntityType = $Item->{ValueEntityType} || '';
|
||||
$EntitySubType = $Item->{ValueEntitySubType} || '';
|
||||
last ITEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my @EntityValues = $Self->EntityValueList(
|
||||
EntityType => $EntityType,
|
||||
EntitySubType => $EntitySubType,
|
||||
);
|
||||
|
||||
# When displaying diff between current and old value, it can happen that value is missing
|
||||
# since it was renamed, or removed. In this case, we need to add this "old" value also.
|
||||
if (
|
||||
$EffectiveValue
|
||||
&& !grep { $_ eq $EffectiveValue } @EntityValues
|
||||
)
|
||||
{
|
||||
push @EntityValues, $EffectiveValue;
|
||||
}
|
||||
|
||||
my %EffectiveValueCheck = (
|
||||
Success => 1,
|
||||
);
|
||||
|
||||
if ( !$Param{SkipEffectiveValueCheck} ) {
|
||||
%EffectiveValueCheck = $Self->SettingEffectiveValueCheck(
|
||||
EffectiveValue => $EffectiveValue,
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
Item => $Param{Item},
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
my $HTML = "<div class='SettingContent'>\n";
|
||||
$HTML .= $Kernel::OM->Get('Kernel::Output::HTML::Layout')->BuildSelection(
|
||||
Data => \@EntityValues,
|
||||
Name => $Param{Name},
|
||||
ID => $Param{Name} . $Param{IDSuffix},
|
||||
Disabled => $Param{RW} ? 0 : 1,
|
||||
SelectedValue => $EffectiveValue,
|
||||
Title => $Param{Name},
|
||||
OptionTitle => 1,
|
||||
Class => "$Param{Class} Modernize",
|
||||
);
|
||||
|
||||
if ( !$EffectiveValueCheck{Success} ) {
|
||||
my $Message = $LanguageObject->Translate("Value is not correct! Please, consider updating this field.");
|
||||
|
||||
$HTML .= $Param{IsValid} ? "<div class='BadEffectiveValue'>\n" : "<div>\n";
|
||||
$HTML .= "<p>* $Message</p>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
$HTML .= "</div>\n";
|
||||
|
||||
if ( !$Param{IsArray} && !$Param{IsHash} ) {
|
||||
my $DefaultText = $LanguageObject->Translate('Default');
|
||||
|
||||
$HTML .= <<"EOF";
|
||||
<div class=\"WidgetMessage Bottom\">
|
||||
$DefaultText: $Param{DefaultValue}
|
||||
</div>
|
||||
EOF
|
||||
}
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
=head2 AddItem()
|
||||
|
||||
Generate HTML for new array/hash item.
|
||||
|
||||
my $HTML = $ValueTypeObject->AddItem(
|
||||
Name => 'SettingName', (required) Name
|
||||
DefaultItem => { (required) DefaultItem hash
|
||||
'Content' => '3 normal',
|
||||
'ValueType' => 'Entity',
|
||||
'ValueEntityType' => 'Priority',
|
||||
'ValueEntitySubType' => 'SomeSubType',
|
||||
},
|
||||
IDSuffix => '_Array1', (optional) IDSuffix is needed for arrays and hashes.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$HTML = '<select class="Modernize" id="SettingName" name="SettingName" title="SettingName">
|
||||
...
|
||||
</select>';
|
||||
|
||||
=cut
|
||||
|
||||
sub AddItem {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check needed stuff.
|
||||
for my $Needed (qw(Name DefaultItem)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{IDSuffix} //= '';
|
||||
|
||||
my @EntityValues = $Self->EntityValueList(
|
||||
EntityType => $Param{DefaultItem}->{ValueEntityType},
|
||||
EntitySubType => $Param{DefaultItem}->{ValueEntitySubType} || '',
|
||||
);
|
||||
|
||||
my $Result = $Kernel::OM->Get('Kernel::Output::HTML::Layout')->BuildSelection(
|
||||
Data => \@EntityValues,
|
||||
Name => $Param{Name},
|
||||
ID => $Param{Name} . $Param{IDSuffix},
|
||||
SelectedValue => $Param{DefaultItem}->{Content},
|
||||
Title => $Param{Name},
|
||||
OptionTitle => 1,
|
||||
Class => "$Param{Class} Modernize Entry",
|
||||
);
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
=head2 EntityLookupFromWebRequest()
|
||||
|
||||
Gets the entity name from the web request
|
||||
|
||||
Called URL: index.pl?Action=AdminQueue;Subaction=Change;QueueID=1
|
||||
|
||||
my $EntityName = $ValueTypeObject->EntityLookupFromWebRequest(
|
||||
EntityType => 'Queue',
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$EntityName = 'Postmaster';
|
||||
|
||||
=cut
|
||||
|
||||
sub EntityLookupFromWebRequest {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(EntityType)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $Loaded = $Kernel::OM->Get('Kernel::System::Main')->Require(
|
||||
"Kernel::System::SysConfig::ValueType::Entity::$Param{EntityType}",
|
||||
);
|
||||
|
||||
return if !$Loaded;
|
||||
|
||||
my $BackendObject = $Kernel::OM->Get(
|
||||
"Kernel::System::SysConfig::ValueType::Entity::$Param{EntityType}",
|
||||
);
|
||||
|
||||
return if !$BackendObject->can('EntityLookupFromWebRequest');
|
||||
|
||||
return $BackendObject->EntityLookupFromWebRequest();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,93 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::Entity::DynamicField;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::ValueType::Entity);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::DynamicField',
|
||||
'Kernel::System::Web::Request',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::Entity::DynamicField - System configuration dynamic-field entity type backend.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $EntityTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::Entity::DynamicField');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
sub EntityValueList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $DynamicFields = $Kernel::OM->Get('Kernel::System::DynamicField')->DynamicFieldList(
|
||||
ObjectType => $Param{EntitySubType} || '',
|
||||
ResultType => 'HASH',
|
||||
Valid => 1,
|
||||
);
|
||||
|
||||
my @Result;
|
||||
|
||||
for my $ID ( sort keys %{$DynamicFields} ) {
|
||||
push @Result, $DynamicFields->{$ID};
|
||||
}
|
||||
|
||||
return @Result;
|
||||
}
|
||||
|
||||
sub EntityLookupFromWebRequest {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $DynamicFieldID = $Kernel::OM->Get('Kernel::System::Web::Request')->GetParam( Param => 'ID' ) // '';
|
||||
|
||||
return if !$DynamicFieldID;
|
||||
|
||||
my $DynamicField = $Kernel::OM->Get('Kernel::System::DynamicField')->DynamicFieldGet(
|
||||
ID => $DynamicFieldID,
|
||||
);
|
||||
|
||||
return if !IsHashRefWithData($DynamicField);
|
||||
|
||||
return $DynamicField->{Name} || '';
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,85 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::Entity::Priority;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::ValueType::Entity);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Priority',
|
||||
'Kernel::System::Web::Request',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::Entity::Priority - System configuration priority entity type backend.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $EntityTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::Entity::Priority');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
sub EntityValueList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my %Priorities = $Kernel::OM->Get('Kernel::System::Priority')->PriorityList(
|
||||
Valid => 1,
|
||||
);
|
||||
|
||||
my @Result;
|
||||
|
||||
for my $ID ( sort keys %Priorities ) {
|
||||
push @Result, $Priorities{$ID};
|
||||
}
|
||||
|
||||
return @Result;
|
||||
}
|
||||
|
||||
sub EntityLookupFromWebRequest {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $PriorityID = $Kernel::OM->Get('Kernel::System::Web::Request')->GetParam( Param => 'PriorityID' ) // '';
|
||||
|
||||
return if !$PriorityID;
|
||||
|
||||
return $Kernel::OM->Get('Kernel::System::Priority')->PriorityLookup( PriorityID => $PriorityID );
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
85
Perl OTRS/Kernel/System/SysConfig/ValueType/Entity/Queue.pm
Normal file
85
Perl OTRS/Kernel/System/SysConfig/ValueType/Entity/Queue.pm
Normal file
@@ -0,0 +1,85 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::Entity::Queue;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::ValueType::Entity);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Queue',
|
||||
'Kernel::System::Web::Request',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::Entity::Queue - System configuration queue entity type backend.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $EntityTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::Entity::Queue');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
sub EntityValueList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my %Queues = $Kernel::OM->Get('Kernel::System::Queue')->QueueList(
|
||||
Valid => 1,
|
||||
);
|
||||
|
||||
my @Result;
|
||||
|
||||
for my $ID ( sort keys %Queues ) {
|
||||
push @Result, $Queues{$ID};
|
||||
}
|
||||
|
||||
return @Result;
|
||||
}
|
||||
|
||||
sub EntityLookupFromWebRequest {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $QueueID = $Kernel::OM->Get('Kernel::System::Web::Request')->GetParam( Param => 'QueueID' ) // '';
|
||||
|
||||
return if !$QueueID;
|
||||
|
||||
return $Kernel::OM->Get('Kernel::System::Queue')->QueueLookup( QueueID => $QueueID );
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
86
Perl OTRS/Kernel/System/SysConfig/ValueType/Entity/State.pm
Normal file
86
Perl OTRS/Kernel/System/SysConfig/ValueType/Entity/State.pm
Normal file
@@ -0,0 +1,86 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::Entity::State;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::ValueType::Entity);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::State',
|
||||
'Kernel::System::Web::Request',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::Entity::State - System configuration state entity type backend.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $EntityTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::Entity::State');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
sub EntityValueList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my %States = $Kernel::OM->Get('Kernel::System::State')->StateList(
|
||||
Valid => 1,
|
||||
UserID => 1,
|
||||
);
|
||||
|
||||
my @Result;
|
||||
|
||||
for my $ID ( sort keys %States ) {
|
||||
push @Result, $States{$ID};
|
||||
}
|
||||
|
||||
return @Result;
|
||||
}
|
||||
|
||||
sub EntityLookupFromWebRequest {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $StateID = $Kernel::OM->Get('Kernel::System::Web::Request')->GetParam( Param => 'ID' ) // '';
|
||||
|
||||
return if !$StateID;
|
||||
|
||||
return $Kernel::OM->Get('Kernel::System::State')->StateLookup( StateID => $StateID );
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
85
Perl OTRS/Kernel/System/SysConfig/ValueType/Entity/Type.pm
Normal file
85
Perl OTRS/Kernel/System/SysConfig/ValueType/Entity/Type.pm
Normal file
@@ -0,0 +1,85 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::Entity::Type;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::ValueType::Entity);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Type',
|
||||
'Kernel::System::Web::Request',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::Entity::Type - System configuration ticket type entity type backend.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $EntityTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::Entity::Type');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
sub EntityValueList {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my %Types = $Kernel::OM->Get('Kernel::System::Type')->TypeList(
|
||||
Valid => 1,
|
||||
);
|
||||
|
||||
my @Result;
|
||||
|
||||
for my $ID ( sort keys %Types ) {
|
||||
push @Result, $Types{$ID};
|
||||
}
|
||||
|
||||
return @Result;
|
||||
}
|
||||
|
||||
sub EntityLookupFromWebRequest {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $TypeID = $Kernel::OM->Get('Kernel::System::Web::Request')->GetParam( Param => 'ID' ) // '';
|
||||
|
||||
return if !$TypeID;
|
||||
|
||||
return $Kernel::OM->Get('Kernel::System::Type')->TypeLookup( TypeID => $TypeID );
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
137
Perl OTRS/Kernel/System/SysConfig/ValueType/File.pm
Normal file
137
Perl OTRS/Kernel/System/SysConfig/ValueType/File.pm
Normal file
@@ -0,0 +1,137 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::File;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::File - System configuration file value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::File');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingEffectiveValueCheck()
|
||||
|
||||
Check if provided EffectiveValue matches structure defined in XMLContentParsed.
|
||||
|
||||
my %Result = $ValueTypeObject->SettingEffectiveValueCheck(
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => '/etc/hosts',
|
||||
'ValueType' => 'File',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
EffectiveValue => '/etc/hosts',
|
||||
);
|
||||
|
||||
Result:
|
||||
%Result = (
|
||||
EffectiveValue => '/etc/hosts', # Note for File ValueTypes EffectiveValue is not changed.
|
||||
Success => 1,
|
||||
Error => undef,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingEffectiveValueCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(XMLContentParsed)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Result = (
|
||||
Success => 0,
|
||||
);
|
||||
|
||||
my $Value = $Param{XMLContentParsed}->{Value};
|
||||
|
||||
for my $Parameter ( sort keys %{ $Param{Parameters} } ) {
|
||||
if ( !defined $Value->[0]->{Item}->[0]->{$Parameter} ) {
|
||||
$Value->[0]->{Item}->[0]->{$Parameter} = $Param{Parameters}->{$Parameter};
|
||||
}
|
||||
}
|
||||
|
||||
# Data should be scalar.
|
||||
if ( ref $Param{EffectiveValue} ) {
|
||||
$Result{Error} = 'EffectiveValue for File must be a scalar!';
|
||||
return %Result;
|
||||
}
|
||||
|
||||
if ( !-e $Param{EffectiveValue} ) {
|
||||
$Result{Error} = "$Param{EffectiveValue} not exists!";
|
||||
return %Result;
|
||||
}
|
||||
|
||||
my $IsDirectory = -d $Param{EffectiveValue};
|
||||
|
||||
if ($IsDirectory) {
|
||||
$Result{Error} = "$Param{EffectiveValue} is directory, but file is expected!";
|
||||
return %Result;
|
||||
}
|
||||
|
||||
$Result{Success} = 1;
|
||||
$Result{EffectiveValue} = $Param{EffectiveValue};
|
||||
|
||||
return %Result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,557 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
## nofilter(TidyAll::Plugin::OTRS::Perl::LayoutObject)
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::FrontendNavigation;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Language',
|
||||
'Kernel::Output::HTML::Layout',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::FrontendNavigation - System configuration frontend navigation value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::FrontendNavigation');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
my @RequiredKeys = (
|
||||
'Name',
|
||||
'Description',
|
||||
'Link',
|
||||
'NavBar',
|
||||
);
|
||||
$Self->{RequiredKeys} = \@RequiredKeys;
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingEffectiveValueCheck()
|
||||
|
||||
Check if provided EffectiveValue matches structure defined in XMLContentParsed.
|
||||
|
||||
my %Result = $ValueTypeObject->SettingEffectiveValueCheck(
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
...
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
EffectiveValue => {
|
||||
...
|
||||
},
|
||||
);
|
||||
|
||||
Result:
|
||||
%Result = (
|
||||
EffectiveValue => { # Note for FrontendNavigation ValueTypes EffectiveValue is not changed.
|
||||
...
|
||||
},
|
||||
Success => 1,
|
||||
Error => undef,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingEffectiveValueCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(XMLContentParsed)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Result = (
|
||||
Success => 0,
|
||||
);
|
||||
|
||||
if ( !IsHashRefWithData( $Param{EffectiveValue} ) ) {
|
||||
$Result{Error} = "FrontendNavigation EffectiveValue must be a hash!";
|
||||
return %Result;
|
||||
}
|
||||
|
||||
KEY:
|
||||
for my $Key (qw(NavBar Link Name Description)) {
|
||||
if ( !defined $Param{EffectiveValue}->{$Key} ) {
|
||||
$Result{Error} = "FrontendNavigation must contain $Key!";
|
||||
last KEY;
|
||||
}
|
||||
}
|
||||
|
||||
return %Result if $Result{Error};
|
||||
|
||||
$Result{Success} = 1;
|
||||
$Result{EffectiveValue} = $Param{EffectiveValue};
|
||||
|
||||
return %Result;
|
||||
}
|
||||
|
||||
=head2 EffectiveValueGet()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $EffectiveValue = $ValueTypeObject->EffectiveValueGet(
|
||||
Value => [
|
||||
{
|
||||
ValueRegex => '', # optional
|
||||
Content => 'TheEffectiveValue',
|
||||
ValueType => 'AValueType', # optional
|
||||
# ...
|
||||
}
|
||||
],
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$EffectiveValue = 'TheEffectiveValue';
|
||||
|
||||
=cut
|
||||
|
||||
sub EffectiveValueGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !IsArrayRefWithData( $Param{Value} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Value is missing or invalid!",
|
||||
);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( scalar @{ $Param{Value} } > 1 ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Value must be a single element!",
|
||||
);
|
||||
return '';
|
||||
}
|
||||
|
||||
return if ( !$Param{Value}->[0]->{Hash} );
|
||||
return if ( !$Param{Value}->[0]->{Hash}->[0] );
|
||||
return if ( !$Param{Value}->[0]->{Hash}->[0]->{Item} );
|
||||
|
||||
my $EffectiveValue;
|
||||
|
||||
for my $Item ( @{ $Param{Value}->[0]->{Hash}->[0]->{Item} } ) {
|
||||
|
||||
if ( grep { $Item->{Key} eq $_ } qw(Group GroupRo) ) {
|
||||
|
||||
# contains array
|
||||
|
||||
if ( $Item->{Array} ) {
|
||||
my @Array = ();
|
||||
|
||||
if (
|
||||
$Item->{Array}
|
||||
&& $Item->{Array}->[0]->{Item}
|
||||
)
|
||||
{
|
||||
for my $ArrayItem ( @{ $Item->{Array}->[0]->{Item} } ) {
|
||||
push @Array, $ArrayItem->{Content} || '';
|
||||
}
|
||||
}
|
||||
$EffectiveValue->{ $Item->{Key} } = \@Array;
|
||||
}
|
||||
}
|
||||
else {
|
||||
# contains value
|
||||
$EffectiveValue->{ $Item->{Key} } = $Item->{Content} || '';
|
||||
}
|
||||
}
|
||||
|
||||
# Set undefined group attributes.
|
||||
for my $Group (qw(Group GroupRo)) {
|
||||
if ( !defined $EffectiveValue->{$Group} ) {
|
||||
$EffectiveValue->{$Group} = [];
|
||||
}
|
||||
}
|
||||
|
||||
return $EffectiveValue;
|
||||
}
|
||||
|
||||
=head2 SettingRender()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $SettingHTML = $ValueTypeObject->SettingRender(
|
||||
Name => 'SettingName',
|
||||
DefaultID => 123, # (required)
|
||||
EffectiveValue => '2016-02-02',
|
||||
DefaultValue => 'Product 5', # (optional)
|
||||
Class => 'My class' # (optional)
|
||||
RW => 1, # (optional) Allow editing. Default 0.
|
||||
Item => [ # (optional) XML parsed item
|
||||
{
|
||||
'ValueType' => 'FrontendNavigation',
|
||||
'Content' => '2016-02-02',
|
||||
'ValueRegex' => '',
|
||||
},
|
||||
],
|
||||
IsArray => 1, # (optional) Item is part of the array
|
||||
IsHash => 1, # (optional) Item is part of the hash
|
||||
IDSuffix => 1, # (optional) Suffix will be added to the element ID
|
||||
SkipEffectiveValueCheck => 1, # (optional) If enabled, system will not perform effective value check.
|
||||
# Default: 1.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$SettingHTML = '<div class "Field"...</div>';
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingRender {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(Name EffectiveValue)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{DefaultValue} //= '';
|
||||
$Param{IDSuffix} //= '';
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
|
||||
|
||||
my $EffectiveValue = $Param{EffectiveValue} // '';
|
||||
|
||||
if ( !IsHashRefWithData($EffectiveValue) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "EffectiveValue must be a hash!"
|
||||
);
|
||||
return '';
|
||||
}
|
||||
|
||||
# Set undefined group attributes.
|
||||
for my $Group (qw(Group GroupRo)) {
|
||||
if ( !defined $EffectiveValue->{$Group} ) {
|
||||
$EffectiveValue->{$Group} = [];
|
||||
}
|
||||
}
|
||||
|
||||
my %EffectiveValueCheck = (
|
||||
Success => 1,
|
||||
);
|
||||
|
||||
if ( !$Param{SkipEffectiveValueCheck} ) {
|
||||
%EffectiveValueCheck = $Self->SettingEffectiveValueCheck(
|
||||
EffectiveValue => $EffectiveValue,
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
Item => $Param{Item},
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
my $HTML = "<div class='Hash'>\n";
|
||||
|
||||
if ( !$EffectiveValueCheck{Success} ) {
|
||||
my $Message = $LanguageObject->Translate("Value is not correct! Please, consider updating this module.");
|
||||
|
||||
$HTML .= $Param{IsValid} ? "<div class='BadEffectiveValue'>\n" : "<div>\n";
|
||||
$HTML .= "<p>* $Message</p>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
my $AddNewEntry = $LanguageObject->Translate("Add new entry");
|
||||
my $RemoveThisEntry = $LanguageObject->Translate("Remove this entry");
|
||||
my $RequiredText = $LanguageObject->Translate("This field is required.");
|
||||
|
||||
my $Readonly = '';
|
||||
if ( !$Param{RW} ) {
|
||||
$Readonly = "readonly='readonly'";
|
||||
}
|
||||
for my $Key ( sort keys %{$EffectiveValue} ) {
|
||||
|
||||
my $IsRequired = grep { $_ eq $Key } @{ $Self->{RequiredKeys} };
|
||||
|
||||
$HTML .= "<div class='HashItem'>\n";
|
||||
$HTML .= "<input type='text' value='$Key' readonly='readonly' class='Key' />\n";
|
||||
$HTML .= "<div class='SettingContent'>\n";
|
||||
|
||||
if ( grep { $Key eq $_ } qw (Group GroupRo) ) {
|
||||
$HTML .= "<div class='Array'>\n";
|
||||
|
||||
my $GroupIndex = 1;
|
||||
for my $GroupItem ( @{ $EffectiveValue->{$Key} } ) {
|
||||
|
||||
my $HTMLGroupItem = $LayoutObject->Ascii2Html(
|
||||
Text => $GroupItem,
|
||||
Type => 'Normal',
|
||||
);
|
||||
|
||||
$HTML .= "<div class='ArrayItem'>\n";
|
||||
$HTML .= "<div class='SettingContent'>\n";
|
||||
$HTML .= "<input type=\"text\" value=\"$HTMLGroupItem\" $Readonly"
|
||||
. "id=\"$Param{Name}$Param{IDSuffix}_Hash###$Key\_Array$GroupIndex\" />\n";
|
||||
$HTML .= "</div>\n";
|
||||
|
||||
if ( $Param{RW} ) {
|
||||
$HTML .= "<button class='RemoveButton' type='button' "
|
||||
. "title='$RemoveThisEntry' value='Remove this entry'>\n"
|
||||
. " <i class='fa fa-minus-circle'></i>\n"
|
||||
. " <span class='InvisibleText'>$RemoveThisEntry</span>\n"
|
||||
. "</button>\n";
|
||||
}
|
||||
|
||||
$HTML .= "</div>\n";
|
||||
|
||||
$GroupIndex++;
|
||||
}
|
||||
|
||||
my $ButtonClass = 'AddArrayItem';
|
||||
if ( !$Param{RW} ) {
|
||||
$ButtonClass .= " Hidden";
|
||||
}
|
||||
|
||||
$HTML
|
||||
.= " <button data-suffix='$Param{Name}$Param{IDSuffix}_Hash###$Key\_Array$GroupIndex' class='$ButtonClass' "
|
||||
. "type='button' title='$AddNewEntry' value='Add new entry'>\n"
|
||||
. " <i class='fa fa-plus-circle'></i>\n"
|
||||
. " <span class='InvisibleText'>$AddNewEntry</span>\n"
|
||||
. " </button>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
else {
|
||||
my $InputClass = '';
|
||||
if ($IsRequired) {
|
||||
$InputClass .= ' Validate_Required';
|
||||
}
|
||||
|
||||
my $HTMLValue = $LayoutObject->Ascii2Html(
|
||||
Text => $EffectiveValue->{$Key},
|
||||
Type => 'Normal',
|
||||
);
|
||||
|
||||
$HTML .= "<input type=\"text\" value=\"$HTMLValue\" Class=\"$InputClass\" $Readonly"
|
||||
. "id=\"$Param{Name}$Param{IDSuffix}_Hash###$Key\" />\n";
|
||||
|
||||
if ($IsRequired) {
|
||||
|
||||
$HTML .= "
|
||||
<div id=\"$Param{Name}$Param{IDSuffix}_Hash###${Key}Error\" class=\"TooltipErrorMessage\">
|
||||
<p>$RequiredText</p>
|
||||
</div>
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
$HTML .= "</div>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
$HTML .= "</div>\n";
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
=head2 AddItem()
|
||||
|
||||
Generate HTML for new array/hash item.
|
||||
|
||||
my $HTML = $ValueTypeObject->AddItem(
|
||||
Name => 'SettingName', (required) Name
|
||||
DefaultItem => { (required) DefaultItem hash
|
||||
Hash => {
|
||||
|
||||
},
|
||||
},
|
||||
IDSuffix => '_Array1', (optional) IDSuffix is needed for arrays and hashes.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$HTML = '<select class="Modernize" id="SettingName" name="SettingName" title="SettingName">
|
||||
...
|
||||
</select>';
|
||||
|
||||
=cut
|
||||
|
||||
sub AddItem {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check needed stuff.
|
||||
for my $Needed (qw(Name DefaultItem)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{DefaultValue} //= '';
|
||||
$Param{IDSuffix} //= '';
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
|
||||
my $HTML = "<div class='Hash FrontendNavigationHash'>\n";
|
||||
|
||||
my @Keys;
|
||||
|
||||
# Check if structure is defined in the XML DefaultItem.
|
||||
if ( $Param{DefaultItem}->{Hash}->[0]->{Item} ) {
|
||||
for my $Item ( @{ $Param{DefaultItem}->{Hash}->[0]->{Item} } ) {
|
||||
push @Keys, $Item->{Key};
|
||||
}
|
||||
}
|
||||
|
||||
if (@Keys) {
|
||||
|
||||
# Make sure that required keys are there.
|
||||
for my $RequiredKey ( @{ $Self->{RequiredKeys} } ) {
|
||||
if ( !grep { $_ eq $RequiredKey } @Keys ) {
|
||||
push @Keys, $RequiredKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
# Default keys.
|
||||
@Keys = (
|
||||
'Group',
|
||||
'GroupRo',
|
||||
'Description',
|
||||
'Name',
|
||||
'Link',
|
||||
'LinkOption',
|
||||
'NavBar',
|
||||
'Type',
|
||||
'Block',
|
||||
'AccessKey',
|
||||
'Prio',
|
||||
);
|
||||
}
|
||||
my $AddNewEntry = $LanguageObject->Translate("Add new entry");
|
||||
my $RequiredText = $LanguageObject->Translate("This field is required.");
|
||||
|
||||
for my $Key ( sort @Keys ) {
|
||||
my $IsRequired = grep { $_ eq $Key } @{ $Self->{RequiredKeys} };
|
||||
|
||||
$HTML .= "<div class='HashItem'>\n";
|
||||
$HTML .= "<input type='text' value='$Key' readonly='readonly' class='Key' />\n";
|
||||
$HTML .= "<div class='SettingContent'>\n";
|
||||
|
||||
if ( grep { $Key eq $_ } qw (Group GroupRo) ) {
|
||||
$HTML .= "<div class='Array'>\n";
|
||||
|
||||
# Add new item button.
|
||||
$HTML .= " <button data-suffix='$Param{Name}$Param{IDSuffix}_Hash###$Key\_Array0' class='AddArrayItem' "
|
||||
. "type='button' title='$AddNewEntry' value='Add new entry'>\n"
|
||||
. " <i class='fa fa-plus-circle'></i>\n"
|
||||
. " <span class='InvisibleText'>$AddNewEntry</span>\n"
|
||||
. " </button>\n";
|
||||
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
else {
|
||||
my $InputClass = '';
|
||||
if ($IsRequired) {
|
||||
$InputClass .= ' Validate_Required';
|
||||
}
|
||||
|
||||
$HTML .= "<input type='text' value='' "
|
||||
. "id='$Param{Name}$Param{IDSuffix}_Hash###$Key' Class='$InputClass' />\n";
|
||||
|
||||
if ($IsRequired) {
|
||||
|
||||
$HTML .= "
|
||||
<div id=\"$Param{Name}$Param{IDSuffix}_Hash###${Key}Error\" class=\"TooltipErrorMessage\">
|
||||
<p>$RequiredText</p>
|
||||
</div>
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
$HTML .= "</div>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
$HTML .= "</div>";
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
=head2 AddSettingContent()
|
||||
|
||||
Checks if a div with class 'SettingContent' should be added when adding new item to an array/hash in some special cases.
|
||||
|
||||
my $AddSettingContent = $ValueTypeObject->AddSettingContent();
|
||||
|
||||
Returns:
|
||||
|
||||
my $AddSettingContent = 0;
|
||||
|
||||
=cut
|
||||
|
||||
sub AddSettingContent {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,392 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
## nofilter(TidyAll::Plugin::OTRS::Perl::LayoutObject)
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::FrontendRegistration;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Language',
|
||||
'Kernel::Output::HTML::Layout',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::FrontendRegistration - System configuration frontend registration value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::FrontendRegistration');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingEffectiveValueCheck()
|
||||
|
||||
Check if provided EffectiveValue matches structure defined in XMLContentParsed.
|
||||
|
||||
my %Result = $ValueTypeObject->SettingEffectiveValueCheck(
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
...
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
EffectiveValue => {
|
||||
...
|
||||
},
|
||||
);
|
||||
|
||||
Result:
|
||||
%Result = (
|
||||
EffectiveValue => { # Note for FrontendRegistration ValueTypes EffectiveValue is not changed.
|
||||
...
|
||||
},
|
||||
Success => 1,
|
||||
Error => undef,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingEffectiveValueCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(XMLContentParsed)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Result = (
|
||||
Success => 0,
|
||||
);
|
||||
|
||||
if ( !IsHashRefWithData( $Param{EffectiveValue} ) ) {
|
||||
$Result{Error} = "FrontendRegistration EffectiveValue must be a hash!";
|
||||
return %Result;
|
||||
}
|
||||
|
||||
DEFINED:
|
||||
for my $Defined (qw(NavBarName Description)) {
|
||||
if ( !defined $Param{EffectiveValue}->{$Defined} ) {
|
||||
$Result{Error} = "FrontendRegistration must define $Defined!";
|
||||
last DEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
return %Result if $Result{Error};
|
||||
|
||||
$Result{Success} = 1;
|
||||
$Result{EffectiveValue} = $Param{EffectiveValue};
|
||||
|
||||
return %Result;
|
||||
}
|
||||
|
||||
=head2 EffectiveValueGet()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $EffectiveValue = $ValueTypeObject->EffectiveValueGet(
|
||||
Value => [
|
||||
{
|
||||
ValueRegex => '', # optional
|
||||
Content => 'TheEffectiveValue',
|
||||
ValueType => 'AValueType', # optional
|
||||
# ...
|
||||
}
|
||||
],
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$EffectiveValue = 'TheEffectiveValue';
|
||||
|
||||
=cut
|
||||
|
||||
sub EffectiveValueGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !IsArrayRefWithData( $Param{Value} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Value is missing or invalid!",
|
||||
);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( scalar @{ $Param{Value} } > 1 ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Value must be a single element!",
|
||||
);
|
||||
return '';
|
||||
}
|
||||
|
||||
return if ( !$Param{Value}->[0]->{Hash} );
|
||||
return if ( !$Param{Value}->[0]->{Hash}->[0] );
|
||||
return if ( !$Param{Value}->[0]->{Hash}->[0]->{Item} );
|
||||
|
||||
my $EffectiveValue;
|
||||
|
||||
for my $Item ( @{ $Param{Value}->[0]->{Hash}->[0]->{Item} } ) {
|
||||
|
||||
if ( grep { $Item->{Key} eq $_ } qw(Group GroupRo) ) {
|
||||
|
||||
# contains array
|
||||
|
||||
if ( $Item->{Array} ) {
|
||||
my @Array = ();
|
||||
|
||||
if (
|
||||
$Item->{Array}
|
||||
&& $Item->{Array}->[0]->{Item}
|
||||
)
|
||||
{
|
||||
for my $ArrayItem ( @{ $Item->{Array}->[0]->{Item} } ) {
|
||||
push @Array, $ArrayItem->{Content} || '';
|
||||
}
|
||||
}
|
||||
$EffectiveValue->{ $Item->{Key} } = \@Array;
|
||||
}
|
||||
}
|
||||
else {
|
||||
# contains value
|
||||
$EffectiveValue->{ $Item->{Key} } = $Item->{Content} || '';
|
||||
}
|
||||
}
|
||||
|
||||
# Set undefined group attributes.
|
||||
for my $Group (qw(Group GroupRo)) {
|
||||
if ( !defined $EffectiveValue->{$Group} ) {
|
||||
$EffectiveValue->{$Group} = [];
|
||||
}
|
||||
}
|
||||
|
||||
return $EffectiveValue;
|
||||
}
|
||||
|
||||
=head2 SettingRender()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $SettingHTML = $ValueTypeObject->SettingRender(
|
||||
Name => 'SettingName',
|
||||
DefaultID => 123, # (required)
|
||||
EffectiveValue => '2016-02-02',
|
||||
DefaultValue => 'Product 5', # (optional)
|
||||
Class => 'My class' # (optional)
|
||||
RW => 1, # (optional) Allow editing. Default 0.
|
||||
Item => [ # (optional) XML parsed item
|
||||
{
|
||||
'ValueType' => 'FrontendRegistration',
|
||||
'Content' => '2016-02-02',
|
||||
'ValueRegex' => '',
|
||||
},
|
||||
],
|
||||
IsArray => 1, # (optional) Item is part of the array
|
||||
IsHash => 1, # (optional) Item is part of the hash
|
||||
IDSuffix => 1, # (optional) Suffix will be added to the element ID
|
||||
SkipEffectiveValueCheck => 1, # (optional) If enabled, system will not perform effective value check.
|
||||
# Default: 1.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$SettingHTML = '<div class "Field"...</div>';
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingRender {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(Name EffectiveValue)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{DefaultValue} //= '';
|
||||
$Param{IDSuffix} //= '';
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
|
||||
|
||||
my $EffectiveValue = $Param{EffectiveValue};
|
||||
|
||||
if ( !IsHashRefWithData($EffectiveValue) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "EffectiveValue must be a hash!"
|
||||
);
|
||||
return '';
|
||||
}
|
||||
|
||||
# Set undefined group attributes.
|
||||
for my $Group (qw(Group GroupRo)) {
|
||||
if ( !defined $EffectiveValue->{$Group} ) {
|
||||
$EffectiveValue->{$Group} = [];
|
||||
}
|
||||
}
|
||||
|
||||
my %EffectiveValueCheck = (
|
||||
Success => 1,
|
||||
);
|
||||
|
||||
if ( !$Param{SkipEffectiveValueCheck} ) {
|
||||
%EffectiveValueCheck = $Self->SettingEffectiveValueCheck(
|
||||
EffectiveValue => $EffectiveValue,
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
Item => $Param{Item},
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
my $HTML = "<div class='Hash'>\n";
|
||||
|
||||
if ( !$EffectiveValueCheck{Success} ) {
|
||||
my $Message = $LanguageObject->Translate("Value is not correct! Please, consider updating this module.");
|
||||
|
||||
$HTML .= $Param{IsValid} ? "<div class='BadEffectiveValue'>\n" : "<div>\n";
|
||||
$HTML .= "<p>* $Message</p>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
my $AddNewEntry = $LanguageObject->Translate("Add new entry");
|
||||
my $RemoveThisEntry = $LanguageObject->Translate("Remove this entry");
|
||||
|
||||
if ( !defined $EffectiveValue->{Title} ) {
|
||||
$EffectiveValue->{Title} = '';
|
||||
}
|
||||
|
||||
my $Readonly = '';
|
||||
if ( !$Param{RW} ) {
|
||||
$Readonly = "readonly='readonly'";
|
||||
}
|
||||
|
||||
for my $Key ( sort keys %{$EffectiveValue} ) {
|
||||
|
||||
$HTML .= "<div class='HashItem'>\n";
|
||||
$HTML .= "<input type='text' value='$Key' readonly='readonly' class='Key' />\n";
|
||||
|
||||
$HTML .= "<div class='SettingContent'>\n";
|
||||
|
||||
if ( grep { $Key eq $_ } qw (Group GroupRo) ) {
|
||||
$HTML .= "<div class='Array'>\n";
|
||||
|
||||
my $GroupIndex = 1;
|
||||
for my $GroupItem ( @{ $EffectiveValue->{$Key} } ) {
|
||||
|
||||
my $HTMLGroupItem = $LayoutObject->Ascii2Html(
|
||||
Text => $GroupItem,
|
||||
Type => 'Normal',
|
||||
);
|
||||
|
||||
$HTML .= "<div class='ArrayItem'>\n";
|
||||
$HTML .= "<div class='SettingContent'>\n";
|
||||
$HTML .= "<input type='text' value='$HTMLGroupItem' "
|
||||
. "id='$Param{Name}_Hash###$Key\_Array$GroupIndex' $Readonly />\n";
|
||||
$HTML .= "</div>\n";
|
||||
|
||||
if ( $Param{RW} ) {
|
||||
$HTML .= "<button class='RemoveButton' type='button' "
|
||||
. "title='$RemoveThisEntry' value='Remove this entry'>\n"
|
||||
. " <i class='fa fa-minus-circle'></i>\n"
|
||||
. " <span class='InvisibleText'>$RemoveThisEntry</span>\n"
|
||||
. "</button>\n";
|
||||
}
|
||||
|
||||
$HTML .= "</div>\n";
|
||||
|
||||
$GroupIndex++;
|
||||
}
|
||||
|
||||
my $ButtonClass = 'AddArrayItem';
|
||||
if ( !$Param{RW} ) {
|
||||
$ButtonClass .= " Hidden";
|
||||
}
|
||||
|
||||
# Always add "AddArrayItem" button, it might be needed when calculating effective value (if array is empty).
|
||||
$HTML .= " <button data-suffix='$Param{Name}_Hash###$Key\_Array$GroupIndex' class='$ButtonClass' "
|
||||
. "type='button' title='$AddNewEntry' value='Add new entry'>\n"
|
||||
. " <i class='fa fa-plus-circle'></i>\n"
|
||||
. " <span class='InvisibleText'>$AddNewEntry</span>\n"
|
||||
. " </button>\n";
|
||||
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
else {
|
||||
my $HTMLValue = $LayoutObject->Ascii2Html(
|
||||
Text => $EffectiveValue->{$Key},
|
||||
Type => 'Normal',
|
||||
);
|
||||
|
||||
$HTML .= "<input type='text' value='$HTMLValue' "
|
||||
. "id='$Param{Name}_Hash###$Key' $Readonly />\n";
|
||||
}
|
||||
|
||||
$HTML .= "</div>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
$HTML .= "</div>\n";
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
218
Perl OTRS/Kernel/System/SysConfig/ValueType/Password.pm
Normal file
218
Perl OTRS/Kernel/System/SysConfig/ValueType/Password.pm
Normal file
@@ -0,0 +1,218 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::Password;
|
||||
## nofilter(TidyAll::Plugin::OTRS::Perl::LayoutObject)
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Language',
|
||||
'Kernel::Output::HTML::Layout',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::Password - System configuration password value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::Password');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingRender()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $SettingHTML = $ValueTypeObject->SettingRender(
|
||||
Name => 'SettingName',
|
||||
EffectiveValue => 'Product 6', # (optional)
|
||||
DefaultValue => 'Product 5', # (optional)
|
||||
Class => 'My class' # (optional)
|
||||
Item => [ # (optional) XML parsed item
|
||||
{
|
||||
'ValueType' => 'Password',
|
||||
'Content' => 'Secret',
|
||||
},
|
||||
],
|
||||
RW => 1, # (optional) Allow editing. Default 0.
|
||||
IsArray => 1, # (optional) Item is part of the array
|
||||
IsHash => 1, # (optional) Item is part of the hash
|
||||
IDSuffix => 1, # (optional) Suffix will be added to the element ID
|
||||
SkipEffectiveValueCheck => 1, # (optional) If enabled, system will not perform effective value check.
|
||||
# Default: 1.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$SettingHTML = '<div class "Field"...</div>';
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingRender {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !defined $Param{Name} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need Name",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $IDSuffix = $Param{IDSuffix} || '';
|
||||
|
||||
my $EffectiveValue = $Param{EffectiveValue};
|
||||
if (
|
||||
!defined $EffectiveValue
|
||||
&& $Param{Item}
|
||||
&& $Param{Item}->[0]->{Content}
|
||||
)
|
||||
{
|
||||
$EffectiveValue = $Param{Item}->[0]->{Content};
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{DefaultValue} //= '';
|
||||
|
||||
my $DefaultValueStrg = $Kernel::OM->Get('Kernel::Language')->Translate('Default');
|
||||
|
||||
my %EffectiveValueCheck = (
|
||||
Success => 1,
|
||||
);
|
||||
|
||||
if ( !$Param{SkipEffectiveValueCheck} ) {
|
||||
%EffectiveValueCheck = $Self->SettingEffectiveValueCheck(
|
||||
EffectiveValue => $EffectiveValue,
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
Item => $Param{Item},
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
my $HTML = "<div class='SettingContent'>\n";
|
||||
$HTML .= "<input class=\"$Param{Class}\" type=\"password\" name=\"$Param{Name}\" id=\"$Param{Name}$IDSuffix\"";
|
||||
|
||||
my $HTMLValue = $Kernel::OM->Get('Kernel::Output::HTML::Layout')->Ascii2Html(
|
||||
Text => $EffectiveValue,
|
||||
Type => 'Normal',
|
||||
);
|
||||
|
||||
$HTML .= "\" value=\"$HTMLValue\" ";
|
||||
|
||||
if ( !$Param{RW} ) {
|
||||
$HTML .= "disabled='disabled' ";
|
||||
}
|
||||
|
||||
$HTML .= " />\n";
|
||||
|
||||
if ( !$EffectiveValueCheck{Success} ) {
|
||||
my $Message = $Kernel::OM->Get('Kernel::Language')
|
||||
->Translate("Value is not correct! Please, consider updating this field.");
|
||||
|
||||
$HTML .= $Param{IsValid} ? "<div class='BadEffectiveValue'>\n" : "<div>\n";
|
||||
$HTML .= "<p>* $Message</p>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
$HTML .= "</div>\n";
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
=head2 AddItem()
|
||||
|
||||
Generate HTML for new array/hash item.
|
||||
|
||||
my $HTML = $ValueTypeObject->AddItem(
|
||||
Name => 'SettingName', (required) Name
|
||||
DefaultItem => { (optional) DefaultItem hash, if available
|
||||
Item => {
|
||||
Content => 'Value',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$HTML = "<input type='password' id='Setting_ExampleArray'
|
||||
value='Value' name='ExampleArray' class='Entry'/>";
|
||||
|
||||
=cut
|
||||
|
||||
sub AddItem {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check needed stuff.
|
||||
for my $Needed (qw(Name)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $IDSuffix = $Param{IDSuffix} || '';
|
||||
my $Class = $Param{Class} || '';
|
||||
|
||||
my $DefaultValue = '';
|
||||
if ( $Param{DefaultItem} && $Param{DefaultItem}->{Item} ) {
|
||||
$DefaultValue = $Param{DefaultItem} && $Param{DefaultItem}->{Item}->{Content} || '';
|
||||
}
|
||||
elsif ( $Param{DefaultItem} ) {
|
||||
$DefaultValue = $Param{DefaultItem} && $Param{DefaultItem}->{Content} || '';
|
||||
}
|
||||
|
||||
my $RemoveThisEntry = $Kernel::OM->Get('Kernel::Language')->Translate("Remove this entry");
|
||||
|
||||
my $Result = "<input type='password' id='$Param{Name}$IDSuffix'
|
||||
value='$DefaultValue' name='$Param{Name}' class='$Class Entry'/>";
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
412
Perl OTRS/Kernel/System/SysConfig/ValueType/PerlModule.pm
Normal file
412
Perl OTRS/Kernel/System/SysConfig/ValueType/PerlModule.pm
Normal file
@@ -0,0 +1,412 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::PerlModule;
|
||||
## nofilter(TidyAll::Plugin::OTRS::Perl::LayoutObject)
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::Language',
|
||||
'Kernel::Output::HTML::Layout',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Main',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::PerlModule - System configuration perl module value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::PerlModule');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingEffectiveValueCheck()
|
||||
|
||||
Check if provided EffectiveValue matches structure defined in XMLContentParsed.
|
||||
|
||||
my %Result = $ValueTypeObject->SettingEffectiveValueCheck(
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => 'Kernel::System::Log::SysLog',
|
||||
'ValueFilter' => 'Kernel/System/Log/*.pm',
|
||||
'ValueType' => 'PerlModule',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
EffectiveValue => 'Kernel::System::Log::SysLog',
|
||||
);
|
||||
|
||||
Result:
|
||||
%Result = (
|
||||
EffectiveValue => 'Kernel::System::Log::SysLog', # Note for PerlModule ValueTypes EffectiveValue is not changed.
|
||||
Success => 1,
|
||||
Error => undef,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingEffectiveValueCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(XMLContentParsed)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Result = (
|
||||
Success => 0,
|
||||
);
|
||||
|
||||
# Data should be scalar.
|
||||
if ( ref $Param{EffectiveValue} ) {
|
||||
$Result{Error} = 'EffectiveValue for PerlModule must be a scalar!';
|
||||
return %Result;
|
||||
}
|
||||
|
||||
# Check if EffectiveValue matches ValueFilter.
|
||||
my $MainObject = $Kernel::OM->Get('Kernel::System::Main');
|
||||
my $Home = $Kernel::OM->Get('Kernel::Config')->Get('Home');
|
||||
|
||||
my $ValueFilter = $Param{XMLContentParsed}->{Value}->[0]->{Item}->[0]->{ValueFilter};
|
||||
|
||||
my @ValidValue = $MainObject->DirectoryRead(
|
||||
Directory => $Home,
|
||||
Filter => $ValueFilter,
|
||||
);
|
||||
|
||||
for my $Value (@ValidValue) {
|
||||
|
||||
# Convert to the relative path.
|
||||
$Value =~ s{^$Home/*(.*?)$}{$1}gsmx;
|
||||
|
||||
# Replace '/' with '::'.
|
||||
$Value =~ s{/}{::}gsmx;
|
||||
|
||||
# Remove extension.
|
||||
$Value =~ s{\..*$}{}gsmx;
|
||||
}
|
||||
|
||||
if ( !grep { $_ eq $Param{EffectiveValue} } @ValidValue ) {
|
||||
$Result{Error} = "$Param{EffectiveValue} doesn't satisfy ValueFilter($ValueFilter)!";
|
||||
return %Result;
|
||||
}
|
||||
|
||||
my $Loaded = $MainObject->Require(
|
||||
$Param{EffectiveValue},
|
||||
Silent => 1,
|
||||
);
|
||||
|
||||
if ( !$Loaded ) {
|
||||
$Result{Error} = "$Param{EffectiveValue} not exists!";
|
||||
return %Result;
|
||||
}
|
||||
|
||||
$Result{Success} = 1;
|
||||
$Result{EffectiveValue} = $Param{EffectiveValue};
|
||||
|
||||
return %Result;
|
||||
}
|
||||
|
||||
=head2 SettingRender()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $SettingHTML = $ValueTypeObject->SettingRender(
|
||||
Name => 'SettingName',
|
||||
EffectiveValue => '3 medium', # (optional)
|
||||
DefaultValue => '3 medium', # (optional)
|
||||
Class => 'My class' # (optional)
|
||||
RW => 1, # (optional) Allow editing. Default 0.
|
||||
Item => [ # (optional) XML parsed item
|
||||
{
|
||||
'ValueType' => 'PerlModule',
|
||||
'ValueFilter' => '"Kernel/System/Log/*.pm',
|
||||
'Content' => 'Kernel::System::Log::SysLog',
|
||||
},
|
||||
],
|
||||
IsArray => 1, # (optional) Item is part of the array
|
||||
IsHash => 1, # (optional) Item is part of the hash
|
||||
SkipEffectiveValueCheck => 1, # (optional) If enabled, system will not perform effective value check.
|
||||
# Default: 1.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$SettingHTML = '<div class "Field"...</div>';
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingRender {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !defined $Param{Name} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need Name",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{DefaultValue} //= '';
|
||||
$Param{IDSuffix} //= '';
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
|
||||
my $Value = $Param{XMLContentParsed}->{Value};
|
||||
|
||||
my $EffectiveValue = $Param{EffectiveValue};
|
||||
if (
|
||||
!defined $EffectiveValue
|
||||
&& $Param{Item}
|
||||
&& $Param{Item}->[0]->{Content}
|
||||
)
|
||||
{
|
||||
$EffectiveValue = $Param{Item}->[0]->{Content};
|
||||
}
|
||||
|
||||
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
|
||||
|
||||
my $Home = $ConfigObject->Get('Home');
|
||||
|
||||
my $Filter;
|
||||
|
||||
if (
|
||||
$Param{Item}
|
||||
&& $Param{Item}->[0]->{ValueFilter}
|
||||
)
|
||||
{
|
||||
$Filter = $Param{Item}->[0]->{ValueFilter};
|
||||
}
|
||||
elsif ( $Value->[0]->{Item} ) {
|
||||
$Filter = $Value->[0]->{Item}->[0]->{ValueFilter};
|
||||
}
|
||||
elsif ( $Value->[0]->{Array} ) {
|
||||
$Filter = $Value->[0]->{Array}->[0]->{DefaultItem}->[0]->{ValueFilter};
|
||||
}
|
||||
elsif ( $Value->[0]->{Hash} ) {
|
||||
if (
|
||||
$Value->[0]->{Hash}->[0]->{DefaultItem}
|
||||
&& $Value->[0]->{Hash}->[0]->{DefaultItem}->[0]->{ValueFilter}
|
||||
)
|
||||
{
|
||||
|
||||
# take ValueFilter from DefaultItem
|
||||
$Filter = $Value->[0]->{Hash}->[0]->{DefaultItem}->[0]->{ValueFilter};
|
||||
}
|
||||
else {
|
||||
# check if there is definition for certain key
|
||||
ITEM:
|
||||
for my $Item ( @{ $Value->[0]->{Hash}->[0]->{Item} } ) {
|
||||
if ( $Item->{Key} eq $Param{Key} ) {
|
||||
$Filter = $Item->{ValueFilter} || '';
|
||||
last ITEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my @PerlModules = $Kernel::OM->Get('Kernel::System::Main')->DirectoryRead(
|
||||
Directory => $Home,
|
||||
Filter => $Filter,
|
||||
);
|
||||
|
||||
for my $Module (@PerlModules) {
|
||||
|
||||
# Convert to the relative path.
|
||||
$Module =~ s{^$Home/*(.*?)$}{$1}gsmx;
|
||||
|
||||
# Replace '/' with '::'.
|
||||
$Module =~ s{/}{::}gsmx;
|
||||
|
||||
# Remove extension.
|
||||
$Module =~ s{\..*$}{}gsmx;
|
||||
}
|
||||
|
||||
my $Name = $Param{Name};
|
||||
|
||||
# When displaying diff between current and old value, it can happen that value is missing
|
||||
# since it was renamed, or removed. In this case, we need to add this "old" value also.
|
||||
if (
|
||||
$EffectiveValue
|
||||
&& !grep { $_ eq $EffectiveValue } @PerlModules
|
||||
)
|
||||
{
|
||||
push @PerlModules, $EffectiveValue;
|
||||
}
|
||||
|
||||
my %EffectiveValueCheck = (
|
||||
Success => 1,
|
||||
);
|
||||
|
||||
if ( !$Param{SkipEffectiveValueCheck} ) {
|
||||
%EffectiveValueCheck = $Self->SettingEffectiveValueCheck(
|
||||
EffectiveValue => $EffectiveValue,
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
Item => $Param{Item},
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
my $HTML = "<div class='SettingContent'>\n";
|
||||
$HTML .= $Kernel::OM->Get('Kernel::Output::HTML::Layout')->BuildSelection(
|
||||
Data => \@PerlModules,
|
||||
Name => $Name,
|
||||
ID => $Param{Name} . $Param{IDSuffix},
|
||||
Disabled => $Param{RW} ? 0 : 1,
|
||||
SelectedValue => $EffectiveValue,
|
||||
Title => $Param{Name},
|
||||
OptionTitle => 1,
|
||||
Class => "$Param{Class} Modernize",
|
||||
);
|
||||
|
||||
if ( !$EffectiveValueCheck{Success} ) {
|
||||
my $Message = $LanguageObject->Translate("Value is not correct! Please, consider updating this field.");
|
||||
|
||||
$HTML .= $Param{IsValid} ? "<div class='BadEffectiveValue'>\n" : "<div>\n";
|
||||
$HTML .= "<p>* $Message</p>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
$HTML .= "</div>\n";
|
||||
|
||||
if ( !$Param{IsArray} && !$Param{IsHash} ) {
|
||||
my $DefaultText = $LanguageObject->Translate('Default');
|
||||
|
||||
$HTML .= <<"EOF";
|
||||
<div class=\"WidgetMessage Bottom\">
|
||||
$DefaultText: $Param{DefaultValue}
|
||||
</div>
|
||||
EOF
|
||||
}
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
=head2 AddItem()
|
||||
|
||||
Generate HTML for new array/hash item.
|
||||
|
||||
my $HTML = $ValueTypeObject->AddItem(
|
||||
Name => 'SettingName', (required) Name
|
||||
DefaultItem => { (required) DefaultItem hash
|
||||
'ValueType' => 'PerlModule',
|
||||
'Content' => 'Kernel::System::Log::SysLog',
|
||||
'ValueFilter' => 'Kernel/System/Log/*.pm'
|
||||
},
|
||||
IDSuffix => '_Array1', (optional) IDSuffix is needed for arrays and hashes.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$HTML = '<select class="Modernize" id="SettingName" name="SettingName" title="SettingName">
|
||||
...
|
||||
</select>';
|
||||
|
||||
=cut
|
||||
|
||||
sub AddItem {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check needed stuff.
|
||||
for my $Needed (qw(Name DefaultItem)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{IDSuffix} //= '';
|
||||
|
||||
my $Home = $Kernel::OM->Get('Kernel::Config')->Get('Home');
|
||||
|
||||
my @PerlModules = $Kernel::OM->Get('Kernel::System::Main')->DirectoryRead(
|
||||
Directory => $Home,
|
||||
Filter => $Param{DefaultItem}->{ValueFilter},
|
||||
);
|
||||
|
||||
for my $Module (@PerlModules) {
|
||||
|
||||
# Convert to the relative path.
|
||||
$Module =~ s{^$Home/*(.*?)$}{$1}gsmx;
|
||||
|
||||
# Replace '/' with '::'.
|
||||
$Module =~ s{/}{::}gsmx;
|
||||
|
||||
# Remove extension.
|
||||
$Module =~ s{\..*$}{}gsmx;
|
||||
}
|
||||
|
||||
my $Result = $Kernel::OM->Get('Kernel::Output::HTML::Layout')->BuildSelection(
|
||||
Data => \@PerlModules,
|
||||
Name => $Param{Name},
|
||||
ID => $Param{Name} . $Param{IDSuffix},
|
||||
SelectedValue => $Param{DefaultItem}->{Content},
|
||||
Title => $Param{Name},
|
||||
OptionTitle => 1,
|
||||
Class => "$Param{Class} Modernize Entry",
|
||||
);
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
498
Perl OTRS/Kernel/System/SysConfig/ValueType/Select.pm
Normal file
498
Perl OTRS/Kernel/System/SysConfig/ValueType/Select.pm
Normal file
@@ -0,0 +1,498 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::Select;
|
||||
## nofilter(TidyAll::Plugin::OTRS::Perl::LayoutObject)
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Language',
|
||||
'Kernel::Output::HTML::Layout',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::Select - System configuration select value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::Select');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingEffectiveValueCheck()
|
||||
|
||||
Check if provided EffectiveValue matches structure defined in XMLContentParsed.
|
||||
|
||||
my %Result = $ValueTypeObject->SettingEffectiveValueCheck(
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => 'Option 1',
|
||||
'Value' => 'option-1',
|
||||
'ValueType' => 'Option',
|
||||
},
|
||||
{
|
||||
'Content' => 'Option 2',
|
||||
'Value' => 'option-2',
|
||||
'ValueType' => 'Option',
|
||||
},
|
||||
],
|
||||
'SelectedID' => 'option-1',
|
||||
'ValueType' => 'Select',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
EffectiveValue => 'option-1',
|
||||
);
|
||||
|
||||
Result:
|
||||
%Result = (
|
||||
EffectiveValue => 'option-1', # Note for Select ValueTypes EffectiveValue is not changed.
|
||||
Success => 1,
|
||||
Error => undef,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingEffectiveValueCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(XMLContentParsed)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Result = (
|
||||
Success => 0,
|
||||
);
|
||||
|
||||
my $Value = $Param{XMLContentParsed}->{Value};
|
||||
|
||||
for my $Parameter ( sort keys %{ $Param{Parameters} } ) {
|
||||
if ( !defined $Value->[0]->{Item}->[0]->{$Parameter} ) {
|
||||
$Value->[0]->{Item}->[0]->{$Parameter} = $Param{Parameters}->{$Parameter};
|
||||
}
|
||||
}
|
||||
|
||||
# Data should be scalar.
|
||||
if ( ref $Param{EffectiveValue} ) {
|
||||
$Result{Error} = 'EffectiveValue for Select must be a scalar!';
|
||||
return %Result;
|
||||
}
|
||||
|
||||
if (
|
||||
!grep {
|
||||
$Param{EffectiveValue} eq $_->{Value}
|
||||
|| ( !$Param{EffectiveValue} && !$_->{Value} )
|
||||
}
|
||||
@{ $Value->[0]->{Item}->[0]->{Item} }
|
||||
)
|
||||
{
|
||||
$Result{Error} = "'$Param{EffectiveValue}' option not found in Select!";
|
||||
return %Result;
|
||||
}
|
||||
|
||||
$Result{Success} = 1;
|
||||
$Result{EffectiveValue} = $Param{EffectiveValue};
|
||||
|
||||
return %Result;
|
||||
}
|
||||
|
||||
sub EffectiveValueGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !IsArrayRefWithData( $Param{Value} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Value is missing or invalid!",
|
||||
);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( scalar @{ $Param{Value} } > 1 ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Value must be a single element!",
|
||||
);
|
||||
return '';
|
||||
}
|
||||
|
||||
$Param{Value}->[0]->{SelectedID} //= '';
|
||||
|
||||
# Check if option is translatable.
|
||||
my ($Option) = grep { $_->{Value} eq $Param{Value}->[0]->{SelectedID} }
|
||||
@{ $Param{Value}->[0]->{Item} };
|
||||
|
||||
if ( !defined $Option ) {
|
||||
|
||||
# TODO: Should this really be logged?
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "'$Param{Value}->[0]->{SelectedID}' not found in select!",
|
||||
);
|
||||
}
|
||||
|
||||
my $EffectiveValue = $Param{Value}->[0]->{SelectedID};
|
||||
|
||||
if (
|
||||
$Param{Translate}
|
||||
&&
|
||||
$Option &&
|
||||
$Option->{Translatable}
|
||||
)
|
||||
{
|
||||
$EffectiveValue = $Kernel::OM->Get('Kernel::Language')->Translate($EffectiveValue);
|
||||
}
|
||||
|
||||
return $EffectiveValue;
|
||||
}
|
||||
|
||||
sub ModifiedValueGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(Value)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $Result = $Param{Value};
|
||||
|
||||
# Update Content
|
||||
$Result->[0]->{Item}->[0]->{SelectedID} = $Param{EffectiveValue} || '';
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
=head2 SettingRender()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $SettingHTML = $ValueTypeObject->SettingRender(
|
||||
Name => 'SettingName',
|
||||
DefaultID => 123, # (required)
|
||||
EffectiveValue => '3 medium',
|
||||
DefaultValue => '3 medium', # (optional)
|
||||
Class => 'My class' # (optional)
|
||||
RW => 1, # (optional) Allow editing. Default 0.
|
||||
Item => [ # (optional) XML parsed item
|
||||
{
|
||||
'ValueType' => 'Select',
|
||||
...
|
||||
},
|
||||
],
|
||||
IsArray => 1, # (optional) Item is part of the array
|
||||
IsHash => 1, # (optional) Item is part of the hash
|
||||
Key => 'Key', # (optional) Hash key (if available)
|
||||
SkipEffectiveValueCheck => 1, # (optional) If enabled, system will not perform effective value check.
|
||||
# Default: 1.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$SettingHTML = '<div class "Field"...</div>';
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingRender {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(Name EffectiveValue Item)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{DefaultValue} //= '';
|
||||
$Param{IDSuffix} //= '';
|
||||
|
||||
if ( !IsArrayRefWithData( $Param{Item} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Item is invalid!",
|
||||
);
|
||||
}
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
|
||||
my $EffectiveValue = $Param{EffectiveValue};
|
||||
|
||||
my %EffectiveValueCheck = (
|
||||
Success => 1,
|
||||
);
|
||||
|
||||
if ( !$Param{SkipEffectiveValueCheck} ) {
|
||||
%EffectiveValueCheck = $Self->SettingEffectiveValueCheck(
|
||||
EffectiveValue => $EffectiveValue,
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
Item => $Param{Item},
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
my %Data;
|
||||
OPTION:
|
||||
for my $Option ( @{ $Param{Item}->[0]->{Item} } ) {
|
||||
next OPTION if $Option->{ValueType} ne 'Option';
|
||||
|
||||
if ( $Option->{Translatable} ) {
|
||||
|
||||
$Data{ $Option->{Value} } = $LanguageObject->Translate( $Option->{Content} );
|
||||
next OPTION;
|
||||
}
|
||||
$Data{ $Option->{Value} } = $Option->{Content};
|
||||
}
|
||||
|
||||
# find data in hash if provided
|
||||
if ( !%Data && $Param{Value}->[0]->{Hash}->[0]->{Item} ) {
|
||||
my ($OptionItems) = grep { $_->{Key} eq $Param{Key} } @{ $Param{Value}->[0]->{Hash}->[0]->{Item} };
|
||||
|
||||
OPTION:
|
||||
for my $Option ( @{ $OptionItems->{Item} } ) {
|
||||
next OPTION if $Option->{ValueType} ne 'Option';
|
||||
|
||||
if ( $Option->{Translatable} ) {
|
||||
$Data{ $Option->{Value} } = $LanguageObject->Translate( $Option->{Content} );
|
||||
next OPTION;
|
||||
}
|
||||
$Data{ $Option->{Value} } = $Option->{Content};
|
||||
}
|
||||
}
|
||||
|
||||
# data not found, try in DefaultItem
|
||||
if (
|
||||
!%Data
|
||||
&& $Param{Value}->[0]->{Hash}->[0]->{DefaultItem}
|
||||
&& $Param{Value}->[0]->{Hash}->[0]->{DefaultItem}->[0]->{Item}
|
||||
)
|
||||
{
|
||||
OPTION:
|
||||
for my $Option ( @{ $Param{Value}->[0]->{Hash}->[0]->{DefaultItem}->[0]->{Item} } ) {
|
||||
next OPTION if $Option->{ValueType} ne 'Option';
|
||||
|
||||
if ( $Option->{Translatable} ) {
|
||||
$Data{ $Option->{Value} } = $LanguageObject->Translate( $Option->{Content} );
|
||||
next OPTION;
|
||||
}
|
||||
$Data{ $Option->{Value} } = $Option->{Content};
|
||||
}
|
||||
}
|
||||
|
||||
# When displaying diff between current and old value, it can happen that value is missing
|
||||
# since it was renamed, or removed. In this case, we need to add this "old" value also.
|
||||
if (
|
||||
!grep {
|
||||
$_ eq $EffectiveValue
|
||||
|| ( !$EffectiveValue && !$_ )
|
||||
} keys %Data
|
||||
)
|
||||
{
|
||||
$Data{$EffectiveValue} = $EffectiveValue;
|
||||
}
|
||||
|
||||
my $OptionStrg = $Kernel::OM->Get('Kernel::Output::HTML::Layout')->BuildSelection(
|
||||
Name => $Param{Name},
|
||||
ID => $Param{Name} . $Param{IDSuffix},
|
||||
Disabled => $Param{RW} ? 0 : 1,
|
||||
Data => \%Data,
|
||||
SelectedID => $EffectiveValue,
|
||||
Class => "$Param{Class} Modernize",
|
||||
Translation => 0,
|
||||
);
|
||||
|
||||
my $HTML = "<div class='SettingContent'>\n";
|
||||
$HTML .= $OptionStrg;
|
||||
|
||||
if ( !$EffectiveValueCheck{Success} ) {
|
||||
my $Message = $LanguageObject->Translate("Value is not correct! Please, consider updating this field.");
|
||||
|
||||
$HTML .= $Param{IsValid} ? "<div class='BadEffectiveValue'>\n" : "<div>\n";
|
||||
$HTML .= "<p>* $Message</p>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
$HTML .= "</div>\n";
|
||||
|
||||
if ( !$Param{IsArray} && !$Param{IsHash} && defined $Param{DefaultValue} ) {
|
||||
my $DefaultValueStrg = $LanguageObject->Translate('Default');
|
||||
|
||||
$HTML .= <<"EOF";
|
||||
|
||||
<div class=\"WidgetMessage Bottom\">
|
||||
$DefaultValueStrg: $Param{DefaultValue}
|
||||
</div>
|
||||
EOF
|
||||
}
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
=head2 AddItem()
|
||||
|
||||
Generate HTML for new array/hash item.
|
||||
|
||||
my $HTML = $ValueTypeObject->AddItem(
|
||||
Name => 'SettingName', (required) Name
|
||||
DefaultItem => { (required) DefaultItem hash
|
||||
'ValueType' => 'Select',
|
||||
'Content' => 'optiont-1',
|
||||
},
|
||||
IDSuffix => '_Array1', (optional) IDSuffix is needed for arrays and hashes.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$HTML = '<select class="Modernize" id="SettingName" name="SettingName" title="SettingName">
|
||||
...
|
||||
</select>';
|
||||
|
||||
=cut
|
||||
|
||||
sub AddItem {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check needed stuff.
|
||||
for my $Needed (qw(Name DefaultItem)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{DefaultValue} //= '';
|
||||
$Param{IDSuffix} //= '';
|
||||
|
||||
my %Data;
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
|
||||
OPTION:
|
||||
for my $Option ( @{ $Param{DefaultItem}->{Item} } ) {
|
||||
next OPTION if $Option->{ValueType} ne 'Option';
|
||||
|
||||
if ( $Option->{Translatable} ) {
|
||||
$Data{ $Option->{Value} } = $LanguageObject->Translate( $Option->{Content} );
|
||||
next OPTION;
|
||||
}
|
||||
$Data{ $Option->{Value} } = $Option->{Content};
|
||||
}
|
||||
|
||||
my $Result = $Kernel::OM->Get('Kernel::Output::HTML::Layout')->BuildSelection(
|
||||
Name => $Param{Name},
|
||||
ID => $Param{Name} . $Param{IDSuffix},
|
||||
Data => \%Data,
|
||||
SelectedID => $Param{DefaultItem}->{SelectedID} || '',
|
||||
Class => "$Param{Class} Modernize Entry",
|
||||
Title => $Param{Name},
|
||||
Translation => 0,
|
||||
);
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
=head2 ValueAttributeGet()
|
||||
|
||||
Returns attribute name in the parsed XML that contains Value.
|
||||
|
||||
my $Result = $ValueTypeObject->ValueAttributeGet();
|
||||
Result:
|
||||
$Result = 'SelectedID';
|
||||
|
||||
=cut
|
||||
|
||||
sub ValueAttributeGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
return 'SelectedID';
|
||||
}
|
||||
|
||||
=head2 ForbiddenValueTypes()
|
||||
|
||||
Return array of value types that are not allowed inside this value type.
|
||||
|
||||
my @ForbiddenValueTypes = $ValueTypeObject->ForbiddenValueTypes();
|
||||
|
||||
Returns:
|
||||
|
||||
@ForbiddenValueTypes = (
|
||||
'Option',
|
||||
...
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub ForbiddenValueTypes {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
return ("Option");
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
58
Perl OTRS/Kernel/System/SysConfig/ValueType/String.pm
Normal file
58
Perl OTRS/Kernel/System/SysConfig/ValueType/String.pm
Normal file
@@ -0,0 +1,58 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::String;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::String - System configuration string value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::String');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
221
Perl OTRS/Kernel/System/SysConfig/ValueType/Textarea.pm
Normal file
221
Perl OTRS/Kernel/System/SysConfig/ValueType/Textarea.pm
Normal file
@@ -0,0 +1,221 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::Textarea;
|
||||
## nofilter(TidyAll::Plugin::OTRS::Perl::LayoutObject)
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Language',
|
||||
'Kernel::Output::HTML::Layout',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::Textarea - System configuration text-area value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::Textarea');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingRender()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $SettingHTML = $ValueTypeObject->SettingRender(
|
||||
Name => 'SettingName',
|
||||
EffectiveValue => 'Textarea content', # (optional)
|
||||
DefaultValue => 'Textarea content', # (optional)
|
||||
Class => 'My class' # (optional)
|
||||
Item => [ # (optional) XML parsed item
|
||||
{
|
||||
'ValueType' => 'Textarea',
|
||||
'Content' => 'Textarea content',
|
||||
},
|
||||
],
|
||||
RW => 1, # (optional) Allow editing. Default 0.
|
||||
IsArray => 1, # (optional) Item is part of the array
|
||||
IsHash => 1, # (optional) Item is part of the hash
|
||||
IDSuffix => 1, # (optional) Suffix will be added to the element ID
|
||||
SkipEffectiveValueCheck => 1, # (optional) If enabled, system will not perform effective value check.
|
||||
# Default: 1.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$SettingHTML = '<div class "Field"...</div>';
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingRender {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !defined $Param{Name} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need Name",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{DefaultValue} //= '';
|
||||
$Param{IDSuffix} //= '';
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
|
||||
my $Name = $Param{Name};
|
||||
|
||||
my $EffectiveValue = $Param{EffectiveValue};
|
||||
if (
|
||||
!defined $EffectiveValue
|
||||
&& $Param{Item}
|
||||
&& $Param{Item}->[0]->{Content}
|
||||
)
|
||||
{
|
||||
$EffectiveValue = $Param{Item}->[0]->{Content};
|
||||
}
|
||||
|
||||
my %EffectiveValueCheck = (
|
||||
Success => 1,
|
||||
);
|
||||
|
||||
if ( !$Param{SkipEffectiveValueCheck} ) {
|
||||
%EffectiveValueCheck = $Self->SettingEffectiveValueCheck(
|
||||
EffectiveValue => $EffectiveValue,
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
Item => $Param{Item},
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
my $HTML = "<div class='SettingContent'>\n";
|
||||
$HTML
|
||||
.= "<textarea rows='15' cols='50' class=\"$Param{Class}\" type=\"text\" name=\"$Name\"" .
|
||||
" id=\"$Param{Name}$Param{IDSuffix}\"";
|
||||
|
||||
if ( !$Param{RW} ) {
|
||||
$HTML .= "disabled='disabled' ";
|
||||
}
|
||||
|
||||
my $HTMLValue = $Kernel::OM->Get('Kernel::Output::HTML::Layout')->Ascii2Html(
|
||||
Text => $EffectiveValue,
|
||||
Type => 'Normal',
|
||||
);
|
||||
|
||||
$HTML .= ">$HTMLValue</textarea>\n";
|
||||
|
||||
if ( !$EffectiveValueCheck{Success} ) {
|
||||
my $Message = $LanguageObject->Translate("Value is not correct! Please, consider updating this field.");
|
||||
|
||||
$HTML .= $Param{IsValid} ? "<div class='BadEffectiveValue'>\n" : "<div>\n";
|
||||
$HTML .= "<p>* $Message</p>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
$HTML .= "</div>\n";
|
||||
|
||||
if ( !$Param{IsArray} && !$Param{IsHash} ) {
|
||||
my $DefaultValueStrg = $LanguageObject->Translate('Default');
|
||||
|
||||
$HTML .= <<"EOF";
|
||||
<div class=\"WidgetMessage Bottom\">
|
||||
$DefaultValueStrg: $Param{DefaultValue}
|
||||
</div>
|
||||
EOF
|
||||
}
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
=head2 AddItem()
|
||||
|
||||
Generate HTML for new array/hash item.
|
||||
|
||||
my $HTML = $ValueTypeObject->AddItem(
|
||||
Name => 'SettingName', (required) Name
|
||||
DefaultItem => { (required) DefaultItem hash
|
||||
'ValueType' => 'Select',
|
||||
'Content' => 'optiont-1',
|
||||
},
|
||||
IDSuffix => '_Array1', (optional) IDSuffix is needed for arrays and hashes.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$HTML = '<textarea rows=\'15\' cols=\'50\' class="" type="text" name="SettingName">
|
||||
...
|
||||
</textarea>';
|
||||
|
||||
=cut
|
||||
|
||||
sub AddItem {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check needed stuff.
|
||||
for my $Needed (qw(Name DefaultItem)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
$Param{Class} //= '';
|
||||
$Param{DefaultValue} //= '';
|
||||
$Param{IDSuffix} //= '';
|
||||
|
||||
my $DefaultValue = $Param{DefaultItem}->{Content} || '';
|
||||
|
||||
my $Result = "<textarea rows='15' cols='100' class=\"$Param{Class} Entry\" type=\"text\" name=\"$Param{Name}\" ";
|
||||
$Result .= "id=\"$Param{Name}$Param{IDSuffix}\">$DefaultValue</textarea>";
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
309
Perl OTRS/Kernel/System/SysConfig/ValueType/TimeZone.pm
Normal file
309
Perl OTRS/Kernel/System/SysConfig/ValueType/TimeZone.pm
Normal file
@@ -0,0 +1,309 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::TimeZone;
|
||||
## nofilter(TidyAll::Plugin::OTRS::Perl::LayoutObject)
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Language',
|
||||
'Kernel::Output::HTML::Layout',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::TimeZone - System configuration time-zone value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::TimeZone');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingEffectiveValueCheck()
|
||||
|
||||
Check if provided EffectiveValue matches structure defined in XMLContentParsed.
|
||||
|
||||
my %Result = $ValueTypeObject->SettingEffectiveValueCheck(
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => 'UTC',
|
||||
'ValueType' => 'TimeZone',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
EffectiveValue => 'UTC',
|
||||
);
|
||||
|
||||
Result:
|
||||
%Result = (
|
||||
EffectiveValue => 'UTC', # Note for common TimeZone EffectiveValue is not changed.
|
||||
Success => 1,
|
||||
Error => undef,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingEffectiveValueCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(XMLContentParsed)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Result = (
|
||||
Success => 0,
|
||||
);
|
||||
|
||||
# Data should be scalar.
|
||||
if ( ref $Param{EffectiveValue} ) {
|
||||
$Result{Error} = 'EffectiveValue for TimeZone must be a scalar!';
|
||||
return %Result;
|
||||
}
|
||||
|
||||
my $DateTimeObject = $Kernel::OM->Create(
|
||||
'Kernel::System::DateTime',
|
||||
);
|
||||
my $TimeZones = $DateTimeObject->TimeZoneList();
|
||||
if ( !grep { $Param{EffectiveValue} eq $_ } @{$TimeZones} ) {
|
||||
$Result{Error} = "$Param{EffectiveValue} is not valid time zone!";
|
||||
return %Result;
|
||||
}
|
||||
|
||||
$Result{Success} = 1;
|
||||
$Result{EffectiveValue} = $Param{EffectiveValue};
|
||||
|
||||
return %Result;
|
||||
}
|
||||
|
||||
=head2 SettingRender()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $SettingHTML = $ValueTypeObject->SettingRender(
|
||||
Name => 'SettingName',
|
||||
EffectiveValue => 'UTC', # (optional)
|
||||
DefaultValue => 'UTC', # (optional)
|
||||
Class => 'My class' # (optional)
|
||||
RW => 1, # (optional) Allow editing. Default 0.
|
||||
Item => [ # (optional) XML parsed item
|
||||
{
|
||||
'ValueType' => 'TimeZone',
|
||||
'Content' => 'UTC',
|
||||
},
|
||||
],
|
||||
IsArray => 1, # (optional) Item is part of the array
|
||||
IsHash => 1, # (optional) Item is part of the hash
|
||||
IDSuffix => 1, # (optional) Suffix will be added to the element ID
|
||||
SkipEffectiveValueCheck => 1, # (optional) If enabled, system will not perform effective value check.
|
||||
# Default: 1.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$SettingHTML = '<div class "Field"...</div>';
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingRender {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !defined $Param{Name} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need Name",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{DefaultValue} //= '';
|
||||
$Param{IDSuffix} //= '';
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
|
||||
my $DateTimeObject = $Kernel::OM->Create(
|
||||
'Kernel::System::DateTime',
|
||||
);
|
||||
my $TimeZones = $DateTimeObject->TimeZoneList();
|
||||
|
||||
my $EffectiveValue = $Param{EffectiveValue};
|
||||
if (
|
||||
!defined $EffectiveValue
|
||||
&& $Param{Item}
|
||||
&& $Param{Item}->[0]->{Content}
|
||||
)
|
||||
{
|
||||
$EffectiveValue = $Param{Item}->[0]->{Content};
|
||||
}
|
||||
|
||||
# When displaying diff between current and old value, it can happen that value is missing
|
||||
# since it was renamed, or removed. In this case, we need to add this "old" value also.
|
||||
if (
|
||||
$EffectiveValue
|
||||
&& !grep { $_ eq $EffectiveValue } @{$TimeZones}
|
||||
)
|
||||
{
|
||||
push @{$TimeZones}, $EffectiveValue;
|
||||
}
|
||||
|
||||
my %EffectiveValueCheck = (
|
||||
Success => 1,
|
||||
);
|
||||
|
||||
if ( !$Param{SkipEffectiveValueCheck} ) {
|
||||
%EffectiveValueCheck = $Self->SettingEffectiveValueCheck(
|
||||
EffectiveValue => $EffectiveValue,
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
Item => $Param{Item},
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
my $HTML = "<div class='SettingContent'>\n";
|
||||
$HTML .= $Kernel::OM->Get('Kernel::Output::HTML::Layout')->BuildSelection(
|
||||
Data => $TimeZones,
|
||||
Name => $Param{Name},
|
||||
ID => $Param{Name} . $Param{IDSuffix},
|
||||
Disabled => $Param{RW} ? 0 : 1,
|
||||
SelectedValue => $EffectiveValue,
|
||||
Title => $Param{Name},
|
||||
OptionTitle => 1,
|
||||
Class => "$Param{Class} Modernize",
|
||||
);
|
||||
|
||||
if ( !$EffectiveValueCheck{Success} ) {
|
||||
my $Message = $LanguageObject->Translate("Value is not correct! Please, consider updating this field.");
|
||||
|
||||
$HTML .= $Param{IsValid} ? "<div class='BadEffectiveValue'>\n" : "<div>\n";
|
||||
$HTML .= "<p>* $Message</p>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
$HTML .= "</div>\n";
|
||||
|
||||
if ( !$Param{IsArray} && !$Param{IsHash} ) {
|
||||
my $DefaultText = $LanguageObject->Translate('Default');
|
||||
|
||||
$HTML .= <<"EOF";
|
||||
<div class=\"WidgetMessage Bottom\">
|
||||
$DefaultText: $Param{DefaultValue}
|
||||
</div>
|
||||
EOF
|
||||
}
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
=head2 AddItem()
|
||||
|
||||
Generate HTML for new array/hash item.
|
||||
|
||||
my $HTML = $ValueTypeObject->AddItem(
|
||||
Name => 'SettingName', (required) Name
|
||||
DefaultItem => { (required) DefaultItem hash
|
||||
'ValueType' => 'TimeZone',
|
||||
'Content' => 'UTC'
|
||||
},
|
||||
IDSuffix => '_Array1', (optional) IDSuffix is needed for arrays and hashes.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$HTML = '<select class="Modernize" id="SettingName" name="SettingName" title="SettingName">
|
||||
...
|
||||
</select>';
|
||||
|
||||
=cut
|
||||
|
||||
sub AddItem {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check needed stuff.
|
||||
for my $Needed (qw(Name DefaultItem)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{DefaultValue} //= '';
|
||||
$Param{IDSuffix} //= '';
|
||||
|
||||
my $DateTimeObject = $Kernel::OM->Create(
|
||||
'Kernel::System::DateTime',
|
||||
);
|
||||
my $TimeZones = $DateTimeObject->TimeZoneList();
|
||||
|
||||
my $Result = $Kernel::OM->Get('Kernel::Output::HTML::Layout')->BuildSelection(
|
||||
Data => $TimeZones,
|
||||
Name => $Param{Name},
|
||||
ID => $Param{Name} . $Param{IDSuffix},
|
||||
SelectedValue => $Param{DefaultItem}->{Content},
|
||||
Title => $Param{Name},
|
||||
OptionTitle => 1,
|
||||
Class => "$Param{Class} Modernize Entry",
|
||||
);
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
552
Perl OTRS/Kernel/System/SysConfig/ValueType/VacationDays.pm
Normal file
552
Perl OTRS/Kernel/System/SysConfig/ValueType/VacationDays.pm
Normal file
@@ -0,0 +1,552 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
## nofilter(TidyAll::Plugin::OTRS::Perl::LayoutObject)
|
||||
package Kernel::System::SysConfig::ValueType::VacationDays;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Language',
|
||||
'Kernel::Output::HTML::Layout',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::VacationDays - System configuration vacation-days value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::VacationDays');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingEffectiveValueCheck()
|
||||
|
||||
Check if provided EffectiveValue matches structure defined in XMLContentParsed.
|
||||
|
||||
my %Result = $ValueTypeObject->SettingEffectiveValueCheck(
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => 'New Year\'s Day',
|
||||
'Translatable' => '1',
|
||||
'ValueDay' => '1',
|
||||
'ValueMonth' => '1',
|
||||
},
|
||||
],
|
||||
'ValueType' => 'VacationDays',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
EffectiveValue => {
|
||||
'1' => {
|
||||
'1' => 'New Year\'s Day',
|
||||
},
|
||||
'12' => {
|
||||
'24' => 'Christmas Eve',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Result:
|
||||
%Result = (
|
||||
EffectiveValue => { # Note for VacationDays ValueTypes EffectiveValue is not changed.
|
||||
'1' => {
|
||||
'1' => 'New Year\'s Day',
|
||||
},
|
||||
'12' => {
|
||||
'24' => 'Christmas Eve',
|
||||
},
|
||||
},
|
||||
Success => 1,
|
||||
Error => undef,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingEffectiveValueCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(XMLContentParsed)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Result = (
|
||||
Success => 0,
|
||||
);
|
||||
|
||||
# Data should be hash.
|
||||
if ( ref $Param{EffectiveValue} ne 'HASH' ) {
|
||||
$Result{Error} = 'EffectiveValue for VacationDays must be a hash!';
|
||||
return %Result;
|
||||
}
|
||||
|
||||
MONTH:
|
||||
for my $Month ( sort keys %{ $Param{EffectiveValue} } ) {
|
||||
if ( $Month !~ m{^([1-9]|1[0-2])$}gsmx ) {
|
||||
$Result{Error} = "'$Month' must be a month number(1..12)!";
|
||||
last MONTH;
|
||||
}
|
||||
|
||||
if ( !IsHashRefWithData( $Param{EffectiveValue}->{$Month} ) ) {
|
||||
$Result{Error} = "'$Month' must be a hash reference!";
|
||||
last MONTH;
|
||||
}
|
||||
|
||||
for my $Day ( sort keys %{ $Param{EffectiveValue}->{$Month} } ) {
|
||||
if ( $Day !~ m{^([1-9]|[12][0-9]|3[01])$}gsmx ) {
|
||||
$Result{Error} = "'$Day' must be a day number(1..31)!";
|
||||
last MONTH;
|
||||
}
|
||||
|
||||
if (
|
||||
ref $Param{EffectiveValue}->{$Month}->{$Day}
|
||||
|| !$Param{EffectiveValue}->{$Month}->{$Day}
|
||||
)
|
||||
{
|
||||
$Result{Error} = "Vacation description must be a string!";
|
||||
last MONTH;
|
||||
}
|
||||
}
|
||||
}
|
||||
return %Result if $Result{Error};
|
||||
|
||||
$Result{Success} = 1;
|
||||
$Result{EffectiveValue} = $Param{EffectiveValue};
|
||||
|
||||
return %Result;
|
||||
}
|
||||
|
||||
sub EffectiveValueGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !IsArrayRefWithData( $Param{Value} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Value is missing or invalid!",
|
||||
);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( scalar @{ $Param{Value} } > 1 ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Value must be a single element!",
|
||||
);
|
||||
return '';
|
||||
}
|
||||
|
||||
return '' if !$Param{Value}->[0]->{Item};
|
||||
|
||||
return '' if ref $Param{Value}->[0]->{Item} ne 'ARRAY';
|
||||
|
||||
my %Result;
|
||||
|
||||
COMPONENT:
|
||||
for my $Component ( @{ $Param{Value}->[0]->{Item} } ) {
|
||||
next COMPONENT if !$Component->{ValueMonth};
|
||||
next COMPONENT if !$Component->{ValueDay};
|
||||
$Result{ $Component->{ValueMonth} }->{ $Component->{ValueDay} } = $Component->{Content};
|
||||
}
|
||||
|
||||
return \%Result;
|
||||
}
|
||||
|
||||
sub ModifiedValueGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(Value EffectiveValue)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ref $Param{EffectiveValue} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "EffectiveValue mush be a hash reference!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $Result = $Param{Value};
|
||||
|
||||
my @Items;
|
||||
|
||||
# Update Content
|
||||
MONTH:
|
||||
for my $Month ( sort { $a <=> $b } keys %{ $Param{EffectiveValue} } ) {
|
||||
|
||||
if ( ref $Param{EffectiveValue}->{$Month} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "EffectiveValue must be a HoH!"
|
||||
);
|
||||
next MONTH;
|
||||
}
|
||||
|
||||
for my $Day ( sort { $a <=> $b } keys %{ $Param{EffectiveValue}->{$Month} } ) {
|
||||
my $Item = {
|
||||
'ValueMonth' => $Month,
|
||||
'ValueDay' => $Day,
|
||||
'Content' => $Param{EffectiveValue}->{$Month}->{$Day},
|
||||
'Translatable' => '1',
|
||||
};
|
||||
|
||||
push @Items, $Item;
|
||||
}
|
||||
}
|
||||
|
||||
$Result->[0]->{Item}->[0]->{Item} = \@Items;
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
=head2 SettingRender()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $SettingHTML = $ValueTypeObject->SettingRender(
|
||||
Name => 'SettingName',
|
||||
DefaultID => 123, # (required)
|
||||
EffectiveValue => '{
|
||||
'1' => {
|
||||
'1' => 'New Year\'s Day',
|
||||
},
|
||||
...
|
||||
},
|
||||
DefaultValue => 'Product 5', # (optional)
|
||||
Class => 'My class' # (optional)
|
||||
Item => [ # (optional) XML parsed item
|
||||
{
|
||||
'ValueType' => 'VacationDays',
|
||||
'Content' => '',
|
||||
'ValueRegex' => '',
|
||||
},
|
||||
],
|
||||
RW => 1, # (optional) Allow editing. Default 0.
|
||||
IsArray => 1, # (optional) Item is part of the array
|
||||
IsHash => 1, # (optional) Item is part of the hash
|
||||
IDSuffix => 1, # (optional) Suffix will be added to the element ID
|
||||
SkipEffectiveValueCheck => 1, # (optional) If enabled, system will not perform effective value check.
|
||||
# Default: 1.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$SettingHTML = '<div class "Field"...</div>';
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingRender {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(Name EffectiveValue)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{Class} .= " VacationDays ";
|
||||
$Param{DefaultValue} //= '';
|
||||
my $IDSuffix = $Param{IDSuffix} || '';
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
|
||||
|
||||
my $EffectiveValue = $Param{EffectiveValue};
|
||||
|
||||
my %EffectiveValueCheck = (
|
||||
Success => 1,
|
||||
);
|
||||
|
||||
if ( !$Param{SkipEffectiveValueCheck} ) {
|
||||
%EffectiveValueCheck = $Self->SettingEffectiveValueCheck(
|
||||
EffectiveValue => $EffectiveValue,
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
Item => $Param{Item},
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
my $HTML = "<div class='Array VacationDaysArray'>\n";
|
||||
|
||||
if ( !$EffectiveValueCheck{Success} ) {
|
||||
my $Message = $LanguageObject->Translate("Value is not correct! Please, consider updating this setting.");
|
||||
|
||||
$HTML .= $Param{IsValid} ? "<div class='BadEffectiveValue'>\n" : "<div>\n";
|
||||
$HTML .= "<p>* $Message</p>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
my @Days;
|
||||
for my $Item ( 1 .. 31 ) {
|
||||
push @Days, sprintf( "%02d", $Item );
|
||||
}
|
||||
|
||||
my @Months;
|
||||
for my $Item ( 1 .. 12 ) {
|
||||
push @Months, sprintf( "%02d", $Item );
|
||||
}
|
||||
|
||||
my $AddNewEntry = $LanguageObject->Translate("Add new entry");
|
||||
my $RemoveThisEntry = $LanguageObject->Translate("Remove this entry");
|
||||
|
||||
my $Index = 1;
|
||||
|
||||
for my $Month ( sort { $a <=> $b } keys %{ $Param{EffectiveValue} } ) {
|
||||
|
||||
for my $Day ( sort { $a <=> $b } keys %{ $Param{EffectiveValue}->{$Month} } ) {
|
||||
my $Text = $Param{EffectiveValue}->{$Month}->{$Day};
|
||||
|
||||
$HTML .= "<div class='ArrayItem'>\n";
|
||||
$HTML .= "<div class='SettingContent'>\n";
|
||||
|
||||
# month
|
||||
$HTML .= $LayoutObject->BuildSelection(
|
||||
Data => \@Months,
|
||||
Name => $Param{Name},
|
||||
ID => $Param{Name} . $IDSuffix . $Index . "Month",
|
||||
Class => $Param{Class},
|
||||
Disabled => $Param{RW} ? 0 : 1,
|
||||
SelectedValue => sprintf( "%02d", $Month ),
|
||||
Title => $LanguageObject->Translate("Month"),
|
||||
);
|
||||
|
||||
$HTML .= "<span>/</span>";
|
||||
|
||||
# day
|
||||
$HTML .= $LayoutObject->BuildSelection(
|
||||
Data => \@Days,
|
||||
Name => $Param{Name},
|
||||
ID => $Param{Name} . $IDSuffix . $Index . "Day",
|
||||
Class => $Param{Class},
|
||||
Disabled => $Param{RW} ? 0 : 1,
|
||||
SelectedValue => sprintf( "%02d", $Day ),
|
||||
Title => $LanguageObject->Translate("Day"),
|
||||
);
|
||||
|
||||
# description
|
||||
my $HTMLDescription = $LayoutObject->Ascii2Html(
|
||||
Text => $Text,
|
||||
Type => 'Normal',
|
||||
);
|
||||
$HTML .= "<input class=\"$Param{Class}\" type=\"text\" name=\"$Param{Name}\" "
|
||||
. "id=\"$Param{Name}$IDSuffix" . $Index . "Description\" value=\"$HTMLDescription\" "
|
||||
. "title=\"" . $LanguageObject->Translate("Description") . "\" ";
|
||||
|
||||
if ( !$Param{RW} ) {
|
||||
$HTML .= "disabled='disabled' ";
|
||||
}
|
||||
|
||||
$HTML .= " />\n";
|
||||
|
||||
$HTML .= "</div>\n"; # SettingContent
|
||||
|
||||
if ( $Param{RW} ) {
|
||||
$HTML .= "<button class='RemoveButton' type='button' "
|
||||
. "title='$RemoveThisEntry' value='Remove this entry'>\n"
|
||||
. " <i class='fa fa-minus-circle'></i>\n"
|
||||
. " <span class='InvisibleText'>$RemoveThisEntry</span>\n"
|
||||
. "</button>\n";
|
||||
}
|
||||
$HTML .= "</div>\n"; # ArrayItem
|
||||
$Index++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $Param{RW} ) {
|
||||
$HTML .= " <button data-suffix='$Index' class='AddArrayItem' "
|
||||
. "type='button' title='$AddNewEntry' value='Add new entry'>\n"
|
||||
. " <i class='fa fa-plus-circle'></i>\n"
|
||||
. " <span class='InvisibleText'>$AddNewEntry</span>\n"
|
||||
. " </button>\n";
|
||||
}
|
||||
$HTML .= "</div>\n"; # Array
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
=head2 AddItem()
|
||||
|
||||
Generate HTML for new array/hash item.
|
||||
|
||||
my $HTML = $ValueTypeObject->AddItem(
|
||||
Name => 'SettingName', (required) Name
|
||||
DefaultItem => { (optional) DefaultItem hash, if available
|
||||
Item => {
|
||||
Content => 'Value',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$HTML = "<input type='text' id='Setting_ExampleArray'
|
||||
value='Value' name='ExampleArray' class='Entry'/>";
|
||||
|
||||
=cut
|
||||
|
||||
sub AddItem {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check needed stuff.
|
||||
for my $Needed (qw(Name)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
|
||||
|
||||
my $IDSuffix = $Param{IDSuffix} || '';
|
||||
my $Class = $Param{Class} || '';
|
||||
$Class .= " VacationDays ";
|
||||
|
||||
my $Name = $Param{Name} . $IDSuffix;
|
||||
|
||||
my @Days;
|
||||
for my $Item ( 1 .. 31 ) {
|
||||
push @Days, sprintf( "%02d", $Item );
|
||||
}
|
||||
|
||||
my @Months;
|
||||
for my $Item ( 1 .. 12 ) {
|
||||
push @Months, sprintf( "%02d", $Item );
|
||||
}
|
||||
|
||||
my $RemoveThisEntry = $Kernel::OM->Get('Kernel::Language')->Translate("Remove this entry");
|
||||
|
||||
my $HTML = "";
|
||||
|
||||
# month
|
||||
$HTML .= $LayoutObject->BuildSelection(
|
||||
Data => \@Months,
|
||||
Name => $Param{Name},
|
||||
ID => $Param{Name} . $IDSuffix . "Month",
|
||||
Class => $Class,
|
||||
SelectedValue => '01',
|
||||
Title => $LanguageObject->Translate("Month"),
|
||||
);
|
||||
|
||||
$HTML .= "<span>/</span>";
|
||||
|
||||
# day
|
||||
$HTML .= $LayoutObject->BuildSelection(
|
||||
Data => \@Days,
|
||||
Name => $Param{Name},
|
||||
ID => $Param{Name} . $IDSuffix . "Day",
|
||||
Class => $Class,
|
||||
SelectedValue => '01',
|
||||
Title => $LanguageObject->Translate("Day"),
|
||||
);
|
||||
|
||||
# Description
|
||||
$HTML .= "<input class=\"$Class\" type=\"text\" name=\"$Param{Name}\" "
|
||||
. "id=\"$Param{Name}$IDSuffix" . "Description\" value=\"\" "
|
||||
. "title=\"" . $LanguageObject->Translate("Description") . "\" "
|
||||
. " />\n";
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
=head2 DefaultItemAdd()
|
||||
|
||||
Return structure of the DefaultItem in case it's not inside of Array or Hash.
|
||||
|
||||
my $DefaultItem = $ValueTypeObject->DefaultItemAdd();
|
||||
|
||||
Returns:
|
||||
|
||||
$DefaultItem = {
|
||||
Item => {
|
||||
Content => '',
|
||||
},
|
||||
ValueType => 'VacationDays',
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub DefaultItemAdd {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my %Result = (
|
||||
Item => {
|
||||
Content => '',
|
||||
},
|
||||
ValueType => 'VacationDays',
|
||||
);
|
||||
|
||||
return \%Result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,598 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
## nofilter(TidyAll::Plugin::OTRS::Perl::LayoutObject)
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::VacationDaysOneTime;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Language',
|
||||
'Kernel::Output::HTML::Layout',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::VacationDaysOneTime - System configuration vacation-days-one-time value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::VacationDaysOneTime');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingEffectiveValueCheck()
|
||||
|
||||
Check if provided EffectiveValue matches structure defined in XMLContentParsed.
|
||||
|
||||
my %Result = $ValueTypeObject->SettingEffectiveValueCheck(
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => 'New Year\'s Day',
|
||||
'Translatable' => '1',
|
||||
'ValueDay' => '1',
|
||||
'ValueMonth' => '1',
|
||||
'ValueYear' => '2004',
|
||||
},
|
||||
],
|
||||
'ValueType' => 'VacationDaysOneTime',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
EffectiveValue => {
|
||||
'2014' => {
|
||||
'1' => {
|
||||
'1' => 'New Year\'s Day',
|
||||
},
|
||||
},
|
||||
'2016' => {
|
||||
'2' => {
|
||||
'2' => 'Test',
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Result:
|
||||
%Result = (
|
||||
EffectiveValue => { # Note for VacationDaysOneTime ValueTypes EffectiveValue is not changed.
|
||||
'2014' => {
|
||||
'1' => {
|
||||
'1' => 'New Year\'s Day',
|
||||
},
|
||||
},
|
||||
'2016' => {
|
||||
'2' => {
|
||||
'2' => 'Test',
|
||||
},
|
||||
},
|
||||
},
|
||||
Success => 1,
|
||||
Error => undef,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingEffectiveValueCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(XMLContentParsed)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Result = (
|
||||
Success => 0,
|
||||
);
|
||||
|
||||
# Data should be hash.
|
||||
if ( ref $Param{EffectiveValue} ne 'HASH' ) {
|
||||
$Result{Error} = 'EffectiveValue for VacationDaysOneTime must be a hash!';
|
||||
return %Result;
|
||||
}
|
||||
|
||||
YEAR:
|
||||
for my $Year ( sort keys %{ $Param{EffectiveValue} } ) {
|
||||
if ( $Year !~ m{^\d{4}$}gsmx ) {
|
||||
$Result{Error} = "'$Year' must be a year number(1000-9999)!";
|
||||
last YEAR;
|
||||
}
|
||||
|
||||
if ( !IsHashRefWithData( $Param{EffectiveValue}->{$Year} ) ) {
|
||||
$Result{Error} = "'$Year' must be a hash reference!";
|
||||
return %Result;
|
||||
}
|
||||
|
||||
for my $Month ( sort keys %{ $Param{EffectiveValue}->{$Year} } ) {
|
||||
if ( $Month !~ m{^([1-9]|1[0-2])$}gsmx ) {
|
||||
$Result{Error} = "'$Month' must be a month number(1..12)!";
|
||||
last YEAR;
|
||||
}
|
||||
|
||||
if ( !IsHashRefWithData( $Param{EffectiveValue}->{$Year}->{$Month} ) ) {
|
||||
$Result{Error} = "'$Month' must be a hash reference!";
|
||||
last YEAR;
|
||||
}
|
||||
|
||||
for my $Day ( sort keys %{ $Param{EffectiveValue}->{$Year}->{$Month} } ) {
|
||||
if ( $Day !~ m{^([1-9]|[12][0-9]|3[01])$}gsmx ) {
|
||||
$Result{Error} = "'$Day' must be a day number(1..31)!";
|
||||
last YEAR;
|
||||
}
|
||||
|
||||
if (
|
||||
ref $Param{EffectiveValue}->{$Year}->{$Month}->{$Day}
|
||||
|| !$Param{EffectiveValue}->{$Year}->{$Month}->{$Day}
|
||||
)
|
||||
{
|
||||
$Result{Error} = "Vacation description must be a string!";
|
||||
last YEAR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return %Result if $Result{Error};
|
||||
|
||||
$Result{Success} = 1;
|
||||
$Result{EffectiveValue} = $Param{EffectiveValue};
|
||||
|
||||
return %Result;
|
||||
}
|
||||
|
||||
sub EffectiveValueGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !IsArrayRefWithData( $Param{Value} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Value is missing or invalid!",
|
||||
);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( scalar @{ $Param{Value} } > 1 ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Value must be a single element!",
|
||||
);
|
||||
return '';
|
||||
}
|
||||
|
||||
return '' if !$Param{Value}->[0]->{Item};
|
||||
|
||||
return '' if ref $Param{Value}->[0]->{Item} ne 'ARRAY';
|
||||
|
||||
my %Result;
|
||||
|
||||
COMPONENT:
|
||||
for my $Component ( @{ $Param{Value}->[0]->{Item} } ) {
|
||||
next COMPONENT if !$Component->{ValueYear};
|
||||
next COMPONENT if !$Component->{ValueMonth};
|
||||
next COMPONENT if !$Component->{ValueDay};
|
||||
$Result{ $Component->{ValueYear} }->{ $Component->{ValueMonth} }->{ $Component->{ValueDay} }
|
||||
= $Component->{Content};
|
||||
}
|
||||
|
||||
return \%Result;
|
||||
}
|
||||
|
||||
sub ModifiedValueGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(Value EffectiveValue)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ref $Param{EffectiveValue} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "EffectiveValue mush be a hash reference!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $Result = $Param{Value};
|
||||
|
||||
my @Items;
|
||||
|
||||
# Update Content
|
||||
YEAR:
|
||||
for my $Year ( sort { $a <=> $b } keys %{ $Param{EffectiveValue} } ) {
|
||||
if ( ref $Param{EffectiveValue}->{$Year} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "EffectiveValue must be a HoH!"
|
||||
);
|
||||
next YEAR;
|
||||
}
|
||||
|
||||
MONTH:
|
||||
for my $Month ( sort { $a <=> $b } keys %{ $Param{EffectiveValue}->{$Year} } ) {
|
||||
|
||||
if ( ref $Param{EffectiveValue}->{$Year}->{$Month} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "EffectiveValue must be a HoHoH!"
|
||||
);
|
||||
next MONTH;
|
||||
}
|
||||
|
||||
for my $Day ( sort { $a <=> $b } keys %{ $Param{EffectiveValue}->{$Year}->{$Month} } ) {
|
||||
my $Item = {
|
||||
'ValueYear' => $Year,
|
||||
'ValueMonth' => $Month,
|
||||
'ValueDay' => $Day,
|
||||
'Content' => $Param{EffectiveValue}->{$Year}->{$Month}->{$Day},
|
||||
};
|
||||
|
||||
push @Items, $Item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$Result->[0]->{Item}->[0]->{Item} = \@Items;
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
=head2 SettingRender()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $SettingHTML = $ValueTypeObject->SettingRender(
|
||||
Name => 'SettingName',
|
||||
DefaultID => 123, # (required)
|
||||
EffectiveValue => '{
|
||||
'2016' => {
|
||||
'1' => {
|
||||
'1' => 'New Year\'s Day',
|
||||
},
|
||||
},
|
||||
...
|
||||
},
|
||||
DefaultValue => 'Product 5', # (optional)
|
||||
Class => 'My class' # (optional)
|
||||
Item => [ # (optional) XML parsed item
|
||||
{
|
||||
'ValueType' => 'VacationDaysOneTime',
|
||||
'Content' => '',
|
||||
'ValueRegex' => '',
|
||||
},
|
||||
],
|
||||
RW => 1, # (optional) Allow editing. Default 0.
|
||||
IsArray => 1, # (optional) Item is part of the array
|
||||
IsHash => 1, # (optional) Item is part of the hash
|
||||
IDSuffix => 1, # (optional) Suffix will be added to the element ID
|
||||
SkipEffectiveValueCheck => 1, # (optional) If enabled, system will not perform effective value check.
|
||||
# Default: 1.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$SettingHTML = '<div class "Field"...</div>';
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingRender {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(Name EffectiveValue)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{Class} .= " VacationDaysOneTime ";
|
||||
$Param{DefaultValue} //= '';
|
||||
my $IDSuffix = $Param{IDSuffix} || '';
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
|
||||
|
||||
my $EffectiveValue = $Param{EffectiveValue};
|
||||
|
||||
my %EffectiveValueCheck = (
|
||||
Success => 1,
|
||||
);
|
||||
|
||||
if ( !$Param{SkipEffectiveValueCheck} ) {
|
||||
%EffectiveValueCheck = $Self->SettingEffectiveValueCheck(
|
||||
EffectiveValue => $EffectiveValue,
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
Item => $Param{Item},
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
my $HTML = "<div class='Array VacationDaysOneTimeArray'>\n";
|
||||
|
||||
if ( !$EffectiveValueCheck{Success} ) {
|
||||
my $Message = $LanguageObject->Translate("Value is not correct! Please, consider updating this setting.");
|
||||
|
||||
$HTML .= $Param{IsValid} ? "<div class='BadEffectiveValue'>\n" : "<div>\n";
|
||||
$HTML .= "<p>* $Message</p>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
my @Days;
|
||||
for my $Item ( 1 .. 31 ) {
|
||||
push @Days, sprintf( "%02d", $Item );
|
||||
}
|
||||
|
||||
my @Months;
|
||||
for my $Item ( 1 .. 12 ) {
|
||||
push @Months, sprintf( "%02d", $Item );
|
||||
}
|
||||
|
||||
my $AddNewEntry = $LanguageObject->Translate("Add new entry");
|
||||
my $RemoveThisEntry = $LanguageObject->Translate("Remove this entry");
|
||||
|
||||
my $Index = 1;
|
||||
|
||||
my $DateTime = $Kernel::OM->Create('Kernel::System::DateTime')->Get();
|
||||
|
||||
for my $Year ( sort { $a <=> $b } keys %{ $Param{EffectiveValue} } ) {
|
||||
for my $Month ( sort { $a <=> $b } keys %{ $Param{EffectiveValue}->{$Year} } ) {
|
||||
|
||||
for my $Day ( sort { $a <=> $b } keys %{ $Param{EffectiveValue}->{$Year}->{$Month} } ) {
|
||||
my $Text = $Param{EffectiveValue}->{$Year}->{$Month}->{$Day};
|
||||
|
||||
$HTML .= "<div class='ArrayItem'>\n";
|
||||
$HTML .= "<div class='SettingContent'>\n";
|
||||
|
||||
my $YearPeriodFuture = 10;
|
||||
my $YearPeriodPast = 10;
|
||||
|
||||
if ( $DateTime->{Year} - 10 > $Year ) {
|
||||
$YearPeriodPast = $DateTime->{Year} - $Year;
|
||||
}
|
||||
elsif ( $DateTime->{Year} + 10 < $Year ) {
|
||||
$YearPeriodFuture = $Year - $DateTime->{Year};
|
||||
}
|
||||
|
||||
my $Prefix = $Param{Name} . $IDSuffix . $Index;
|
||||
|
||||
$HTML .= $LayoutObject->BuildDateSelection(
|
||||
Prefix => $Prefix,
|
||||
$Prefix . "Year" => $Year,
|
||||
$Prefix . "Month" => $Month,
|
||||
$Prefix . "Day" => $Day,
|
||||
$Prefix . "Class" => $Param{Class},
|
||||
YearPeriodFuture => $YearPeriodFuture,
|
||||
YearPeriodPast => $YearPeriodPast,
|
||||
Format => 'DateInputFormat',
|
||||
Validate => 1,
|
||||
Disabled => $Param{RW} ? 0 : 1,
|
||||
);
|
||||
|
||||
# description
|
||||
my $HTMLDescription = $LayoutObject->Ascii2Html(
|
||||
Text => $Text,
|
||||
Type => 'Normal',
|
||||
);
|
||||
$HTML .= "<input class=\"$Param{Class}\" type=\"text\" name=\"$Param{Name}\" "
|
||||
. "id=\"$Param{Name}$IDSuffix" . $Index . "Description\" value=\"$HTMLDescription\" "
|
||||
. "title=\"" . $LanguageObject->Translate("Description") . "\" ";
|
||||
|
||||
if ( !$Param{RW} ) {
|
||||
$HTML .= "disabled='disabled' ";
|
||||
}
|
||||
|
||||
$HTML .= " />\n";
|
||||
|
||||
$HTML .= "</div>\n"; # SettingContent
|
||||
|
||||
if ( $Param{RW} ) {
|
||||
$HTML .= "<button class='RemoveButton' type='button' "
|
||||
. "title='$RemoveThisEntry' value='Remove this entry'>\n"
|
||||
. " <i class='fa fa-minus-circle'></i>\n"
|
||||
. " <span class='InvisibleText'>$RemoveThisEntry</span>\n"
|
||||
. "</button>\n";
|
||||
}
|
||||
$HTML .= "</div>\n"; # ArrayItem
|
||||
$Index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $Param{RW} ) {
|
||||
$HTML .= " <button data-suffix='$Index' class='AddArrayItem' "
|
||||
. "type='button' title='$AddNewEntry' value='Add new entry'>\n"
|
||||
. " <i class='fa fa-plus-circle'></i>\n"
|
||||
. " <span class='InvisibleText'>$AddNewEntry</span>\n"
|
||||
. " </button>\n";
|
||||
}
|
||||
$HTML .= "</div>\n"; # Array
|
||||
|
||||
if ( $Param{IsAjax} && $LayoutObject->{_JSOnDocumentComplete} && $Param{RW} ) {
|
||||
for my $JS ( @{ $LayoutObject->{_JSOnDocumentComplete} } ) {
|
||||
$HTML .= "<script>$JS</script>";
|
||||
}
|
||||
}
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
=head2 AddItem()
|
||||
|
||||
Generate HTML for new array/hash item.
|
||||
|
||||
my $HTML = $ValueTypeObject->AddItem(
|
||||
Name => 'SettingName', (required) Name
|
||||
DefaultItem => { (optional) DefaultItem hash, if available
|
||||
Item => {
|
||||
Content => 'Value',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$HTML = "<input type='text' id='Setting_ExampleArray'
|
||||
value='Value' name='ExampleArray' class='Entry'/>";
|
||||
|
||||
=cut
|
||||
|
||||
sub AddItem {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check needed stuff.
|
||||
for my $Needed (qw(Name)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
|
||||
|
||||
my $IDSuffix = $Param{IDSuffix} || '';
|
||||
my $Class = $Param{Class} || '';
|
||||
$Class .= " VacationDaysOneTime ";
|
||||
|
||||
my $Name = $Param{Name} . $IDSuffix;
|
||||
|
||||
my @Days;
|
||||
for my $Item ( 1 .. 31 ) {
|
||||
push @Days, sprintf( "%02d", $Item );
|
||||
}
|
||||
|
||||
my @Months;
|
||||
for my $Item ( 1 .. 12 ) {
|
||||
push @Months, sprintf( "%02d", $Item );
|
||||
}
|
||||
|
||||
my $RemoveThisEntry = $Kernel::OM->Get('Kernel::Language')->Translate("Remove this entry");
|
||||
|
||||
my $DateTime = $Kernel::OM->Create('Kernel::System::DateTime')->Get();
|
||||
|
||||
my $HTML = "";
|
||||
|
||||
my $Prefix = $Param{Name} . $IDSuffix;
|
||||
|
||||
$HTML .= $LayoutObject->BuildDateSelection(
|
||||
Prefix => $Prefix,
|
||||
$Prefix . "Year" => $DateTime->{Year},
|
||||
$Prefix . "Month" => $DateTime->{Month},
|
||||
$Prefix . "Day" => $DateTime->{Day},
|
||||
$Prefix . "Class" => $Class,
|
||||
YearPeriodFuture => 10,
|
||||
YearPeriodPast => 10,
|
||||
Format => 'DateInputFormat',
|
||||
Validate => 1,
|
||||
);
|
||||
|
||||
# Description
|
||||
$HTML .= "<input class=\"$Class\" type=\"text\" name=\"$Param{Name}\" "
|
||||
. "id=\"$Param{Name}$IDSuffix" . "Description\" value=\"\" "
|
||||
. "title=\"" . $LanguageObject->Translate("Description") . "\" "
|
||||
. " />\n";
|
||||
|
||||
for my $JS ( @{ $LayoutObject->{_JSOnDocumentComplete} } ) {
|
||||
$HTML .= "<script>$JS</script>";
|
||||
}
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
=head2 DefaultItemAdd()
|
||||
|
||||
Return structure of the DefaultItem in case it's not inside of Array or Hash.
|
||||
|
||||
my $DefaultItem = $ValueTypeObject->DefaultItemAdd();
|
||||
|
||||
Returns:
|
||||
|
||||
$DefaultItem = {
|
||||
Item => {
|
||||
Content => '',
|
||||
},
|
||||
ValueType => 'VacationDaysOneTime',
|
||||
};
|
||||
|
||||
=cut
|
||||
|
||||
sub DefaultItemAdd {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my %Result = (
|
||||
Item => {
|
||||
Content => '',
|
||||
},
|
||||
ValueType => 'VacationDaysOneTime',
|
||||
);
|
||||
|
||||
return \%Result;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
408
Perl OTRS/Kernel/System/SysConfig/ValueType/WorkingHours.pm
Normal file
408
Perl OTRS/Kernel/System/SysConfig/ValueType/WorkingHours.pm
Normal file
@@ -0,0 +1,408 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::ValueType::WorkingHours;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use parent qw(Kernel::System::SysConfig::BaseValueType);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Language',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::ValueType::WorkingHours - System configuration working-hours value type backed.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::WorkingHours');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# Allocate new hash for object.
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingEffectiveValueCheck()
|
||||
|
||||
Check if provided EffectiveValue matches structure defined in XMLContentParsed.
|
||||
|
||||
my %Result = $ValueTypeObject->SettingEffectiveValueCheck(
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Item' => [
|
||||
{
|
||||
'Content' => '8',
|
||||
'ValueType' => 'Hour',
|
||||
},
|
||||
],
|
||||
'ValueName' => 'Tue',
|
||||
'ValueType' => 'Day',
|
||||
},
|
||||
],
|
||||
'ValueType' => 'WorkingHours',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
EffectiveValue => {
|
||||
'Fri' => [
|
||||
'8',
|
||||
'9',
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
Result:
|
||||
%Result = (
|
||||
EffectiveValue => { # Note for WorkingHours ValueTypes EffectiveValue is not changed.
|
||||
'Fri' => [
|
||||
'8',
|
||||
'9',
|
||||
],
|
||||
},
|
||||
Success => 1,
|
||||
Error => undef,
|
||||
);
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingEffectiveValueCheck {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(XMLContentParsed)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!"
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my %Result = (
|
||||
Success => 0,
|
||||
);
|
||||
|
||||
# Data should be hash.
|
||||
if ( ref $Param{EffectiveValue} ne 'HASH' ) {
|
||||
$Result{Error} = 'EffectiveValue for WorkingHours must be a hash!';
|
||||
return %Result;
|
||||
}
|
||||
|
||||
my @Days = ( 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' );
|
||||
|
||||
DAY:
|
||||
for my $Day ( sort keys %{ $Param{EffectiveValue} } ) {
|
||||
if ( !grep { $_ eq $Day } @Days ) {
|
||||
$Result{Error} = "'$Day' must be Mon, Tue, Wed, Thu, Fri, Sat or Sun!";
|
||||
last DAY;
|
||||
}
|
||||
|
||||
if ( ref $Param{EffectiveValue}->{$Day} ne 'ARRAY' ) {
|
||||
$Result{Error} = "'$Day' must be an array reference!";
|
||||
last DAY;
|
||||
}
|
||||
|
||||
for my $Hour ( @{ $Param{EffectiveValue}->{$Day} } ) {
|
||||
|
||||
if ( $Hour !~ m{^([0-9]|1[0-9]|2[0-3])$}msx ) {
|
||||
$Result{Error} = "'$Hour' must be number(0-23)!";
|
||||
last DAY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return %Result if $Result{Error};
|
||||
|
||||
$Result{Success} = 1;
|
||||
$Result{EffectiveValue} = $Param{EffectiveValue};
|
||||
|
||||
return %Result;
|
||||
}
|
||||
|
||||
sub EffectiveValueGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
if ( !IsArrayRefWithData( $Param{Value} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Value is missing or invalid!",
|
||||
);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( scalar @{ $Param{Value} } > 1 ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Value must be a single element!",
|
||||
);
|
||||
return '';
|
||||
}
|
||||
|
||||
return '' if !$Param{Value}->[0]->{Item};
|
||||
|
||||
return '' if ref $Param{Value}->[0]->{Item} ne 'ARRAY';
|
||||
|
||||
my %Result;
|
||||
|
||||
COMPONENT:
|
||||
for my $Component ( @{ $Param{Value}->[0]->{Item} } ) {
|
||||
next COMPONENT if !$Component->{ValueName};
|
||||
next COMPONENT if !$Component->{ValueType};
|
||||
|
||||
$Result{ $Component->{ValueName} } = [];
|
||||
|
||||
next COMPONENT if !$Component->{Item};
|
||||
next COMPONENT if ref $Component->{Item} ne 'ARRAY';
|
||||
|
||||
HOUR:
|
||||
for my $Hour ( @{ $Component->{Item} } ) {
|
||||
next HOUR if !$Hour->{Content};
|
||||
|
||||
push @{ $Result{ $Component->{ValueName} } }, $Hour->{Content};
|
||||
}
|
||||
}
|
||||
|
||||
return \%Result;
|
||||
}
|
||||
|
||||
sub ModifiedValueGet {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(Value EffectiveValue)) {
|
||||
if ( !$Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ref $Param{EffectiveValue} ne 'HASH' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "EffectiveValue mush be a hash reference!"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $Result = $Param{Value};
|
||||
|
||||
my @Days = ( 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' );
|
||||
|
||||
my @Items;
|
||||
|
||||
# Update Content
|
||||
DAY:
|
||||
for my $Day (@Days) {
|
||||
if ( !$Param{EffectiveValue}->{$Day} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Missing value for $Day!"
|
||||
);
|
||||
next DAY;
|
||||
}
|
||||
|
||||
if ( ref $Param{EffectiveValue}->{$Day} ne 'ARRAY' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "EffectiveValue must be HoA!"
|
||||
);
|
||||
next DAY;
|
||||
}
|
||||
|
||||
my @HourItems;
|
||||
|
||||
for my $Hour ( @{ $Param{EffectiveValue}->{$Day} } ) {
|
||||
push @HourItems, {
|
||||
Content => $Hour,
|
||||
ValueType => 'Hour',
|
||||
};
|
||||
}
|
||||
|
||||
my $Item = {
|
||||
'ValueName' => $Day,
|
||||
'ValueType' => 'Day',
|
||||
};
|
||||
|
||||
if ( scalar @HourItems ) {
|
||||
$Item->{Item} = \@HourItems;
|
||||
}
|
||||
else {
|
||||
$Item->{Content} = '';
|
||||
}
|
||||
|
||||
push @Items, $Item;
|
||||
}
|
||||
|
||||
$Result->[0]->{Item}->[0]->{Item} = \@Items;
|
||||
|
||||
return $Result;
|
||||
}
|
||||
|
||||
=head2 SettingRender()
|
||||
|
||||
Extracts the effective value from a XML parsed setting.
|
||||
|
||||
my $SettingHTML = $ValueTypeObject->SettingRender(
|
||||
Name => 'SettingName',
|
||||
DefaultID => 123, # (required)
|
||||
EffectiveValue => '{
|
||||
'1' => {
|
||||
'1' => 'New Year\'s Day',
|
||||
},
|
||||
...
|
||||
},
|
||||
DefaultValue => 'Product 5', # (optional)
|
||||
Class => 'My class' # (optional)
|
||||
Item => [ # (optional) XML parsed item
|
||||
{
|
||||
'ValueType' => 'VacationDays',
|
||||
'Content' => '',
|
||||
'ValueRegex' => '',
|
||||
},
|
||||
],
|
||||
RW => 1, # (optional) Allow editing. Default 0.
|
||||
IsArray => 1, # (optional) Item is part of the array
|
||||
IsHash => 1, # (optional) Item is part of the hash
|
||||
IDSuffix => 1, # (optional) Suffix will be added to the element ID
|
||||
SkipEffectiveValueCheck => 1, # (optional) If enabled, system will not perform effective value check.
|
||||
# Default: 1.
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$SettingHTML = '<div class "Field"...</div>';
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingRender {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
for my $Needed (qw(Name EffectiveValue)) {
|
||||
if ( !defined $Param{$Needed} ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Need $Needed",
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$Param{Class} //= '';
|
||||
$Param{Class} .= " WorkingHoursContainer ";
|
||||
|
||||
my $IDSuffix = $Param{IDSuffix} || '';
|
||||
|
||||
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
|
||||
|
||||
my $EffectiveValue = $Param{EffectiveValue};
|
||||
|
||||
my %EffectiveValueCheck = (
|
||||
Success => 1,
|
||||
);
|
||||
|
||||
if ( !$Param{SkipEffectiveValueCheck} ) {
|
||||
%EffectiveValueCheck = $Self->SettingEffectiveValueCheck(
|
||||
EffectiveValue => $EffectiveValue,
|
||||
XMLContentParsed => {
|
||||
Value => [
|
||||
{
|
||||
Item => $Param{Item},
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
my $HTML = "<div class='SettingContent'>\n";
|
||||
|
||||
if ( !$EffectiveValueCheck{Success} ) {
|
||||
my $Message = $LanguageObject->Translate("Value is not correct! Please, consider updating this field.");
|
||||
|
||||
$HTML .= $Param{IsValid} ? "<div class='BadEffectiveValue'>\n" : "<div>\n";
|
||||
$HTML .= "<p>* $Message</p>\n";
|
||||
$HTML .= "</div>\n";
|
||||
}
|
||||
|
||||
for my $Day (qw(Mon Tue Wed Thu Fri Sat Sun)) {
|
||||
$HTML .= "<p class='WorkingHoursDayName'>" . $LanguageObject->Translate($Day) . "</p>\n";
|
||||
|
||||
for my $Hour ( 0 .. 23 ) {
|
||||
my $Checked = 0;
|
||||
if ( grep { $_ == $Hour } @{ $EffectiveValue->{$Day} } ) {
|
||||
$Checked = 1;
|
||||
}
|
||||
|
||||
my $Title = $Hour . ':00 - ' . $Hour . ':59';
|
||||
|
||||
$HTML
|
||||
.= "<div title='"
|
||||
. $Title
|
||||
. "' class='WorkingHoursItem "
|
||||
. ( ($Checked) ? 'Checked' : '' )
|
||||
. "'><div><div>\n";
|
||||
$HTML .= "<label for='$Param{Name}$IDSuffix$Day$Hour'>$Hour</label>\n";
|
||||
$HTML .= "<input type='checkbox' value='$Hour' name='$Param{Name}' "
|
||||
. "id='$Param{Name}$IDSuffix$Day$Hour' data-day='$Day' class='WorkingHours' ";
|
||||
|
||||
if ($Checked) {
|
||||
$HTML .= "checked='checked' ";
|
||||
}
|
||||
|
||||
$HTML .= " />\n";
|
||||
|
||||
$HTML .= "</div></div></div>\n";
|
||||
}
|
||||
|
||||
$HTML .= "<div class='Clear'></div>\n";
|
||||
}
|
||||
$HTML .= "</div>\n";
|
||||
|
||||
return $HTML;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
222
Perl OTRS/Kernel/System/SysConfig/XML.pm
Normal file
222
Perl OTRS/Kernel/System/SysConfig/XML.pm
Normal file
@@ -0,0 +1,222 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SysConfig::XML;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::XML::Simple',
|
||||
);
|
||||
|
||||
use Kernel::System::VariableCheck qw( :all );
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::SysConfig::XML - Manage system configuration settings in XML.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
Create an object. Do not use it directly, instead use:
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $SysConfigXMLObject = $Kernel::OM->Get('Kernel::System::SysConfig::XML');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
# allocate new hash for object
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 SettingListParse()
|
||||
|
||||
Parses XML files into a list of perl structures and meta data.
|
||||
|
||||
my $PerlStructure = $SysConfigXMLObject->SettingListParse(
|
||||
XMLInput => '
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<otrs_config version="2.0" init="Application">
|
||||
<Setting Name="Test1" Required="1" Valid="1">
|
||||
<Description Translatable="1">Test 1.</Description>
|
||||
<Navigation>Core::Ticket</Navigation>
|
||||
<Value>
|
||||
<Item ValueType="String" ValueRegex=".*">123</Item>
|
||||
</Value>
|
||||
</Setting>
|
||||
<Setting Name="Test2" Required="1" Valid="1">
|
||||
<Description Translatable="1">Test 2.</Description>
|
||||
<Navigation>Core::Ticket</Navigation>
|
||||
<Value>
|
||||
<Item ValueType="File">/usr/bin/gpg</Item>
|
||||
</Value>
|
||||
</Setting>
|
||||
</otrs_config>
|
||||
',
|
||||
XMLFilename => 'Test.xml'
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
[
|
||||
{
|
||||
XMLContentParsed => {
|
||||
Description => [
|
||||
{
|
||||
Content => 'Test.',
|
||||
Translatable => '1',
|
||||
},
|
||||
],
|
||||
Name => 'Test',
|
||||
Required => '1',
|
||||
Value => [
|
||||
{
|
||||
Item => [
|
||||
{
|
||||
ValueRegex => '.*',
|
||||
ValueType => 'String',
|
||||
Content => '123',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
Navigation => [
|
||||
{
|
||||
Content => 'Core::Ticket',
|
||||
},
|
||||
],
|
||||
Valid => '1',
|
||||
},
|
||||
XMLContentRaw => '<Setting Name="Test1" Required="1" Valid="1">
|
||||
<Description Translatable="1">Test 1.</Description>
|
||||
<Navigation>Core::Ticket</Navigation>
|
||||
<Value>
|
||||
<Item ValueType="String" ValueRegex=".*">123</Item>
|
||||
</Value>
|
||||
</Setting>',
|
||||
XMLFilename => 'Test.xml'
|
||||
},
|
||||
]
|
||||
|
||||
=cut
|
||||
|
||||
sub SettingListParse {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
if ( !IsStringWithData( $Param{XMLInput} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Parameter XMLInput needs to be a string!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $XMLSimpleObject = $Kernel::OM->Get('Kernel::System::XML::Simple');
|
||||
|
||||
my $XMLContent = $Param{XMLInput};
|
||||
|
||||
# Remove all lines that starts with comment (#).
|
||||
$XMLContent =~ s{^#.*?$}{}gm;
|
||||
|
||||
# Remove comments <!-- ... -->.
|
||||
$XMLContent =~ s{<!--.*?-->}{}gsm;
|
||||
|
||||
$XMLContent =~ m{otrs_config.*?version="(.*?)"};
|
||||
my $ConfigVersion = $1;
|
||||
|
||||
if ( $ConfigVersion ne '2.0' ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Invalid XML format found in $Param{XMLFilename} (version must be 2.0)! File skipped.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
while ( $XMLContent =~ m{<ConfigItem.*?Name="(.*?)"}smxg ) {
|
||||
|
||||
# Old style ConfigItem detected.
|
||||
my $SettingName = $1;
|
||||
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Old ConfigItem $SettingName detected in $Param{XMLFilename}!"
|
||||
);
|
||||
}
|
||||
|
||||
# Fetch XML of Setting elements.
|
||||
my @ParsedSettings;
|
||||
|
||||
SETTING:
|
||||
while (
|
||||
$XMLContent =~ m{(?<RawSetting> <Setting[ ]+ .*? Name="(?<SettingName> .*? )" .*? > .*? </Setting> )}smxg
|
||||
)
|
||||
{
|
||||
|
||||
my $RawSetting = $+{RawSetting};
|
||||
my $SettingName = $+{SettingName};
|
||||
|
||||
next SETTING if !IsStringWithData($RawSetting);
|
||||
next SETTING if !IsStringWithData($SettingName);
|
||||
|
||||
my $PerlStructure = $XMLSimpleObject->XMLIn(
|
||||
XMLInput => $RawSetting,
|
||||
Options => {
|
||||
KeepRoot => 1,
|
||||
ForceArray => 1,
|
||||
ForceContent => 1,
|
||||
ContentKey => 'Content',
|
||||
},
|
||||
);
|
||||
|
||||
if ( !IsHashRefWithData($PerlStructure) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Resulting Perl structure must be a hash reference with data!",
|
||||
);
|
||||
next SETTING;
|
||||
}
|
||||
|
||||
if ( !IsArrayRefWithData( $PerlStructure->{Setting} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Resulting Perl structure must have Setting elements!",
|
||||
);
|
||||
next SETTING;
|
||||
}
|
||||
|
||||
push @ParsedSettings, {
|
||||
XMLContentParsed => $PerlStructure->{Setting}->[0],
|
||||
XMLContentRaw => $RawSetting,
|
||||
XMLFilename => $Param{XMLFilename},
|
||||
};
|
||||
}
|
||||
|
||||
return @ParsedSettings;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
Reference in New Issue
Block a user