% if ( exists($opt{'redirect'}) && $opt{'redirect'} % && scalar(@$rows) == 1 && $total == 1 % && $type ne 'html-print' % ) { % my $redirect = $opt{'redirect'}; % $redirect = &{$redirect}($rows->[0], $cgi) if ref($redirect) eq 'CODE'; % my( $url, $method ) = @$redirect; % redirect( $url. $rows->[0]->$method() ); % } elsif ( exists($opt{'redirect_empty'}) && ! scalar(@$rows) && $total == 0 % && $type ne 'html-print' % && $opt{'redirect_empty'} % && ( ref($opt{'redirect_empty'}) ne 'CODE' % || &{$opt{'redirect_empty'}}($cgi) ) % ) { % my $redirect = $opt{'redirect_empty'}; % $redirect = &{$redirect}($cgi) if ref($redirect) eq 'CODE'; % redirect( $redirect ); % } else { % if ( $opt{'name_singular'} ) { % $opt{'name'} = PL($opt{'name_singular'}); % } % ( my $xlsname = $opt{'name'} ) =~ s/\W//g; % if ( $total == 1 ) { % if ( $opt{'name_singular'} ) { % $opt{'name'} = $opt{'name_singular'} % } else { % #$opt{'name'} =~ s/s$// if $total == 1; % $opt{'name'} =~ s/((s)e)?s$/$2/ if $total == 1; % } % } % % unless ( $opt{nohtmlheader} ) { % % if ( $type eq 'html-print' ) { <& /elements/header-popup.html, $opt{'title'} &> % } else { % if ( $type eq 'select' ) { <&/elements/header-popup.html, $opt{'title'} &> % } else { % % my @menubar = (); % if ( $opt{'menubar'} ) { % @menubar = @{ $opt{'menubar'} }; % #} else { % # @menubar = ( 'Main menu' => $p ); % } <& /elements/header.html, $opt{'title'}, include( '/elements/menubar.html', @menubar ) &> % } % } % % } % % unless ( $type eq 'html-print' ) { % if ( $opt{'add_link'} ) { #or after html_init? Add a <% $opt{'name_singular'} %>

% } <% defined($opt{'html_init'}) ? ( ref($opt{'html_init'}) ? &{$opt{'html_init'}}() : $opt{'html_init'} ) : '' %> % } % unless ( $total ) { % unless ( $opt{'disable_nonefound'} ) {

No matching <% $opt{'name'} %> found.
% } % } % % if ( $total || $opt{'disableable'} ) { #hmm... and there *are* ones to show?? % if ( $curuser->access_right('Download report data') % and !$opt{'disable_download'} % and $type ne 'html-print' ) { % $cgi->param('_type', "html" ); % } % my $h2 = 0; % my $colspan = 0; % my @fields = @{ $opt{'sort_fields'} || $opt{'fields'} || [] }; % my $order_by = $cgi->param('order_by'); % foreach my $header ( @{ $opt{header} } ) { % % my $field = shift @fields; % % $colspan-- if $colspan > 0; % next if $colspan; % % my $label = ref($header) ? $header->{label} : $header; % unless ( ref($field) || !$field ) { % if ( $order_by eq $field ) { % $cgi->param('order_by', "$field DESC"); % } else { % $cgi->param('order_by', $field); % } % $label = qq($label); % } % % $colspan = ref($header) ? $header->{colspan} : 0; % my $rowspan = 1; % my $style = ''; % if ( $opt{header2} ) { % if ( !length($opt{header2}->[$h2]) ) { % $rowspan = 2; % splice @{ $opt{header2} }, $h2, 1; % } else { % $h2++; % $style = 'STYLE="border-bottom: none"' % } % } % } % if ( $opt{header2} ) { % foreach my $header ( @{ $opt{header2} } ) { % my $label = ref($header) ? $header->{label} : $header; % } % } % my $bgcolor1 = '#eeeeee'; % my $bgcolor2 = '#ffffff'; % my $bgcolor; % % foreach my $row ( @$rows ) { % % if ( $bgcolor eq $bgcolor1 ) { % $bgcolor = $bgcolor2; % } else { % $bgcolor = $bgcolor1; % } % my $rowstyle = ''; % if ( $row eq $opt{'footer_data'} ) { % $rowstyle = ' STYLE="border-top: dashed 1px black; font-style: italic"'; % $bgcolor = '#dddddd'; % } % my $trid = ''; % if ( $opt{'link_field' } ) { % my $link_field = $opt{'link_field'}; % if ( ref($link_field) eq 'CODE' ) { % $trid = &{$link_field}($row); % } else { % $trid = $row->$link_field(); % } % } > % if ( $opt{'fields'} ) { % % my $links = $opt{'links'} ? [ @{$opt{'links'}} ] : ''; % my $onclicks = $opt{'link_onclicks'} ? [ @{$opt{'link_onclicks'}} ] : []; % my $tooltips = $opt{'tooltips'} ? [ @{$opt{'tooltips'}} ] : []; % my $aligns = $opt{'align'} ? [ @{$opt{'align'}} ] : ''; % my $colors = $opt{'color'} ? [ @{$opt{'color'}} ] : []; % my $sizes = $opt{'size'} ? [ @{$opt{'size'}} ] : []; % my $styles = $opt{'style'} ? [ @{$opt{'style'}} ] : []; % my $cstyles = $opt{'cell_style'} ? [ @{$opt{'cell_style'}} ] : []; % % foreach my $field ( % % map { % if ( ref($_) eq 'ARRAY' ) { % % my $tableref = $_; % % '
% if (! $opt{'disable_total'}) { <% $total %> total <% $opt{'name'} %> % } % if ( $confmax && $total > $confmax % && ! $opt{'disable_maxselect'} % && $type ne 'html-print' ) % { % $cgi->delete('maxrecords'); % $cgi->param('_dummy', 1); ( show per page ) % $cgi->param('maxrecords', $maxrecords); % } % if ( defined($opt{'html_posttotal'}) && $type ne 'html-print' ) { <% ref($opt{'html_posttotal'}) ? &{$opt{'html_posttotal'}}() : $opt{'html_posttotal'} %> % }
% if ( $opt{'count_addl'} ) { % my $n=0; % foreach my $count ( @{$opt{'count_addl'}} ) { % my $data = $count_arrayref->[++$n]; % if ( ref($count) ) { <% &{ $count }( $data ) %> % } else { <% sprintf( $count, $data ) %>
% } % } % }
<% $opt{'download_label'} || 'Download full results' %>
% $cgi->param('_type', "$xlsname.xls" ); as query_string %>">Excel spreadsheet
% $cgi->param('_type', 'csv'); as query_string %>">CSV file
% if ( defined($opt{xml_elements}) ) { % $cgi->param('_type', 'xml'); as query_string %>">XML file
% } % $cgi->param('_type', 'html-print'); as query_string %>">printable copy
% my $pager = ''; % unless ( $type eq 'html_print' ) { <% $pager = include( '/elements/pager.html', 'offset' => $offset, 'num_rows' => scalar(@$rows), 'total' => $total, 'maxrecords' => $maxrecords, ) %> <% defined($opt{'html_form'}) ? ( ref($opt{'html_form'}) ? &{$opt{'html_form'}}() : $opt{'html_form'} ) : '' %> % } <% include('/elements/table-grid.html') %>
<% $style %> > <% $label %>
<% $label %>
'. % % join('', map { % % my $rowref = $_; % % ''. % % join('', map { % % my $e = $_; % % ''; % % } @$rowref ). % % ''; % } @$tableref ). % % '
{$_}), % qw( align bgcolor colspan rowspan % style valign width ) % ). % '>'. % % ( $e->{'link'} % ? '' % : '' % ). % ( $e->{'onclick'} # don't use with 'link' % ? '' % : '' % ). % ( $e->{'size'} % ? '' % : '' % ). % ( $e->{'data_style'} % ? '<'. uc($e->{'data_style'}). '>' % : '' % ). % $e->{'data'}. % ( $e->{'data_style'} % ? '{'data_style'}). '>' % : '' % ). % ( $e->{'size'} ? '' : '' ). % ( $e->{'link'} || $e->{'onclick'} % ? '' % : '' ). % '
'; % % } else { % $_; % } % } % % map { % if ( ref($_) eq 'CODE' ) { % &{$_}($row); % } elsif ( ref($row) eq 'ARRAY' and % $_ =~ /^\d+$/ ) { % # for the 'straight SQL' case: specify fields % # by position % encode_entities($row->[$_]); % } else { % encode_entities($row->$_()); % } % } % @{$opt{'fields'}} % % ) { % %# my $class = ( $field =~ /^agentnum ) % || grep { $row->agentnum == $_ } % @link_agentnums % ) { % % $link = &{$link}($row) % if ref($link) eq 'CODE'; % % $onclick = &{$onclick}($row) % if ref($onclick) eq 'CODE'; % $onclick = qq( onClick="$onclick") if $onclick; % % $tooltip = &{$tooltip}($row) % if ref($tooltip) eq 'CODE'; % $tooltip = qq! id="a$id" !. % qq! onmouseover="return overlib(!. % $m->interp->apply_escapes($tooltip, 'h', 'js_string'). % qq!, FGCLASS, 'tooltip', REF, 'a$id', !. % qq!REFC, 'LL', REFP, 'UL')"! if $tooltip; % % if ( $link ) { % my( $url, $method ) = @{$link}; % if ( ref($method) eq 'CODE' ) { % $a = $url. &{$method}($row); % } else { % $a = $url. $row->$method(); % } % $a = qq(); % } % elsif ( $onclick ) { % $a = qq(); % } % elsif ( $tooltip ) { % $a = qq(); % } % $id++; % } % % } % % my $font = ''; % my $color = shift @$colors; % $color = &{$color}($row) if ref($color) eq 'CODE'; % my $size = shift @$sizes; % $size = &{$size}($row) if ref($size) eq 'CODE'; % if ( $color || $size ) { % $font = ''; % } % % my($s, $es) = ( '', '' ); % my $style = shift @$styles; % $style = &{$style}($row) if ref($style) eq 'CODE'; % if ( $style ) { % $s = join( '', map "<$_>", split('', $style) ); % $es = join( '', map "", split('', $style) ); % } % % my $cstyle = shift @$cstyles; % $cstyle = &{$cstyle}($row) if ref($cstyle) eq 'CODE'; % $cstyle = qq(STYLE="$cstyle") % if $cstyle; % } % % } else { % % foreach ( @$row ) { % } % % } % } % if ( $opt{'footer'} ) { % foreach my $footer ( @{ $opt{'footer'} } ) { % $footer = &{$footer}() if ref($footer) eq 'CODE'; % } % }
<% $cstyle %>><% $a %><% $font %><% $s %><% $field %><% $es %><% $font ? '' : '' %><% $a ? '' : '' %><% $_ %>
<% $footer %>
<% $pager %> % } % if ( $type eq 'html-print' ) { % unless ( $opt{nohtmlheader} ) { % } % } else { <% defined($opt{'html_foot'}) ? ( ref($opt{'html_foot'}) ? &{$opt{'html_foot'}}() : $opt{'html_foot'} ) : '' %> <% $opt{nohtmlheader} ? '' : include( '/elements/footer.html' ) %> % } % } <%init> my $curuser = $FS::CurrentUser::CurrentUser; my %args = @_; my $type = $args{'type'}; my $header = $args{'header'}; my $rows = $args{'rows'}; my @link_agentnums = @{ $args{'link_agentnums'} }; my $null_link = $args{'null_link'}; my $confmax = $args{'confmax'}; my $maxrecords = $args{'maxrecords'}; my $offset = $args{'offset'}; my %opt = %{ $args{'opt'} }; my $self_url = $opt{'url'} || $cgi->url('-path_info' => 1, '-full' =>1); my $count_sth = dbh->prepare($opt{'count_query'}) or die "Error preparing $opt{'count_query'}: ". dbh->errstr; $count_sth->execute or die "Error executing $opt{'count_query'}: ". $count_sth->errstr; my $count_arrayref = $count_sth->fetchrow_arrayref; my $total = $count_arrayref->[0]; my $id = 0;