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'}}($opt{html_init_data})
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);
98 % my $query = $m->scomp('/elements/create_uri_query');
100 ( show <SELECT NAME="maxrecords" onChange="window.location = '<% "$self_url?$query" %>;maxrecords=' + this.options[this.selectedIndex].value;">
102 % foreach my $max ( map { $_ * $confmax } qw( 1 5 10 25 ) ) {
103 <OPTION VALUE="<% $max %>" <% ( $maxrecords == $max ) ? 'SELECTED' : '' %>><% $max %></OPTION>
108 % $cgi->param('maxrecords', $maxrecords);
111 % if ( defined($opt{'html_posttotal'}) && $type ne 'html-print' ) {
112 <% ref($opt{'html_posttotal'})
113 ? &{$opt{'html_posttotal'}}()
114 : $opt{'html_posttotal'}
119 % if ( $opt{'count_addl'} ) {
121 % foreach my $count ( @{$opt{'count_addl'}} ) {
122 % my $data = $count_arrayref->[++$n];
123 % if ( ref($count) ) {
124 <% &{ $count }( $data ) %>
126 <% sprintf( $count, $data ) %><BR>
134 % if ( $curuser->access_right('Download report data')
135 % and !$opt{'disable_download'}
136 % and $type ne 'html-print' ) {
138 <TD ALIGN="right" CLASS="noprint">
140 <% $opt{'download_label'} || 'Download results:' %>
142 % $cgi->param('_type', "$xlsname.xls" );
143 % my $query = $m->scomp('/elements/create_uri_query');
144 <A HREF="<% "$self_url?$query" %>">Spreadsheet</A> |
146 % $cgi->param('_type', 'csv');
147 % my $query = $m->scomp('/elements/create_uri_query');
148 <A HREF="<% "$self_url?$query" %>">CSV</A> |
150 % if ( defined($opt{xml_elements}) ) {
151 % $cgi->param('_type', 'xml');
152 % my $query = $m->scomp('/elements/create_uri_query');
153 <A HREF="<% "$self_url?$query" %>">XML</A> |
156 % $cgi->param('_type', 'html-print');
157 % my $query = $m->scomp('/elements/create_uri_query');
158 <A HREF="<% "$self_url?$query" %>">webpage</A>
160 %# "save search" -- for now, obey disable_download and the 'Download
161 %# report data' ACL, because saving a search allows the user to receive
162 %# copies of the data.
164 %# XXX should do a check here on whether the user already has this
166 <& /elements/popup_link.html,
167 'action' => $fsurl.'/edit/saved_search.html?title='.
168 uri_escape($opt{title}),
169 'label' => 'Save this search',
170 'actionlabel' => 'Save this search',
175 % $cgi->param('_type', "html" );
183 % unless ( $type eq 'html_print' ) {
185 <% $pager = include( '/elements/pager.html',
187 'num_rows' => scalar(@$rows),
189 'maxrecords' => $maxrecords,
193 <% defined($opt{'html_form'})
194 ? ( ref($opt{'html_form'})
195 ? &{$opt{'html_form'}}()
205 null_link => $null_link,
206 link_agentnums => \@link_agentnums,
207 self_url => $self_url,
218 % if ( $type eq 'html-print' ) {
219 % unless ( $opt{nohtmlheader} ) {
226 <% defined($opt{'html_foot'})
227 ? ( ref($opt{'html_foot'})
228 ? &{$opt{'html_foot'}}()
234 <% $opt{nohtmlheader}
236 : include( '/elements/footer.html' )
244 my $curuser = $FS::CurrentUser::CurrentUser;
247 my $type = $args{'type'};
248 my $header = $args{'header'};
249 my $rows = $args{'rows'};
250 my @link_agentnums = @{ $args{'link_agentnums'} };
251 my $null_link = $args{'null_link'};
252 my $confmax = $args{'confmax'};
253 my $maxrecords = $args{'maxrecords'};
254 my $offset = $args{'offset'};
255 my %opt = %{ $args{'opt'} };
257 # must be an arrayref of the row count, followed by any other totals
258 my $count_arrayref = $args{'totals'};
259 my $total = $count_arrayref->[0];
261 # there used to be an option to override this, for highly dubious reasons
262 my $self_url = $cgi->url('-path_info' => 1, '-full' =>1);
267 % my $rows = delete $opt{rows};
268 % my $self_url = delete $opt{self_url};
269 <& /elements/table-grid.html &>
273 'header' => $opt{'header'},
274 'header2' => $opt{'header2'},
275 'sort_fields' => ($opt{'sort_fields'} || $opt{'fields'}),
280 <& SELF:data_rows, rows => $rows, opt => \%opt &>
283 % if ( $opt{'footer'} ) {
285 <& SELF:footer_row, row => $opt{'footer'}, opt => \%opt &>
299 % my $order_by = $cgi->param('order_by');
300 % my $self_url = $cgi->url('-path_info' => 1, '-full' =>1);
301 % foreach my $header ( @header ) {
303 % my $field = shift @sort_fields;
305 % $colspan-- if $colspan > 0;
308 % my $label = ref($header) ? $header->{label} : $header;
309 % unless ( ref($field) || !$field ) {
310 % if ( $order_by eq $field ) {
311 % $cgi->param('order_by', "$field DESC");
313 % $cgi->param('order_by', $field);
315 % my $query = $m->scomp('/elements/create_uri_query');
316 % $label = qq(<A HREF="$self_url?$query">$label</A>);
319 % $colspan = ref($header) ? $header->{colspan} : 0;
323 % if ( !length($header2[$h2]) ) {
325 % splice @header2, $h2, 1;
328 % $style = 'STYLE="border-bottom: none"'
333 ROWSPAN = "<% $rowspan %>"
334 <% $colspan ? 'COLSPAN = "'.$colspan.'"' : '' %>
345 % foreach my $header ( @header2 ) {
346 % my $label = ref($header) ? $header->{label} : $header;
347 <TH CLASS="grid" BGCOLOR="#cccccc">
348 <FONT SIZE="-1"><% $label %></FONT>
366 % if ( $opt{align} and !ref($opt{align}) ) {
367 % $opt{align} = [ map $align{$_}, split(//, $opt{align}) ];
370 % my $i = 0; # for row striping # XXX CSS - nth-child
372 % foreach my $row ( @$rows ) {
375 % if ( $row eq $opt{'footer_data'} ) { # XXX CSS - tfoot
376 % $rowstyle = ' STYLE="border-top: dashed 1px black; font-style: italic background-color=#dddddd"';
380 % if ( $opt{'link_field' } ) {
381 % my $link_field = $opt{'link_field'};
382 % if ( ref($link_field) eq 'CODE' ) {
383 % $trid = &{$link_field}($row);
385 % $trid = $row->$link_field();
388 <TR ID="<%$trid |h%>" CLASS="row<% $i % 2 %>"<%$rowstyle%>>
390 % if ( $opt{'fields'} ) {
392 % my $links = $opt{'links'} ? [ @{$opt{'links'}} ] : '';
393 % my $onclicks = $opt{'link_onclicks'} ? [ @{$opt{'link_onclicks'}} ] : [];
394 % my $tooltips = $opt{'tooltips'} ? [ @{$opt{'tooltips'}} ] : [];
395 % my $aligns = $opt{'align'} ? [ @{$opt{'align'}} ] : '';
396 % my $colors = $opt{'color'} ? [ @{$opt{'color'}} ] : [];
397 % my $sizes = $opt{'size'} ? [ @{$opt{'size'}} ] : [];
398 % my $styles = $opt{'style'} ? [ @{$opt{'style'}} ] : [];
399 % my $cstyles = $opt{'cell_style'} ? [ @{$opt{'cell_style'}} ] : [];
400 % my $formats = $opt{'format'} ? [ @{$opt{'format'}} ] : [];
402 % foreach my $field (
404 % # if the value of the field is an arrayref, then construct a table in
406 % # if it's a (non-empty) scalar, and a format has been specified, then
407 % # format the scalar with that.
408 % # otherwise, just output the value.
409 % # XXX we should also do date formats like this
411 % if ( ref($_) eq 'ARRAY' ) {
415 % '<TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0 WIDTH="100%">'.
429 % uc($_).'="'. $e->{$_}. '"';
431 % grep exists($e->{$_}),
432 % qw( align bgcolor colspan rowspan
433 % style valign width )
438 % ? '<A HREF="'. $e->{'link'}. '">'
441 % ( $e->{'onclick'} # don't use with 'link'
442 % ? '<A HREF="#" onclick="' .
443 % $e->{'onclick'}.'">'
447 % ? '<FONT SIZE="'.uc($e->{'size'}).'">'
450 % ( $e->{'data_style'}
451 % ? '<'. uc($e->{'data_style'}). '>'
455 % ( $e->{'data_style'}
456 % ? '</'. uc($e->{'data_style'}). '>'
459 % ( $e->{'size'} ? '</FONT>' : '' ).
460 % ( $e->{'link'} || $e->{'onclick'}
473 % if ( length($_) > 0 and my $format = shift @$formats ) {
474 % $_ = sprintf($format, $_);
480 % # get the value of the field spec:
481 % # - if the spec is a coderef, evaluate the coderef
482 % # - if the spec is a string, call that string as a method
483 % # - if the spec is an integer, get the field in that position
485 % if ( ref($_) eq 'CODE' ) {
487 % } elsif ( ref($row) eq 'ARRAY' and
489 % # for the 'straight SQL' case: specify fields
491 % encode_entities($row->[$_]);
493 % encode_entities($row->$_());
500 % my $class = ( $field =~ /^<TABLE/i ) ? 'inv' : 'grid';
501 % my $class = 'grid';
503 % my $align = $aligns ? shift @$aligns : '';
504 % $align = " ALIGN=$align" if $align;
508 % my $link = shift @$links;
509 % my $onclick = shift @$onclicks;
510 % my $tooltip = shift @$tooltips;
512 % if ( ! $opt{'agent_virt'}
513 % || ( $opt{'null_link'} && ! $row->agentnum )
514 % || grep { $row->agentnum == $_ }
515 % @{ $opt{link_agentnums} }
518 % $link = &{$link}($row)
519 % if ref($link) eq 'CODE';
521 % $onclick = &{$onclick}($row)
522 % if ref($onclick) eq 'CODE';
523 % $onclick = qq( onClick="$onclick") if $onclick;
525 % $tooltip = &{$tooltip}($row)
526 % if ref($tooltip) eq 'CODE';
527 % $tooltip = qq! id="a$id" !.
528 % qq! onmouseover="return overlib(!.
529 % $m->interp->apply_escapes($tooltip, 'h', 'js_string').
530 % qq!, FGCLASS, 'tooltip', REF, 'a$id', !.
531 % qq!REFC, 'LL', REFP, 'UL')"! if $tooltip;
534 % my( $url, $method ) = @{$link};
535 % if ( ref($method) eq 'CODE' ) {
536 % $a = $url. &{$method}($row);
538 % $a = $url. $row->$method();
540 % $a = qq(<A HREF="$a"$onclick$tooltip>);
542 % elsif ( $onclick ) {
543 % $a = qq(<A HREF="javascript:void(0);"$onclick>);
545 % elsif ( $tooltip ) {
546 % $a = qq(<A $tooltip>);
555 % my $color = shift @$colors;
556 % $color = &{$color}($row) if ref($color) eq 'CODE';
557 % my $size = shift @$sizes;
558 % $size = &{$size}($row) if ref($size) eq 'CODE';
559 % if ( $color || $size ) {
561 % ( $color ? "COLOR=#$color " : '' ).
562 % ( $size ? qq(SIZE="$size" ) : '' ).
566 % my($s, $es) = ( '', '' );
567 % my $style = shift @$styles;
568 % $style = &{$style}($row) if ref($style) eq 'CODE';
570 % $s = join( '', map "<$_>", split('', $style) );
571 % $es = join( '', map "</$_>", split('', $style) );
574 % my $cstyle = shift @$cstyles;
575 % $cstyle = &{$cstyle}($row) if ref($cstyle) eq 'CODE';
576 % $cstyle = qq(STYLE="$cstyle")
579 <TD CLASS="<% $class %>" <% $align %> <% $cstyle %>><% $a %><% $font %><% $s %><% $field %><% $es %><% $font ? '</FONT>' : '' %><% $a ? '</A>' : '' %></TD>
583 % } else { # not $opt{'fields'}
585 % foreach ( @$row ) {
586 <TD CLASS="grid"><% $_ %></TD>
602 %# don't try to respect all the styling options, just the ones that are
603 %# hard to replicate with CSS
611 % if ( $opt{align} and !ref($opt{align}) ) {
612 % $opt{align} = [ map $align{$_}, split(//, $opt{align}) ];
614 % my @aligns = @{ $opt{align} };
617 % foreach my $footer ( @$row ) {
618 % $footer = &{$footer}() if ref($footer) eq 'CODE';
619 % my $align = shift @aligns;
621 % $style .= "text-align: $align;" if $align;
622 <TD CLASS="grid" STYLE="<% $style %>"><% $footer %></TD>