From 40a1b4002e1619d9e9112f08ba198dc847f3e0f1 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Sat, 24 Jan 2015 21:41:48 +0100 Subject: Rename to DefaultRecipient. There are only two hard things in Computer Science: cache invalidation and naming things. --- DefaultRecipient.sopm | 67 ++++ DefaultTo.sopm | 67 ---- Kernel/Config/Files/DefaultRecipient.xml | 58 ++++ Kernel/Config/Files/DefaultTo.xml | 58 ---- Kernel/Modules/AdminDefaultRecipient.pm | 359 ++++++++++++++++++++ Kernel/Modules/AdminDefaultRecipientTemplates.pm | 364 +++++++++++++++++++++ Kernel/Modules/AdminDefaultTo.pm | 359 -------------------- Kernel/Modules/AdminDefaultToTemplates.pm | 364 --------------------- Kernel/Output/HTML/DefaultRecipient.pm | 103 ++++++ Kernel/Output/HTML/DefaultTo.pm | 103 ------ .../Output/HTML/Standard/AdminDefaultRecipient.tt | 194 +++++++++++ .../Standard/AdminDefaultRecipientTemplates.tt | 172 ++++++++++ Kernel/Output/HTML/Standard/AdminDefaultTo.tt | 194 ----------- .../HTML/Standard/AdminDefaultToTemplates.tt | 172 ---------- Kernel/System/DefaultRecipient.pm | 351 ++++++++++++++++++++ Kernel/System/DefaultTo.pm | 351 -------------------- 16 files changed, 1668 insertions(+), 1668 deletions(-) create mode 100644 DefaultRecipient.sopm delete mode 100644 DefaultTo.sopm create mode 100644 Kernel/Config/Files/DefaultRecipient.xml delete mode 100644 Kernel/Config/Files/DefaultTo.xml create mode 100644 Kernel/Modules/AdminDefaultRecipient.pm create mode 100644 Kernel/Modules/AdminDefaultRecipientTemplates.pm delete mode 100644 Kernel/Modules/AdminDefaultTo.pm delete mode 100644 Kernel/Modules/AdminDefaultToTemplates.pm create mode 100644 Kernel/Output/HTML/DefaultRecipient.pm delete mode 100644 Kernel/Output/HTML/DefaultTo.pm create mode 100644 Kernel/Output/HTML/Standard/AdminDefaultRecipient.tt create mode 100644 Kernel/Output/HTML/Standard/AdminDefaultRecipientTemplates.tt delete mode 100644 Kernel/Output/HTML/Standard/AdminDefaultTo.tt delete mode 100644 Kernel/Output/HTML/Standard/AdminDefaultToTemplates.tt create mode 100644 Kernel/System/DefaultRecipient.pm delete mode 100644 Kernel/System/DefaultTo.pm diff --git a/DefaultRecipient.sopm b/DefaultRecipient.sopm new file mode 100644 index 0000000..166ec8f --- /dev/null +++ b/DefaultRecipient.sopm @@ -0,0 +1,67 @@ + + + DefaultRecipient + 1.0.0 + 4.0.x + spline.de + http://www.spline.de/ + GNU AFFERO GENERAL PUBLIC LICENSE Version 3, November 2007 + + + ? + ? + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DefaultTo.sopm b/DefaultTo.sopm deleted file mode 100644 index 1cad73b..0000000 --- a/DefaultTo.sopm +++ /dev/null @@ -1,67 +0,0 @@ - - - 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/DefaultRecipient.xml b/Kernel/Config/Files/DefaultRecipient.xml new file mode 100644 index 0000000..de680e1 --- /dev/null +++ b/Kernel/Config/Files/DefaultRecipient.xml @@ -0,0 +1,58 @@ + + + + Change the default To address, based on the response template. + Ticket + Frontend::Agent::Ticket::ViewCompose + + + Kernel::Output::HTML::DefaultRecipient + + + 1 + + + + + + + Frontend module registration for the agent interface. + Ticket + Frontend::Admin::ModuleRegistration + + + admin + Admin + DefaultRecipient + Admin + + Kernel::Output::HTML::NavBarModuleAdmin + DefaultRecipient + Create and manage DefaultRecipients. + Queue + 300 + + + + + + Frontend module registration for the agent interface. + Ticket + Frontend::Admin::ModuleRegistration + + + admin + Admin + Templates <-> DefaultRecipient + Admin + + Kernel::Output::HTML::NavBarModuleAdmin + Templates <-> DefaultRecipient + Link templates to DefaultRecipients. + Queue + 300 + + + + + diff --git a/Kernel/Config/Files/DefaultTo.xml b/Kernel/Config/Files/DefaultTo.xml deleted file mode 100644 index 2a075a5..0000000 --- a/Kernel/Config/Files/DefaultTo.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - 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 - DefaultTo - Admin - - Kernel::Output::HTML::NavBarModuleAdmin - DefaultTo - Create and manage DefaultTo entries. - Queue - 300 - - - - - - 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/Modules/AdminDefaultRecipient.pm b/Kernel/Modules/AdminDefaultRecipient.pm new file mode 100644 index 0000000..29097b3 --- /dev/null +++ b/Kernel/Modules/AdminDefaultRecipient.pm @@ -0,0 +1,359 @@ +# -- +# Kernel/Modules/AdminDefaultRecipient.pm - provides admin DefaultRecipient 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::Modules::AdminDefaultRecipient; + +use strict; +use warnings; + +our @ObjectDependencies = qw( + Kernel::Config + Kernel::Output::HTML::Layout + Kernel::System::DB + Kernel::System::Web::Request + Kernel::System::DefaultRecipient +); + +sub new { + my ( $Type, %Param ) = @_; + + # allocate new hash for object + my $Self = {%Param}; + bless( $Self, $Type ); + + # check all needed objects + for my $Needed (qw(ParamObject DBObject LayoutObject ConfigObject)) { + if ( !$Self->{$Needed} ) { + $Self->{LayoutObject}->FatalError( Message => "Got no $Needed!" ); + } + } + + return $Self; +} + +sub Run { + my ( $Self, %Param ) = @_; + + # ------------------------------------------------------------ # + # change + # ------------------------------------------------------------ # + if ( $Self->{Subaction} eq 'Change' ) { + my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ) || ''; + my $DefaultRecipientObject = $Kernel::OM->Get('Kernel::System::DefaultRecipient'); + my %Data = $DefaultRecipientObject->Get( + ID => $ID, + ); + + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Self->_Edit( + Action => 'Change', + %Data, + ); + $Output .= $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultRecipient', + Data => \%Param, + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + + # ------------------------------------------------------------ # + # change action + # ------------------------------------------------------------ # + elsif ( $Self->{Subaction} eq 'ChangeAction' ) { + # challenge token check for write action + $Self->{LayoutObject}->ChallengeTokenCheck(); + + my $DefaultRecipientObject = $Kernel::OM->Get('Kernel::System::DefaultRecipient'); + my @NewIDs = $Self->{ParamObject}->GetArray( Param => 'IDs' ); + my ( %GetParam, %Errors ); + for my $Parameter (qw(ID Title RemoveDefault AddNew NewAddress + Comment)) { + $GetParam{$Parameter} = $Self->{ParamObject}->GetParam( + Param => $Parameter + ); + } + + # check needed data + $Errors{TitleInvalid} = 'ServerError' if !$GetParam{Title}; + + # check if a DefaultRecipient entry exist with this title + my $TitleExists = $DefaultRecipientObject->TitleExistsCheck( + Title => $GetParam{Title}, + ID => $GetParam{ID} + ); + + if ($TitleExists) { + $Errors{TitleExists} = 1; + $Errors{TitleInvalid} = 'ServerError'; + } + + # if no errors occurred + if ( !%Errors ) { + + if ( $DefaultRecipientObject->Update( + %GetParam, + UserID => $Self->{UserID}, + ) + ) + { + $Self->_Overview(); + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->{LayoutObject}->Notify( Info => 'Template updated!' ); + $Output .= $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultRecipient', + Data => \%Param, + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + } + + # something has gone wrong + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->{LayoutObject}->Notify( Priority => 'Error' ); + $Self->_Edit( + Action => 'Change', + Errors => \%Errors, + %GetParam, + ); + $Output .= $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultRecipient', + Data => \%Param, + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + + # ------------------------------------------------------------ # + # add + # ------------------------------------------------------------ # + elsif ( $Self->{Subaction} eq 'Add' ) { + my $Title = $Self->{ParamObject}->GetParam( Param => 'Title' ); + + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Self->_Edit( + Action => 'Add', + Title => $Title, + ); + $Output .= $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultRecipient', + Data => \%Param, + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + + # ------------------------------------------------------------ # + # add action + # ------------------------------------------------------------ # + elsif ( $Self->{Subaction} eq 'AddAction' ) { + # challenge token check for write action + $Self->{LayoutObject}->ChallengeTokenCheck(); + + my $DefaultRecipientObject = $Kernel::OM->Get('Kernel::System::DefaultRecipient'); + my @NewIDs = $Self->{ParamObject}->GetArray( Param => 'IDs' ); + my ( %GetParam, %Errors ); + + for my $Parameter (qw(ID Title RemoveDefault AddNew NewAddress + Comment)) { + $GetParam{$Parameter} = $Self->{ParamObject}->GetParam( Param => $Parameter ); + } + + # check needed data + $Errors{TitleInvalid} = 'ServerError' if !$GetParam{Title}; + + # check if a DefaultRecipient entry exists with this title + my $TitleExists = $DefaultRecipientObject->TitleExistsCheck( Title => $GetParam{Title} ); + if ($TitleExists) { + $Errors{TitleExists} = 1; + $Errors{TitleInvalid} = 'ServerError'; + } + + # if no errors occurred + if ( !%Errors ) { + + # add DefaultRecipient entry + my $ID = $DefaultRecipientObject->Add( + %GetParam, + UserID => $Self->{UserID}, + ); + + if ($ID) { + $Self->_Overview(); + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->{LayoutObject}->Notify( Info => 'Template added!' ); + $Output .= $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultRecipient', + Data => \%Param, + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + } + + # something has gone wrong + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->{LayoutObject}->Notify( Priority => 'Error' ); + $Self->_Edit( + Action => 'Add', + Errors => \%Errors, + %GetParam, + ); + $Output .= $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultRecipient', + Data => \%Param, + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + + # ------------------------------------------------------------ # + # delete action + # ------------------------------------------------------------ # + elsif ( $Self->{Subaction} eq 'Delete' ) { + # challenge token check for write action + $Self->{LayoutObject}->ChallengeTokenCheck(); + + my $DefaultRecipientObject = $Kernel::OM->Get('Kernel::System::DefaultRecipient'); + my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); + + my $Delete = $DefaultRecipientObject->Delete( + ID => $ID, + ); + if ( !$Delete ) { + return $Self->{LayoutObject}->ErrorScreen(); + } + + return $Self->{LayoutObject}->Redirect( OP => "Action=$Self->{Action}" ); + } + + # ------------------------------------------------------------ + # overview + # ------------------------------------------------------------ + else { + $Self->_Overview(); + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultRecipient', + Data => \%Param, + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } +} + +sub _Edit { + my ( $Self, %Param ) = @_; + $Param{Errors} = {} unless defined $Param{Errors}; + + $Self->{LayoutObject}->Block( + Name => 'Overview', + Data => \%Param, + ); + + $Self->{LayoutObject}->Block( Name => 'ActionList' ); + $Self->{LayoutObject}->Block( Name => 'ActionOverview' ); + + $Param{DefaultRecipientTitleString} = ''; + + $Param{DefaultRecipientRemoveDefaultOption} = $Self->{LayoutObject}->BuildSelection( + Data => $Self->{ConfigObject}->Get('YesNoOptions'), + Name => 'RemoveDefault', + SelectedID => $Param{RemoveDefault} || 0, + ); + + $Param{DefaultRecipientAddNewOption} = $Self->{LayoutObject}->BuildSelection( + Data => $Self->{ConfigObject}->Get('YesNoOptions'), + Name => 'AddNew', + SelectedID => $Param{AddNew} || 0, + ); + + $Param{DefaultRecipientNewAddressString} = ''; + + $Self->{LayoutObject}->Block( + Name => 'OverviewUpdate', + Data => { + %Param, + %{ $Param{Errors} }, + }, + ); + + # shows header + if ( $Param{Action} eq 'Change' ) { + $Self->{LayoutObject}->Block( Name => 'HeaderEdit' ); + } + else { + $Self->{LayoutObject}->Block( Name => 'HeaderAdd' ); + } + + # show appropriate messages for ServerError + if ( defined $Param{Errors}->{TitleExists} && $Param{Errors}->{TitleExists} == 1 ) { + $Self->{LayoutObject}->Block( Name => 'ExistTitleServerError' ); + } + else { + $Self->{LayoutObject}->Block( Name => 'TitleServerError' ); + } + + return 1; +} + +sub _Overview { + my ( $Self, %Param ) = @_; + + $Self->{LayoutObject}->Block( + Name => 'Overview', + Data => \%Param, + ); + + $Self->{LayoutObject}->Block( Name => 'ActionList' ); + $Self->{LayoutObject}->Block( Name => 'ActionAdd' ); + $Self->{LayoutObject}->Block( Name => 'Filter' ); + + $Self->{LayoutObject}->Block( + Name => 'OverviewResult', + Data => \%Param, + ); + + my $DefaultRecipientObject = $Kernel::OM->Get('Kernel::System::DefaultRecipient'); + my %List = $DefaultRecipientObject->List(); + + for my $ID ( sort { $List{$a} cmp $List{$b} } keys %List ) + { + my %DefaultRecipient = $DefaultRecipientObject->Get( + ID => $ID, + ); + + $Self->{LayoutObject}->Block( + Name => 'OverviewResultRow', + Data => { + %DefaultRecipient, + }, + ); + } + + # otherwise it displays a no data found message + if ( ! %List ) { + $Self->{LayoutObject}->Block( + Name => 'NoDataFoundMsg', + Data => {}, + ); + } + + return 1; +} + +1; diff --git a/Kernel/Modules/AdminDefaultRecipientTemplates.pm b/Kernel/Modules/AdminDefaultRecipientTemplates.pm new file mode 100644 index 0000000..b83f30f --- /dev/null +++ b/Kernel/Modules/AdminDefaultRecipientTemplates.pm @@ -0,0 +1,364 @@ +# -- +# Kernel/Modules/AdminDefaultRecipientTemplates.pm - to manage DefaultRecipient <-> 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::AdminDefaultRecipientTemplates; + +use strict; +use warnings; + +our @ObjectDependencies = qw( + Kernel::Output::HTML::Layout + Kernel::System::DB + Kernel::System::DefaultRecipient + Kernel::System::StandardTemplate + Kernel::System::Web::Request +); + +sub new { + my ( $Type, %Param ) = @_; + + # allocate new hash for object + my $Self = {%Param}; + bless( $Self, $Type ); + + # check all needed objects + for (qw(ParamObject DBObject LayoutObject)) { + if ( !$Self->{$_} ) { + $Self->{LayoutObject}->FatalError( Message => "Got no $_!" ); + } + } + + return $Self; +} + +sub Run { + my ( $Self, %Param ) = @_; + + # ------------------------------------------------------------ # + # template <-> DefaultRecipient 1:n + # ------------------------------------------------------------ # + if ( $Self->{Subaction} eq 'Template' ) { + + # get template data + my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); + my $StandardTemplateObject = $Kernel::OM->Get('Kernel::System::StandardTemplate'); + my %StandardTemplateData = $StandardTemplateObject->StandardTemplateGet( ID => $ID ); + my $StandardTemplateType = $Self->{LayoutObject}->{LanguageObject}->Translate( + $StandardTemplateData{TemplateType}, + ); + my $Name = $StandardTemplateType . ' - ' . $StandardTemplateData{Name}; + + # get DefaultRecipient data + my $DefaultRecipientObject = $Kernel::OM->Get('Kernel::System::DefaultRecipient'); + my %DefaultRecipientData = $DefaultRecipientObject->List(); + my %Member = $DefaultRecipientObject->MappingList( + TemplateID => $ID, + ); + + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->_Change( + Data => \%DefaultRecipientData, + ID => $ID, + Name => $Name, + Mapping => \%Member, + Type => 'Template', + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + + # ------------------------------------------------------------ # + # templates <-> DefaultRecipient n:1 + # ------------------------------------------------------------ # + elsif ( $Self->{Subaction} eq 'DefaultRecipient' ) { + + my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); + my $DefaultRecipientObject = $Kernel::OM->Get('Kernel::System::DefaultRecipient'); + my %DefaultRecipientData = $DefaultRecipientObject->Get( ID => $ID ); + + # get templates + my $StandardTemplateObject = $Kernel::OM->Get('Kernel::System::StandardTemplate'); + my %StandardTemplateData = $StandardTemplateObject->StandardTemplateList( + Valid => 1, + ); + + if (%StandardTemplateData) { + for my $StandardTemplateID ( sort keys %StandardTemplateData ) { + my %Data = $StandardTemplateObject->StandardTemplateGet( + ID => $StandardTemplateID + ); + $StandardTemplateData{$StandardTemplateID} + = $Self->{LayoutObject}->{LanguageObject}->Translate( $Data{TemplateType} ) + . ' - ' + . $Data{Name}; + } + } + + # get assigned templates + my %Member = $DefaultRecipientObject->MappingList( + DefaultRecipientID => $ID, + ); + + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->_Change( + Data => \%StandardTemplateData, + ID => $ID, + Name => $DefaultRecipientData{Title}, + Mapping => \%Member, + Type => 'DefaultRecipient', + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + + # ------------------------------------------------------------ # + # add templates to DefaultRecipient + # ------------------------------------------------------------ # + elsif ( $Self->{Subaction} eq 'ChangeDefaultRecipient' ) { + + # challenge token check for write action + $Self->{LayoutObject}->ChallengeTokenCheck(); + + # get current mapping + my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); + my $DefaultRecipientObject = $Kernel::OM->Get('Kernel::System::DefaultRecipient'); + my %Mapping = $DefaultRecipientObject->MappingList( + DefaultRecipientID => $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} ) { + $DefaultRecipientObject->MappingAdd( + TemplateID => $TemplateID, + DefaultRecipientID => $ID, + ); + } + } + else { + if ( $Mapping{$TemplateID} ) { + $DefaultRecipientObject->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 $DefaultRecipientObject = $Kernel::OM->Get('Kernel::System::DefaultRecipient'); + my %Mapping = $DefaultRecipientObject->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 $DefaultRecipientID (@All) { + if ( $Selected{$DefaultRecipientID} ) { + if ( ! $Mapping{$DefaultRecipientID} ) { + $DefaultRecipientObject->MappingAdd( + TemplateID => $ID, + DefaultRecipientID => $DefaultRecipientID, + ); + } + } + else { + if ( $Mapping{$DefaultRecipientID} ) { + $DefaultRecipientObject->MappingDelete( + ID => $Mapping{$DefaultRecipientID}, + ); + } + } + } + + 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 = 'DefaultRecipient'; + $NeType = 'Template' if $Type eq 'DefaultRecipient'; + + $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 => 'AdminDefaultRecipientTemplates', + 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 => 'FilterDefaultRecipient' ); + $Self->{LayoutObject}->Block( Name => 'OverviewResult' ); + + # get std template list + my $StandardTemplateObject = $Kernel::OM->Get('Kernel::System::StandardTemplate'); + my %StandardTemplateData = $StandardTemplateObject->StandardTemplateList( + Valid => 1, + ); + + # if there are results to show + if (%StandardTemplateData) { + for my $StandardTemplateID ( sort keys %StandardTemplateData ) { + my %Data = $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 $DefaultRecipientObject = $Kernel::OM->Get('Kernel::System::DefaultRecipient'); + my %DefaultRecipientData = $DefaultRecipientObject->List(); + + # if there are results to show + if (%DefaultRecipientData) { + for my $ID ( + sort { uc( $DefaultRecipientData{$a} ) cmp uc( $DefaultRecipientData{$b} ) } + keys %DefaultRecipientData + ) + { + + # set output class + $Self->{LayoutObject}->Block( + Name => 'Listn1', + Data => { + Name => $DefaultRecipientData{$ID}, + Subaction => 'DefaultRecipient', + ID => $ID, + }, + ); + } + } + + # otherwise it displays a no data found message + else { + $Self->{LayoutObject}->Block( + Name => 'NoDefaultRecipientFoundMsg', + Data => {}, + ); + } + + # return output + return $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultRecipientTemplates', + Data => \%Param, + ); +} + +1; diff --git a/Kernel/Modules/AdminDefaultTo.pm b/Kernel/Modules/AdminDefaultTo.pm deleted file mode 100644 index e6951e8..0000000 --- a/Kernel/Modules/AdminDefaultTo.pm +++ /dev/null @@ -1,359 +0,0 @@ -# -- -# Kernel/Modules/AdminDefaultTo.pm - provides admin DefaultTo 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::Modules::AdminDefaultTo; - -use strict; -use warnings; - -our @ObjectDependencies = qw( - Kernel::Config - Kernel::Output::HTML::Layout - Kernel::System::DB - Kernel::System::Web::Request - Kernel::System::DefaultTo -); - -sub new { - my ( $Type, %Param ) = @_; - - # allocate new hash for object - my $Self = {%Param}; - bless( $Self, $Type ); - - # check all needed objects - for my $Needed (qw(ParamObject DBObject LayoutObject ConfigObject)) { - if ( !$Self->{$Needed} ) { - $Self->{LayoutObject}->FatalError( Message => "Got no $Needed!" ); - } - } - - return $Self; -} - -sub Run { - my ( $Self, %Param ) = @_; - - # ------------------------------------------------------------ # - # change - # ------------------------------------------------------------ # - if ( $Self->{Subaction} eq 'Change' ) { - my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ) || ''; - my $DefaultToObject = $Kernel::OM->Get('Kernel::System::DefaultTo'); - my %Data = $DefaultToObject->Get( - ID => $ID, - ); - - my $Output = $Self->{LayoutObject}->Header(); - $Output .= $Self->{LayoutObject}->NavigationBar(); - $Self->_Edit( - Action => 'Change', - %Data, - ); - $Output .= $Self->{LayoutObject}->Output( - TemplateFile => 'AdminDefaultTo', - Data => \%Param, - ); - $Output .= $Self->{LayoutObject}->Footer(); - return $Output; - } - - # ------------------------------------------------------------ # - # change action - # ------------------------------------------------------------ # - elsif ( $Self->{Subaction} eq 'ChangeAction' ) { - # challenge token check for write action - $Self->{LayoutObject}->ChallengeTokenCheck(); - - my $DefaultToObject = $Kernel::OM->Get('Kernel::System::DefaultTo'); - my @NewIDs = $Self->{ParamObject}->GetArray( Param => 'IDs' ); - my ( %GetParam, %Errors ); - for my $Parameter (qw(ID Title RemoveDefault AddNew NewAddress - Comment)) { - $GetParam{$Parameter} = $Self->{ParamObject}->GetParam( - Param => $Parameter - ); - } - - # check needed data - $Errors{TitleInvalid} = 'ServerError' if !$GetParam{Title}; - - # check if a DefaultTo entry exist with this title - my $TitleExists = $DefaultToObject->TitleExistsCheck( - Title => $GetParam{Title}, - ID => $GetParam{ID} - ); - - if ($TitleExists) { - $Errors{TitleExists} = 1; - $Errors{TitleInvalid} = 'ServerError'; - } - - # if no errors occurred - if ( !%Errors ) { - - if ( $DefaultToObject->Update( - %GetParam, - UserID => $Self->{UserID}, - ) - ) - { - $Self->_Overview(); - my $Output = $Self->{LayoutObject}->Header(); - $Output .= $Self->{LayoutObject}->NavigationBar(); - $Output .= $Self->{LayoutObject}->Notify( Info => 'Template updated!' ); - $Output .= $Self->{LayoutObject}->Output( - TemplateFile => 'AdminDefaultTo', - Data => \%Param, - ); - $Output .= $Self->{LayoutObject}->Footer(); - return $Output; - } - } - - # something has gone wrong - my $Output = $Self->{LayoutObject}->Header(); - $Output .= $Self->{LayoutObject}->NavigationBar(); - $Output .= $Self->{LayoutObject}->Notify( Priority => 'Error' ); - $Self->_Edit( - Action => 'Change', - Errors => \%Errors, - %GetParam, - ); - $Output .= $Self->{LayoutObject}->Output( - TemplateFile => 'AdminDefaultTo', - Data => \%Param, - ); - $Output .= $Self->{LayoutObject}->Footer(); - return $Output; - } - - # ------------------------------------------------------------ # - # add - # ------------------------------------------------------------ # - elsif ( $Self->{Subaction} eq 'Add' ) { - my $Title = $Self->{ParamObject}->GetParam( Param => 'Title' ); - - my $Output = $Self->{LayoutObject}->Header(); - $Output .= $Self->{LayoutObject}->NavigationBar(); - $Self->_Edit( - Action => 'Add', - Title => $Title, - ); - $Output .= $Self->{LayoutObject}->Output( - TemplateFile => 'AdminDefaultTo', - Data => \%Param, - ); - $Output .= $Self->{LayoutObject}->Footer(); - return $Output; - } - - # ------------------------------------------------------------ # - # add action - # ------------------------------------------------------------ # - elsif ( $Self->{Subaction} eq 'AddAction' ) { - # challenge token check for write action - $Self->{LayoutObject}->ChallengeTokenCheck(); - - my $DefaultToObject = $Kernel::OM->Get('Kernel::System::DefaultTo'); - my @NewIDs = $Self->{ParamObject}->GetArray( Param => 'IDs' ); - my ( %GetParam, %Errors ); - - for my $Parameter (qw(ID Title RemoveDefault AddNew NewAddress - Comment)) { - $GetParam{$Parameter} = $Self->{ParamObject}->GetParam( Param => $Parameter ); - } - - # check needed data - $Errors{TitleInvalid} = 'ServerError' if !$GetParam{Title}; - - # check if a DefaultTo entry exists with this title - my $TitleExists = $DefaultToObject->TitleExistsCheck( Title => $GetParam{Title} ); - if ($TitleExists) { - $Errors{TitleExists} = 1; - $Errors{TitleInvalid} = 'ServerError'; - } - - # if no errors occurred - if ( !%Errors ) { - - # add DefaultTo entry - my $ID = $DefaultToObject->Add( - %GetParam, - UserID => $Self->{UserID}, - ); - - if ($ID) { - $Self->_Overview(); - my $Output = $Self->{LayoutObject}->Header(); - $Output .= $Self->{LayoutObject}->NavigationBar(); - $Output .= $Self->{LayoutObject}->Notify( Info => 'Template added!' ); - $Output .= $Self->{LayoutObject}->Output( - TemplateFile => 'AdminDefaultTo', - Data => \%Param, - ); - $Output .= $Self->{LayoutObject}->Footer(); - return $Output; - } - } - - # something has gone wrong - my $Output = $Self->{LayoutObject}->Header(); - $Output .= $Self->{LayoutObject}->NavigationBar(); - $Output .= $Self->{LayoutObject}->Notify( Priority => 'Error' ); - $Self->_Edit( - Action => 'Add', - Errors => \%Errors, - %GetParam, - ); - $Output .= $Self->{LayoutObject}->Output( - TemplateFile => 'AdminDefaultTo', - Data => \%Param, - ); - $Output .= $Self->{LayoutObject}->Footer(); - return $Output; - } - - # ------------------------------------------------------------ # - # delete action - # ------------------------------------------------------------ # - elsif ( $Self->{Subaction} eq 'Delete' ) { - # challenge token check for write action - $Self->{LayoutObject}->ChallengeTokenCheck(); - - my $DefaultToObject = $Kernel::OM->Get('Kernel::System::DefaultTo'); - my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); - - my $Delete = $DefaultToObject->Delete( - ID => $ID, - ); - if ( !$Delete ) { - return $Self->{LayoutObject}->ErrorScreen(); - } - - return $Self->{LayoutObject}->Redirect( OP => "Action=$Self->{Action}" ); - } - - # ------------------------------------------------------------ - # overview - # ------------------------------------------------------------ - else { - $Self->_Overview(); - my $Output = $Self->{LayoutObject}->Header(); - $Output .= $Self->{LayoutObject}->NavigationBar(); - $Output .= $Self->{LayoutObject}->Output( - TemplateFile => 'AdminDefaultTo', - Data => \%Param, - ); - $Output .= $Self->{LayoutObject}->Footer(); - return $Output; - } -} - -sub _Edit { - my ( $Self, %Param ) = @_; - $Param{Errors} = {} unless defined $Param{Errors}; - - $Self->{LayoutObject}->Block( - Name => 'Overview', - Data => \%Param, - ); - - $Self->{LayoutObject}->Block( Name => 'ActionList' ); - $Self->{LayoutObject}->Block( Name => 'ActionOverview' ); - - $Param{DefaultToTitleString} = ''; - - $Param{DefaultToRemoveDefaultOption} = $Self->{LayoutObject}->BuildSelection( - Data => $Self->{ConfigObject}->Get('YesNoOptions'), - Name => 'RemoveDefault', - SelectedID => $Param{RemoveDefault} || 0, - ); - - $Param{DefaultToAddNewOption} = $Self->{LayoutObject}->BuildSelection( - Data => $Self->{ConfigObject}->Get('YesNoOptions'), - Name => 'AddNew', - SelectedID => $Param{AddNew} || 0, - ); - - $Param{DefaultToNewAddressString} = ''; - - $Self->{LayoutObject}->Block( - Name => 'OverviewUpdate', - Data => { - %Param, - %{ $Param{Errors} }, - }, - ); - - # shows header - if ( $Param{Action} eq 'Change' ) { - $Self->{LayoutObject}->Block( Name => 'HeaderEdit' ); - } - else { - $Self->{LayoutObject}->Block( Name => 'HeaderAdd' ); - } - - # show appropriate messages for ServerError - if ( defined $Param{Errors}->{TitleExists} && $Param{Errors}->{TitleExists} == 1 ) { - $Self->{LayoutObject}->Block( Name => 'ExistTitleServerError' ); - } - else { - $Self->{LayoutObject}->Block( Name => 'TitleServerError' ); - } - - return 1; -} - -sub _Overview { - my ( $Self, %Param ) = @_; - - $Self->{LayoutObject}->Block( - Name => 'Overview', - Data => \%Param, - ); - - $Self->{LayoutObject}->Block( Name => 'ActionList' ); - $Self->{LayoutObject}->Block( Name => 'ActionAdd' ); - $Self->{LayoutObject}->Block( Name => 'Filter' ); - - $Self->{LayoutObject}->Block( - Name => 'OverviewResult', - Data => \%Param, - ); - - my $DefaultToObject = $Kernel::OM->Get('Kernel::System::DefaultTo'); - my %List = $DefaultToObject->List(); - - for my $ID ( sort { $List{$a} cmp $List{$b} } keys %List ) - { - my %DefaultTo = $DefaultToObject->Get( - ID => $ID, - ); - - $Self->{LayoutObject}->Block( - Name => 'OverviewResultRow', - Data => { - %DefaultTo, - }, - ); - } - - # otherwise it displays a no data found message - if ( ! %List ) { - $Self->{LayoutObject}->Block( - Name => 'NoDataFoundMsg', - Data => {}, - ); - } - - return 1; -} - -1; diff --git a/Kernel/Modules/AdminDefaultToTemplates.pm b/Kernel/Modules/AdminDefaultToTemplates.pm deleted file mode 100644 index af49b00..0000000 --- a/Kernel/Modules/AdminDefaultToTemplates.pm +++ /dev/null @@ -1,364 +0,0 @@ -# -- -# 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; - -our @ObjectDependencies = qw( - Kernel::Output::HTML::Layout - Kernel::System::DB - Kernel::System::DefaultTo - Kernel::System::StandardTemplate - Kernel::System::Web::Request -); - -sub new { - my ( $Type, %Param ) = @_; - - # allocate new hash for object - my $Self = {%Param}; - bless( $Self, $Type ); - - # check all needed objects - for (qw(ParamObject DBObject LayoutObject)) { - if ( !$Self->{$_} ) { - $Self->{LayoutObject}->FatalError( Message => "Got no $_!" ); - } - } - - 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 $StandardTemplateObject = $Kernel::OM->Get('Kernel::System::StandardTemplate'); - my %StandardTemplateData = $StandardTemplateObject->StandardTemplateGet( ID => $ID ); - my $StandardTemplateType = $Self->{LayoutObject}->{LanguageObject}->Translate( - $StandardTemplateData{TemplateType}, - ); - my $Name = $StandardTemplateType . ' - ' . $StandardTemplateData{Name}; - - # get DefaultTo data - my $DefaultToObject = $Kernel::OM->Get('Kernel::System::DefaultTo'); - my %DefaultToData = $DefaultToObject->List(); - my %Member = $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 $DefaultToObject = $Kernel::OM->Get('Kernel::System::DefaultTo'); - my %DefaultToData = $DefaultToObject->Get( ID => $ID ); - - # get templates - my $StandardTemplateObject = $Kernel::OM->Get('Kernel::System::StandardTemplate'); - my %StandardTemplateData = $StandardTemplateObject->StandardTemplateList( - Valid => 1, - ); - - if (%StandardTemplateData) { - for my $StandardTemplateID ( sort keys %StandardTemplateData ) { - my %Data = $StandardTemplateObject->StandardTemplateGet( - ID => $StandardTemplateID - ); - $StandardTemplateData{$StandardTemplateID} - = $Self->{LayoutObject}->{LanguageObject}->Translate( $Data{TemplateType} ) - . ' - ' - . $Data{Name}; - } - } - - # get assigned templates - my %Member = $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 $DefaultToObject = $Kernel::OM->Get('Kernel::System::DefaultTo'); - my %Mapping = $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} ) { - $DefaultToObject->MappingAdd( - TemplateID => $TemplateID, - DefaultToID => $ID, - ); - } - } - else { - if ( $Mapping{$TemplateID} ) { - $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 $DefaultToObject = $Kernel::OM->Get('Kernel::System::DefaultTo'); - my %Mapping = $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} ) { - $DefaultToObject->MappingAdd( - TemplateID => $ID, - DefaultToID => $DefaultToID, - ); - } - } - else { - if ( $Mapping{$DefaultToID} ) { - $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 $StandardTemplateObject = $Kernel::OM->Get('Kernel::System::StandardTemplate'); - my %StandardTemplateData = $StandardTemplateObject->StandardTemplateList( - Valid => 1, - ); - - # if there are results to show - if (%StandardTemplateData) { - for my $StandardTemplateID ( sort keys %StandardTemplateData ) { - my %Data = $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 $DefaultToObject = $Kernel::OM->Get('Kernel::System::DefaultTo'); - my %DefaultToData = $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/Output/HTML/DefaultRecipient.pm b/Kernel/Output/HTML/DefaultRecipient.pm new file mode 100644 index 0000000..5d94c4a --- /dev/null +++ b/Kernel/Output/HTML/DefaultRecipient.pm @@ -0,0 +1,103 @@ +# -- +# Kernel/Output/HTML/DefaultRecipient.pm +# Copyright (C) 2015 Alexander Sulfrian +# -- + +package Kernel::Output::HTML::DefaultRecipient; + +use strict; +use warnings; + +our @ObjectDependencies = qw( + Kernel::System::Log + Kernel::System::DefaultRecipient +); + +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->{DefaultRecipientObject} = $Kernel::OM->Get('Kernel::System::DefaultRecipient'); + bless( $Self, $Type ); + + return $Self; +} + +sub Run { + my ( $Self, %Param ) = @_; + return if !$Self->{LayoutObject}; + + for (qw(LogObject LayoutObject DefaultRecipientObject)) { + 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 DefaultRecipient + my %MappedDefaultRecipient = $Self->{DefaultRecipientObject}->MappingList( + TemplateID => $Ticket->{TemplateID}, + ); + + my $RemoveDefault = 0; + my @Addresses = (); + foreach my $ID ( values %MappedDefaultRecipient ) { + my %DefaultRecipient = $Self->{DefaultRecipientObject}->Get( + ID => $ID, + ); + + $RemoveDefault = 1 if $DefaultRecipient{RemoveDefault}; + if ( $DefaultRecipient{AddNew} ) { + push @Addresses, $DefaultRecipient{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/DefaultTo.pm b/Kernel/Output/HTML/DefaultTo.pm deleted file mode 100644 index 1d09b40..0000000 --- a/Kernel/Output/HTML/DefaultTo.pm +++ /dev/null @@ -1,103 +0,0 @@ -# -- -# 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/Standard/AdminDefaultRecipient.tt b/Kernel/Output/HTML/Standard/AdminDefaultRecipient.tt new file mode 100644 index 0000000..613a243 --- /dev/null +++ b/Kernel/Output/HTML/Standard/AdminDefaultRecipient.tt @@ -0,0 +1,194 @@ +# -- +# AdminDefaultRecipient.tt - provides HTML form for AdminDefaultRecipient +# 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 DefaultRecipient") | html %]

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

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

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

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

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

+
+
+ +

+ [% Translate("With DefaultRecipient you could change or extend the default To address in a ticket response dependent on the used template.") | html %] +

+

+ [% Translate("Attention") | html %]: + [% Translate("Don't forget to add new DefaultRecipients to templates.") | html %] +

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

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

+
+
+ + + + + + + + + + + + + + + + + +[% RenderBlockStart("NoDataFoundMsg") %] + + + +[% RenderBlockEnd("NoDataFoundMsg") %] +[% RenderBlockStart("OverviewResultRow") %] + + + + + + + + + + +[% RenderBlockEnd("OverviewResultRow") %] + +
[% Translate("Title") | html %][% Translate("Remove default") | html %][% Translate("Add new") | html %][% Translate("New address") | html %][% Translate("Comment") | html %][% Translate("Changed") | html %][% Translate("Created") | html %][% Translate("Delete") | html %]
+ [% Translate("No data found.") | html %] +
+ [% Data.Title | html %] + [% Translate(Data.RemoveDefault) | html %][% Translate(Data.AddNew) | html %][% Data.NewAddress | html %][% Data.Comment | truncate(26) | html %][% Data.ChangeTime | Localize("TimeShort") %][% Data.CreateTime | Localize("TimeShort") %] + + [% Translate("Delete this entry") | html %] + + +
+
+
+[% WRAPPER JSOnDocumentComplete %] + +[% END %] +[% RenderBlockEnd("OverviewResult") %] +[% RenderBlockStart("OverviewUpdate") %] + +
+
+[% RenderBlockStart("HeaderAdd") %] +

[% Translate("Add DefaultRecipient") | html %]

+[% RenderBlockEnd("HeaderAdd") %] +[% RenderBlockStart("HeaderEdit") %] +

[% Translate("Edit DefaultRecipient") | html %]

+[% RenderBlockEnd("HeaderEdit") %] +
+
+
+ + + +
+ +
+ +
+

[% Translate("This field is required.") | html %]

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

[% Translate("This field is required.") | html %]

+[% RenderBlockEnd("TitleServerError") %] +[% RenderBlockStart("ExistTitleServerError") %] +

[% Translate("A DefaultRecipient entry with this title already exists!") | html %]

+[% RenderBlockEnd("TitleServerError") %] +
+
+
+ + +
+ [% Data.DefaultRecipientRemoveDefaultOption %] +
+
+ + +
+ [% Data.DefaultRecipientAddNewOption %] +
+
+ + +
+ +
+
+ + +
+ +
+
+ +
+ + [% Translate("or") | html %] + [% Translate("Cancel") | html %] +
+
+
+
+
+
+[% RenderBlockEnd("OverviewUpdate") %] +
+
+
+[% RenderBlockEnd("Overview") %] diff --git a/Kernel/Output/HTML/Standard/AdminDefaultRecipientTemplates.tt b/Kernel/Output/HTML/Standard/AdminDefaultRecipientTemplates.tt new file mode 100644 index 0000000..a3fd402 --- /dev/null +++ b/Kernel/Output/HTML/Standard/AdminDefaultRecipientTemplates.tt @@ -0,0 +1,172 @@ +# -- +# AdminDefaultRecipientTemplates.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-DefaultRecipient Relations") | html %]

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

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

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

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

+
+
+ +
+
+[% RenderBlockEnd("FilterDefaultRecipient") %] + +
+ +
+
+ +[% 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("DefaultRecipient") | html %]
  • + +[% RenderBlockStart("NoDefaultRecipientFoundMsg") %] +
  • [% Translate("No data found.") | html %]
  • +[% RenderBlockEnd("NoDefaultRecipientFoundMsg") %] +[% RenderBlockStart("Listn1") %] +
  • [% Data.Name | html %]
  • +[% RenderBlockEnd("Listn1") %] +
+
+
+
+ +[% WRAPPER JSOnDocumentComplete %] + +[% END %] +[% RenderBlockEnd("OverviewResult") %] +[% RenderBlockStart("Change") %] +
+

+[% RenderBlockStart("ChangeHeaderDefaultRecipient") %] + [% Translate("Change DefaultRecipient Relations for Template") | html %] +[% RenderBlockEnd("ChangeHeaderDefaultRecipient") %] +[% RenderBlockStart("ChangeHeaderTemplate") %] + [% Translate("Change Template Relations for DefaultRecipient") | 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/AdminDefaultTo.tt b/Kernel/Output/HTML/Standard/AdminDefaultTo.tt deleted file mode 100644 index 2c1744d..0000000 --- a/Kernel/Output/HTML/Standard/AdminDefaultTo.tt +++ /dev/null @@ -1,194 +0,0 @@ -# -- -# AdminDefaultTo.tt - provides HTML form for AdminDefaultTo -# 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 DefaultTo") | html %]

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

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

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

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

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

-
-
- -

- [% Translate("With DefaultTo you could change or extend the default To address in a ticket response dependent on the used template.") | html %] -

-

- [% Translate("Attention") | html %]: - [% Translate("Don't forget to add new DefaultTo entries to templates.") | html %] -

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

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

-
-
- - - - - - - - - - - - - - - - - -[% RenderBlockStart("NoDataFoundMsg") %] - - - -[% RenderBlockEnd("NoDataFoundMsg") %] -[% RenderBlockStart("OverviewResultRow") %] - - - - - - - - - - -[% RenderBlockEnd("OverviewResultRow") %] - -
[% Translate("Title") | html %][% Translate("Remove default") | html %][% Translate("Add new") | html %][% Translate("New address") | html %][% Translate("Comment") | html %][% Translate("Changed") | html %][% Translate("Created") | html %][% Translate("Delete") | html %]
- [% Translate("No data found.") | html %] -
- [% Data.Title | html %] - [% Translate(Data.RemoveDefault) | html %][% Translate(Data.AddNew) | html %][% Data.NewAddress | html %][% Data.Comment | truncate(26) | html %][% Data.ChangeTime | Localize("TimeShort") %][% Data.CreateTime | Localize("TimeShort") %] - - [% Translate("Delete this entry") | html %] - - -
-
-
-[% WRAPPER JSOnDocumentComplete %] - -[% END %] -[% RenderBlockEnd("OverviewResult") %] -[% RenderBlockStart("OverviewUpdate") %] - -
-
-[% RenderBlockStart("HeaderAdd") %] -

[% Translate("Add DefaultTo") | html %]

-[% RenderBlockEnd("HeaderAdd") %] -[% RenderBlockStart("HeaderEdit") %] -

[% Translate("Edit DefaultTo") | html %]

-[% RenderBlockEnd("HeaderEdit") %] -
-
-
- - - -
- -
- -
-

[% Translate("This field is required.") | html %]

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

[% Translate("This field is required.") | html %]

-[% RenderBlockEnd("TitleServerError") %] -[% RenderBlockStart("ExistTitleServerError") %] -

[% Translate("A DefaultTo entry with this title already exists!") | html %]

-[% RenderBlockEnd("TitleServerError") %] -
-
-
- - -
- [% Data.DefaultToRemoveDefaultOption %] -
-
- - -
- [% Data.DefaultToAddNewOption %] -
-
- - -
- -
-
- - -
- -
-
- -
- - [% Translate("or") | html %] - [% Translate("Cancel") | html %] -
-
-
-
-
-
-[% RenderBlockEnd("OverviewUpdate") %] -
-
-
-[% RenderBlockEnd("Overview") %] diff --git a/Kernel/Output/HTML/Standard/AdminDefaultToTemplates.tt b/Kernel/Output/HTML/Standard/AdminDefaultToTemplates.tt deleted file mode 100644 index e3436f7..0000000 --- a/Kernel/Output/HTML/Standard/AdminDefaultToTemplates.tt +++ /dev/null @@ -1,172 +0,0 @@ -# -- -# 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/System/DefaultRecipient.pm b/Kernel/System/DefaultRecipient.pm new file mode 100644 index 0000000..d9b72d6 --- /dev/null +++ b/Kernel/System/DefaultRecipient.pm @@ -0,0 +1,351 @@ +# -- +# Kernel/System/DefaultRecipient.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::DefaultRecipient; + +use strict; +use warnings; + +our @ObjectDependencies = qw( + Kernel::System::DB + Kernel::System::Log +); + +sub new { + my ( $Type, %Param ) = @_; + + # allocate new hash for object + my $Self = {}; + bless ($Self, $Type); + + return $Self; +} + +sub Add { + my ( $Self, %Param ) = @_; + + # check needed stuff + for my $Needed (qw(Title RemoveDefault AddNew NewAddress Comment UserID)) { + if ( ! defined $Param{$Needed} ) { + my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); + $LogObject->Log( + Priority => 'error', + Message => "Need $Needed!", + ); + return; + } + } + + my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); + + # insert new DefaultRecipient + return if !$DBObject->Do( + SQL => 'INSERT INTO default_recipient ' + . '(title, remove_default, add_new, new_address, comments, ' + . ' create_time, create_by, change_time, change_by) ' + . 'VALUES (?, ?, ?, ?, ?, current_timestamp, ?, current_timestamp, ?)', + Bind => [ + \$Param{Title}, + \$Param{RemoveDefault}, + \$Param{AddNew}, + \$Param{NewAddress}, + \$Param{Comment}, + \$Param{UserID}, + \$Param{UserID}, + ], + ); + + # get new id + return if !$DBObject->Prepare( + SQL => 'SELECT MAX(id) FROM default_recipient WHERE title = ?', + Bind => [ \$Param{Title}, ], + Limit => 1, + ); + + my $ID; + while ( my @Row = $DBObject->FetchrowArray() ) { + $ID = $Row[0]; + } + + # log notice + my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); + $LogObject->Log( + Priority => 'notice', + Message => "DefaultRecipient '$ID' created successfully!", + ); + + return $ID; +} + +sub Update { + my ( $Self, %Param ) = @_; + + # check needed stuff + for my $Needed (qw(ID Title RemoveDefault AddNew NewAddress Comment + UserID)) { + if ( ! defined $Param{$Needed} ) { + my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); + $LogObject->Log( + Priority => 'error', + Message => "Need $Needed!", + ); + return; + } + } + + my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); + + # insert new DefaultRecipient + return if !$DBObject->Do( + SQL => 'UPDATE default_recipient SET title = ?, remove_default = ?, ' + . 'add_new = ?, new_address = ?, comments = ?, change_by = ?, ' + . 'change_time = current_timestamp ' + . 'WHERE id = ?', + Bind => [ + \$Param{Title}, + \$Param{RemoveDefault}, + \$Param{AddNew}, + \$Param{NewAddress}, + \$Param{Comment}, + \$Param{UserID}, + \$Param{ID}, + ], + ); + + return 1; +} + +sub Get { + my ( $Self, %Param ) = @_; + + # check needed stuff + if ( !$Param{ID} ) { + my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); + $LogObject->Log( + Priority => 'error', + Message => 'Need ID!', + ); + return; + } + + my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); + + # get RrsponseChangeDefaultTO obejct + return if !$DBObject->Prepare( + SQL => 'SELECT id, title, remove_default, add_new, new_address, ' + . 'comments, create_time, create_by, change_time, change_by ' + . 'FROM default_recipient WHERE id = ?', + Bind => [ \$Param{ID} ], + Limit => 1, + ); + + my %DefaultRecipient; + while ( my @Data = $DBObject->FetchrowArray() ) { + %DefaultRecipient = ( + ID => $Data[0], + Title => $Data[1], + RemoveDefault => $Data[2], + AddNew => $Data[3], + NewAddress => $Data[4], + Comment => $Data[5], + CreateTime => $Data[6], + CreateBy => $Data[7], + ChangeTime => $Data[8], + ChangeBy => $Data[9], + ); + } + + return %DefaultRecipient; +} + +sub Delete { + my ( $Self, %Param ) = @_; + + # check needed stuff + if ( !$Param{ID} ) { + my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); + $LogObject->Log( + Priority => 'error', + Message => 'Need ID!', + ); + return; + } + + my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); + + # delete mapping + return if !$DBObject->Do( + SQL => 'DELETE FROM default_recipient_response ' + . 'WHERE default_recipient_id = ?', + Bind => [ \$Param{ID} ], + ); + + # delete entry + return $DBObject->Do( + SQL => 'DELETE FROM default_recipient WHERE id = ?', + Bind => [ \$Param{ID} ], + ); +} + +sub List { + my ( $Self, %Param ) = @_; + my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); + + $DBObject->Prepare( + SQL => 'SELECT id, title FROM default_recipient', + ); + + my %DefaultRecipient; + while ( my @Data = $DBObject->FetchrowArray() ) { + $DefaultRecipient{ $Data[0] } = $Data[1]; + } + + return %DefaultRecipient; +} + +sub TitleExistsCheck { + my ( $Self, %Param ) = @_; + my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); + + return if !$DBObject->Prepare( + SQL => 'SELECT id FROM default_recipient WHERE title = ?', + Bind => [ \$Param{Title} ], + ); + + # fetch the result + my $Flag; + while ( my @Row = $DBObject->FetchrowArray() ) { + if ( !$Param{ID} || $Param{ID} ne $Row[0] ) { + $Flag = 1; + } + } + if ($Flag) { + return 1; + } + return 0; +} + +sub MappingAdd { + my ( $Self, %Param ) = @_; + + # check needed stuff + for my $Needed (qw(TemplateID DefaultRecipientID)) { + if ( !$Param{$Needed} ) { + my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); + $LogObject->Log( + Priority => 'error', + Message => "Need $Needed!", + ); + return; + } + } + + my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); + + # insert new mapping + return if !$DBObject->Do( + SQL => 'INSERT INTO default_recipient_response ' + . '(template_id, default_recipient_id) VALUES (?, ?)', + Bind => [ + \$Param{TemplateID}, + \$Param{DefaultRecipientID}, + ], + ); + + # get new id + return if !$DBObject->Prepare( + SQL => 'SELECT MAX(id) FROM default_recipient_response ' + . 'WHERE template_id = ? AND default_recipient_id = ?', + Bind => [ + \$Param{TemplateID}, + \$Param{DefaultRecipientID}, ], + Limit => 1, + ); + + my $ID; + while ( my @Row = $DBObject->FetchrowArray() ) { + $ID = $Row[0]; + } + + # log notice + my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); + $LogObject->Log( + Priority => 'notice', + Message => "DefaultRecipient mapping '$ID' " + . "created successfully!", + ); + + return $ID; +} + +sub MappingDelete { + my ( $Self, %Param ) = @_; + + # check needed stuff + if ( !$Param{ID} ) { + my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); + $LogObject->Log( + Priority => 'error', + Message => 'Need ID!', + ); + return; + } + + my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); + + # delete mapping + return $DBObject->Do( + SQL => 'DELETE FROM default_recipient_response ' + . 'WHERE id = ?', + Bind => [ \$Param{ID} ], + ); +} + +sub MappingList { + my ( $Self, %Param ) = @_; + + # check needed stuff + if ( !$Param{TemplateID} && !$Param{DefaultRecipientID} ) { + my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); + $LogObject->Log( + Priority => 'error', + Message => 'Got no TemplateID or DefaultRecipientID!' + ); + return; + } + + my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); + + # find mapped objects + if ( $Param{TemplateID} ) { + $DBObject->Prepare( + SQL => 'SELECT id, default_recipient_id ' + . 'FROM default_recipient_response ' + . 'WHERE template_id = ?', + Bind => [ \$Param{TemplateID}, ], + ); + } + else { + $DBObject->Prepare( + SQL => 'SELECT id, template_id ' + . 'FROM default_recipient_response ' + . 'WHERE default_recipient_id = ?', + Bind => [ \$Param{DefaultRecipientID}, ], + ); + } + + my %Mapping; + while ( my @Data = $DBObject->FetchrowArray() ) { + $Mapping{ $Data[0] } = $Data[1]; + } + + return %Mapping; +} + +1; diff --git a/Kernel/System/DefaultTo.pm b/Kernel/System/DefaultTo.pm deleted file mode 100644 index 9e8acdb..0000000 --- a/Kernel/System/DefaultTo.pm +++ /dev/null @@ -1,351 +0,0 @@ -# -- -# 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 -); - -sub new { - my ( $Type, %Param ) = @_; - - # allocate new hash for object - my $Self = {}; - bless ($Self, $Type); - - return $Self; -} - -sub Add { - my ( $Self, %Param ) = @_; - - # check needed stuff - for my $Needed (qw(Title RemoveDefault AddNew NewAddress Comment UserID)) { - if ( ! defined $Param{$Needed} ) { - my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); - $LogObject->Log( - Priority => 'error', - Message => "Need $Needed!", - ); - return; - } - } - - my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); - - # insert new DefaultTo - return if !$DBObject->Do( - SQL => 'INSERT INTO default_to ' - . '(title, remove_default, add_new, new_address, comments, ' - . ' create_time, create_by, change_time, change_by) ' - . 'VALUES (?, ?, ?, ?, ?, current_timestamp, ?, current_timestamp, ?)', - Bind => [ - \$Param{Title}, - \$Param{RemoveDefault}, - \$Param{AddNew}, - \$Param{NewAddress}, - \$Param{Comment}, - \$Param{UserID}, - \$Param{UserID}, - ], - ); - - # get new id - return if !$DBObject->Prepare( - SQL => 'SELECT MAX(id) FROM default_to WHERE title = ?', - Bind => [ \$Param{Title}, ], - Limit => 1, - ); - - my $ID; - while ( my @Row = $DBObject->FetchrowArray() ) { - $ID = $Row[0]; - } - - # log notice - my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); - $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 Comment - UserID)) { - if ( ! defined $Param{$Needed} ) { - my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); - $LogObject->Log( - Priority => 'error', - Message => "Need $Needed!", - ); - return; - } - } - - my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); - - # insert new DefaultTo - return if !$DBObject->Do( - SQL => 'UPDATE default_to SET title = ?, remove_default = ?, ' - . 'add_new = ?, new_address = ?, comments = ?, change_by = ?, ' - . 'change_time = current_timestamp ' - . 'WHERE id = ?', - Bind => [ - \$Param{Title}, - \$Param{RemoveDefault}, - \$Param{AddNew}, - \$Param{NewAddress}, - \$Param{Comment}, - \$Param{UserID}, - \$Param{ID}, - ], - ); - - return 1; -} - -sub Get { - my ( $Self, %Param ) = @_; - - # check needed stuff - if ( !$Param{ID} ) { - my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); - $LogObject->Log( - Priority => 'error', - Message => 'Need ID!', - ); - return; - } - - my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); - - # get RrsponseChangeDefaultTO obejct - return if !$DBObject->Prepare( - SQL => 'SELECT id, title, remove_default, add_new, new_address, ' - . 'comments, create_time, create_by, change_time, change_by ' - . 'FROM default_to WHERE id = ?', - Bind => [ \$Param{ID} ], - Limit => 1, - ); - - my %DefaultTo; - while ( my @Data = $DBObject->FetchrowArray() ) { - %DefaultTo = ( - ID => $Data[0], - Title => $Data[1], - RemoveDefault => $Data[2], - AddNew => $Data[3], - NewAddress => $Data[4], - Comment => $Data[5], - CreateTime => $Data[6], - CreateBy => $Data[7], - ChangeTime => $Data[8], - ChangeBy => $Data[9], - ); - } - - return %DefaultTo; -} - -sub Delete { - my ( $Self, %Param ) = @_; - - # check needed stuff - if ( !$Param{ID} ) { - my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); - $LogObject->Log( - Priority => 'error', - Message => 'Need ID!', - ); - return; - } - - my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); - - # delete mapping - return if !$DBObject->Do( - SQL => 'DELETE FROM default_to_response ' - . 'WHERE default_to_id = ?', - Bind => [ \$Param{ID} ], - ); - - # delete entry - return $DBObject->Do( - SQL => 'DELETE FROM default_to WHERE id = ?', - Bind => [ \$Param{ID} ], - ); -} - -sub List { - my ( $Self, %Param ) = @_; - my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); - - $DBObject->Prepare( - SQL => 'SELECT id, title FROM default_to', - ); - - my %DefaultTo; - while ( my @Data = $DBObject->FetchrowArray() ) { - $DefaultTo{ $Data[0] } = $Data[1]; - } - - return %DefaultTo; -} - -sub TitleExistsCheck { - my ( $Self, %Param ) = @_; - my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); - - return if !$DBObject->Prepare( - SQL => 'SELECT id FROM default_to WHERE title = ?', - Bind => [ \$Param{Title} ], - ); - - # fetch the result - my $Flag; - while ( my @Row = $DBObject->FetchrowArray() ) { - if ( !$Param{ID} || $Param{ID} ne $Row[0] ) { - $Flag = 1; - } - } - if ($Flag) { - return 1; - } - return 0; -} - -sub MappingAdd { - my ( $Self, %Param ) = @_; - - # check needed stuff - for my $Needed (qw(TemplateID DefaultToID)) { - if ( !$Param{$Needed} ) { - my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); - $LogObject->Log( - Priority => 'error', - Message => "Need $Needed!", - ); - return; - } - } - - my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); - - # insert new mapping - return if !$DBObject->Do( - SQL => 'INSERT INTO default_to_response ' - . '(template_id, default_to_id) VALUES (?, ?)', - Bind => [ - \$Param{TemplateID}, - \$Param{DefaultToID}, - ], - ); - - # get new id - return if !$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 = $DBObject->FetchrowArray() ) { - $ID = $Row[0]; - } - - # log notice - my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); - $LogObject->Log( - Priority => 'notice', - Message => "DefaultTo mapping '$ID' " - . "created successfully!", - ); - - return $ID; -} - -sub MappingDelete { - my ( $Self, %Param ) = @_; - - # check needed stuff - if ( !$Param{ID} ) { - my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); - $LogObject->Log( - Priority => 'error', - Message => 'Need ID!', - ); - return; - } - - my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); - - # delete mapping - return $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} ) { - my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); - $LogObject->Log( - Priority => 'error', - Message => 'Got no TemplateID or DefaultToID!' - ); - return; - } - - my $DBObject = $Kernel::OM->Get('Kernel::System::DB'); - - # find mapped objects - if ( $Param{TemplateID} ) { - $DBObject->Prepare( - SQL => 'SELECT id, default_to_id ' - . 'FROM default_to_response ' - . 'WHERE template_id = ?', - Bind => [ \$Param{TemplateID}, ], - ); - } - else { - $DBObject->Prepare( - SQL => 'SELECT id, template_id ' - . 'FROM default_to_response ' - . 'WHERE default_to_id = ?', - Bind => [ \$Param{DefaultToID}, ], - ); - } - - my %Mapping; - while ( my @Data = $DBObject->FetchrowArray() ) { - $Mapping{ $Data[0] } = $Data[1]; - } - - return %Mapping; -} - -1; -- cgit v1.2.3-1-g7c22