1 % if ( exists($opt{'redirect'}) && $opt{'redirect'}
2 % && scalar(@$rows) == 1 && $total == 1
3 % && $type ne 'html-print'
5 % my $redirect = $opt{'redirect'};
6 % $redirect = &{$redirect}($rows->[0], $cgi) if ref($redirect) eq 'CODE';
7 % my( $url, $method ) = @$redirect;
8 % redirect( $url. $rows->[0]->$method() );
9 % } elsif ( exists($opt{'redirect_empty'}) && ! scalar(@$rows) && $total == 0
10 % && $type ne 'html-print'
11 % && $opt{'redirect_empty'}
12 % && ( ref($opt{'redirect_empty'}) ne 'CODE'
13 % || &{$opt{'redirect_empty'}}($cgi) )
15 % my $redirect = $opt{'redirect_empty'};
16 % $redirect = &{$redirect}($cgi) if ref($redirect) eq 'CODE';
17 % redirect( $redirect );
19 % if ( $opt{'name_singular'} ) {
20 % $opt{'name'} = PL($opt{'name_singular'});
22 % ( my $xlsname = $opt{'name'} ) =~ s/\W//g;
23 % if ( $total == 1 ) {
24 % if ( $opt{'name_singular'} ) {
25 % $opt{'name'} = $opt{'name_singular'}
27 % #$opt{'name'} =~ s/s$// if $total == 1;
28 % $opt{'name'} =~ s/((s)e)?s$/$2/ if $total == 1;
32 % unless ( $opt{nohtmlheader} ) {
34 % if ( $type eq 'html-print' ) {
35 <& /elements/header-popup.html, $opt{'title'} &>
37 % if ( $type eq 'select' ) {
38 <&/elements/header-popup.html, $opt{'title'} &>
42 % if ( $opt{'menubar'} ) {
43 % @menubar = @{ $opt{'menubar'} };
45 % # @menubar = ( 'Main menu' => $p );
48 <& /elements/header.html, $opt{'title'},
49 include( '/elements/menubar.html', @menubar )
57 % unless ( $type eq 'html-print' ) {
59 % if ( $opt{'add_link'} ) { #or after html_init?
60 <A HREF="<%$p%>edit/<% $opt{query}->{table} %>.html"><I>Add a <% $opt{'name_singular'} %></I></A><BR><BR>
63 <% defined($opt{'html_init'})
64 ? ( ref($opt{'html_init'})
65 ? &{$opt{'html_init'}}()
74 % unless ( $opt{'disable_nonefound'} ) {
75 <BR><BR>No matching <% $opt{'name'} %> found.<BR>
79 % if ( $total || $opt{'disableable'} ) { #hmm... and there *are* ones to show??
88 % if (! $opt{'disable_total'}) {
89 <% $total %> total <% $opt{'name'} %>
92 % if ( $confmax && $total > $confmax
93 % && ! $opt{'disable_maxselect'}
94 % && $type ne 'html-print' )
96 % $cgi->delete('maxrecords');
97 % $cgi->param('_dummy', 1);
99 ( show <SELECT NAME="maxrecords" onChange="window.location = '<% "$self_url?". $cgi->query_string %>;maxrecords=' + this.options[this.selectedIndex].value;">
101 % foreach my $max ( map { $_ * $confmax } qw( 1 5 10 25 ) ) {
102 <OPTION VALUE="<% $max %>" <% ( $maxrecords == $max ) ? 'SELECTED' : '' %>><% $max %></OPTION>
107 % $cgi->param('maxrecords', $maxrecords);
110 % if ( defined($opt{'html_posttotal'}) && $type ne 'html-print' ) {
111 <% ref($opt{'html_posttotal'})
112 ? &{$opt{'html_posttotal'}}()
113 : $opt{'html_posttotal'}
118 % if ( $opt{'count_addl'} ) {
120 % foreach my $count ( @{$opt{'count_addl'}} ) {
121 % my $data = $count_arrayref->[++$n];
122 % if ( ref($count) ) {
123 <% &{ $count }( $data ) %>
125 <% sprintf( $count, $data ) %><BR>
133 % if ( $curuser->access_right('Download report data')
134 % and !$opt{'disable_download'}
135 % and $type ne 'html-print' ) {
137 <TD ALIGN="right" CLASS="noprint">
139 <% $opt{'download_label'} || 'Download full results' %><BR>
141 % $cgi->param('_type', "$xlsname.xls" );
142 as <A HREF="<% "$self_url?". $cgi->query_string %>">Excel spreadsheet</A><BR>
144 % $cgi->param('_type', 'csv');
145 as <A HREF="<% "$self_url?". $cgi->query_string %>">CSV file</A><BR>
147 % if ( defined($opt{xml_elements}) ) {
148 % $cgi->param('_type', 'xml');
149 as <A HREF="<% "$self_url?". $cgi->query_string %>">XML file</A><BR>
152 % $cgi->param('_type', 'html-print');
153 as <A HREF="<% "$self_url?". $cgi->query_string %>">printable copy</A>
156 % $cgi->param('_type', "html" );
164 % unless ( $type eq 'html_print' ) {
166 <% $pager = include( '/elements/pager.html',
168 'num_rows' => scalar(@$rows),
170 'maxrecords' => $maxrecords,
174 <% defined($opt{'html_form'})
175 ? ( ref($opt{'html_form'})
176 ? &{$opt{'html_form'}}()
186 null_link => $null_link,
187 link_agentnums => \@link_agentnums,
188 self_url => $self_url,
199 % if ( $type eq 'html-print' ) {
200 % unless ( $opt{nohtmlheader} ) {
207 <% defined($opt{'html_foot'})
208 ? ( ref($opt{'html_foot'})
209 ? &{$opt{'html_foot'}}()
215 <% $opt{nohtmlheader}
217 : include( '/elements/footer.html' )
225 my $curuser = $FS::CurrentUser::CurrentUser;
228 my $type = $args{'type'};
229 my $header = $args{'header'};
230 my $rows = $args{'rows'};
231 my @link_agentnums = @{ $args{'link_agentnums'} };
232 my $null_link = $args{'null_link'};
233 my $confmax = $args{'confmax'};
234 my $maxrecords = $args{'maxrecords'};
235 my $offset = $args{'offset'};
236 my %opt = %{ $args{'opt'} };
238 # must be an arrayref of the row count, followed by any other totals
239 my $count_arrayref = $args{'totals'};
240 my $total = $count_arrayref->[0];
242 # there used to be an option to override this, for highly dubious reasons
243 my $self_url = $cgi->url('-path_info' => 1, '-full' =>1);
248 % my $rows = delete $opt{rows};
249 % my $self_url = delete $opt{self_url};
250 <& /elements/table-grid.html &>
254 'header' => $opt{'header'},
255 'header2' => $opt{'header2'},
256 'sort_fields' => ($opt{'sort_fields'} || $opt{'fields'}),
261 <& SELF:data_rows, rows => $rows, opt => \%opt &>
264 % if ( $opt{'footer'} ) {
266 <& SELF:footer_row, row => $opt{'footer'}, opt => \%opt &>
280 % my $order_by = $cgi->param('order_by');
281 % my $self_url = $cgi->url('-path_info' => 1, '-full' =>1);
282 % foreach my $header ( @header ) {
284 % my $field = shift @sort_fields;
286 % $colspan-- if $colspan > 0;
289 % my $label = ref($header) ? $header->{label} : $header;
290 % unless ( ref($field) || !$field ) {
291 % if ( $order_by eq $field ) {
292 % $cgi->param('order_by', "$field DESC");
294 % $cgi->param('order_by', $field);
296 % $label = qq(<A HREF="$self_url?). $cgi->query_string.
300 % $colspan = ref($header) ? $header->{colspan} : 0;
304 % if ( !length($header2[$h2]) ) {
306 % splice @header2, $h2, 1;
309 % $style = 'STYLE="border-bottom: none"'
314 ROWSPAN = "<% $rowspan %>"
315 <% $colspan ? 'COLSPAN = "'.$colspan.'"' : '' %>
326 % foreach my $header ( @header2 ) {
327 % my $label = ref($header) ? $header->{label} : $header;
328 <TH CLASS="grid" BGCOLOR="#cccccc">
329 <FONT SIZE="-1"><% $label %></FONT>
347 % if ( $opt{align} and !ref($opt{align}) ) {
348 % $opt{align} = [ map $align{$_}, split(//, $opt{align}) ];
351 % my $i = 0; # for row striping # XXX CSS - nth-child
353 % foreach my $row ( @$rows ) {
356 % if ( $row eq $opt{'footer_data'} ) { # XXX CSS - tfoot
357 % $rowstyle = ' STYLE="border-top: dashed 1px black; font-style: italic background-color=#dddddd"';
361 % if ( $opt{'link_field' } ) {
362 % my $link_field = $opt{'link_field'};
363 % if ( ref($link_field) eq 'CODE' ) {
364 % $trid = &{$link_field}($row);
366 % $trid = $row->$link_field();
369 <TR ID="<%$trid |h%>" CLASS="row<% $i % 2 %>"<%$rowstyle%>>
371 % if ( $opt{'fields'} ) {
373 % my $links = $opt{'links'} ? [ @{$opt{'links'}} ] : '';
374 % my $onclicks = $opt{'link_onclicks'} ? [ @{$opt{'link_onclicks'}} ] : [];
375 % my $tooltips = $opt{'tooltips'} ? [ @{$opt{'tooltips'}} ] : [];
376 % my $aligns = $opt{'align'} ? [ @{$opt{'align'}} ] : '';
377 % my $colors = $opt{'color'} ? [ @{$opt{'color'}} ] : [];
378 % my $sizes = $opt{'size'} ? [ @{$opt{'size'}} ] : [];
379 % my $styles = $opt{'style'} ? [ @{$opt{'style'}} ] : [];
380 % my $cstyles = $opt{'cell_style'} ? [ @{$opt{'cell_style'}} ] : [];
381 % my $formats = $opt{'format'} ? [ @{$opt{'format'}} ] : [];
383 % foreach my $field (
385 % # if the value of the field is an arrayref, then construct a table in
387 % # if it's a (non-empty) scalar, and a format has been specified, then
388 % # format the scalar with that.
389 % # otherwise, just output the value.
390 % # XXX we should also do date formats like this
392 % if ( ref($_) eq 'ARRAY' ) {
396 % '<TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0 WIDTH="100%">'.
410 % uc($_).'="'. $e->{$_}. '"';
412 % grep exists($e->{$_}),
413 % qw( align bgcolor colspan rowspan
414 % style valign width )
419 % ? '<A HREF="'. $e->{'link'}. '">'
422 % ( $e->{'onclick'} # don't use with 'link'
423 % ? '<A HREF="#" onclick="' .
424 % $e->{'onclick'}.'">'
428 % ? '<FONT SIZE="'.uc($e->{'size'}).'">'
431 % ( $e->{'data_style'}
432 % ? '<'. uc($e->{'data_style'}). '>'
436 % ( $e->{'data_style'}
437 % ? '</'. uc($e->{'data_style'}). '>'
440 % ( $e->{'size'} ? '</FONT>' : '' ).
441 % ( $e->{'link'} || $e->{'onclick'}
454 % if ( length($_) > 0 and my $format = shift @$formats ) {
455 % $_ = sprintf($format, $_);
461 % # get the value of the field spec:
462 % # - if the spec is a coderef, evaluate the coderef
463 % # - if the spec is a string, call that string as a method
464 % # - if the spec is an integer, get the field in that position
466 % if ( ref($_) eq 'CODE' ) {
468 % } elsif ( ref($row) eq 'ARRAY' and
470 % # for the 'straight SQL' case: specify fields
472 % encode_entities($row->[$_]);
474 % encode_entities($row->$_());
481 % my $class = ( $field =~ /^<TABLE/i ) ? 'inv' : 'grid';
482 % my $class = 'grid';
484 % my $align = $aligns ? shift @$aligns : '';
485 % $align = " ALIGN=$align" if $align;
489 % my $link = shift @$links;
490 % my $onclick = shift @$onclicks;
491 % my $tooltip = shift @$tooltips;
493 % if ( ! $opt{'agent_virt'}
494 % || ( $opt{'null_link'} && ! $row->agentnum )
495 % || grep { $row->agentnum == $_ }
496 % @{ $opt{link_agentnums} }
499 % $link = &{$link}($row)
500 % if ref($link) eq 'CODE';
502 % $onclick = &{$onclick}($row)
503 % if ref($onclick) eq 'CODE';
504 % $onclick = qq( onClick="$onclick") if $onclick;
506 % $tooltip = &{$tooltip}($row)
507 % if ref($tooltip) eq 'CODE';
508 % $tooltip = qq! id="a$id" !.
509 % qq! onmouseover="return overlib(!.
510 % $m->interp->apply_escapes($tooltip, 'h', 'js_string').
511 % qq!, FGCLASS, 'tooltip', REF, 'a$id', !.
512 % qq!REFC, 'LL', REFP, 'UL')"! if $tooltip;
515 % my( $url, $method ) = @{$link};
516 % if ( ref($method) eq 'CODE' ) {
517 % $a = $url. &{$method}($row);
519 % $a = $url. $row->$method();
521 % $a = qq(<A HREF="$a"$onclick$tooltip>);
523 % elsif ( $onclick ) {
524 % $a = qq(<A HREF="javascript:void(0);"$onclick>);
526 % elsif ( $tooltip ) {
527 % $a = qq(<A $tooltip>);
536 % my $color = shift @$colors;
537 % $color = &{$color}($row) if ref($color) eq 'CODE';
538 % my $size = shift @$sizes;
539 % $size = &{$size}($row) if ref($size) eq 'CODE';
540 % if ( $color || $size ) {
542 % ( $color ? "COLOR=#$color " : '' ).
543 % ( $size ? qq(SIZE="$size" ) : '' ).
547 % my($s, $es) = ( '', '' );
548 % my $style = shift @$styles;
549 % $style = &{$style}($row) if ref($style) eq 'CODE';
551 % $s = join( '', map "<$_>", split('', $style) );
552 % $es = join( '', map "</$_>", split('', $style) );
555 % my $cstyle = shift @$cstyles;
556 % $cstyle = &{$cstyle}($row) if ref($cstyle) eq 'CODE';
557 % $cstyle = qq(STYLE="$cstyle")
560 <TD CLASS="<% $class %>" <% $align %> <% $cstyle %>><% $a %><% $font %><% $s %><% $field %><% $es %><% $font ? '</FONT>' : '' %><% $a ? '</A>' : '' %></TD>
564 % } else { # not $opt{'fields'}
566 % foreach ( @$row ) {
567 <TD CLASS="grid"><% $_ %></TD>
583 %# don't try to respect all the styling options, just the ones that are
584 %# hard to replicate with CSS
592 % if ( $opt{align} and !ref($opt{align}) ) {
593 % $opt{align} = [ map $align{$_}, split(//, $opt{align}) ];
595 % my @aligns = @{ $opt{align} };
598 % foreach my $footer ( @$row ) {
599 % $footer = &{$footer}() if ref($footer) eq 'CODE';
600 % my $align = shift @aligns;
602 % $style .= "text-align: $align;" if $align;
603 <TD CLASS="grid" STYLE="<% $style %>"><% $footer %></TD>