Commit edd2f499 authored by Timmer, Marius's avatar Timmer, Marius

Feature: Use Hooks

parent 8e8d8b64
This diff is collapsed.
# --
# Copyright (C) 2016 Westfälische Wilhelms-Universität Münster, https://www.uni-muenster.de/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::Modules::AgentTicketPrintIntern;
use strict;
use warnings;
use Kernel::System::VariableCheck qw(:all);
our @ObjectDependencies = (
'Kernel::System::CustomerUser',
'Kernel::System::LinkObject',
'Kernel::System::PDF',
'Kernel::System::DynamicField',
'Kernel::System::DynamicField::Backend',
'Kernel::Modules::AgentTicketPrint'
);
use base qw( Kernel::Modules::AgentTicketPrint );
sub Run {
my ( $Self, %Param ) = @_;
$Self->{LinkObject} = $Kernel::OM->Get('Kernel::System::LinkObject');
$Self->{LayoutObject} = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
$Self->{ConfigObject} = $Kernel::OM->Get('Kernel::Config');
# Some linked elements requires the user id which comes from the
# layout object. That is why we insert it here the nasty way.
$Self->{LayoutObject}->{UserID} = $Self->{UserID};
$Self->{LayoutObject}->{UserType} = 'User';
# get ticket object
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
my $ParamObject = $Kernel::OM->Get('Kernel::System::Web::Request');
my $Output;
my $QueueID = $TicketObject->TicketQueueID( TicketID => $Self->{TicketID} );
my $ArticleID = $ParamObject->GetParam( Param => 'ArticleID' );
# get layout object
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
# check needed stuff
if ( !$Self->{TicketID} || !$QueueID ) {
return $LayoutObject->ErrorScreen(
Message => Translatable('Need TicketID!'),
);
}
# check permissions
my $Access = $TicketObject->TicketPermission(
Type => 'ro',
TicketID => $Self->{TicketID},
UserID => $Self->{UserID}
);
return $LayoutObject->NoPermission( WithHeader => 'yes' ) if !$Access;
# get ACL restrictions
my %PossibleActions = ( 1 => $Self->{Action} );
my $ACL = $TicketObject->TicketAcl(
Data => \%PossibleActions,
Action => $Self->{Action},
TicketID => $Self->{TicketID},
ReturnType => 'Action',
ReturnSubType => '-',
UserID => $Self->{UserID},
);
my %AclAction = $TicketObject->TicketAclActionData();
# check if ACL restrictions exist
if ( $ACL || IsHashRefWithData( \%AclAction ) ) {
my %AclActionLookup = reverse %AclAction;
# show error screen if ACL prohibits this action
if ( !$AclActionLookup{ $Self->{Action} } ) {
return $LayoutObject->NoPermission( WithHeader => 'yes' );
}
}
# get linked objects
my $LinkObject = $Kernel::OM->Get('Kernel::System::LinkObject');
my $LinkListWithData = $LinkObject->LinkListWithData(
Object => 'Ticket',
Key => $Self->{TicketID},
State => 'Valid',
UserID => $Self->{UserID},
ObjectParameters => {
Ticket => {
IgnoreLinkedTicketStateTypes => 1,
},
},
);
# get link type list
my %LinkTypeList = $LinkObject->TypeList(
UserID => $Self->{UserID},
);
# get the link data
my %LinkData;
if ( $LinkListWithData && ref $LinkListWithData eq 'HASH' && %{$LinkListWithData} ) {
%LinkData = $LayoutObject->LinkObjectTableCreate(
LinkListWithData => $LinkListWithData,
ViewMode => 'SimpleRaw',
);
}
# get content
my %Ticket = $TicketObject->TicketGet(
TicketID => $Self->{TicketID},
UserID => $Self->{UserID},
);
my @ArticleBox = $TicketObject->ArticleContentIndex(
TicketID => $Self->{TicketID},
StripPlainBodyAsAttachment => 1,
UserID => $Self->{UserID},
DynamicFields => 0,
);
# check if only one article need printed
if ($ArticleID) {
ARTICLE:
for my $Article (@ArticleBox) {
if ( $Article->{ArticleID} == $ArticleID ) {
@ArticleBox = ($Article);
last ARTICLE;
}
}
}
# get config object
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
# show total accounted time if feature is active:
if ( $ConfigObject->Get('Ticket::Frontend::AccountTime') ) {
$Ticket{TicketTimeUnits} = $TicketObject->TicketAccountedTimeGet(
TicketID => $Ticket{TicketID},
);
}
# get user object
my $UserObject = $Kernel::OM->Get('Kernel::System::User');
# user info
my %UserInfo = $UserObject->GetUserData(
User => $Ticket{Owner},
);
# responsible info
my %ResponsibleInfo;
if ( $ConfigObject->Get('Ticket::Responsible') && $Ticket{Responsible} ) {
%ResponsibleInfo = $UserObject->GetUserData(
User => $Ticket{Responsible},
);
}
# customer info
my %CustomerData;
if ( $Ticket{CustomerUserID} ) {
%CustomerData = $Kernel::OM->Get('Kernel::System::CustomerUser')->CustomerUserDataGet(
User => $Ticket{CustomerUserID},
);
}
# do some html quoting
$Ticket{Age} = $LayoutObject->CustomerAge(
Age => $Ticket{Age},
Space => ' ',
);
if ( $Ticket{UntilTime} ) {
$Ticket{PendingUntil} = $LayoutObject->CustomerAge(
Age => $Ticket{UntilTime},
Space => ' ',
);
}
# get needed objects
$Kernel::OM->ObjectsDiscard(
Objects => ['Kernel::System::PDF']
);
my $PDFObject = $Kernel::OM->Get('Kernel::System::PDF');
my $TimeObject = $Kernel::OM->Get('Kernel::System::Time');
my $PrintedBy = $LayoutObject->{LanguageObject}->Translate('printed by');
my $Time = $LayoutObject->{LanguageObject}->FormatTimeString(
$TimeObject->CurrentTimestamp(),
'DateFormat',
);
my %Page;
# get maximum number of pages
$Page{MaxPages} = $ConfigObject->Get('PDF::MaxPages');
if ( !$Page{MaxPages} || $Page{MaxPages} < 1 || $Page{MaxPages} > 1000 ) {
$Page{MaxPages} = 100;
}
my $HeaderRight = $ConfigObject->Get('Ticket::Hook') . $Ticket{TicketNumber};
my $HeadlineLeft = $HeaderRight;
my $Title = $HeaderRight;
if ( $Ticket{Title} ) {
$HeadlineLeft = $Ticket{Title};
$Title .= ' / ' . $Ticket{Title};
}
$Page{MarginTop} = 30;
$Page{MarginRight} = 40;
$Page{MarginBottom} = 40;
$Page{MarginLeft} = 40;
$Page{HeaderRight} = $HeaderRight;
$Page{FooterLeft} = '';
$Page{PageText} = $LayoutObject->{LanguageObject}->Translate('Page');
$Page{PageCount} = 1;
# create new pdf document
$PDFObject->DocumentNew(
Title => $ConfigObject->Get('Product') . ': ' . $Title,
Encode => $LayoutObject->{UserCharset},
);
# create first pdf page
$PDFObject->PageNew(
%Page,
FooterRight => $Page{PageText} . ' ' . $Page{PageCount},
);
$Page{PageCount}++;
$PDFObject->PositionSet(
Move => 'relativ',
Y => -6,
);
# output title
$PDFObject->Text(
Text => $Ticket{Title},
FontSize => 13,
);
$PDFObject->PositionSet(
Move => 'relativ',
Y => -6,
);
# output "printed by"
$PDFObject->Text(
Text => $PrintedBy . ' '
. $Self->{UserFirstname} . ' '
. $Self->{UserLastname} . ' ('
. $Self->{UserEmail} . ')'
. ', ' . $Time,
FontSize => 9,
);
$PDFObject->PositionSet(
Move => 'relativ',
Y => -14,
);
# output ticket infos
$Self->SUPER::_PDFOutputTicketInfos(
PageData => \%Page,
TicketData => \%Ticket,
UserData => \%UserInfo,
ResponsibleData => \%ResponsibleInfo,
);
$PDFObject->PositionSet(
Move => 'relativ',
Y => -6,
);
# output ticket dynamic fields
$Self->SUPER::_PDFOutputTicketDynamicFields(
PageData => \%Page,
TicketData => \%Ticket,
);
$PDFObject->PositionSet(
Move => 'relativ',
Y => -6,
);
# output linked objects
if (%LinkData) {
$Self->SUPER::_PDFOutputLinkedObjects(
PageData => \%Page,
LinkData => \%LinkData,
LinkTypeList => \%LinkTypeList,
);
}
# output customer infos
if (%CustomerData) {
$Self->SUPER::_PDFOutputCustomerInfos(
PageData => \%Page,
CustomerData => \%CustomerData,
);
}
# output articles
$Self->SUPER::_PDFOutputArticles(
PageData => \%Page,
ArticleData => \@ArticleBox,
ArticleNumber => $ParamObject->GetParam( Param => 'ArticleNumber' ),
);
# get time object and use the UserTimeObject, if the system use UTC as
# system time and the TimeZoneUser feature is active
if (
!$Kernel::OM->Get('Kernel::System::Time')->ServerLocalTimeOffsetSeconds()
&& $Kernel::OM->Get('Kernel::Config')->Get('TimeZoneUser')
&& $Self->{UserTimeZone}
)
{
$TimeObject = $LayoutObject->{UserTimeObject};
}
# return the pdf document
my $Filename = 'Ticket_' . $Ticket{TicketNumber};
my ( $s, $m, $h, $D, $M, $Y ) = $TimeObject->SystemTime2Date(
SystemTime => $TimeObject->SystemTime(),
);
$M = sprintf( "%02d", $M );
$D = sprintf( "%02d", $D );
$h = sprintf( "%02d", $h );
$m = sprintf( "%02d", $m );
return $PDFObject->DocumentOutput();
}
1;
......@@ -6,7 +6,7 @@ use warnings;
use Kernel::Modules::AgentTicketPrint;
our @ObjectDependencies = (
'Kernel::Modules::AgentTicketPrintIntern',
'Kernel::Modules::AgentTicketPrint',
'Kernel::System::DB',
'Kernel::System::Encode',
'Kernel::System::Group',
......@@ -124,14 +124,16 @@ sub CreatePDF {
);
# Just call a new instance of our modified version of the pdf printer
my $TicketPrinter = $Kernel::OM->Get('Kernel::Modules::AgentTicketPrintIntern');
my $TicketPrinter = $Kernel::OM->Get('Kernel::Modules::AgentTicketPrint');
$TicketPrinter->{TicketID} = $Param{TicketID};
$TicketPrinter->{UserID} = $RootUserData{UserID};
$TicketPrinter->{UserFirstname} = $RootUserData{UserFirstname};
$TicketPrinter->{UserLastname} = $RootUserData{UserLastname};
$TicketPrinter->{UserEmail} = $RootUserData{UserEmail};
$TicketPrinter->{Action} = 'AgentTicketPrint';
return $TicketPrinter->Run();
return $TicketPrinter->Run(
Raw => 1
);
}
sub GetTicketList {
......
......@@ -14,6 +14,6 @@
<Filelist>
<File Permission="644" Location="Kernel/System/Console/Command/Admin/Queue/TicketExport.pm"></File>
<File Permission="644" Location="Kernel/System/TicketExport.pm"></File>
<File Permission="644" Location="Kernel/Modules/AgentTicketPrintIntern.pm"></File>
<File Permission="644" Location="Custom/Kernel/Modules/AgentTicketPrint.pm"></File>
</Filelist>
</otrs_package>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment