This commit is contained in:
2024-10-14 00:08:40 +02:00
parent dbfba56f66
commit 1462d52e13
4572 changed files with 2658864 additions and 0 deletions

View File

@@ -0,0 +1,271 @@
# --
# 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::Output::HTML::Article::Base;
use strict;
use warnings;
use Kernel::System::VariableCheck qw(IsHashRefWithData);
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::Output::HTML::Layout',
'Kernel::System::DynamicField',
'Kernel::System::DynamicField::Backend',
'Kernel::System::Log',
'Kernel::System::Main',
'Kernel::System::Queue',
'Kernel::System::Ticket',
'Kernel::System::Ticket::Article',
);
sub new {
my ( $Type, %Param ) = @_;
my $Self = {};
bless( $Self, $Type );
return $Self;
}
=head2 ArticleFields()
Returns article fields for specific article backend.
my %ArticleFields = $LayoutObject->ArticleFields(
TicketID => 123, # (required)
ArticleID => 123, # (required)
);
Returns article fields hash:
%ArticleFields = (
Sender => { # mandatory
Label => 'Sender',
Value => 'John Smith',
Prio => 100,
},
Subject => { # mandatory
Label => 'Subject',
Value => 'Message',
Prio => 200,
},
DynamicField_Item => { # optional
Label => 'Item',
Value => 'Value',
Prio => 300,
},
...
);
=cut
sub ArticleFields {
die 'Virtual method in base class must not be called.';
}
=head2 ArticlePreview()
Get article content preview as returned by specific article backend.
my $ArticlePreview = $LayoutObject->ArticlePreview(
TicketID => 123, # (required)
ArticleID => 123, # (required)
ResultType => 'plain', # (optional) plain|HTML, default: HTML
MaxLength => 50, # (optional) performs trimming (for plain result only)
);
Returns article preview in scalar form:
$ArticlePreview = 'Hello, world!';
=cut
sub ArticlePreview {
die 'Virtual method in base class must not be called.';
}
=head2 ArticleActions()
Returns article actions for current channel, based on registration in the config.
my @Actions = $LayoutObject->ArticleActions(
TicketID => 123, # (required)
ArticleID => 123, # (required)
UserID => 1, # (required)
Type => 'Static', # (required) Static or OnLoad
);
Returns an array of hashes for every single action that should be displayed:
@Actions = (
{
ItemType => 'Dropdown',
DropdownType => 'Reply',
StandardResponsesStrg => $StandardResponsesStrg,
Name => 'Reply',
Class => 'AsPopup PopupType_TicketAction',
Action => 'AgentTicketCompose',
FormID => 'Reply' . $Article{ArticleID},
ResponseElementID => 'ResponseID',
Type => $Param{Type},
},
{
ItemType => 'Link',
Description => 'Forward article via mail',
Name => 'Forward',
Class => 'AsPopup PopupType_TicketAction',
Link =>
"Action=AgentTicketForward;TicketID=$Ticket{TicketID};ArticleID=$Article{ArticleID}"
},
...
);
=cut
sub ArticleActions {
my ( $Self, %Param ) = @_;
for my $Needed (qw(TicketID ArticleID Type UserID)) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
);
return;
}
}
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
my @Actions;
# Get article data.
my $ArticleBackendObject = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForArticle(%Param);
# Determine channel name for this Article.
my $ChannelName = $ArticleBackendObject->ChannelNameGet();
my $ActionsConfig = $ConfigObject->Get('Ticket::Frontend::Article::Actions');
my $Config = {};
if ( IsHashRefWithData($ActionsConfig) ) {
$Config = $ActionsConfig->{$ChannelName};
}
return () if !$Config;
# Get ACL restrictions.
my %PossibleActions;
my $Counter = 0;
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
# Get all registered actions.
if ( ref $ConfigObject->Get('Frontend::Module') eq 'HASH' ) {
my %Actions = %{ $ConfigObject->Get('Frontend::Module') };
# Only use those actions that start with 'Agent'.
%PossibleActions = map { ++$Counter => $_ }
grep { substr( $_, 0, length 'Agent' ) eq 'Agent' }
sort keys %Actions;
}
my $ACL = $TicketObject->TicketAcl(
Data => \%PossibleActions,
Action => 'AgentTicketZoom',
TicketID => $Param{Ticket}->{TicketID},
ReturnType => 'Action',
ReturnSubType => '-',
UserID => $Param{UserID},
);
my %AclAction = %PossibleActions;
if ($ACL) {
%AclAction = $TicketObject->TicketAclActionData();
}
my %AclActionLookup = reverse %AclAction;
# Get ticket attributes.
my %Ticket = $TicketObject->TicketGet(
TicketID => $Param{TicketID},
DynamicFields => 0,
);
my $BackendObject = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForArticle(%Param);
my %Article = $BackendObject->ArticleGet(%Param);
my %StandardTemplates = $Kernel::OM->Get('Kernel::System::Queue')->QueueStandardTemplateMemberList(
QueueID => $Ticket{QueueID},
TemplateTypes => 1,
Valid => 1,
);
ACTION:
for my $Action ( sort { $Config->{$a}->{Prio} <=> $Config->{$b}->{Prio} } keys %{$Config} ) {
next ACTION if !$Config->{$Action}->{Valid};
if ( $Config->{$Action}->{Module} ) {
my $Loaded = $Kernel::OM->Get('Kernel::System::Main')->Require(
$Config->{$Action}->{Module},
Silent => 1,
);
next ACTION if !$Loaded;
my $ModuleObject = $Kernel::OM->Get( $Config->{$Action}->{Module} );
# Check access.
next ACTION if !$ModuleObject->CheckAccess(
Ticket => \%Ticket,
Article => \%Article,
ChannelName => $ChannelName,
AclActionLookup => \%AclActionLookup,
UserID => $Param{UserID},
);
my @ActionConfig = $ModuleObject->GetConfig(
Ticket => \%Ticket,
Article => \%Article,
StandardTemplates => \%StandardTemplates,
UserID => $Param{UserID},
Type => $Param{Type},
);
push @Actions, @ActionConfig;
}
}
return @Actions;
}
=head2 ArticleCustomerRecipientsGet()
Get customer users from an article to use as recipients.
my @CustomerUserIDs = $LayoutObject->ArticleCustomerRecipientsGet(
TicketID => 123, # (required)
ArticleID => 123, # (required)
);
Returns array of customer user IDs who should receive a message:
@CustomerUserIDs = (
'customer-1',
'customer-2',
...
);
=cut
sub ArticleCustomerRecipientsGet {
die 'Virtual method in base class must not be called.';
}
1;

View File

@@ -0,0 +1,270 @@
# --
# 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::Output::HTML::Article::Chat;
use strict;
use warnings;
use parent 'Kernel::Output::HTML::Article::Base';
use Kernel::System::VariableCheck qw(:all);
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::Language',
'Kernel::Output::HTML::Article::Base',
'Kernel::Output::HTML::Layout',
'Kernel::System::CustomerUser',
'Kernel::System::HTMLUtils',
'Kernel::System::Log',
'Kernel::System::Ticket::Article',
'Kernel::System::User',
);
=head2 ArticleFields()
Returns common article fields for a Chat article.
my %ArticleFields = $LayoutObject->ArticleFields(
TicketID => 123, # (required)
ArticleID => 123, # (required)
);
Returns:
%ArticleFields = (
Sender => { # mandatory
Label => 'Sender',
Value => 'John Doe',
Prio => 100,
},
Subject => { # mandatory
Label => 'Subject',
Value => 'Article subject',
Prio => 200,
},
...
);
=cut
sub ArticleFields {
my ( $Self, %Param ) = @_;
# Check needed stuff.
for my $Needed (qw(TicketID ArticleID)) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
);
return;
}
}
my $ArticleBackendObject = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForArticle(%Param);
my %Article = $ArticleBackendObject->ArticleGet(
%Param,
);
my $Sender;
my $SenderRealname;
if ( IsArrayRefWithData( $Article{ChatMessageList} ) ) {
# Get ID and type of first person in conversation.
if (
IsHashRefWithData( $Article{ChatMessageList}->[0] )
&& $Article{ChatMessageList}->[0]->{ChatterType}
)
{
# Get agent data.
if ( $Article{ChatMessageList}->[0]->{ChatterType} eq 'User' ) {
my %AgentData = $Kernel::OM->Get('Kernel::System::User')->GetUserData(
UserID => $Article{ChatMessageList}->[0]->{ChatterID},
NoOutOfOffice => 1,
);
$Sender = "$AgentData{UserFullname} <$AgentData{UserEmail}>";
$SenderRealname = $AgentData{UserFullname};
}
# Get customer data.
elsif ( $Article{ChatMessageList}->[0]->{ChatterType} eq 'Customer' ) {
my $CustomerUserObject = $Kernel::OM->Get('Kernel::System::CustomerUser');
my %CustomerData = $CustomerUserObject->CustomerUserDataGet(
User => $Article{ChatMessageList}->[0]->{ChatterID},
);
my $CustomerName = $CustomerUserObject->CustomerName(
UserLogin => $Article{ChatMessageList}->[0]->{ChatterID},
);
$Sender = "$CustomerName <$CustomerData{UserEmail}>";
$SenderRealname = $CustomerName;
}
}
}
my $SenderDisplayType = $Kernel::OM->Get('Kernel::Config')->Get('Ticket::Frontend::DefaultSenderDisplayType')
|| 'Realname';
my $HiddenType = $SenderDisplayType eq 'Realname' ? 'Value' : 'Realname';
my %Result = (
Sender => {
Label => 'Sender',
Value => $Sender,
Realname => $SenderRealname,
Prio => 100,
$HiddenType . Hidden => 'Hidden',
},
Subject => {
Label => 'Subject',
Value => $Kernel::OM->Get('Kernel::Language')->Translate('Chat'),
Prio => 200,
},
);
return %Result;
}
=head2 ArticlePreview()
Returns article preview for a Chat article.
$LayoutObject->ArticlePreview(
TicketID => 123, # (required)
ArticleID => 123, # (required)
ResultType => 'plain', # (optional) plain|HTML. Default HTML.
MaxLength => 50, # (optional) performs trimming (for plain result only)
);
Returns article preview in scalar form:
$ArticlePreview = 'John Doe [2017-06-08 15:46:51] Hello, world!';
=cut
sub ArticlePreview {
my ( $Self, %Param ) = @_;
# Check needed stuff.
for my $Needed (qw(TicketID ArticleID)) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
);
return;
}
}
if ( $Param{MaxLength} && !IsPositiveInteger( $Param{MaxLength} ) ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "MaxLength must be positive integer!"
);
return;
}
my $ArticleBackendObject = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForArticle(%Param);
my %Article = $ArticleBackendObject->ArticleGet(
%Param,
DynamicFields => 0,
);
my $Result = $Kernel::OM->Get('Kernel::Output::HTML::Layout')->Output(
TemplateFile => 'ArticleContent/Chat',
Data => {
ChatMessages => $Article{ChatMessageList},
},
);
if ( $Param{ResultType} && $Param{ResultType} eq 'plain' ) {
$Result = $Kernel::OM->Get('Kernel::System::HTMLUtils')->ToAscii(
String => $Result,
);
$Result =~ s{\n\s*\n}{\n}g; # Remove extra new lines.
$Result =~ s/[^\S\n]+/ /g; # Remove extra spaces.
if ( $Param{MaxLength} ) {
# trim
$Result = substr( $Result, 0, $Param{MaxLength} );
}
}
return $Result;
}
=head2 ArticleCustomerRecipientsGet()
Get customer users from an article to use as recipients.
my @CustomerUserIDs = $LayoutObject->ArticleCustomerRecipientsGet(
TicketID => 123, # (required)
ArticleID => 123, # (required)
);
Returns array of customer user IDs who should receive a message:
@CustomerUserIDs = (
'customer-1',
'customer-2',
...
);
=cut
sub ArticleCustomerRecipientsGet {
my ( $Self, %Param ) = @_;
for my $Needed (qw(TicketID ArticleID)) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
);
return;
}
}
my %Article = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForArticle(%Param)->ArticleGet(%Param);
return if !%Article;
my $CustomerUserObject = $Kernel::OM->Get('Kernel::System::CustomerUser');
my @CustomerUserIDs;
CHAT_MESSAGE:
for my $ChatMessage ( @{ $Article{ChatMessageList} // [] } ) {
# Process all chat messages where the sender was a customer.
next CHAT_MESSAGE if !$ChatMessage->{ChatterType} eq 'Customer';
# Get single customer user from customer backend based on the ID address.
my %CustomerSearch = $CustomerUserObject->CustomerSearch(
UserLogin => $ChatMessage->{ChatterID},
Limit => 1,
);
next CHAT_MESSAGE if !%CustomerSearch;
# Save customer user ID if not already present in the list.
for my $CustomerUserID ( sort keys %CustomerSearch ) {
push @CustomerUserIDs, $CustomerUserID if !grep { $_ eq $CustomerUserID } @CustomerUserIDs;
}
}
return @CustomerUserIDs;
}
1;

View File

@@ -0,0 +1,20 @@
# --
# 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::Output::HTML::Article::Email;
use strict;
use warnings;
use parent 'Kernel::Output::HTML::Article::MIMEBase';
our @ObjectDependencies = (
);
1;

View File

@@ -0,0 +1,20 @@
# --
# 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::Output::HTML::Article::Internal;
use strict;
use warnings;
use parent 'Kernel::Output::HTML::Article::MIMEBase';
our @ObjectDependencies = (
);
1;

View File

@@ -0,0 +1,185 @@
# --
# 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::Output::HTML::Article::Invalid;
use strict;
use warnings;
use parent 'Kernel::Output::HTML::Article::Base';
use Kernel::System::VariableCheck qw(:all);
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::Output::HTML::Layout',
'Kernel::System::CommunicationChannel',
'Kernel::System::HTMLUtils',
'Kernel::System::Log',
'Kernel::System::Ticket::Article',
);
=head2 ArticleFields()
Returns common article fields for an invalid article.
my %ArticleFields = $LayoutObject->ArticleFields(
TicketID => 123, # (required)
ArticleID => 123, # (required)
);
Returns:
%ArticleFields = (
Sender => { # mandatory
Label => 'Sender',
Value => 'PackageName',
Prio => 100,
},
Subject => { # mandatory
Label => 'Subject',
Value => 'Invalid article',
Prio => 200,
},
...
);
=cut
sub ArticleFields {
my ( $Self, %Param ) = @_;
for my $Needed (qw(TicketID ArticleID)) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
);
return;
}
}
my $ArticleBackendObject = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForArticle(%Param);
my %Article = $ArticleBackendObject->ArticleGet(%Param);
# Get communication channel data.
my %CommunicationChannel = $Kernel::OM->Get('Kernel::System::CommunicationChannel')->ChannelGet(
ChannelID => $Article{CommunicationChannelID},
);
my %Result = (
Sender => {
Label => 'Sender',
Value => '-',
Realname => '-',
Prio => 100,
},
Subject => {
Label => 'Subject',
Value => '-',
Prio => 200,
},
);
return %Result;
}
=head2 ArticlePreview()
Returns article preview for an invalid article.
$LayoutObject->ArticlePreview(
TicketID => 123, # (required)
ArticleID => 123, # (required)
ResultType => 'plain', # (optional) plain|HTML. Default HTML.
MaxLength => 50, # (optional) performs trimming (for plain result only)
);
Returns article preview in scalar form:
$ArticlePreview = 'Preview of this article is not possible because...';
=cut
sub ArticlePreview {
my ( $Self, %Param ) = @_;
for my $Needed (qw(TicketID ArticleID)) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
);
return;
}
}
if ( $Param{MaxLength} && !IsPositiveInteger( $Param{MaxLength} ) ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => 'MaxLength must be positive integer!',
);
return;
}
my $ArticleBackendObject = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForArticle(%Param);
my %Article = $ArticleBackendObject->ArticleGet(%Param);
# Get communication channel data.
my %CommunicationChannel = $Kernel::OM->Get('Kernel::System::CommunicationChannel')->ChannelGet(
ChannelID => $Article{CommunicationChannelID},
);
my $Result = $Kernel::OM->Get('Kernel::Output::HTML::Layout')->Output(
TemplateFile => 'ArticleContent/Invalid',
Data => \%CommunicationChannel,
);
if ( $Param{ResultType} && $Param{ResultType} eq 'plain' ) {
$Result = $Kernel::OM->Get('Kernel::System::HTMLUtils')->ToAscii(
String => $Result,
);
$Result =~ s{\n\s*\n}{\n}g; # Remove extra new lines.
$Result =~ s/[^\S\n]+/ /g; # Remove extra spaces.
# Trim to length.
if ( $Param{MaxLength} ) {
$Result = substr( $Result, 0, $Param{MaxLength} );
}
}
return $Result;
}
=head2 ArticleCustomerRecipientsGet()
Dummy function. Invalid channel always returns no recipients.
=cut
sub ArticleCustomerRecipientsGet {
my ( $Self, %Param ) = @_;
for my $Needed (qw(TicketID ArticleID)) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
);
return;
}
}
return;
}
1;

View File

@@ -0,0 +1,435 @@
# --
# 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::Output::HTML::Article::MIMEBase;
use strict;
use warnings;
use parent 'Kernel::Output::HTML::Article::Base';
use Mail::Address;
use Kernel::Language qw(Translatable);
use Kernel::System::VariableCheck qw(:all);
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::Output::HTML::Layout',
'Kernel::System::CheckItem',
'Kernel::System::CustomerUser',
'Kernel::System::Encode',
'Kernel::System::Log',
'Kernel::System::Main',
'Kernel::System::Ticket',
'Kernel::System::Ticket::Article',
);
sub new {
my ( $Type, %Param ) = @_;
my $Self = {};
bless( $Self, $Type );
return $Self;
}
=head2 ArticleFields()
Returns common article fields for a MIMEBase article.
my %ArticleFields = $LayoutObject->ArticleFields(
TicketID => 123, # (required)
ArticleID => 123, # (required)
);
Returns:
%ArticleFields = (
Sender => { # mandatory
Label => 'Sender',
Value => 'John Doe',
Prio => 100,
},
Subject => { # mandatory
Label => 'Subject',
Value => 'Article subject',
Prio => 200,
},
PGP => {
Label => 'PGP', # mandatory
Value => 'Value', # mandatory
Class => 'Class', # optional
...
},
...
);
=cut
sub ArticleFields {
my ( $Self, %Param ) = @_;
# Check needed stuff.
for my $Needed (qw(TicketID ArticleID)) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
);
return;
}
}
my %Result;
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
my $MainObject = $Kernel::OM->Get('Kernel::System::Main');
my $ArticleBackendObject = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForArticle(%Param);
my %Ticket = $Kernel::OM->Get('Kernel::System::Ticket')->TicketGet(
%Param,
DynamicFields => 0,
);
my %Article = $ArticleBackendObject->ArticleGet(
%Param,
DynamicFields => 1,
RealNames => 1,
);
# cleanup subject
$Article{Subject} = $Kernel::OM->Get('Kernel::System::Ticket')->TicketSubjectClean(
TicketNumber => $Ticket{TicketNumber},
Subject => $Article{Subject} || '',
Size => 0,
);
$Result{Subject} = {
Label => 'Subject',
Value => $Article{Subject},
};
# run article view modules
my $Config = $ConfigObject->Get('Ticket::Frontend::ArticleViewModule');
if ( ref $Config eq 'HASH' ) {
my %Jobs = %{$Config};
JOB:
for my $Job ( sort keys %Jobs ) {
# load module
next JOB if !$MainObject->Require( $Jobs{$Job}->{Module} );
my $Object = $Jobs{$Job}->{Module}->new(
TicketID => $Self->{TicketID},
ArticleID => $Param{ArticleID},
UserID => $Param{UserID} || 1,
);
# run module
my @Data = $Object->Check(
Article => \%Article,
%Ticket, Config => $Jobs{$Job}
);
for my $DataRef (@Data) {
if ( !$DataRef->{Successful} ) {
$DataRef->{Result} = 'Error';
}
else {
$DataRef->{Result} = 'Notice';
}
$Result{ $DataRef->{Key} } = {
Label => $DataRef->{Key},
Value => $DataRef->{Value},
Class => $DataRef->{Result},
Type => 'ArticleOption',
};
for my $Warning ( @{ $DataRef->{Warnings} } ) {
$Result{ $DataRef->{Key} } = {
Label => $Warning->{Key},
Value => $Warning->{Value},
Class => $Warning->{Result},
Type => 'ArticleOption',
};
}
}
# TODO: Check how to implement this.
# # filter option
# $Object->Filter(
# Article => \%Article,
# %Ticket, Config => $Jobs{$Job}
# );
}
}
# do some strips && quoting
my $RecipientDisplayType = $ConfigObject->Get('Ticket::Frontend::DefaultRecipientDisplayType') || 'Realname';
my $SenderDisplayType = $ConfigObject->Get('Ticket::Frontend::DefaultSenderDisplayType') || 'Realname';
KEY:
for my $Key (qw(From To Cc Bcc)) {
next KEY if !$Article{$Key};
my $DisplayType = $Key eq 'From' ? $SenderDisplayType : $RecipientDisplayType;
my $HiddenType = $DisplayType eq 'Realname' ? 'Value' : 'Realname';
$Result{$Key} = {
Label => $Key,
Value => $Article{$Key},
Realname => $Article{ $Key . 'Realname' },
ArticleID => $Article{ArticleID},
$HiddenType . Hidden => 'Hidden',
HideInCustomerInterface => $Key eq 'Bcc' ? 1 : undef,
};
if ( $Key eq 'From' ) {
$Result{Sender} = {
Label => Translatable('Sender'),
Value => $Article{From},
Realname => $Article{FromRealname},
$HiddenType . Hidden => 'Hidden',
HideInTimelineView => 1,
HideInTicketPrint => 1,
};
}
}
# Assign priority.
my $Priority = 100;
for my $Key (qw(From To Cc Bcc)) {
if ( $Result{$Key} ) {
$Result{$Key}->{Prio} = $Priority;
$Priority += 100;
}
}
my @FieldsWithoutPrio = grep { !$Result{$_}->{Prio} } sort keys %Result;
my $BasePrio = 100000;
for my $Key (@FieldsWithoutPrio) {
$Result{$Key}->{Prio} = $BasePrio++;
}
return %Result;
}
=head2 ArticlePreview()
Returns article preview for a MIMEBase article.
$LayoutObject->ArticlePreview(
TicketID => 123, # (required)
ArticleID => 123, # (required)
ResultType => 'plain', # (optional) plain|HTML. Default HTML.
MaxLength => 50, # (optional) performs trimming (for plain result only)
);
Returns article preview in scalar form:
$ArticlePreview = 'Hello, world!';
If HTML preview was requested, but HTML content does not exist for an article, this function will return undef.
=cut
sub ArticlePreview {
my ( $Self, %Param ) = @_;
# Check needed stuff.
for my $Needed (qw(TicketID ArticleID)) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
);
return;
}
}
if ( $Param{MaxLength} && !IsPositiveInteger( $Param{MaxLength} ) ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "MaxLength must be positive integer!"
);
return;
}
my $ArticleBackendObject = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForArticle(%Param);
my %Article = $ArticleBackendObject->ArticleGet(
%Param,
DynamicFields => 0,
);
my $Result;
if ( $Param{ResultType} && $Param{ResultType} eq 'plain' ) {
# plain
$Result = $Article{Body};
if ( $Param{MaxLength} ) {
# trim
$Result = substr( $Result, 0, $Param{MaxLength} );
}
}
else {
my $HTMLBodyAttachmentID = $Self->HTMLBodyAttachmentIDGet(%Param);
if ($HTMLBodyAttachmentID) {
# Preview doesn't include inline images...
my %Data = $ArticleBackendObject->ArticleAttachment(
ArticleID => $Param{ArticleID},
FileID => $HTMLBodyAttachmentID,
);
# Get the charset directly from the attachment hash and convert content to the internal charset (utf-8).
# Please see bug#13367 for more information.
my $Charset;
if ( $Data{ContentType} =~ m/.+?charset=("|'|)(?<Charset>.+)/ig ) {
$Charset = $+{Charset};
$Charset =~ s/"|'//g;
}
else {
$Charset = 'us-ascii';
}
$Result = $Kernel::OM->Get('Kernel::System::Encode')->Convert(
Text => $Data{Content},
From => $Charset,
To => 'utf-8',
Check => 1,
);
}
}
return $Result;
}
=head2 HTMLBodyAttachmentIDGet()
Returns HTMLBodyAttachmentID.
my $HTMLBodyAttachmentID = $LayoutObject->HTMLBodyAttachmentIDGet(
TicketID => 123, # (required)
ArticleID => 123, # (required)
);
Returns
$HTMLBodyAttachmentID = 23;
=cut
sub HTMLBodyAttachmentIDGet {
my ( $Self, %Param ) = @_;
# Check needed stuff.
for my $Needed (qw(TicketID ArticleID)) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
);
return;
}
}
my $ArticleBackendObject = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForArticle(%Param);
# Get a HTML attachment.
my %AttachmentIndexHTMLBody = $ArticleBackendObject->ArticleAttachmentIndex(
ArticleID => $Param{ArticleID},
OnlyHTMLBody => 1,
);
my ($HTMLBodyAttachmentID) = sort keys %AttachmentIndexHTMLBody;
return $HTMLBodyAttachmentID;
}
=head2 ArticleCustomerRecipientsGet()
Get customer users from an article to use as recipients.
my @CustomerUserIDs = $LayoutObject->ArticleCustomerRecipientsGet(
TicketID => 123, # (required)
ArticleID => 123, # (required)
);
Returns array of customer user IDs who should receive a message:
@CustomerUserIDs = (
'customer-1',
'customer-2',
...
);
=cut
sub ArticleCustomerRecipientsGet {
my ( $Self, %Param ) = @_;
for my $Needed (qw(TicketID ArticleID)) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
);
return;
}
}
my %Article = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForArticle(%Param)->ArticleGet(%Param);
return if !%Article;
my $RecipientEmail = $Article{From};
# Check ReplyTo.
if ( $Article{ReplyTo} ) {
$RecipientEmail = $Article{ReplyTo};
}
# Check article type and use To in case sender is not customer.
if ( $Article{SenderType} !~ /customer/ ) {
$RecipientEmail = $Article{To};
$Article{ReplyTo} = '';
}
my $CheckItemObject = $Kernel::OM->Get('Kernel::System::CheckItem');
my $CustomerUserObject = $Kernel::OM->Get('Kernel::System::CustomerUser');
my @CustomerUserIDs;
EMAIL:
for my $Email ( Mail::Address->parse($RecipientEmail) ) {
next EMAIL if !$CheckItemObject->CheckEmail( Address => $Email->address() );
# Get single customer user from customer backend based on the email address.
my %CustomerSearch = $CustomerUserObject->CustomerSearch(
PostMasterSearch => $Email->address(),
Limit => 1,
);
next EMAIL if !%CustomerSearch;
# Save customer user ID if not already present in the list.
for my $CustomerUserID ( sort keys %CustomerSearch ) {
push @CustomerUserIDs, $CustomerUserID if !grep { $_ eq $CustomerUserID } @CustomerUserIDs;
}
}
return @CustomerUserIDs;
}
1;

View File

@@ -0,0 +1,20 @@
# --
# 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::Output::HTML::Article::Phone;
use strict;
use warnings;
use parent 'Kernel::Output::HTML::Article::MIMEBase';
our @ObjectDependencies = (
);
1;