From fcdc19f698f46ad9d92e3a50a59b5ac34afd37a1 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 21 Jan 2015 02:36:54 +0100 Subject: Rename ResponseChangeDefaultTo to DefaultTo --- DefaultTo.sopm | 60 ++++ Kernel/Config/Files/DefaultTo.xml | 38 +++ Kernel/Config/Files/ResponseChangeDefaultTo.xml | 38 --- Kernel/Modules/AdminDefaultToTemplates.pm | 355 ++++++++++++++++++++ .../AdminResponseChangeDefaultToTemplates.pm | 361 --------------------- Kernel/Output/HTML/DefaultTo.pm | 103 ++++++ Kernel/Output/HTML/ResponseChangeDefaultTo.pm | 106 ------ .../HTML/Standard/AdminDefaultToTemplates.tt | 172 ++++++++++ .../AdminResponseChangeDefaultToTemplates.tt | 172 ---------- Kernel/System/DefaultTo.pm | 321 ++++++++++++++++++ Kernel/System/ResponseChangeDefaultTo.pm | 321 ------------------ ResponseChangeDefaultTo.sopm | 60 ---- 12 files changed, 1049 insertions(+), 1058 deletions(-) create mode 100644 DefaultTo.sopm create mode 100644 Kernel/Config/Files/DefaultTo.xml delete mode 100644 Kernel/Config/Files/ResponseChangeDefaultTo.xml create mode 100644 Kernel/Modules/AdminDefaultToTemplates.pm delete mode 100644 Kernel/Modules/AdminResponseChangeDefaultToTemplates.pm create mode 100644 Kernel/Output/HTML/DefaultTo.pm delete mode 100644 Kernel/Output/HTML/ResponseChangeDefaultTo.pm create mode 100644 Kernel/Output/HTML/Standard/AdminDefaultToTemplates.tt delete mode 100644 Kernel/Output/HTML/Standard/AdminResponseChangeDefaultToTemplates.tt create mode 100644 Kernel/System/DefaultTo.pm delete mode 100644 Kernel/System/ResponseChangeDefaultTo.pm delete mode 100644 ResponseChangeDefaultTo.sopm diff --git a/DefaultTo.sopm b/DefaultTo.sopm new file mode 100644 index 0000000..64f0282 --- /dev/null +++ b/DefaultTo.sopm @@ -0,0 +1,60 @@ + + + DefaultTo + 1.0.0 + 4.0.x + spline.de + http://www.spline.de/ + GNU AFFERO GENERAL PUBLIC LICENSE Version 3, November 2007 + + + ? + ? + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Kernel/Config/Files/DefaultTo.xml b/Kernel/Config/Files/DefaultTo.xml new file mode 100644 index 0000000..9dd0f64 --- /dev/null +++ b/Kernel/Config/Files/DefaultTo.xml @@ -0,0 +1,38 @@ + + + + Change the default To address, based on the response template. + Ticket + Frontend::Agent::Ticket::ViewCompose + + + Kernel::Output::HTML::DefaultTo + + + 1 + + + + + + + Frontend module registration for the agent interface. + Ticket + Frontend::Admin::ModuleRegistration + + + admin + Admin + Templates <-> DefaultTo + Admin + + Kernel::Output::HTML::NavBarModuleAdmin + Templates <-> DefaultTo + Link templates to DefaultTo. + Queue + 300 + + + + + diff --git a/Kernel/Config/Files/ResponseChangeDefaultTo.xml b/Kernel/Config/Files/ResponseChangeDefaultTo.xml deleted file mode 100644 index 0c19c0f..0000000 --- a/Kernel/Config/Files/ResponseChangeDefaultTo.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - Change the default To address, based on the response template. - Ticket - Frontend::Agent::Ticket::ViewCompose - - - Kernel::Output::HTML::ResponseChangeDefaultTo - - - 1 - - - - - - - Frontend module registration for the agent interface. - Ticket - Frontend::Admin::ModuleRegistration - - - admin - Admin - Templates <-> ResponseChangeDefaultTo - Admin - - Kernel::Output::HTML::NavBarModuleAdmin - Templates <-> ResponseChangeDefaultTo - Link templates to ResponseChangeDefaultTo. - Queue - 300 - - - - - diff --git a/Kernel/Modules/AdminDefaultToTemplates.pm b/Kernel/Modules/AdminDefaultToTemplates.pm new file mode 100644 index 0000000..12c5826 --- /dev/null +++ b/Kernel/Modules/AdminDefaultToTemplates.pm @@ -0,0 +1,355 @@ +# -- +# Kernel/Modules/AdminDefaultToTemplates.pm - to manage DefaultTo <-> templates assignments +# Copyright (C) 2015 Alexander Sulfrian +# -- +# 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::AdminDefaultToTemplates; + +use strict; +use warnings; + +use Kernel::System::DefaultTo; +use Kernel::System::StandardTemplate; + +sub new { + my ( $Type, %Param ) = @_; + + # allocate new hash for object + my $Self = {%Param}; + bless( $Self, $Type ); + + # check all needed objects + for (qw(ParamObject DBObject QueueObject LayoutObject ConfigObject LogObject)) { + if ( !$Self->{$_} ) { + $Self->{LayoutObject}->FatalError( Message => "Got no $_!" ); + } + } + + $Self->{DefaultToObject} = Kernel::System::DefaultTo->new(%Param); + $Self->{StandardTemplateObject} = + Kernel::System::StandardTemplate->new(%Param); + + return $Self; +} + +sub Run { + my ( $Self, %Param ) = @_; + + # ------------------------------------------------------------ # + # template <-> DefaultTo 1:n + # ------------------------------------------------------------ # + if ( $Self->{Subaction} eq 'Template' ) { + + # get template data + my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); + my %StandardTemplateData = $Self->{StandardTemplateObject}->StandardTemplateGet( ID => $ID ); + my $StandardTemplateType = $Self->{LayoutObject}->{LanguageObject}->Translate( + $StandardTemplateData{TemplateType}, + ); + my $Name = $StandardTemplateType . ' - ' . $StandardTemplateData{Name}; + + # get DefaultTo data + my %DefaultToData = $Self->{DefaultToObject}->List(); + my %Member = $Self->{DefaultToObject}->MappingList( + TemplateID => $ID, + ); + + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->_Change( + Data => \%DefaultToData, + ID => $ID, + Name => $Name, + Mapping => \%Member, + Type => 'Template', + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + + # ------------------------------------------------------------ # + # templates <-> DefaultTo n:1 + # ------------------------------------------------------------ # + elsif ( $Self->{Subaction} eq 'DefaultTo' ) { + + my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); + my %DefaultToData = $Self->{DefaultToObject}->Get( ID => $ID ); + + # get templates + my %StandardTemplateData = $Self->{StandardTemplateObject}->StandardTemplateList( + Valid => 1, + ); + + if (%StandardTemplateData) { + for my $StandardTemplateID ( sort keys %StandardTemplateData ) { + my %Data = $Self->{StandardTemplateObject}->StandardTemplateGet( + ID => $StandardTemplateID + ); + $StandardTemplateData{$StandardTemplateID} + = $Self->{LayoutObject}->{LanguageObject}->Translate( $Data{TemplateType} ) + . ' - ' + . $Data{Name}; + } + } + + # get assigned templates + my %Member = $Self->{DefaultToObject}->MappingList( + DefaultToID => $ID, + ); + + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->_Change( + Data => \%StandardTemplateData, + ID => $ID, + Name => $DefaultToData{Title}, + Mapping => \%Member, + Type => 'DefaultTo', + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + + # ------------------------------------------------------------ # + # add templates to DefaultTo + # ------------------------------------------------------------ # + elsif ( $Self->{Subaction} eq 'ChangeDefaultTo' ) { + + # challenge token check for write action + $Self->{LayoutObject}->ChallengeTokenCheck(); + + # get current mapping + my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); + my %Mapping = $Self->{DefaultToObject}->MappingList( + DefaultToID => $ID, + ); + + # get new templates + my @TemplatesSelected = $Self->{ParamObject}->GetArray( Param => 'ItemsSelected' ); + my @TemplatesAll = $Self->{ParamObject}->GetArray( Param => 'ItemsAll' ); + + # create hash with selected templates + my %TemplatesSelected = map { $_ => 1 } @TemplatesSelected; + + # check all used templates + for my $TemplateID (@TemplatesAll) { + if ( $TemplatesSelected{$TemplateID} ) { + if ( ! $Mapping{$TemplateID} ) { + $Self->{DefaultToObject}->MappingAdd( + TemplateID => $TemplateID, + DefaultToID => $ID, + ); + } + } + else { + if ( $Mapping{$TemplateID} ) { + $Self->{DefaultToObject}->MappingDelete( + ID => $Mapping{$TemplateID}, + ); + } + } + } + + return $Self->{LayoutObject}->Redirect( OP => "Action=$Self->{Action}" ); + } + + # ------------------------------------------------------------ # + # add queues to template + # ------------------------------------------------------------ # + elsif ( $Self->{Subaction} eq 'ChangeTemplate' ) { + + # challenge token check for write action + $Self->{LayoutObject}->ChallengeTokenCheck(); + + # get current mapping + my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); + my %Mapping = $Self->{DefaultToObject}->MappingList( + TemplateID => $ID, + ); + + # get new queues + my @Selected = $Self->{ParamObject}->GetArray( Param => 'ItemsSelected' ); + my @All = $Self->{ParamObject}->GetArray( Param => 'ItemsAll' ); + + # create hash with selected queues + my %Selected = map { $_ => 1 } @Selected; + + # check all used queues + for my $DefaultToID (@All) { + if ( $Selected{$DefaultToID} ) { + if ( ! $Mapping{$DefaultToID} ) { + $Self->{DefaultToObject}->MappingAdd( + TemplateID => $ID, + DefaultToID => $DefaultToID, + ); + } + } + else { + if ( $Mapping{$DefaultToID} ) { + $Self->{DefaultToObject}->MappingDelete( + ID => $Mapping{$DefaultToID}, + ); + } + } + } + + return $Self->{LayoutObject}->Redirect( OP => "Action=$Self->{Action}" ); + } + + # ------------------------------------------------------------ # + # overview + # ------------------------------------------------------------ # + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->_Overview(); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; +} + +sub _Change { + my ( $Self, %Param ) = @_; + + my %Data = %{ $Param{Data} }; + my %Mapping = %{ $Param{Mapping} }; + my $Type = $Param{Type} || 'Template'; + my $NeType = 'DefaultTo'; + $NeType = 'Template' if $Type eq 'DefaultTo'; + + $Self->{LayoutObject}->Block( Name => 'Overview' ); + $Self->{LayoutObject}->Block( Name => 'ActionList' ); + $Self->{LayoutObject}->Block( Name => 'ActionOverview' ); + $Self->{LayoutObject}->Block( Name => 'Filter' ); + + $Self->{LayoutObject}->Block( + Name => 'Change', + Data => { + ID => $Param{ID}, + Name => $Param{Name}, + ActionHome => 'Admin' . $Type, + NeType => $NeType, + }, + ); + + $Self->{LayoutObject}->Block( Name => "ChangeHeader$NeType" ); + + for my $ID ( sort { uc( $Data{$a} ) cmp uc( $Data{$b} ) } keys %Data ) { + + # set output class + my $Selected = $Mapping{$ID} ? ' checked="checked"' : ''; + + $Self->{LayoutObject}->Block( + Name => 'ChangeRow', + Data => { + Type => $NeType, + ID => $ID, + Name => $Data{$ID}, + Selected => $Selected, + }, + ); + } + + return $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultToTemplates', + Data => \%Param, + ); +} + +sub _Overview { + my ( $Self, %Param ) = @_; + + $Self->{LayoutObject}->Block( + Name => 'Overview', + Data => {}, + ); + + # no actions in action list + # $Self->{LayoutObject}->Block(Name=>'ActionList'); + $Self->{LayoutObject}->Block( Name => 'FilterTemplate' ); + $Self->{LayoutObject}->Block( Name => 'FilterDefaultTo' ); + $Self->{LayoutObject}->Block( Name => 'OverviewResult' ); + + # get std template list + my %StandardTemplateData = $Self->{StandardTemplateObject}->StandardTemplateList( + Valid => 1, + ); + + # if there are results to show + if (%StandardTemplateData) { + for my $StandardTemplateID ( sort keys %StandardTemplateData ) { + my %Data = $Self->{StandardTemplateObject}->StandardTemplateGet( + ID => $StandardTemplateID, + ); + $StandardTemplateData{$StandardTemplateID} + = $Self->{LayoutObject}->{LanguageObject}->Translate( $Data{TemplateType} ) + . ' - ' + . $Data{Name}; + } + for my $StandardTemplateID ( + sort { uc( $StandardTemplateData{$a} ) cmp uc( $StandardTemplateData{$b} ) } + keys %StandardTemplateData + ) + { + + # set output class + $Self->{LayoutObject}->Block( + Name => 'List1n', + Data => { + Name => $StandardTemplateData{$StandardTemplateID}, + Subaction => 'Template', + ID => $StandardTemplateID, + }, + ); + } + } + + # otherwise it displays a no data found message + else { + $Self->{LayoutObject}->Block( + Name => 'NoTemplatesFoundMsg', + Data => {}, + ); + } + + # get queue data + my %DefaultToData = $Self->{DefaultToObject}->List(); + + # if there are results to show + if (%DefaultToData) { + for my $ID ( + sort { uc( $DefaultToData{$a} ) cmp uc( $DefaultToData{$b} ) } + keys %DefaultToData + ) + { + + # set output class + $Self->{LayoutObject}->Block( + Name => 'Listn1', + Data => { + Name => $DefaultToData{$ID}, + Subaction => 'DefaultTo', + ID => $ID, + }, + ); + } + } + + # otherwise it displays a no data found message + else { + $Self->{LayoutObject}->Block( + Name => 'NoDefaultToFoundMsg', + Data => {}, + ); + } + + # return output + return $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultToTemplates', + Data => \%Param, + ); +} + +1; diff --git a/Kernel/Modules/AdminResponseChangeDefaultToTemplates.pm b/Kernel/Modules/AdminResponseChangeDefaultToTemplates.pm deleted file mode 100644 index 02a0b36..0000000 --- a/Kernel/Modules/AdminResponseChangeDefaultToTemplates.pm +++ /dev/null @@ -1,361 +0,0 @@ -# -- -# Kernel/Modules/AdminResponseChangeDefaultToTemplates.pm - to manage ResponseChangeDefaultTo <-> templates assignments -# Copyright (C) 2015 Alexander Sulfrian -# -- -# 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::AdminResponseChangeDefaultToTemplates; - -use strict; -use warnings; - -use Kernel::System::ResponseChangeDefaultTo; -use Kernel::System::StandardTemplate; - -sub new { - my ( $Type, %Param ) = @_; - - # allocate new hash for object - my $Self = {%Param}; - bless( $Self, $Type ); - - # check all needed objects - for (qw(ParamObject DBObject QueueObject LayoutObject ConfigObject LogObject)) { - if ( !$Self->{$_} ) { - $Self->{LayoutObject}->FatalError( Message => "Got no $_!" ); - } - } - - $Self->{ResponseChangeDefaultToObject} = - Kernel::System::ResponseChangeDefaultTo->new(%Param); - $Self->{StandardTemplateObject} = - Kernel::System::StandardTemplate->new(%Param); - - return $Self; -} - -sub Run { - my ( $Self, %Param ) = @_; - - # ------------------------------------------------------------ # - # template <-> ResponseChangeDefaultTo 1:n - # ------------------------------------------------------------ # - if ( $Self->{Subaction} eq 'Template' ) { - - # get template data - my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); - my %StandardTemplateData = $Self->{StandardTemplateObject}->StandardTemplateGet( ID => $ID ); - my $StandardTemplateType = $Self->{LayoutObject}->{LanguageObject}->Translate( - $StandardTemplateData{TemplateType}, - ); - my $Name = $StandardTemplateType . ' - ' . $StandardTemplateData{Name}; - - # get ResponseChangeDefaultTo data - my %ResponseChangeDefaultToData = - $Self->{ResponseChangeDefaultToObject}->List(); - - my %Member = $Self->{ResponseChangeDefaultToObject}->MappingList( - ResponseID => $ID, - ); - - my $Output = $Self->{LayoutObject}->Header(); - $Output .= $Self->{LayoutObject}->NavigationBar(); - $Output .= $Self->_Change( - Data => \%ResponseChangeDefaultToData, - ID => $ID, - Name => $Name, - Mapping => \%Member, - Type => 'Template', - ); - $Output .= $Self->{LayoutObject}->Footer(); - return $Output; - } - - # ------------------------------------------------------------ # - # templates <-> ResponseChangeDefaultTo n:1 - # ------------------------------------------------------------ # - elsif ( $Self->{Subaction} eq 'ResponseChangeDefaultTo' ) { - - my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); - my %ResponseChangeDefaultToData = - $Self->{ResponseChangeDefaultToObject}->Get( ID => $ID ); - - # get templates - my %StandardTemplateData = $Self->{StandardTemplateObject}->StandardTemplateList( - Valid => 1, - ); - - if (%StandardTemplateData) { - for my $StandardTemplateID ( sort keys %StandardTemplateData ) { - my %Data = $Self->{StandardTemplateObject}->StandardTemplateGet( - ID => $StandardTemplateID - ); - $StandardTemplateData{$StandardTemplateID} - = $Self->{LayoutObject}->{LanguageObject}->Translate( $Data{TemplateType} ) - . ' - ' - . $Data{Name}; - } - } - - # get assigned templates - my %Member = $Self->{ResponseChangeDefaultToObject}->MappingList( - ResponseChangeDefaultToID => $ID, - ); - - my $Output = $Self->{LayoutObject}->Header(); - $Output .= $Self->{LayoutObject}->NavigationBar(); - $Output .= $Self->_Change( - Data => \%StandardTemplateData, - ID => $ID, - Name => $ResponseChangeDefaultToData{Title}, - Mapping => \%Member, - Type => 'ResponseChangeDefaultTo', - ); - $Output .= $Self->{LayoutObject}->Footer(); - return $Output; - } - - # ------------------------------------------------------------ # - # add templates to ResponseChangeDefaultTo - # ------------------------------------------------------------ # - elsif ( $Self->{Subaction} eq 'ChangeResponseChangeDefaultTo' ) { - - # challenge token check for write action - $Self->{LayoutObject}->ChallengeTokenCheck(); - - # get current mapping - my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); - my %Mapping = $Self->{ResponseChangeDefaultToObject}->MappingList( - ResponseChangeDefaultToID => $ID, - ); - - # get new templates - my @TemplatesSelected = $Self->{ParamObject}->GetArray( Param => 'ItemsSelected' ); - my @TemplatesAll = $Self->{ParamObject}->GetArray( Param => 'ItemsAll' ); - - # create hash with selected templates - my %TemplatesSelected = map { $_ => 1 } @TemplatesSelected; - - # check all used templates - for my $TemplateID (@TemplatesAll) { - if ( $TemplatesSelected{$TemplateID} ) { - if ( ! $Mapping{$TemplateID} ) { - $Self->{ResponseChangeDefaultToObject}->MappingAdd( - ResponseID => $TemplateID, - ResponseChangeDefaultToID => $ID, - ); - } - } - else { - if ( $Mapping{$TemplateID} ) { - $Self->{ResponseChangeDefaultToObject}->MappingDelete( - ID => $Mapping{$TemplateID}, - ); - } - } - } - - return $Self->{LayoutObject}->Redirect( OP => "Action=$Self->{Action}" ); - } - - # ------------------------------------------------------------ # - # add queues to template - # ------------------------------------------------------------ # - elsif ( $Self->{Subaction} eq 'ChangeTemplate' ) { - - # challenge token check for write action - $Self->{LayoutObject}->ChallengeTokenCheck(); - - # get current mapping - my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); - my %Mapping = $Self->{ResponseChangeDefaultToObject}->MappingList( - ResponseID => $ID, - ); - - # get new queues - my @Selected = $Self->{ParamObject}->GetArray( Param => 'ItemsSelected' ); - my @All = $Self->{ParamObject}->GetArray( Param => 'ItemsAll' ); - - # create hash with selected queues - my %Selected = map { $_ => 1 } @Selected; - - # check all used queues - for my $DefaultToID (@All) { - if ( $Selected{$DefaultToID} ) { - if ( ! $Mapping{$DefaultToID} ) { - $Self->{ResponseChangeDefaultToObject}->MappingAdd( - ResponseID => $ID, - ResponseChangeDefaultToID => $DefaultToID, - ); - } - } - else { - if ( $Mapping{$DefaultToID} ) { - $Self->{ResponseChangeDefaultToObject}->MappingDelete( - ID => $Mapping{$DefaultToID}, - ); - } - } - } - - return $Self->{LayoutObject}->Redirect( OP => "Action=$Self->{Action}" ); - } - - # ------------------------------------------------------------ # - # overview - # ------------------------------------------------------------ # - my $Output = $Self->{LayoutObject}->Header(); - $Output .= $Self->{LayoutObject}->NavigationBar(); - $Output .= $Self->_Overview(); - $Output .= $Self->{LayoutObject}->Footer(); - return $Output; -} - -sub _Change { - my ( $Self, %Param ) = @_; - - my %Data = %{ $Param{Data} }; - my %Mapping = %{ $Param{Mapping} }; - my $Type = $Param{Type} || 'Template'; - my $NeType = 'ResponseChangeDefaultTo'; - $NeType = 'Template' if $Type eq 'ResponseChangeDefaultTo'; - - $Self->{LayoutObject}->Block( Name => 'Overview' ); - $Self->{LayoutObject}->Block( Name => 'ActionList' ); - $Self->{LayoutObject}->Block( Name => 'ActionOverview' ); - $Self->{LayoutObject}->Block( Name => 'Filter' ); - - $Self->{LayoutObject}->Block( - Name => 'Change', - Data => { - ID => $Param{ID}, - Name => $Param{Name}, - ActionHome => 'Admin' . $Type, - NeType => $NeType, - }, - ); - - $Self->{LayoutObject}->Block( Name => "ChangeHeader$NeType" ); - - for my $ID ( sort { uc( $Data{$a} ) cmp uc( $Data{$b} ) } keys %Data ) { - - # set output class - my $Selected = $Mapping{$ID} ? ' checked="checked"' : ''; - - $Self->{LayoutObject}->Block( - Name => 'ChangeRow', - Data => { - Type => $NeType, - ID => $ID, - Name => $Data{$ID}, - Selected => $Selected, - }, - ); - } - - return $Self->{LayoutObject}->Output( - TemplateFile => 'AdminResponseChangeDefaultToTemplates', - Data => \%Param, - ); -} - -sub _Overview { - my ( $Self, %Param ) = @_; - - $Self->{LayoutObject}->Block( - Name => 'Overview', - Data => {}, - ); - - # no actions in action list - # $Self->{LayoutObject}->Block(Name=>'ActionList'); - $Self->{LayoutObject}->Block( Name => 'FilterTemplate' ); - $Self->{LayoutObject}->Block( Name => 'FilterResponseChangeDefaultTo' ); - $Self->{LayoutObject}->Block( Name => 'OverviewResult' ); - - # get std template list - my %StandardTemplateData = $Self->{StandardTemplateObject}->StandardTemplateList( - Valid => 1, - ); - - # if there are results to show - if (%StandardTemplateData) { - for my $StandardTemplateID ( sort keys %StandardTemplateData ) { - my %Data = $Self->{StandardTemplateObject}->StandardTemplateGet( - ID => $StandardTemplateID, - ); - $StandardTemplateData{$StandardTemplateID} - = $Self->{LayoutObject}->{LanguageObject}->Translate( $Data{TemplateType} ) - . ' - ' - . $Data{Name}; - } - for my $StandardTemplateID ( - sort { uc( $StandardTemplateData{$a} ) cmp uc( $StandardTemplateData{$b} ) } - keys %StandardTemplateData - ) - { - - # set output class - $Self->{LayoutObject}->Block( - Name => 'List1n', - Data => { - Name => $StandardTemplateData{$StandardTemplateID}, - Subaction => 'Template', - ID => $StandardTemplateID, - }, - ); - } - } - - # otherwise it displays a no data found message - else { - $Self->{LayoutObject}->Block( - Name => 'NoTemplatesFoundMsg', - Data => {}, - ); - } - - # get queue data - my %ResponseChangeDefaultToData = - $Self->{ResponseChangeDefaultToObject}->List(); - - # if there are results to show - if (%ResponseChangeDefaultToData) { - for my $ID ( - sort { uc( $ResponseChangeDefaultToData{$a} ) cmp - uc( $ResponseChangeDefaultToData{$b} ) } - keys %ResponseChangeDefaultToData - ) - { - - # set output class - $Self->{LayoutObject}->Block( - Name => 'Listn1', - Data => { - Name => $ResponseChangeDefaultToData{$ID}, - Subaction => 'ResponseChangeDefaultTo', - ID => $ID, - }, - ); - } - } - - # otherwise it displays a no data found message - else { - $Self->{LayoutObject}->Block( - Name => 'NoResponseChangeDefaultToFoundMsg', - Data => {}, - ); - } - - # return output - return $Self->{LayoutObject}->Output( - TemplateFile => 'AdminResponseChangeDefaultToTemplates', - Data => \%Param, - ); -} - -1; diff --git a/Kernel/Output/HTML/DefaultTo.pm b/Kernel/Output/HTML/DefaultTo.pm new file mode 100644 index 0000000..1d09b40 --- /dev/null +++ b/Kernel/Output/HTML/DefaultTo.pm @@ -0,0 +1,103 @@ +# -- +# Kernel/Output/HTML/DefaultTo.pm +# Copyright (C) 2015 Alexander Sulfrian +# -- + +package Kernel::Output::HTML::DefaultTo; + +use strict; +use warnings; + +our @ObjectDependencies = qw( + Kernel::System::Log + Kernel::System::DefaultTo +); + +sub new { + my ( $Type, %Param ) = @_; + + # allocate new hash for object + my $Self = {}; + $Self->{LayoutObject} = $Param{LayoutObject} || die "Got no LayoutObject!"; + $Self->{LogObject} = $Kernel::OM->Get('Kernel::System::Log'); + $Self->{DefaultToObject} = $Kernel::OM->Get('Kernel::System::DefaultTo'); + bless( $Self, $Type ); + + return $Self; +} + +sub Run { + my ( $Self, %Param ) = @_; + return if !$Self->{LayoutObject}; + + for (qw(LogObject LayoutObject DefaultToObject)) { + return if !$Self->{$_}; + } + + # check needed stuff + if ( !defined $Param{Data} ) { + $Self->{LogObject}->Log( + Priority => 'error', + Message => 'Need Data!' + ); + $Self->{LayoutObject}->FatalDie(); + } + + my $BlockData = $Self->{LayoutObject}->{BlockData}; + + # get ticket data + my $Ticket; + BLOCK: + for my $block ( @$BlockData ) { + if ( $block->{Name} eq 'TicketBack' ) { + $Ticket = $block->{Data}; + last BLOCK; + } + } + + # return if not generated from template + return unless $Ticket->{TemplateID}; + + # get all DefaultTo + my %MappedDefaultTo = $Self->{DefaultToObject}->MappingList( + TemplateID => $Ticket->{TemplateID}, + ); + + my $RemoveDefault = 0; + my @Addresses = (); + foreach my $ID ( values %MappedDefaultTo ) { + my %DefaultTo = $Self->{DefaultToObject}->Get( + ID => $ID, + ); + + $RemoveDefault = 1 if $DefaultTo{RemoveDefault}; + if ( $DefaultTo{AddNew} ) { + push @Addresses, $DefaultTo{NewAddress}; + } + } + + if ( $RemoveDefault ) { + # remove preselected "To" address + for my $block ( @$BlockData ) { + if ( $block->{Name} eq 'PreFilledToRow' ) { + $block->{Data} = undef; + } + } + + $Self->{LayoutObject}->{BlockData} = $BlockData; + } + + # add new addresses + foreach my $Address ( @Addresses ) { + $Self->{LayoutObject}->Block( + Name => 'PreFilledToRow', + Data => { + Email => $Address, + }, + ); + } + + return $Param{Data}; +} + +1; diff --git a/Kernel/Output/HTML/ResponseChangeDefaultTo.pm b/Kernel/Output/HTML/ResponseChangeDefaultTo.pm deleted file mode 100644 index b411139..0000000 --- a/Kernel/Output/HTML/ResponseChangeDefaultTo.pm +++ /dev/null @@ -1,106 +0,0 @@ -# -- -# Kernel/Output/HTML/ResponseChangeDefaultTo.pm -# Copyright (C) 2015 Alexander Sulfrian -# -- - -package Kernel::Output::HTML::ResponseChangeDefaultTo; - -use strict; -use warnings; - -our @ObjectDependencies = qw( - Kernel::System::Log - Kernel::System::ResponseChangeDefaultTo -); - -sub new { - my ( $Type, %Param ) = @_; - - # allocate new hash for object - my $Self = {}; - $Self->{LayoutObject} = $Param{LayoutObject} || die "Got no LayoutObject!"; - $Self->{LogObject} = $Kernel::OM->Get('Kernel::System::Log'); - $Self->{ResponseChangeDefaultToObject} = - $Kernel::OM->Get('Kernel::System::ResponseChangeDefaultTo'); - bless( $Self, $Type ); - - return $Self; -} - -sub Run { - my ( $Self, %Param ) = @_; - return if !$Self->{LayoutObject}; - - for (qw(LogObject LayoutObject ResponseChangeDefaultToObject)) { - return if !$Self->{$_}; - } - - # check needed stuff - if ( !defined $Param{Data} ) { - $Self->{LogObject}->Log( - Priority => 'error', - Message => 'Need Data!' - ); - $Self->{LayoutObject}->FatalDie(); - } - - my $BlockData = $Self->{LayoutObject}->{BlockData}; - - # get ticket data - my $Ticket; - BLOCK: - for my $block ( @$BlockData ) { - if ( $block->{Name} eq 'TicketBack' ) { - $Ticket = $block->{Data}; - last BLOCK; - } - } - - # return if not generated from template - return unless $Ticket->{ResponseID}; - - # get all ResponseChangeDefaultTo - my %MappedResponseChangeDefaultTo = - $Self->{ResponseChangeDefaultToObject}->MappingList( - ResponseID => $Ticket->{ResponseID}, - ); - - my $RemoveDefault = 0; - my @Addresses = (); - foreach my $ID ( values %MappedResponseChangeDefaultTo ) { - my %ResponseChangeDefaultTo = - $Self->{ResponseChangeDefaultToObject}->Get( - ID => $ID, - ); - - $RemoveDefault = 1 if $ResponseChangeDefaultTo{RemoveDefault}; - if ( $ResponseChangeDefaultTo{AddNew} ) { - push @Addresses, $ResponseChangeDefaultTo{NewAddress}; - } - } - - if ( $RemoveDefault ) { - # remove preselected "To" address - for my $block ( @$BlockData ) { - if ( $block->{Name} eq 'PreFilledToRow' ) { - $block->{Data} = undef; - } - } - - $Self->{LayoutObject}->{BlockData} = $BlockData; - } - - # add new addresses - foreach my $Address ( @Addresses ) { - $Self->{LayoutObject}->Block( - Name => 'PreFilledToRow', - Data => { - Email => $Address, - }, - ); - } - - return $Param{Data}; -} - -1; diff --git a/Kernel/Output/HTML/Standard/AdminDefaultToTemplates.tt b/Kernel/Output/HTML/Standard/AdminDefaultToTemplates.tt new file mode 100644 index 0000000..e3436f7 --- /dev/null +++ b/Kernel/Output/HTML/Standard/AdminDefaultToTemplates.tt @@ -0,0 +1,172 @@ +# -- +# AdminDefaultToTemplates.tt - provides HTML form for AdminInterface +# Copyright (C) 2015 Alexander Sulfrian +# -- +# 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. +# -- + +[% RenderBlockStart("Overview") %] +
+

[% Translate("Manage Template-DefaultTo Relations") | html %]

+ +
+ +[% RenderBlockStart("ActionList") %] +
+
+

+
+
+ +
+
+[% RenderBlockEnd("ActionList") %] + +[% RenderBlockStart("Filter") %] +
+
+

+
+
+ +
+
+[% RenderBlockEnd("Filter") %] + +[% RenderBlockStart("FilterTemplate") %] +
+
+

+
+
+ +
+
+[% RenderBlockEnd("FilterTemplate") %] +[% RenderBlockStart("FilterDefaultTo") %] +
+
+

+
+
+ +
+
+[% RenderBlockEnd("FilterDefaultTo") %] + +
+ +
+
+ +[% RenderBlockStart("OverviewResult") %] +
+

[% Translate("Overview") | html %]

+
+
+
+
    +
  • [% Translate("Templates") | html %]
  • + +[% RenderBlockStart("NoTemplatesFoundMsg") %] +
  • [% Translate("No data found.") | html %]
  • +[% RenderBlockEnd("NoTemplatesFoundMsg") %] +[% RenderBlockStart("List1n") %] +
  • [% Data.Name | html %]
  • +[% RenderBlockEnd("List1n") %] +
+
+
+
    +
  • [% Translate("DefaultTo") | html %]
  • + +[% RenderBlockStart("NoDefaultToFoundMsg") %] +
  • [% Translate("No data found.") | html %]
  • +[% RenderBlockEnd("NoDefaultToFoundMsg") %] +[% RenderBlockStart("Listn1") %] +
  • [% Data.Name | html %]
  • +[% RenderBlockEnd("Listn1") %] +
+
+
+
+ +[% WRAPPER JSOnDocumentComplete %] + +[% END %] +[% RenderBlockEnd("OverviewResult") %] +[% RenderBlockStart("Change") %] +
+

+[% RenderBlockStart("ChangeHeaderDefaultTo") %] + [% Translate("Change DefaultTo Relations for Template") | html %] +[% RenderBlockEnd("ChangeHeaderDefaultTo") %] +[% RenderBlockStart("ChangeHeaderTemplate") %] + [% Translate("Change Template Relations for DefaultTo") | html %] +[% RenderBlockEnd("ChangeHeaderTemplate") %] + [% Data.Name | html %] +

+
+
+
+ + + + + + + + + + + +[% RenderBlockStart("ChangeRow") %] + + + + +[% RenderBlockEnd("ChangeRow") %] + +
[% Translate(Data.NeType) | html %] + + [% Translate("Active") | html %] +
[% Data.Name | html %] + + + +
+
+ + [% Translate("or") | html %] + [% Translate("Cancel") | html %] +
+
+
+
+[% WRAPPER JSOnDocumentComplete %] + +[% END %] +[% RenderBlockEnd("Change") %] +
+
+
+ +
+[% RenderBlockEnd("Overview") %] diff --git a/Kernel/Output/HTML/Standard/AdminResponseChangeDefaultToTemplates.tt b/Kernel/Output/HTML/Standard/AdminResponseChangeDefaultToTemplates.tt deleted file mode 100644 index 090716f..0000000 --- a/Kernel/Output/HTML/Standard/AdminResponseChangeDefaultToTemplates.tt +++ /dev/null @@ -1,172 +0,0 @@ -# -- -# AdminResponseChangeDefaultToTemplates.tt - provides HTML form for AdminInterface -# Copyright (C) 2015 Alexander Sulfrian -# -- -# 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. -# -- - -[% RenderBlockStart("Overview") %] -
-

[% Translate("Manage Template-ResponseChangeDefaultTo Relations") | html %]

- -
- -[% RenderBlockStart("ActionList") %] -
-
-

-
-
- -
-
-[% RenderBlockEnd("ActionList") %] - -[% RenderBlockStart("Filter") %] -
-
-

-
-
- -
-
-[% RenderBlockEnd("Filter") %] - -[% RenderBlockStart("FilterTemplate") %] -
-
-

-
-
- -
-
-[% RenderBlockEnd("FilterTemplate") %] -[% RenderBlockStart("FilterResponseChangeDefaultTo") %] -
-
-

-
-
- -
-
-[% RenderBlockEnd("FilterResponseChangeDefaultTo") %] - -
- -
-
- -[% RenderBlockStart("OverviewResult") %] -
-

[% Translate("Overview") | html %]

-
-
-
-
    -
  • [% Translate("Templates") | html %]
  • - -[% RenderBlockStart("NoTemplatesFoundMsg") %] -
  • [% Translate("No data found.") | html %]
  • -[% RenderBlockEnd("NoTemplatesFoundMsg") %] -[% RenderBlockStart("List1n") %] -
  • [% Data.Name | html %]
  • -[% RenderBlockEnd("List1n") %] -
-
-
-
    -
  • [% Translate("ResponseChangeDefaultTo") | html %]
  • - -[% RenderBlockStart("NoResponseChangeDefaultToFoundMsg") %] -
  • [% Translate("No data found.") | html %]
  • -[% RenderBlockEnd("NoResponseChangeDefaultToFoundMsg") %] -[% RenderBlockStart("Listn1") %] -
  • [% Data.Name | html %]
  • -[% RenderBlockEnd("Listn1") %] -
-
-
-
- -[% WRAPPER JSOnDocumentComplete %] - -[% END %] -[% RenderBlockEnd("OverviewResult") %] -[% RenderBlockStart("Change") %] -
-

-[% RenderBlockStart("ChangeHeaderResponseChangeDefaultTo") %] - [% Translate("Change ResponseChangeDefaultTo Relations for Template") | html %] -[% RenderBlockEnd("ChangeHeaderResponseChangeDefaultTo") %] -[% RenderBlockStart("ChangeHeaderTemplate") %] - [% Translate("Change Template Relations for ResponseChangeDefaultTo") | html %] -[% RenderBlockEnd("ChangeHeaderTemplate") %] - [% Data.Name | html %] -

-
-
-
- - - - - - - - - - - -[% RenderBlockStart("ChangeRow") %] - - - - -[% RenderBlockEnd("ChangeRow") %] - -
[% Translate(Data.NeType) | html %] - - [% Translate("Active") | html %] -
[% Data.Name | html %] - - - -
-
- - [% Translate("or") | html %] - [% Translate("Cancel") | html %] -
-
-
-
-[% WRAPPER JSOnDocumentComplete %] - -[% END %] -[% RenderBlockEnd("Change") %] -
-
-
- -
-[% RenderBlockEnd("Overview") %] diff --git a/Kernel/System/DefaultTo.pm b/Kernel/System/DefaultTo.pm new file mode 100644 index 0000000..7a1257b --- /dev/null +++ b/Kernel/System/DefaultTo.pm @@ -0,0 +1,321 @@ +# -- +# Kernel/System/DefaultTo.pm - core module +# Copyright (C) 2015 Alexander Sulfrian +# -- +# 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::System::DefaultTo; + +use strict; +use warnings; + +our @ObjectDependencies = qw( + Kernel::System::DB + Kernel::System::Log + Kernel::System::StandardTemplate +); + +sub new { + my ( $Type, %Param ) = @_; + + # allocate new hash for object + my $Self = {}; + $Self->{DBObject} = $Kernel::OM->Get('Kernel::System::DB'); + $Self->{LogObject} = $Kernel::OM->Get('Kernel::System::Log'); + $Self->{StandardTemplateObject} = + $Kernel::OM->Get('Kernel::System::StandardTemplate'); + bless ($Self, $Type); + + return $Self; +} + +sub Add { + my ( $Self, %Param ) = @_; + + # check needed stuff + for my $Needed (qw(Title RemoveDefault AddNew NewAddress)) { + if ( !$Param{$Needed} ) { + $Self->{LogObject}->Log( + Priority => 'error', + Message => "Need $Needed!", + ); + return; + } + } + + # insert new DefaultTo + return if !$Self->{DBObject}->Do( + SQL => 'INSERT INTO default_to ' + . '(title, remove_default, add_new, new_address) ' + . 'VALUES (?, ?, ?, ?)', + Bind => [ + \$Param{Title}, + \$Param{RemoveDefault}, + \$Param{AddNew}, + \$Param{NewAddress}, + ], + ); + + # get new id + return if !$Self->{DBObject}->Prepare( + SQL => 'SELECT MAX(id) FROM default_to WHERE title = ?', + Bind => [ \$Param{Title}, ], + Limit => 1, + ); + + my $ID; + while ( my @Row = $Self->{DBObject}->FetchrowArray() ) { + $ID = $Row[0]; + } + + # log notice + $Self->{LogObject}->Log( + Priority => 'notice', + Message => "DefaultTo '$ID' created successfully!", + ); + + return $ID; +} + +sub Update { + my ( $Self, %Param ) = @_; + + # check needed stuff + for my $Needed (qw(ID Title RemoveDefault AddNew NewAddress)) { + if ( !$Param{$Needed} ) { + $Self->{LogObject}->Log( + Priority => 'error', + Message => "Need $Needed!", + ); + return; + } + } + + # insert new DefaultTo + return if !$Self->{DBObject}->Do( + SQL => 'UPDATE default_to SET title = ?, ' + . 'remove_default = ?, add_new = ?, new_address = ? ' + . 'WHERE id = ?', + Bind => [ + \$Param{Title}, + \$Param{RemoveDefault}, + \$Param{AddNew}, + \$Param{NewAddress}, + \$Param{ID}, + ], + ); + + return 1; +} + +sub Get { + my ( $Self, %Param ) = @_; + + # check needed stuff + if ( !$Param{ID} ) { + $Self->{LogObject}->Log( + Priority => 'error', + Message => 'Need ID!', + ); + return; + } + + # get RrsponseChangeDefaultTO obejct + return if !$Self->{DBObject}->Prepare( + SQL => 'SELECT id, title, remove_default, add_new, new_address ' + . 'FROM default_to WHERE id = ?', + Bind => [ \$Param{ID} ], + Limit => 1, + ); + + my %DefaultTo; + while ( my @Data = $Self->{DBObject}->FetchrowArray() ) { + %DefaultTo = ( + ID => $Data[0], + Title => $Data[1], + RemoveDefault => $Data[2], + AddNew => $Data[3], + NewAddress => $Data[4], + ); + } + + # make sure we have a valid object + return unless %DefaultTo; + + # get the assigned responses + return if !$Self->{DBObject}->Prepare( + SQL => 'SELECT id, response_id ' + . 'FROM response_change_default_to_response ' + . 'WHERE response_change_default_to_id = ?', + Bind => [ \$DefaultTo{ID} ], + ); + + while ( my @Data = $Self->{DBObject}->FetchrowArray() ) { + my $Response = + $Self->{StandardTemplateObject}->StandardTemplateLookup( + StandardTemplateID => $Data[1], + ); + + if ( $Response ) { + $DefaultTo{Responses}->{$Data[0]} = { + ID => $Data[1], + Name => $Response, + }; + } + } + + return %DefaultTo; +} + +sub Delete { + my ( $Self, %Param ) = @_; + + # check needed stuff + if ( !$Param{ID} ) { + $Self->{LogObject}->Log( + Priority => 'error', + Message => 'Need ID!', + ); + return; + } + + # delete mapping + return if !$Self->{DBObject}->Do( + SQL => 'DELETE FROM default_to_response ' + . 'WHERE default_to_id = ?', + Bind => [ \$Param{ID} ], + ); + + # delete entry + return $Self->{DBObject}->Do( + SQL => 'DELETE FROM default_to WHERE id = ?', + Bind => [ \$Param{ID} ], + ); +} + +sub List { + my ( $Self, %Param ) = @_; + + $Self->{DBObject}->Prepare( + SQL => 'SELECT id, title FROM default_to', + ); + + my %DefaultTo; + while ( my @Data = $Self->{DBObject}->FetchrowArray() ) { + $DefaultTo{ $Data[0] } = $Data[1]; + } + + return %DefaultTo; +} + +sub MappingAdd { + my ( $Self, %Param ) = @_; + + # check needed stuff + for my $Needed (qw(TemplateID DefaultToID)) { + if ( !$Param{$Needed} ) { + $Self->{LogObject}->Log( + Priority => 'error', + Message => "Need $Needed!", + ); + return; + } + } + + # insert new mapping + return if !$Self->{DBObject}->Do( + SQL => 'INSERT INTO default_to_response ' + . '(template_id, default_to_id) VALUES (?, ?)', + Bind => [ + \$Param{TemplateID}, + \$Param{DefaultToID}, + ], + ); + + # get new id + return if !$Self->{DBObject}->Prepare( + SQL => 'SELECT MAX(id) FROM default_to_response ' + . 'WHERE template_id = ? AND default_to_id = ?', + Bind => [ + \$Param{TemplateID}, + \$Param{DefaultToID}, ], + Limit => 1, + ); + + my $ID; + while ( my @Row = $Self->{DBObject}->FetchrowArray() ) { + $ID = $Row[0]; + } + + # log notice + $Self->{LogObject}->Log( + Priority => 'notice', + Message => "DefaultTo mapping '$ID' " + . "created successfully!", + ); + + return $ID; +} + +sub MappingDelete { + my ( $Self, %Param ) = @_; + + # check needed stuff + if ( !$Param{ID} ) { + $Self->{LogObject}->Log( + Priority => 'error', + Message => 'Need ID!', + ); + return; + } + + # delete mapping + return $Self->{DBObject}->Do( + SQL => 'DELETE FROM default_to_response ' + . 'WHERE id = ?', + Bind => [ \$Param{ID} ], + ); +} + +sub MappingList { + my ( $Self, %Param ) = @_; + + # check needed stuff + if ( !$Param{TemplateID} && !$Param{DefaultToID} ) { + $Self->{LogObject}->Log( + Priority => 'error', + Message => 'Got no TemplateID or DefaultToID!' + ); + return; + } + + # find mapped objects + if ( $Param{TemplateID} ) { + $Self->{DBObject}->Prepare( + SQL => 'SELECT id, default_to_id ' + . 'FROM default_to_response ' + . 'WHERE template_id = ?', + Bind => [ \$Param{TemplateID}, ], + ); + } + else { + $Self->{DBObject}->Prepare( + SQL => 'SELECT id, template_id ' + . 'FROM default_to_response ' + . 'WHERE default_to_id = ?', + Bind => [ \$Param{DefaultToID}, ], + ); + } + + my %Mapping; + while ( my @Data = $Self->{DBObject}->FetchrowArray() ) { + $Mapping{ $Data[0] } = $Data[1]; + } + + return %Mapping; +} + +1; diff --git a/Kernel/System/ResponseChangeDefaultTo.pm b/Kernel/System/ResponseChangeDefaultTo.pm deleted file mode 100644 index 91d80e1..0000000 --- a/Kernel/System/ResponseChangeDefaultTo.pm +++ /dev/null @@ -1,321 +0,0 @@ -# -- -# Kernel/System/ResponseChangeDefaultTo.pm - core module -# Copyright (C) 2015 Alexander Sulfrian -# -- -# 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::System::ResponseChangeDefaultTo; - -use strict; -use warnings; - -our @ObjectDependencies = qw( - Kernel::System::DB - Kernel::System::Log - Kernel::System::StandardTemplate -); - -sub new { - my ( $Type, %Param ) = @_; - - # allocate new hash for object - my $Self = {}; - $Self->{DBObject} = $Kernel::OM->Get('Kernel::System::DB'); - $Self->{LogObject} = $Kernel::OM->Get('Kernel::System::Log'); - $Self->{StandardTemplateObject} = - $Kernel::OM->Get('Kernel::System::StandardTemplate'); - bless ($Self, $Type); - - return $Self; -} - -sub Add { - my ( $Self, %Param ) = @_; - - # check needed stuff - for my $Needed (qw(Title RemoveDefault AddNew NewAddress)) { - if ( !$Param{$Needed} ) { - $Self->{LogObject}->Log( - Priority => 'error', - Message => "Need $Needed!", - ); - return; - } - } - - # insert new ResponseChangeDefaultTo - return if !$Self->{DBObject}->Do( - SQL => 'INSERT INTO response_change_default_to ' - . '(title, remove_default, add_new, new_address) ' - . 'VALUES (?, ?, ?, ?)', - Bind => [ - \$Param{Title}, - \$Param{RemoveDefault}, - \$Param{AddNew}, - \$Param{NewAddress}, - ], - ); - - # get new id - return if !$Self->{DBObject}->Prepare( - SQL => 'SELECT MAX(id) FROM response_change_default_to WHERE title = ?', - Bind => [ \$Param{Title}, ], - Limit => 1, - ); - - my $ID; - while ( my @Row = $Self->{DBObject}->FetchrowArray() ) { - $ID = $Row[0]; - } - - # log notice - $Self->{LogObject}->Log( - Priority => 'notice', - Message => "ResponseChangeDefaultTo '$ID' created successfully!", - ); - - return $ID; -} - -sub Update { - my ( $Self, %Param ) = @_; - - # check needed stuff - for my $Needed (qw(ID Title RemoveDefault AddNew NewAddress)) { - if ( !$Param{$Needed} ) { - $Self->{LogObject}->Log( - Priority => 'error', - Message => "Need $Needed!", - ); - return; - } - } - - # insert new ResponseChangeDefaultTo - return if !$Self->{DBObject}->Do( - SQL => 'UPDATE response_change_default_to SET title = ?, ' - . 'remove_default = ?, add_new = ?, new_address = ? ' - . 'WHERE id = ?', - Bind => [ - \$Param{Title}, - \$Param{RemoveDefault}, - \$Param{AddNew}, - \$Param{NewAddress}, - \$Param{ID}, - ], - ); - - return 1; -} - -sub Get { - my ( $Self, %Param ) = @_; - - # check needed stuff - if ( !$Param{ID} ) { - $Self->{LogObject}->Log( - Priority => 'error', - Message => 'Need ID!', - ); - return; - } - - # get RrsponseChangeDefaultTO obejct - return if !$Self->{DBObject}->Prepare( - SQL => 'SELECT id, title, remove_default, add_new, new_address ' - . 'FROM response_change_default_to WHERE id = ?', - Bind => [ \$Param{ID} ], - Limit => 1, - ); - - my %ResponseChangeDefaultTo; - while ( my @Data = $Self->{DBObject}->FetchrowArray() ) { - %ResponseChangeDefaultTo = ( - ID => $Data[0], - Title => $Data[1], - RemoveDefault => $Data[2], - AddNew => $Data[3], - NewAddress => $Data[4], - ); - } - - # make sure we have a valid object - return unless %ResponseChangeDefaultTo; - - # get the assigned responses - return if !$Self->{DBObject}->Prepare( - SQL => 'SELECT id, response_id ' - . 'FROM response_change_default_to_response ' - . 'WHERE response_change_default_to_id = ?', - Bind => [ \$ResponseChangeDefaultTo{ID} ], - ); - - while ( my @Data = $Self->{DBObject}->FetchrowArray() ) { - my $Response = - $Self->{StandardTemplateObject}->StandardTemplateLookup( - StandardTemplateID => $Data[1], - ); - - if ( $Response ) { - $ResponseChangeDefaultTo{Responses}->{$Data[0]} = { - ID => $Data[1], - Name => $Response, - }; - } - } - - return %ResponseChangeDefaultTo; -} - -sub Delete { - my ( $Self, %Param ) = @_; - - # check needed stuff - if ( !$Param{ID} ) { - $Self->{LogObject}->Log( - Priority => 'error', - Message => 'Need ID!', - ); - return; - } - - # delete mapping - return if !$Self->{DBObject}->Do( - SQL => 'DELETE FROM response_change_default_to_response ' - . 'WHERE response_change_default_to_id = ?', - Bind => [ \$Param{ID} ], - ); - - # delete entry - return $Self->{DBObject}->Do( - SQL => 'DELETE FROM response_change_default_to WHERE id = ?', - Bind => [ \$Param{ID} ], - ); -} - -sub List { - my ( $Self, %Param ) = @_; - - $Self->{DBObject}->Prepare( - SQL => 'SELECT id, title FROM response_change_default_to', - ); - - my %ResponseChangeDefaultTo; - while ( my @Data = $Self->{DBObject}->FetchrowArray() ) { - $ResponseChangeDefaultTo{ $Data[0] } = $Data[1]; - } - - return %ResponseChangeDefaultTo; -} - -sub MappingAdd { - my ( $Self, %Param ) = @_; - - # check needed stuff - for my $Needed (qw(ResponseID ResponseChangeDefaultToID)) { - if ( !$Param{$Needed} ) { - $Self->{LogObject}->Log( - Priority => 'error', - Message => "Need $Needed!", - ); - return; - } - } - - # insert new mapping - return if !$Self->{DBObject}->Do( - SQL => 'INSERT INTO response_change_default_to_response ' - . '(response_id, response_change_default_to_id) VALUES (?, ?)', - Bind => [ - \$Param{ResponseID}, - \$Param{ResponseChangeDefaultToID}, - ], - ); - - # get new id - return if !$Self->{DBObject}->Prepare( - SQL => 'SELECT MAX(id) FROM response_change_default_to_response ' - . 'WHERE response_id = ? AND response_change_default_to_id = ?', - Bind => [ - \$Param{ResponseID}, - \$Param{ResponseChangeDefaultToID}, ], - Limit => 1, - ); - - my $ID; - while ( my @Row = $Self->{DBObject}->FetchrowArray() ) { - $ID = $Row[0]; - } - - # log notice - $Self->{LogObject}->Log( - Priority => 'notice', - Message => "ResponseChangeDefaultTo mapping '$ID' " - . "created successfully!", - ); - - return $ID; -} - -sub MappingDelete { - my ( $Self, %Param ) = @_; - - # check needed stuff - if ( !$Param{ID} ) { - $Self->{LogObject}->Log( - Priority => 'error', - Message => 'Need ID!', - ); - return; - } - - # delete mapping - return $Self->{DBObject}->Do( - SQL => 'DELETE FROM response_change_default_to_response ' - . 'WHERE id = ?', - Bind => [ \$Param{ID} ], - ); -} - -sub MappingList { - my ( $Self, %Param ) = @_; - - # check needed stuff - if ( !$Param{ResponseID} && !$Param{ResponseChangeDefaultToID} ) { - $Self->{LogObject}->Log( - Priority => 'error', - Message => 'Got no ResponseID or ResponseChangeDefaultToID!' - ); - return; - } - - # find mapped objects - if ( $Param{ResponseID} ) { - $Self->{DBObject}->Prepare( - SQL => 'SELECT id, response_change_default_to_id ' - . 'FROM response_change_default_to_response ' - . 'WHERE response_id = ?', - Bind => [ \$Param{ResponseID}, ], - ); - } - else { - $Self->{DBObject}->Prepare( - SQL => 'SELECT id, response_id ' - . 'FROM response_change_default_to_response ' - . 'WHERE response_change_default_to_id = ?', - Bind => [ \$Param{ResponseChangeDefaultToID}, ], - ); - } - - my %Mapping; - while ( my @Data = $Self->{DBObject}->FetchrowArray() ) { - $Mapping{ $Data[0] } = $Data[1]; - } - - return %Mapping; -} - -1; diff --git a/ResponseChangeDefaultTo.sopm b/ResponseChangeDefaultTo.sopm deleted file mode 100644 index f0fd854..0000000 --- a/ResponseChangeDefaultTo.sopm +++ /dev/null @@ -1,60 +0,0 @@ - - - ResponseChangeDefaultTo - 1.0.0 - 4.0.x - spline.de - http://www.spline.de/ - GNU AFFERO GENERAL PUBLIC LICENSE Version 3, November 2007 - - - ? - ? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3-1-g7c22