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. --- Kernel/Modules/AdminDefaultRecipient.pm | 359 ++++++++++++++++++++++ Kernel/Modules/AdminDefaultRecipientTemplates.pm | 364 +++++++++++++++++++++++ Kernel/Modules/AdminDefaultTo.pm | 359 ---------------------- Kernel/Modules/AdminDefaultToTemplates.pm | 364 ----------------------- 4 files changed, 723 insertions(+), 723 deletions(-) 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 (limited to 'Kernel/Modules') 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; -- cgit v1.2.3-1-g7c22