1# --
2# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/
3# --
4# This software comes with ABSOLUTELY NO WARRANTY. For details, see
5# the enclosed file COPYING for license information (GPL). If you
6# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
7# --
8
9package Kernel::Output::HTML::CustomerNewTicket::QueueSelectionGeneric;
10
11use strict;
12use warnings;
13
14our $ObjectManagerDisabled = 1;
15
16sub new {
17    my ( $Type, %Param ) = @_;
18
19    # allocate new hash for object
20    my $Self = {};
21    bless( $Self, $Type );
22
23    # get needed objects
24    for my $Needed (qw( UserID SystemAddress)) {
25        $Self->{$Needed} = $Param{$Needed} || die "Got no $Needed!";
26    }
27
28    return $Self;
29}
30
31sub Run {
32    my ( $Self, %Param ) = @_;
33
34    # get needed objects
35    my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
36    my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
37    my $QueueObject  = $Kernel::OM->Get('Kernel::System::Queue');
38
39    # check if own selection is configured
40    my %NewTos;
41    if ( $ConfigObject->{CustomerPanelOwnSelection} ) {
42        for my $Queue ( sort keys %{ $ConfigObject->{CustomerPanelOwnSelection} } ) {
43            my $Value = $ConfigObject->{CustomerPanelOwnSelection}->{$Queue};
44            if ( $Queue =~ /^\d+$/ ) {
45                $NewTos{$Queue} = $Value;
46            }
47            else {
48                if ( $QueueObject->QueueLookup( Queue => $Queue ) ) {
49                    $NewTos{ $QueueObject->QueueLookup( Queue => $Queue ) } = $Value;
50                }
51                else {
52                    $NewTos{$Queue} = $Value;
53                }
54            }
55        }
56
57        # check create permissions
58        my %Queues = $TicketObject->MoveList(
59            %{ $Param{ACLParams} },
60            CustomerUserID => $Param{Env}->{UserID},
61            Type           => 'create',
62            Action         => $Param{Env}->{Action},
63        );
64        for my $QueueID ( sort keys %NewTos ) {
65            if ( !$Queues{$QueueID} ) {
66                delete $NewTos{$QueueID};
67            }
68        }
69    }
70    else {
71
72        # SelectionType Queue or SystemAddress?
73        my %Tos;
74        if ( $ConfigObject->Get('CustomerPanelSelectionType') eq 'Queue' ) {
75            %Tos = $TicketObject->MoveList(
76                %{ $Param{ACLParams} },
77                CustomerUserID => $Param{Env}->{UserID},
78                Type           => 'create',
79                Action         => $Param{Env}->{Action},
80            );
81        }
82        else {
83            my %Queues = $TicketObject->MoveList(
84                %{ $Param{ACLParams} },
85                CustomerUserID => $Param{Env}->{UserID},
86                Type           => 'create',
87                Action         => $Param{Env}->{Action},
88            );
89            my %SystemTos = $Kernel::OM->Get('Kernel::System::SystemAddress')->SystemAddressQueueList();
90            for my $QueueID ( sort keys %Queues ) {
91                if ( $SystemTos{$QueueID} ) {
92                    $Tos{$QueueID} = $Queues{$QueueID};
93                }
94            }
95        }
96        %NewTos = %Tos;
97
98        # build selection string
99        for my $QueueID ( sort keys %NewTos ) {
100            my %QueueData = $QueueObject->QueueGet( ID => $QueueID );
101            my $String    = $ConfigObject->Get('CustomerPanelSelectionString')
102                || '<Realname> <<Email>> - Queue: <Queue>';
103            $String =~ s/<Queue>/$QueueData{Name}/g;
104            $String =~ s/<QueueComment>/$QueueData{Comment}/g;
105            if ( $ConfigObject->Get('CustomerPanelSelectionType') ne 'Queue' ) {
106                my %SystemAddressData = $Self->{SystemAddress}->SystemAddressGet( ID => $QueueData{SystemAddressID} );
107                $String =~ s/<Realname>/$SystemAddressData{Realname}/g;
108                $String =~ s/<Email>/$SystemAddressData{Name}/g;
109            }
110            $NewTos{$QueueID} = $String;
111        }
112    }
113    return %NewTos;
114}
115
1161;
117