Das persönliche Profil (https://zivgitlab.uni-muenster.de/USERID) wurde für alle Nutzer administrativ auf "privat" gesetzt. Wenn sie möchten, dass dieses wieder für alle internen Nutzer sichtbar wird, deaktivieren sie bitte das "private profile" unter den persönlichen Einstellungen (https://zivgitlab.uni-muenster.de/-/profile).

Commit d0c44c6f authored by Marius Timmer's avatar Marius Timmer

Bugfix: Rewritten

parent 8b61e10d
# --
# 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->{TicketObject} = $Kernel::OM->Get('Kernel::System::Ticket');
$Self->{ParamObject} = $Kernel::OM->Get('Kernel::System::Web::Request');
$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';
my $Output;
my $QueueID = $Self->{TicketObject}->TicketQueueID( TicketID => $Self->{TicketID} );
my $ArticleID = $Self->{ParamObject}->GetParam( Param => 'ArticleID' );
# check needed stuff
if ( !$Self->{TicketID} || !$QueueID ) {
return $Self->{LayoutObject}->ErrorScreen( Message => 'Need TicketID!' );
}
# get ACL restrictions
$Self->{TicketObject}->TicketAcl(
Data => '-',
TicketID => $Self->{TicketID},
ReturnType => 'Action',
ReturnSubType => '-',
UserID => $Self->{UserID},
);
my %AclAction = $Self->{TicketObject}->TicketAclActionData();
# check if ACL restrictions exist
if ( IsHashRefWithData( \%AclAction ) ) {
# show error screen if ACL prohibits this action
if ( defined $AclAction{ $Self->{Action} } && $AclAction{ $Self->{Action} } eq '0' ) {
return $Self->{LayoutObject}->NoPermission( WithHeader => 'yes' );
}
}
# get linked objects
my $LinkListWithData = $Self->{LinkObject}->LinkListWithData(
Object => 'Ticket',
Key => $Self->{TicketID},
State => 'Valid',
UserID => $Self->{UserID},
);
# get link type list
my %LinkTypeList = $Self->{LinkObject}->TypeList(
UserID => $Self->{UserID},
);
# get the link data
my %LinkData;
if ( $LinkListWithData && ref $LinkListWithData eq 'HASH' && %{$LinkListWithData} ) {
%LinkData = $Self->{LayoutObject}->LinkObjectTableCreate(
LinkListWithData => $LinkListWithData,
ViewMode => 'SimpleRaw',
);
}
# get content
my %Ticket = $Self->{TicketObject}->TicketGet(
TicketID => $Self->{TicketID},
UserID => $Self->{UserID},
);
my @ArticleBox = $Self->{TicketObject}->ArticleContentIndex(
TicketID => $Self->{TicketID},
StripPlainBodyAsAttachment => 1,
UserID => $Self->{UserID},
DynamicFields => 0,
);
# check if only one article need printed
if ($ArticleID) {
my @NewArticleBox;
for my $Article (@ArticleBox) {
if ( $Article->{ArticleID} == $ArticleID ) {
@NewArticleBox = ($Article);
}
}
if (@NewArticleBox) {
@ArticleBox = @NewArticleBox;
}
}
# resort article order
if (($Self->{ZoomExpandSort}) &&
($Self->{ZoomExpandSort} eq 'reverse')) {
@ArticleBox = reverse(@ArticleBox);
}
# show total accounted time if feature is active:
if ( $Self->{ConfigObject}->Get('Ticket::Frontend::AccountTime') ) {
$Ticket{TicketTimeUnits} = $Self->{TicketObject}->TicketAccountedTimeGet(
TicketID => $Ticket{TicketID},
);
}
# user info
my %UserInfo = $Self->{UserObject}->GetUserData(
User => $Ticket{Owner},
);
# responsible info
my %ResponsibleInfo;
if ( $Self->{ConfigObject}->Get('Ticket::Responsible') && $Ticket{Responsible} ) {
%ResponsibleInfo = $Self->{UserObject}->GetUserData(
User => $Ticket{Responsible},
);
}
# customer info
my %CustomerData;
if ( $Ticket{CustomerUserID} ) {
%CustomerData = $Self->{CustomerUserObject}->CustomerUserDataGet(
User => $Ticket{CustomerUserID},
);
}
# do some html quoting
$Ticket{Age} = $Self->{LayoutObject}->CustomerAge(
Age => $Ticket{Age},
Space => ' ',
);
if ( $Ticket{UntilTime} ) {
$Ticket{PendingUntil} = $Self->{LayoutObject}->CustomerAge(
Age => $Ticket{UntilTime},
Space => ' ',
);
}
# generate pdf output
if ( $Self->{PDFObject} ) {
my $PrintedBy = $Self->{LayoutObject}->{LanguageObject}->Get('printed by');
my $Time = $Self->{LayoutObject}->Output( Template => '$Env{"Time"}' );
my $Url = ' ';
if ( $ENV{REQUEST_URI} ) {
$Url = $Self->{ConfigObject}->Get('HttpType') . '://'
. $Self->{ConfigObject}->Get('FQDN')
. $ENV{REQUEST_URI};
}
my %Page;
# get maximum number of pages
$Page{MaxPages} = $Self->{ConfigObject}->Get('PDF::MaxPages');
if ( !$Page{MaxPages} || $Page{MaxPages} < 1 || $Page{MaxPages} > 1000 ) {
$Page{MaxPages} = 100;
}
my $HeaderRight = $Self->{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{HeadlineLeft} = $HeadlineLeft;
$Page{HeadlineRight}
= $PrintedBy . ' '
. $Self->{UserFirstname} . ' '
. $Self->{UserLastname} . ' ('
. $Self->{UserEmail} . ') '
. $Time;
$Page{FooterLeft} = $Url;
$Page{PageText} = $Self->{LayoutObject}->{LanguageObject}->Get('Page');
$Page{PageCount} = 1;
# create new pdf document
$Self->{PDFObject}->DocumentNew(
Title => $Self->{ConfigObject}->Get('Product') . ': ' . $Title,
Encode => $Self->{LayoutObject}->{UserCharset},
);
# create first pdf page
$Self->{PDFObject}->PageNew(
%Page, FooterRight => $Page{PageText} . ' ' . $Page{PageCount},
);
$Page{PageCount}++;
# type of print tag
my $PrintTag = '';
$PrintTag = ($ArticleID) ? 'Article' : 'Ticket';
$PrintTag = ( $Self->{LayoutObject}->{LanguageObject}->Get($PrintTag) ) . ' ' .
( $Self->{LayoutObject}->{LanguageObject}->Get('Print') );
# output headline
$Self->{PDFObject}->Text(
Text => $PrintTag,
Height => 9,
Type => 'Cut',
Font => 'ProportionalBold',
Align => 'right',
FontSize => 9,
Color => '#666666',
);
$Self->{PDFObject}->PositionSet(
Move => 'relativ',
Y => -6,
);
# output ticket infos
$Self->_PDFOutputTicketInfos(
PageData => \%Page,
TicketData => \%Ticket,
UserData => \%UserInfo,
ResponsibleData => \%ResponsibleInfo,
);
# output ticket dynamic fields
$Self->_PDFOutputTicketDynamicFields(
PageData => \%Page,
TicketData => \%Ticket,
);
# output linked objects
if (%LinkData) {
$Self->_PDFOutputLinkedObjects(
PageData => \%Page,
LinkData => \%LinkData,
LinkTypeList => \%LinkTypeList,
);
}
# output customer infos
if (%CustomerData) {
$Self->_PDFOutputCustomerInfos(
PageData => \%Page,
CustomerData => \%CustomerData,
);
}
# output articles
$Self->_PDFOutputArticles(
PageData => \%Page,
ArticleData => \@ArticleBox,
);
return $Self->{PDFObject}->DocumentOutput();
}
# generate html output
else {
# output header
$Output .= $Self->{LayoutObject}->PrintHeader( Value => $Ticket{TicketNumber} );
if (%LinkData) {
# output link data
$Self->{LayoutObject}->Block(
Name => 'Link',
);
for my $LinkTypeLinkDirection ( sort { lc $a cmp lc $b } keys %LinkData ) {
# investigate link type name
my @LinkData = split q{::}, $LinkTypeLinkDirection;
# output link type data
$Self->{LayoutObject}->Block(
Name => 'LinkType',
Data => {
LinkTypeName => $LinkTypeList{ $LinkData[0] }->{ $LinkData[1] . 'Name' },
},
);
# extract object list
my $ObjectList = $LinkData{$LinkTypeLinkDirection};
for my $Object ( sort { lc $a cmp lc $b } keys %{$ObjectList} ) {
for my $Item ( @{ $ObjectList->{$Object} } ) {
# output link type data
$Self->{LayoutObject}->Block(
Name => 'LinkTypeRow',
Data => {
LinkStrg => $Item->{Title},
},
);
}
}
}
}
# output customer infos
if (%CustomerData) {
$Param{CustomerTable} = $Self->{LayoutObject}->AgentCustomerViewTable(
Data => \%CustomerData,
Max => 100,
);
}
# show ticket
$Output .= $Self->_HTMLMask(
TicketID => $Self->{TicketID},
QueueID => $QueueID,
ArticleBox => \@ArticleBox,
ResponsibleData => \%ResponsibleInfo,
%Param,
%UserInfo,
%Ticket,
);
# add footer
$Output .= $Self->{LayoutObject}->PrintFooter();
# return output
return $Output;
}
}
1;
package Kernel::System::TicketExport;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::Modules::AgentTicketPrintIntern',
'Kernel::System::DB',
'Kernel::System::Encode',
'Kernel::System::Group',
'Kernel::System::Log',
'Kernel::System::Queue',
'Kernel::System::Ticket',
'Kernel::System::User'
);
sub new {
my ($Type, %Param) = @_;
my $Self = {
DBObject => $Kernel::OM->Get('Kernel::System::DB'),
EncodeObject => $Kernel::OM->Get('Kernel::System::Encode'),
GroupObject => $Kernel::OM->Get('Kernel::System::Group'),
LogObject => $Kernel::OM->Get('Kernel::System::Log'),
QueueObject => $Kernel::OM->Get('Kernel::System::Queue'),
TicketObject => $Kernel::OM->Get('Kernel::System::Ticket'),
UserObject => $Kernel::OM->Get('Kernel::System::User')
};
bless($Self, $Type);
return $Self;
}
=item Run()
Exports all tickets and writes them into files.
my $NumberOfWrittenTickets = $TicketExportObject->Run(
QueueID => 1,
Filepath => './',
Print => 1
);
=cut;
sub Run {
my ($Self, %Param) = @_;
# Check the needed stuff
for my $Key (qw( QueueID Filepath Print )) {
if (!$Param{$Key}) {
return 0;
}
}
my $QueueID = $Param{QueueID};
my $Filepath = $Param{Filepath};
$Self->{UserID} = $Param{UserID} || 1;
my $QueueName = $Self->{QueueObject}->QueueLookup(
QueueID => $QueueID
);
# Fetch the ids of all tickets which belong to the requested queue.
# Remember that we do that using our own method which uses SQL.
my @TicketList = $Self->GetTicketList(
QueueID => $QueueID
);
for my $TicketID (@TicketList) {
my %TicketData = $Self->{TicketObject}->TicketGet(
TicketID => $TicketID,
UserID => $Self->{UserID}
);
my $Filename = sprintf('%s%s_%d_%d.pdf', $Filepath, $QueueName, $TicketID, $TicketData{TicketNumber});
print "Writing \"". $Filename ."\"\n";
# Create the PDF data string
my $PDFString = $Self->CreatePDF(
TicketID => $TicketID
);
}
}
sub CreatePDF {
my ($Self, %Param) = @_;
if (!$Param{TicketID}) {
# There is no ticket id given
return;
}
my %RootUserData = $Self->{UserObject}->GetUserData(
UserID => $Self->{UserID}
);
# Just call a new instance of our modified version of the pdf printer
my $TicketPrinter = $Kernel::OM->Get('Kernel::Modules::AgentTicketPrintIntern');
$TicketPrinter->{GroupObject} = $Self->{GroupObject};
$TicketPrinter->{UserObject} = $Self->{UserObject};
$TicketPrinter->{TicketID} = $Param{TicketID};
$TicketPrinter->{UserID} = $RootUserData{UserID};
$TicketPrinter->{UserFirstname} = $RootUserData{UserFirstname};
$TicketPrinter->{UserLastname} = $RootUserData{UserLastname};
$TicketPrinter->{UserEmail} = $RootUserData{UserEmail};
return $TicketPrinter->Run();
}
sub GetTicketList {
my ($Self, %Param) = @_;
if (!$Param{QueueID}) {
return;
}
my $Query = 'SELECT id FROM ticket WHERE queue_id = ?;';
my @TicketIDs;
$Self->{DBObject}->Prepare(
SQL => $Query,
Bind => [ \$Param{QueueID} ]
);
while (my ($ID) = $Self->{DBObject}->FetchrowArray()) {
push(@TicketIDs, $ID);
}
return @TicketIDs;
}
1;
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