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::Layout::CustomerUser; 10 11use strict; 12use warnings; 13 14use Kernel::System::VariableCheck qw(:all); 15 16our $ObjectManagerDisabled = 1; 17 18=head1 NAME 19 20Kernel::Output::HTML::Layout::CustomerUser - all CustomerUser related HTML functions 21 22=head1 PUBLIC INTERFACE 23 24=head2 CustomerUserAddressBookListShow() 25 26Returns a list of customer user as sort-able list with pagination. 27 28This function is similar to L<Kernel::Output::HTML::Layout::CustomerUser::CustomerUserAddressBookListShow()> 29in F<Kernel/Output/HTML/Layout/CustomerUser.pm>. 30 31 my $Output = $LayoutObject->CustomerUserAddressBookListShow( 32 CustomerUserIDs => $CustomerUserIDsRef, # total list of customer user ids, that can be listed 33 Total => scalar @{ $CustomerUserIDsRef }, # total number of customer user ids 34 View => $Self->{View}, # optional, the default value is 'AddressBook' 35 Filter => 'All', 36 Filters => \%NavBarFilter, 37 LinkFilter => $LinkFilter, 38 TitleName => 'Overview: CustomerUsers', 39 TitleValue => $Self->{Filter}, 40 Env => $Self, 41 LinkPage => $LinkPage, 42 LinkSort => $LinkSort, 43 Frontend => 'Agent', # optional (Agent|Customer), default: Agent, indicates from which frontend this function was called 44 ); 45 46=cut 47 48sub CustomerUserAddressBookListShow { 49 my ( $Self, %Param ) = @_; 50 51 # Take object ref to local, remove it from %Param (prevent memory leak). 52 my $Env = delete $Param{Env}; 53 54 my $Frontend = $Param{Frontend} || 'Agent'; 55 56 # Set defaut view mode to 'AddressBook'. 57 my $View = $Param{View} || 'AddressBook'; 58 59 my $ConfigObject = $Kernel::OM->Get('Kernel::Config'); 60 61 # get backend from config 62 my $Backends = $ConfigObject->Get('CustomerUser::Frontend::Overview'); 63 if ( !$Backends ) { 64 return $Self->FatalError( 65 Message => 'Need config option CustomerUser::Frontend::Overview', 66 ); 67 } 68 69 # check for hash-ref 70 if ( ref $Backends ne 'HASH' ) { 71 return $Self->FatalError( 72 Message => 'Config option CustomerUser::Frontend::Overview needs to be a HASH ref!', 73 ); 74 } 75 76 # check for config key 77 if ( !$Backends->{$View} ) { 78 return $Self->FatalError( 79 Message => "No config option found for the view '$View'!", 80 ); 81 } 82 83 # nav bar 84 my $StartHit = $Kernel::OM->Get('Kernel::System::Web::Request')->GetParam( 85 Param => 'StartHit', 86 ) || 1; 87 88 # get personal page shown count 89 my $PageShown = $ConfigObject->Get("CustomerUser::Frontend::$Self->{Action}")->{PageShown} || 100; 90 91 # check start option, if higher then elements available, set 92 # it to the last overview page (Thanks to Stefan Schmidt!) 93 if ( $StartHit > $Param{Total} ) { 94 my $Pages = int( ( $Param{Total} / $PageShown ) + 0.99999 ); 95 $StartHit = ( ( $Pages - 1 ) * $PageShown ) + 1; 96 } 97 98 # set page limit and build page nav 99 my $Limit = $Param{Limit} || 20_000; 100 my %PageNav = $Self->PageNavBar( 101 Limit => $Limit, 102 StartHit => $StartHit, 103 PageShown => $PageShown, 104 AllHits => $Param{Total} || 0, 105 Action => 'Action=' . $Self->{Action}, 106 Link => $Param{LinkPage}, 107 ); 108 109 # build navbar content 110 $Self->Block( 111 Name => 'OverviewNavBar', 112 Data => \%Param, 113 ); 114 115 # back link 116 if ( $Param{LinkBack} ) { 117 $Self->Block( 118 Name => 'OverviewNavBarPageBack', 119 Data => \%Param, 120 ); 121 } 122 123 # check if page nav is available 124 if (%PageNav) { 125 $Self->Block( 126 Name => 'OverviewNavBarPageNavBar', 127 Data => \%PageNav, 128 ); 129 130 # don't show context settings in AJAX case (e. g. in customer ticket history), 131 # because the submit with page reload will not work there 132 if ( !$Param{AJAX} ) { 133 $Self->Block( 134 Name => 'ContextSettings', 135 Data => { 136 %PageNav, 137 %Param, 138 }, 139 ); 140 } 141 } 142 143 # build html content 144 my $OutputNavBar = $Self->Output( 145 TemplateFile => 'AgentCustomerUserAddressBookOverviewNavBar', 146 Data => {%Param}, 147 ); 148 149 # create output 150 my $OutputRaw = ''; 151 if ( !$Param{Output} ) { 152 $Self->Print( 153 Output => \$OutputNavBar, 154 ); 155 } 156 else { 157 $OutputRaw .= $OutputNavBar; 158 } 159 160 # load module 161 if ( !$Kernel::OM->Get('Kernel::System::Main')->Require( $Backends->{$View}->{Module} ) ) { 162 return $Self->FatalError(); 163 } 164 165 # check for backend object 166 my $Object = $Backends->{$View}->{Module}->new( %{$Env} ); 167 return if !$Object; 168 169 # run module 170 my $Output = $Object->Run( 171 %Param, 172 Limit => $Limit, 173 StartHit => $StartHit, 174 PageShown => $PageShown, 175 AllHits => $Param{Total} || 0, 176 Frontend => $Frontend, 177 ); 178 179 # create output 180 if ( !$Param{Output} ) { 181 $Self->Print( 182 Output => \$Output, 183 ); 184 } 185 else { 186 $OutputRaw .= $Output; 187 } 188 189 # create overview nav bar 190 $Self->Block( 191 Name => 'OverviewNavBar', 192 Data => {%Param}, 193 ); 194 195 # return content if available 196 return $OutputRaw; 197} 198 1991; 200 201=head1 TERMS AND CONDITIONS 202 203This software is part of the OTRS project (L<https://otrs.org/>). 204 205This software comes with ABSOLUTELY NO WARRANTY. For details, see 206the enclosed file COPYING for license information (GPL). If you 207did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>. 208 209=cut 210