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 01df1720 authored by mtimm_01's avatar mtimm_01

Print all tickets into one pdf document

parent f4c4ae1c
......@@ -17,14 +17,37 @@ use Kernel::System::VariableCheck qw(:all);
our @ObjectDependencies = (
'Kernel::Language',
'Kernel::Modules::AgentTicketPrint',
'Kernel::System::DB',
'Kernel::System::PDF',
'Kernel::System::Queue',
'Kernel::System::VariableCheck'
);
sub GetTicketList {
my ($Self, %Param) = @_;
if (!defined($Param{QueueID})) {
# Can not work without a queue id
return;
}
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
my $Query = 'SELECT id FROM ticket WHERE queue_id = ?;';
my @TicketIDs;
$DBObject->Prepare(
SQL => $Query,
Bind => [ \$Param{QueueID} ]
);
while (my @Row = $DBObject->FetchrowArray()) {
push(@TicketIDs, $Row[0]);
}
return @TicketIDs;
}
sub CreatePDF {
my ($Self, %Param) = @_;
if (!defined($Param{TicketID})) {
if (!defined($Param{TicketList})) {
# There is no ticket id given
return;
}
......@@ -35,160 +58,163 @@ sub CreatePDF {
my $PDFObject = $Kernel::OM->Get('Kernel::System::PDF');
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
my $UserObject = $Kernel::OM->Get('Kernel::System::User');
my $QueueID = $TicketObject->TicketQueueID( TicketID => $Param{TicketID} );
my $LinkListWithData = $LinkObject->LinkListWithData(
Object => 'Ticket',
Key => $Param{TicketID},
State => 'Valid',
UserID => 1,
ObjectParameters => {
Ticket => {
IgnoreLinkedTicketStateTypes => 1,
},
},
);
my %LinkTypeList = $LinkObject->TypeList(
UserID => 1,
);
my %Ticket = $TicketObject->TicketGet(
TicketID => $Param{TicketID},
UserID => 1
);
my @ArticleBox = $TicketObject->ArticleContentIndex(
TicketID => $Param{TicketID},
StripPlainBodyAsAttachment => 1,
UserID => 1,
DynamicFields => 0
my %Page;
$Page{PageCount} = 1;
$PDFObject->DocumentNew(
Title => $ConfigObject->Get('Product') .': '. $LayoutObject->{LanguageObject}->Translate('All'),
Encode => $LayoutObject->{UserCharset}
);
if ($ConfigObject->Get('Ticket::Frontend::AccountTime')) {
$Ticket{TicketTimeUnits} = $TicketObject->TicketAccountedTimeGet(
TicketID => $Ticket{TicketID}
);
$Page{MaxPages} = $ConfigObject->Get('PDF::MaxPages');
if ( !$Page{MaxPages} || $Page{MaxPages} < 1 || $Page{MaxPages} > 10000 ) {
# Just make sure the max pages value makes any sense
$Page{MaxPages} = 1000;
}
my %UserInfo = $UserObject->GetUserData(
User => $Ticket{Owner}
);
# responsible info
my %ResponsibleInfo;
if ( $ConfigObject->Get('Ticket::Responsible') && $Ticket{Responsible} ) {
%ResponsibleInfo = $UserObject->GetUserData(
User => $Ticket{Responsible},
for my $TicketID (split(',', $Param{TicketList})) {
my $LinkListWithData = $LinkObject->LinkListWithData(
Object => 'Ticket',
Key => $TicketID,
State => 'Valid',
UserID => 1,
ObjectParameters => {
Ticket => {
IgnoreLinkedTicketStateTypes => 1,
},
},
);
}
# customer info
my %CustomerData;
if ( $Ticket{CustomerUserID} ) {
%CustomerData = $Kernel::OM->Get('Kernel::System::CustomerUser')->CustomerUserDataGet(
User => $Ticket{CustomerUserID},
my %LinkTypeList = $LinkObject->TypeList(
UserID => 1,
);
my %Ticket = $TicketObject->TicketGet(
TicketID => $TicketID,
UserID => 1
);
my @ArticleBox = $TicketObject->ArticleContentIndex(
TicketID => $TicketID,
StripPlainBodyAsAttachment => 1,
UserID => 1,
DynamicFields => 0
);
if ($ConfigObject->Get('Ticket::Frontend::AccountTime')) {
$Ticket{TicketTimeUnits} = $TicketObject->TicketAccountedTimeGet(
TicketID => $Ticket{TicketID}
);
}
my %UserInfo = $UserObject->GetUserData(
User => $Ticket{Owner}
);
}
if ( $Ticket{UntilTime} ) {
$Ticket{PendingUntil} = $Ticket{UntilTime};
}
# responsible info
my %ResponsibleInfo;
if ( $ConfigObject->Get('Ticket::Responsible') && $Ticket{Responsible} ) {
%ResponsibleInfo = $UserObject->GetUserData(
User => $Ticket{Responsible},
);
}
my $PrintedBy = $LayoutObject->{LanguageObject}->Translate('printed by');
my $Time = $LayoutObject->{Time};
# customer info
my %CustomerData;
if ( $Ticket{CustomerUserID} ) {
%CustomerData = $Kernel::OM->Get('Kernel::System::CustomerUser')->CustomerUserDataGet(
User => $Ticket{CustomerUserID},
);
}
my %Page;
$Page{MaxPages} = $ConfigObject->Get('PDF::MaxPages');
if ( !$Page{MaxPages} || $Page{MaxPages} < 1 || $Page{MaxPages} > 1000 ) {
# Just make sure the max pages value makes any sense
$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;
$PDFObject->DocumentNew(
Title => $ConfigObject->Get('Product') .': '. $Title,
Encode => $LayoutObject->{UserCharset}
);
if ( $Ticket{UntilTime} ) {
$Ticket{PendingUntil} = $Ticket{UntilTime};
}
# create first pdf page
$PDFObject->PageNew(
%Page,
FooterRight => $Page{PageText} .' '. $Page{PageCount},
);
$Page{PageCount}++;
my $PrintedBy = $LayoutObject->{LanguageObject}->Translate('printed by');
my $Time = $LayoutObject->{Time};
$PDFObject->PositionSet(
Move => 'relativ',
Y => -6,
);
# output title
$PDFObject->Text(
Text => $Ticket{Title},
FontSize => 13,
);
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('Ticket');
# create first pdf page
$PDFObject->PageNew(
%Page,
FooterRight => $Page{PageText} .' '. $Page{PageCount},
);
$Page{PageCount}++;
$PDFObject->PositionSet(
Move => 'relativ',
Y => -6,
);
# output "printed by"
$PDFObject->Text(
Text => sprintf(
'%s %s, %s',
$PrintedBy,
'root',
$Time
),
FontSize => 9,
);
$PDFObject->PositionSet(
Move => 'relativ',
Y => -6,
);
# output title
$PDFObject->Text(
Text => $Ticket{Title},
FontSize => 13,
);
$PDFObject->PositionSet(
Move => 'relativ',
Y => -14,
);
# output ticket infos
$Self->_PDFOutputTicketInfos(
PageData => \%Page,
TicketData => \%Ticket,
UserData => \%UserInfo,
ResponsibleData => \%ResponsibleInfo,
);
$PDFObject->PositionSet(
Move => 'relativ',
Y => -6,
);
# output "printed by"
$PDFObject->Text(
Text => sprintf(
'%s %s, %s',
$PrintedBy,
'root',
$Time
),
FontSize => 9,
);
$PDFObject->PositionSet(
Move => 'relativ',
Y => -6,
);
# output ticket dynamic fields
$Self->_PDFOutputTicketDynamicFields(
PageData => \%Page,
TicketData => \%Ticket,
);
$PDFObject->PositionSet(
Move => 'relativ',
Y => -14,
);
# output ticket infos
$Self->_PDFOutputTicketInfos(
PageData => \%Page,
TicketData => \%Ticket,
UserData => \%UserInfo,
ResponsibleData => \%ResponsibleInfo,
);
$PDFObject->PositionSet(
Move => 'relativ',
Y => -6,
);
if (%CustomerData) {
$Self->_PDFOutputCustomerInfos(
PageData => \%Page,
CustomerData => \%CustomerData,
$PDFObject->PositionSet(
Move => 'relativ',
Y => -6,
);
# output ticket dynamic fields
$Self->_PDFOutputTicketDynamicFields(
PageData => \%Page,
TicketData => \%Ticket,
);
}
# output articles
$Self->_PDFOutputArticles(
PageData => \%Page,
ArticleData => \@ArticleBox
);
$PDFObject->PositionSet(
Move => 'relativ',
Y => -6,
);
if (%CustomerData) {
$Self->_PDFOutputCustomerInfos(
PageData => \%Page,
CustomerData => \%CustomerData,
);
}
# output articles
$Self->_PDFOutputArticles(
PageData => \%Page,
ArticleData => \@ArticleBox
);
}
return $PDFObject->DocumentOutput();
}
......@@ -205,19 +231,12 @@ sub Configure {
ValueRegex => qr/.*/smx
);
$Self->AddOption(
Name => 'target-directory',
Description => 'Directory which should store the exported files',
Name => 'filename',
Description => 'File in which the exported tickets should be stored.',
Required => 1,
HasValue => 1,
ValueRegex => qr/.*/smx
);
$Self->AddOption(
Name => 'target-prefix',
Description => 'Prefix for the exported file names.',
Required => 0,
HasValue => 1,
ValueRegex => qr/.*/smx
);
return;
}
......@@ -225,68 +244,53 @@ sub Run {
my ($Self, %Param) = @_;
my $QueueName = $Self->GetOption('queue');
my $QueueID = $Kernel::OM->Get('Kernel::System::Queue')->QueueLookup( Queue => $QueueName );
my $ExportName = $Self->GetOption('target-prefix') || 'Queue_'. $QueueName;
my $ExportDir = $Self->GetOption('target-directory');
if (substr($ExportDir, -1) ne '/') {
# The directory information does not end with a '/'-Character.
# So it will be added here.
$ExportDir .= '/';
}
if (!-d $ExportDir) {
# The target directory does not exists. Inform the user and abort.
$Self->Print(sprintf("<red>%s: \"%s\"</red>\n", 'The target directory does not exists', $ExportDir));
return $Self->ExitCodeError();
}
my $Filename = $Self->GetOption('filename');
# If the given Queue could not be found the execution has to stop here
if (!$QueueID) {
$Self->Print(sprintf("<red>%s: %s</red>\n", 'Could not find queue', $QueueName));
return $Self->ExitCodeError();
}
my @TicketList = $Self->GetTicketList( QueueID => $QueueID );
$Self->Print(sprintf("<yellow>%s: \"%s\" [%d]</yellow>\n", 'Exporting all tickets of the queue', $QueueName, $QueueID));
my @TicketList = (17, 18, 19);
for my $TicketID (@TicketList) {
my $PDFString;
my $OutputStatusColor;
my $OutputStatusText;
my $FileWritingStatus;
my $Filename = sprintf("%s_Ticket_%d.pdf", $ExportName, $TicketID);
$Self->Print(sprintf("<yellow>%s</yellow> <green>%-30s</green> ", 'Writing file', $Filename));
$PDFString = $Self->CreatePDF(
TicketID => $TicketID
);
$Self->Print(sprintf("<yellow>%s: \"%s\" #%d [%d tickets]</yellow>\n", 'Exporting all tickets of the queue', $QueueName, $QueueID, scalar(@TicketList)));
if ($PDFString) {
# Write the file if the pdf content is available
$FileWritingStatus = $Self->WriteFile(
Filename => $ExportDir . $Filename,
Content => $PDFString
);
}
my $PDFString;
my $OutputStatusColor;
my $OutputStatusText;
my $FileWritingStatus;
$Self->Print(sprintf("<yellow>%s</yellow> <green>%-30s</green> ", 'Writing file', $Filename));
$PDFString = $Self->CreatePDF(
TicketList => join(',', @TicketList)
);
# Prepare the output color and the text of the status message in the console
$OutputStatusColor = 'green';
$OutputStatusText = ' Okay ';
if ((!$PDFString) || (!$FileWritingStatus)) {
# Error occured
$OutputStatusColor = 'red';
$OutputStatusText = 'Failed';
}
$Self->Print(sprintf("<%s>[%s]</%s>\n", $OutputStatusColor, $OutputStatusText, $OutputStatusColor));
# After printing out that a possible error occured we
# can print a more detailed message to the console.
if (!$PDFString) {
$Self->Print(sprintf("\t<red>%s</red>\n", 'Could not build the pdf content!'));
}
if (!$FileWritingStatus) {
$Self->Print(sprintf("\t<red>%s</red>\n", 'Could not create file!'));
}
if ($PDFString) {
# Write the file if the pdf content is available
$FileWritingStatus = $Self->WriteFile(
Filename => $Filename,
Content => $PDFString
);
}
# Prepare the output color and the text of the status message in the console
$OutputStatusColor = 'green';
$OutputStatusText = ' Okay ';
if ((!$PDFString) || (!$FileWritingStatus)) {
# Error occured
$OutputStatusColor = 'red';
$OutputStatusText = 'Failed';
}
$Self->Print(sprintf("<%s>[%s]</%s>\n", $OutputStatusColor, $OutputStatusText, $OutputStatusColor));
# After printing out that a possible error occured we
# can print a more detailed message to the console.
if (!$PDFString) {
$Self->Print(sprintf("\t<red>%s</red>\n", 'Could not build the pdf content!'));
return $Self->ExitCodeError();
}
if (!$FileWritingStatus) {
$Self->Print(sprintf("\t<red>%s</red>\n", 'Could not create file!'));
return $Self->ExitCodeError();
}
return $Self->ExitCodeOk();
}
......
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