[otrs-cvs] ITSMConfigurationManagement/Kernel/Modules AgentITSMConfigItemZoom.pm, 1.13, 1.14 AgentITSMConfigItemEdit.pm, 1.32, 1.33 AgentITSMConfigItemPrint.pm, 1.9, 1.10
"CVS commits notifications of OTRS.org" <[email protected]>
| Newsgroups | gmane.comp.otrs.cvs |
|---|---|
| Message-ID | <[email protected]> |
Comments:
Update of /home/cvs/ITSMConfigurationManagement/Kernel/Modules
In directory lancelot:/tmp/cvs-serv13159/Kernel/Modules
Modified Files:
AgentITSMConfigItemZoom.pm AgentITSMConfigItemEdit.pm
AgentITSMConfigItemPrint.pm
Log Message:
Added attachment support for ITSM config items.
Author: ub
Index: AgentITSMConfigItemZoom.pm
===================================================================
RCS file: /home/cvs/ITSMConfigurationManagement/Kernel/Modules/AgentITSMConfigItemZoom.pm,v
retrieving revision 1.13
retrieving revision 1.14
diff -2 -u -d -r1.13 -r1.14
--- AgentITSMConfigItemZoom.pm 29 Oct 2012 18:54:49 -0000 1.13
+++ AgentITSMConfigItemZoom.pm 30 Nov 2012 17:10:41 -0000 1.14
@@ -346,4 +346,75 @@
}
+ my @Attachments = $Self->{ConfigItemObject}->ConfigItemAttachmentList(
+ ConfigItemID => $ConfigItemID,
+ );
+
+ if (@Attachments) {
+
+ # get the metadata of the 1st attachment
+ my $FirstAttachment = $Self->{ConfigItemObject}->ConfigItemAttachmentGet(
+ ConfigItemID => $ConfigItemID,
+ Filename => $Attachments[0],
+ );
+
+ $Self->{LayoutObject}->Block(
+ Name => 'Attachments',
+ Data => {
+ ConfigItemID => $ConfigItemID,
+ Filename => $FirstAttachment->{Filename},
+ Filesize => $FirstAttachment->{Filesize},
+ },
+ );
+
+ # the 1st attachment was directly rendered into the 1st row's right cell, all further
+ # attachments are rendered into a separate row
+ ATTACHMENT:
+ for my $Attachment (@Attachments) {
+
+ # skip the 1st attachment
+ next ATTACHMENT if $Attachment eq $Attachments[0];
+
+ # get the metadata of the current attachment
+ my $AttachmentData = $Self->{ConfigItemObject}->ConfigItemAttachmentGet(
+ ConfigItemID => $ConfigItemID,
+ Filename => $Attachment,
+ );
+
+ $Self->{LayoutObject}->Block(
+ Name => 'AttachmentRow',
+ Data => {
+ ConfigItemID => $ConfigItemID,
+ Filename => $AttachmentData->{Filename},
+ Filesize => $AttachmentData->{Filesize},
+ },
+ );
+ }
+ }
+
+ # handle DownloadAttachment
+ if ( $Self->{Subaction} eq 'DownloadAttachment' ) {
+
+ # get data for attachment
+ my $Filename = $Self->{ParamObject}->GetParam( Param => 'Filename' );
+ my $AttachmentData = $Self->{ConfigItemObject}->ConfigItemAttachmentGet(
+ ConfigItemID => $ConfigItemID,
+ Filename => $Filename,
+ );
+
+ # return error if file does not exist
+ if ( !$AttachmentData ) {
+ $Self->{LogObject}->Log(
+ Message => "No such attachment ($Filename)!",
+ Priority => 'error',
+ );
+ return $Self->{LayoutObject}->ErrorScreen();
+ }
+
+ return $Self->{LayoutObject}->Attachment(
+ %{$AttachmentData},
+ Type => 'attachment',
+ );
+ }
+
# store last screen
$Self->{SessionObject}->UpdateSessionID(
Author: ub
Index: AgentITSMConfigItemEdit.pm
===================================================================
RCS file: /home/cvs/ITSMConfigurationManagement/Kernel/Modules/AgentITSMConfigItemEdit.pm,v
retrieving revision 1.32
retrieving revision 1.33
diff -2 -u -d -r1.32 -r1.33
--- AgentITSMConfigItemEdit.pm 21 Nov 2012 10:21:40 -0000 1.32
+++ AgentITSMConfigItemEdit.pm 30 Nov 2012 17:10:41 -0000 1.33
@@ -17,4 +17,5 @@
use Kernel::System::ITSMConfigItem;
use Kernel::System::GeneralCatalog;
+use Kernel::System::Web::UploadCache;
use vars qw($VERSION);
@@ -38,8 +39,17 @@
$Self->{ConfigItemObject} = Kernel::System::ITSMConfigItem->new(%Param);
$Self->{GeneralCatalogObject} = Kernel::System::GeneralCatalog->new(%Param);
+ $Self->{UploadCacheObject} = Kernel::System::Web::UploadCache->new(%Param);
# get config of frontend module
$Self->{Config} = $Self->{ConfigObject}->Get("ITSMConfigItem::Frontend::$Self->{Action}");
+ # get form id
+ $Self->{FormID} = $Self->{ParamObject}->GetParam( Param => 'FormID' );
+
+ # create form id
+ if ( !$Self->{FormID} ) {
+ $Self->{FormID} = $Self->{UploadCacheObject}->FormIDCreate();
+ }
+
return $Self;
}
@@ -139,4 +149,34 @@
}
+ # when there's no ClassID it means, an existing config item is edited as the ClassID is only
+ # provided as GET param when creating a new config item
+ if ( !$Self->{ParamObject}->GetParam( Param => 'ClassID' ) ) {
+
+ # get all attachments meta data
+ my @ExistingAttachments = $Self->{ConfigItemObject}->ConfigItemAttachmentList(
+ ConfigItemID => $ConfigItem->{ConfigItemID},
+ );
+
+ # copy all existing attachments to upload cache
+ FILENAME:
+ for my $Filename (@ExistingAttachments) {
+
+ # get the existing attachment data
+ my $AttachmentData = $Self->{ConfigItemObject}->ConfigItemAttachmentGet(
+ ConfigItemID => $ConfigItem->{ConfigItemID},
+ Filename => $Filename,
+ UserID => $Self->{UserID},
+ );
+
+ # add attachment to the upload cache
+ $Self->{UploadCacheObject}->FormIDAddFile(
+ FormID => $Self->{FormID},
+ Filename => $AttachmentData->{Filename},
+ Content => $AttachmentData->{Content},
+ ContentType => $AttachmentData->{ContentType},
+ );
+ }
+ }
+
# get submit save
my $SubmitSave = $Self->{ParamObject}->GetParam( Param => 'SubmitSave' );
@@ -145,4 +185,38 @@
my $Version = {};
if ( $Self->{Subaction} eq 'VersionSave' ) {
+
+ # check if an attachment must be deleted
+ ATTACHMENT:
+ for my $Number ( 1 .. 32 ) {
+
+ # check if the delete button was pressed for this attachment
+ my $Delete = $Self->{ParamObject}->GetParam( Param => "AttachmentDelete$Number" );
+
+ # check next attachment if it was not pressed
+ next ATTACHMENT if !$Delete;
+
+ # remove the attachment from the upload cache
+ $Self->{UploadCacheObject}->FormIDRemoveFile(
+ FormID => $Self->{FormID},
+ FileID => $Number,
+ );
+ }
+
+ # check if there was an attachment upload
+ if ( $Self->{ParamObject}->GetParam( Param => 'AttachmentUpload' ) ) {
+
+ # get the uploaded attachment
+ my %UploadStuff = $Self->{ParamObject}->GetUploadAll(
+ Param => 'FileUpload',
+ Source => 'string',
+ );
+
+ # add attachment to the upload cache
+ $Self->{UploadCacheObject}->FormIDAddFile(
+ FormID => $Self->{FormID},
+ %UploadStuff,
+ );
+ }
+
my $AllRequired = 1;
@@ -164,4 +238,5 @@
# save version to database
if ( $SubmitSave && $AllRequired ) {
+
if ( $ConfigItem->{ConfigItemID} eq 'NEW' ) {
$ConfigItem->{ConfigItemID} = $Self->{ConfigItemObject}->ConfigItemAdd(
@@ -171,4 +246,83 @@
}
+ # get all attachments from upload cache
+ my @Attachments = $Self->{UploadCacheObject}->FormIDGetAllFilesData(
+ FormID => $Self->{FormID},
+ );
+
+ # build a lookup lookup hash of the new attachments
+ my %NewAttachment;
+ for my $Attachment (@Attachments) {
+
+ # the key is the filename + filesize + content type
+ my $Key = $Attachment->{Filename}
+ . $Attachment->{Filesize}
+ . $Attachment->{ContentType};
+
+ # store all of the new attachment data
+ $NewAttachment{$Key} = $Attachment;
+ }
+
+ # get all attachments meta data
+ my @ExistingAttachments = $Self->{ConfigItemObject}->ConfigItemAttachmentList(
+ ConfigItemID => $ConfigItem->{ConfigItemID},
+ );
+
+ # check the existing attachments
+ FILENAME:
+ for my $Filename (@ExistingAttachments) {
+
+ # get the existing attachment data
+ my $AttachmentData = $Self->{ConfigItemObject}->ConfigItemAttachmentGet(
+ ConfigItemID => $ConfigItem->{ConfigItemID},
+ Filename => $Filename,
+ UserID => $Self->{UserID},
+ );
+
+ # the key is the filename + filesize + content type
+ # (no content id, as existing attachments don't have it)
+ my $Key = $AttachmentData->{Filename}
+ . $AttachmentData->{Filesize}
+ . $AttachmentData->{ContentType};
+
+ # attachment is already existing, we can delete it from the new attachment hash
+ if ( $NewAttachment{$Key} ) {
+ delete $NewAttachment{$Key};
+ }
+
+ # existing attachment is no longer in new attachments hash
+ else {
+
+ # delete the existing attachment
+ my $DeleteSuccessful = $Self->{ConfigItemObject}->ConfigItemAttachmentDelete(
+ ConfigItemID => $ConfigItem->{ConfigItemID},
+ Filename => $Filename,
+ UserID => $Self->{UserID},
+ );
+
+ # check error
+ if ( !$DeleteSuccessful ) {
+ return $Self->{LayoutObject}->FatalError();
+ }
+ }
+ }
+
+ # write the new attachments
+ ATTACHMENT:
+ for my $Attachment ( values %NewAttachment ) {
+
+ # add attachment
+ my $Success = $Self->{ConfigItemObject}->ConfigItemAttachmentAdd(
+ %{$Attachment},
+ ConfigItemID => $ConfigItem->{ConfigItemID},
+ UserID => $Self->{UserID},
+ );
+
+ # check error
+ if ( !$Success ) {
+ return $Self->{LayoutObject}->FatalError();
+ }
+ }
+
# add version
$Self->{ConfigItemObject}->VersionAdd(
@@ -326,4 +480,24 @@
}
+ # show the attachment upload button
+ $Self->{LayoutObject}->Block(
+ Name => 'AttachmentUpload',
+ Data => {%Param},
+ );
+
+ # get all attachments meta data
+ my @Attachments = $Self->{UploadCacheObject}->FormIDGetAllFilesMeta(
+ FormID => $Self->{FormID},
+ );
+
+ # show attachments
+ ATTACHMENT:
+ for my $Attachment (@Attachments) {
+ $Self->{LayoutObject}->Block(
+ Name => 'Attachment',
+ Data => $Attachment,
+ );
+ }
+
my $Output = '';
if ( ( $ConfigItem->{ConfigItemID} && $ConfigItem->{ConfigItemID} ne 'NEW' ) || $DuplicateID ) {
@@ -351,4 +525,5 @@
%Param,
%{$ConfigItem},
+ FormID => $Self->{FormID},
},
);
@@ -410,4 +585,5 @@
%Param,
%{$ConfigItem},
+ FormID => $Self->{FormID},
},
);
Author: ub
Index: AgentITSMConfigItemPrint.pm
===================================================================
RCS file: /home/cvs/ITSMConfigurationManagement/Kernel/Modules/AgentITSMConfigItemPrint.pm,v
retrieving revision 1.9
retrieving revision 1.10
diff -2 -u -d -r1.9 -r1.10
--- AgentITSMConfigItemPrint.pm 23 Aug 2012 16:40:58 -0000 1.9
+++ AgentITSMConfigItemPrint.pm 30 Nov 2012 17:10:41 -0000 1.10
@@ -160,4 +160,9 @@
}
+ # get attachments
+ my @Attachments = $Self->{ConfigItemObject}->ConfigItemAttachmentList(
+ ConfigItemID => $ConfigItemID,
+ );
+
# generate pdf output
if ( $Self->{PDFObject} ) {
@@ -224,4 +229,13 @@
}
+ # output attachments
+ if (@Attachments) {
+ $Self->_PDFOutputAttachments(
+ PageData => \%Page,
+ ConfigItemID => $ConfigItemID,
+ AttachmentData => \@Attachments,
+ );
+ }
+
# output version infos
$Self->_PDFOutputVersionInfos(
@@ -330,4 +344,46 @@
}
+ if (@Attachments) {
+
+ # get the metadata of the 1st attachment
+ my $FirstAttachment = $Self->{ConfigItemObject}->ConfigItemAttachmentGet(
+ ConfigItemID => $ConfigItemID,
+ Filename => $Attachments[0],
+ );
+
+ $Self->{LayoutObject}->Block(
+ Name => 'Attachments',
+ Data => {
+ ConfigItemID => $ConfigItemID,
+ Filename => $FirstAttachment->{Filename},
+ Filesize => $FirstAttachment->{Filesize},
+ },
+ );
+
+ # the 1st attachment was directly rendered into the 1st row's right cell, all further
+ # attachments are rendered into a separate row
+ ATTACHMENT:
+ for my $Attachment (@Attachments) {
+
+ # skip the 1st attachment
+ next ATTACHMENT if $Attachment eq $Attachments[0];
+
+ # get the metadata of the current attachment
+ my $AttachmentData = $Self->{ConfigItemObject}->ConfigItemAttachmentGet(
+ ConfigItemID => $ConfigItemID,
+ Filename => $Attachment,
+ );
+
+ $Self->{LayoutObject}->Block(
+ Name => 'AttachmentRow',
+ Data => {
+ ConfigItemID => $ConfigItemID,
+ Filename => $AttachmentData->{Filename},
+ Filesize => $AttachmentData->{Filesize},
+ },
+ );
+ }
+ }
+
# generate output
$Output .= $Self->{LayoutObject}->Output(
@@ -571,4 +627,91 @@
}
+sub _PDFOutputAttachments {
+ my ( $Self, %Param ) = @_;
+
+ # check needed stuff
+ for (qw(PageData ConfigItemID AttachmentData)) {
+ if ( !defined( $Param{$_} ) ) {
+ $Self->{LogObject}->Log( Priority => 'error', Message => "Need $_!" );
+ return;
+ }
+ }
+
+ my %Page = %{ $Param{PageData} };
+ my %TableParam;
+ my $Row = 0;
+
+ # attachments are rendered into a separate row
+ ATTACHMENT:
+ for my $Attachment ( @{ $Param{AttachmentData} } ) {
+
+ # get the metadata of the current attachment
+ my $AttachmentData = $Self->{ConfigItemObject}->ConfigItemAttachmentGet(
+ ConfigItemID => $Param{ConfigItemID},
+ Filename => $Attachment,
+ );
+
+ # define attachment line
+ $TableParam{CellData}[$Row][0]{Content}
+ = $AttachmentData->{Filename} . ' (' . $AttachmentData->{Filesize} . ')';
+
+ $Row++;
+ }
+
+ $TableParam{ColumnData}[0]{Width} = 80;
+ $TableParam{ColumnData}[1]{Width} = 431;
+
+ # set new position
+ $Self->{PDFObject}->PositionSet(
+ Move => 'relativ',
+ Y => -15,
+ );
+
+ # output headline
+ $Self->{PDFObject}->Text(
+ Text => $Self->{LayoutObject}->{LanguageObject}->Get('Attachments'),
+ Height => 7,
+ Type => 'Cut',
+ Font => 'ProportionalBoldItalic',
+ FontSize => 7,
+ Color => '#666666',
+ );
+
+ # set new position
+ $Self->{PDFObject}->PositionSet(
+ Move => 'relativ',
+ Y => -4,
+ );
+
+ # table params
+ $TableParam{Type} = 'Cut';
+ $TableParam{Border} = 0;
+ $TableParam{FontSize} = 6;
+ $TableParam{BackgroundColor} = '#DDDDDD';
+ $TableParam{Padding} = 1;
+ $TableParam{PaddingTop} = 3;
+ $TableParam{PaddingBottom} = 3;
+
+ # output table
+ for ( $Page{PageCount} .. $Page{MaxPages} ) {
+
+ # output table (or a fragment of it)
+ %TableParam = $Self->{PDFObject}->Table( %TableParam, );
+
+ # stop output or output next page
+ if ( $TableParam{State} ) {
+ last;
+ }
+ else {
+ $Self->{PDFObject}->PageNew(
+ %Page, FooterRight => $Page{PageText} . ' ' . $Page{PageCount},
+ );
+ $Page{PageCount}++;
+ }
+ }
+
+ return 1;
+}
+
sub _PDFOutputVersionInfos {
my ( $Self, %Param ) = @_;
---------------------------------------------------------------------
OTRS mailing list: cvs-log - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/cvs-log
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/cvs-log