event refactor, landing on HEAD!
[freeside.git] / httemplate / search / elements / search.html
1 %  # options example...  
2 %  # (everything not commented required is optional)
3 %  #
4 %  # # basic options, required
5 %  # 'title'         => 'Page title',
6 %  # 
7 %  # 'name_singular' => 'item',  #singular name for the records returned
8 %  #    #OR#                     # (preferred, will be pluralized automatically)
9 %  # 'name'          => 'items', #plural name for the records returned
10 %  #                             # (deprecated, will be singularlized
11 %  #                             #  simplisticly)
12 %  #
13 %  # # some HTML callbacks...
14 %  # 'menubar'          => '', #menubar arrayref
15 %  # 'html_init'        => '', #after the header/menubar and before the pager
16 %  # 'html_form'        => '', #after the pager, right before the results
17 %  #                           # (only shown if there are results)
18 %  #                           # (use this for any form-opening tag rather than
19 %  #                           #  html_init, to avoid a nested form)
20 %  # 'html_foot'        => '', #at the bottom
21 %  # 'html_posttotal'   => '', #at the bottom
22 %  #                           # (these three can be strings or coderefs)
23 %  # 
24 %  #
25 %  # #literal SQL query string or qsearch hashref, required
26 %  # 'query'       => {
27 %  #                    'table'     => 'tablename',
28 %  #                    #everything else is optional...
29 %  #                    'hashref'   => { 'field' => 'value',
30 %  #                                     'field' => { 'op'    => '<',
31 %  #                                                  'value' => '54',
32 %  #                                                },
33 %  #                                   },
34 %  #                    'select'    => '*',
35 %  #                    'addl_from' => '', #'LEFT JOIN othertable USING ( key )',
36 %  #                    'extra_sql' => '', #'AND otherstuff', #'WHERE onlystuff',
37 %  #                    'order_by'  => 'ORDER BY something',
38 %  #
39 %  #                  },
40 %  #                  # "select * from tablename";
41 %  #
42 %  # #required unless 'query' is an SQL query string (shouldn't be...)
43 %  # 'count_query' => 'SELECT COUNT(*) FROM tablename',
44 %  #
45 %  # 'count_addl' => [], #additional count fields listref of sprintf strings
46 %  #                     # [ $money_char.'%.2f total paid', ],
47 %  #
48 %  # #listref of column labels, <TH>
49 %  # #required unless 'query' is an SQL query string
50 %  # # (if not specified the database column names will be used)
51 %  # 'header'      => [ '#', 'Item' ],
52 %  #
53 %  # 'disable_download' => '', # set true to hide the CSV/Excel download links
54 %  # 'disable_nonefound' => '', # set true to disable the "No matching Xs found"
55 %  #                            # message
56 %  #
57 %  # 'disableable' => 1,  # set true if this table has a "disabled" field, to
58 %  #                      # hide disabled records & have "show disabled" links
59 %  # 'disabled_statuspos' => 3, #optional position (starting from 0) to insert
60 %  #                            #a Status column when showing disabled records
61 %  #                            #(query needs to be a qsearch hashref and
62 %  #                            # header & fields need to be defined)
63
64 %  # 'agent_virt' => 1, # set true if this search should be agent-virtualized
65 %  # 'agent_null_right' => 'Access Right', #opt. right to view global records
66 %  # 'agent_pos' => 3, #optional position (starting from 0) to insert
67 %  #                   #an Agent column 
68 %  #                   #(query needs to be a qsearch hashref and
69 %  #                   # header & fields need to be defined)
70 %  #
71 %  # #listref - each item is a literal column name (or method) or coderef
72 %  # #if not specified all columns will be shown
73 %  # 'fields'      => [
74 %  #                    'column',
75 %  #                    sub { my $row = shift; $row->column; },
76 %  #                  ],
77 %  #
78 %  # #listref of column footers
79 %  # 'footer'      => [],
80 %  # 
81 %  # #listref - each item is the empty string, or a listref of ...
82 %  # 'links'       =>
83 %  #
84 %  #
85 %  # 'align'       => 'lrc.', #one letter for each column, left/right/center/none
86 %  #                          # can also pass a listref with full values:
87 %  #                          # [ 'left', 'right', 'center', '' ]
88 %  #
89 %  # #listrefs...
90 %  # #currently only HTML, maybe eventually Excel too
91 %  # 'color'       => [],
92 %  # 'size'        => [],
93 %  # 'style'       => [],
94 %  # 
95 %  # #redirect if there's only one item...
96 %  # # listref of URL base and column name (or method)
97 %  # # or a coderef that returns the same
98 %  # 'redirect' =>
99 %  #
100 %  # #set to 1 (or column position for "disabled" status col) to enable
101 %  # #"show disabled/hide disabled" links
102 %  # #(can't be used with a literal query)
103 %  # 'disableable' => 1,
104 %
105 %  my(%opt) = @_;
106 %  #warn join(' / ', map { "$_ => $opt{$_}" } keys %opt ). "\n";
107 %
108 %  my $curuser = $FS::CurrentUser::CurrentUser;
109 %
110 %  my %align = (
111 %    'l' => 'left',
112 %    'r' => 'right',
113 %    'c' => 'center',
114 %    ' ' => '',
115 %    '.' => '',
116 %  );
117 %  $opt{align} = [ map $align{$_}, split(//, $opt{align}) ],
118 %    unless !$opt{align} || ref($opt{align});
119 %
120 %  if ( $opt{'agent_virt'} ) {
121 %
122 %    my $agentnums_sql = $curuser->agentnums_sql(
123 %                          'null_right' => $opt{'agent_null_right'}
124 %                        );
125 %
126 %    $opt{'query'}{'extra_sql'} .=
127 %      ( $opt{'query'}       =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
128 %      $agentnums_sql;
129 %    $opt{'count_query'} .=
130 %      ( $opt{'count_query'} =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
131 %      $agentnums_sql;
132 %
133 %    if ( $opt{'agent_pos'} || $opt{'agent_pos'} eq '0'
134 %         and scalar($curuser->agentnums) > 1           ) {
135 %      #false laziness w/statuspos above
136 %      my $pos = $opt{'agent_pos'};
137 %
138 %      foreach my $att (qw( align style color size )) {
139 %        $opt{$att} ||= [ map '', @{ $opt{'fields'} } ];
140 %      }
141 %
142 %      splice @{ $opt{'header'} }, $pos, 0, 'Agent'; 
143 %      splice @{ $opt{'align'}  }, $pos, 0, 'c'; 
144 %      splice @{ $opt{'style'}  }, $pos, 0, ''; 
145 %      splice @{ $opt{'size'}   }, $pos, 0, ''; 
146 %      splice @{ $opt{'fields'} }, $pos, 0,
147 %        sub { $_[0]->agentnum ? $_[0]->agent->agent : '(global)'; };
148 %      splice @{ $opt{'color'}  }, $pos, 0, '';
149 %      splice @{ $opt{'links'}  }, $pos, 0, '' #[ 'agent link?', 'agentnum' ]
150 %        if $opt{'links'};
151 %
152 %    }
153 %
154 %  }
155 %
156 %  if ( $opt{'disableable'} ) {
157 %  
158 %    unless ( $cgi->param('showdisabled') ) { #modify searches
159 %  
160 %      $opt{'query'}{'hashref'}{'disabled'} = '';
161 %      $opt{'query'}{'extra_sql'} =~ s/^\s*WHERE/ AND/i;
162 %  
163 %      $opt{'count_query'} .=
164 %        ( $opt{'count_query'} =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
165 %        "( disabled = '' OR disabled IS NULL )";
166 %
167 %    } elsif (    $opt{'disabled_statuspos'}
168 %              || $opt{'disabled_statuspos'} eq '0' ) { #add status column
169 %
170 %      my $pos = $opt{'disabled_statuspos'};
171 %
172 %      foreach my $att (qw( align style color size )) {
173 %        $opt{$att} ||= [ map '', @{ $opt{'fields'} } ];
174 %      }
175 %
176 %      splice @{ $opt{'header'} }, $pos, 0, 'Status'; 
177 %      splice @{ $opt{'align'}  }, $pos, 0, 'c'; 
178 %      splice @{ $opt{'style'}  }, $pos, 0, 'b'; 
179 %      splice @{ $opt{'size'}   }, $pos, 0, ''; 
180 %      splice @{ $opt{'fields'} }, $pos, 0,
181 %        sub { shift->disabled ? 'DISABLED' : 'Active'; };
182 %      splice @{ $opt{'color'}  }, $pos, 0,
183 %        sub { shift->disabled ? 'FF0000'   : '00CC00'; };
184 %      splice @{ $opt{'links'}  }, $pos, 0, ''
185 %        if $opt{'links'};
186 %    }
187 %  
188 %    #add show/hide disabled links
189 %    my $items = $opt{'name'} || PL($opt{'name_singular'});
190 %    if ( $cgi->param('showdisabled') ) {
191 %      $cgi->param('showdisabled', 0);
192 %      $opt{'html_posttotal'} .=
193 %        '( <a href="'. $cgi->self_url. qq!">hide disabled $items</a> )!;
194 %      $cgi->param('showdisabled', 1);
195 %    } else {
196 %      $cgi->param('showdisabled', 1);
197 %      $opt{'html_posttotal'} .=
198 %        '( <a href="'. $cgi->self_url. qq!">show disabled $items</a> )!;
199 %      $cgi->param('showdisabled', 0);
200 %    }
201 %  
202 %  }
203 %
204 %  my $type = '';
205 %  my $limit = '';
206 %  my($confmax, $maxrecords, $total, $offset, $count_arrayref);
207 %
208 %  if ( $cgi->param('_type') =~ /^(csv|\w*\.xls)$/ ) {
209 %  
210 %    $type = $1;
211 %
212 %  } else { #setup some pagination things if we're in html mode
213 %
214 %    unless (exists($opt{count_query}) && length($opt{count_query})) {
215 %      ( $opt{count_query} = $opt{query} ) =~
216 %        s/^\s*SELECT\s*(.*?)\s+FROM\s/SELECT COUNT(*) FROM /i; #silly vim:/
217 %    }
218 %
219 %    if ( $opt{disableable} && ! $cgi->param('showdisabled') ) {
220 %      $opt{count_query} .=
221 %        ( ( $opt{count_query} =~ /WHERE/i ) ? ' AND ' : ' WHERE ' ).
222 %        "( disabled = '' OR disabled IS NULL )";
223 %    }
224 %
225 %    my $conf = new FS::Conf;
226 %    $confmax = $conf->config('maxsearchrecordsperpage');
227 %    if ( $cgi->param('maxrecords') =~ /^(\d+)$/ ) {
228 %      $maxrecords = $1;
229 %    } else {
230 %      $maxrecords ||= $confmax;
231 %    }
232 %
233 %    $limit = $maxrecords ? "LIMIT $maxrecords" : '';
234 %
235 %    $offset = $cgi->param('offset') || 0;
236 %    $limit .= " OFFSET $offset" if $offset;
237 %
238 %    my $count_sth = dbh->prepare($opt{'count_query'})
239 %      or die "Error preparing $opt{'count_query'}: ". dbh->errstr;
240 %    $count_sth->execute
241 %      or die "Error executing $opt{'count_query'}: ". $count_sth->errstr;
242 %    $count_arrayref = $count_sth->fetchrow_arrayref;
243 %    $total = $count_arrayref->[0];
244 %
245 %  }
246 %
247 %  # run the query
248 %
249 %  my $header = $opt{header};
250 %  my $rows;
251 %  if ( ref($opt{query}) ) {
252 %
253 %    if ( $opt{disableable} && ! $cgi->param('showdisabled') ) {
254 %      #%search = ( 'disabled' => '' );
255 %      $opt{'query'}->{'hashref'}->{'disabled'} = '';
256 %      $opt{'query'}->{'extra_sql'} =~ s/^\s*WHERE/ AND/i;
257 %    }
258 %
259 %    #eval "use FS::$opt{'query'};";
260 %    $rows = [ qsearch({
261 %      'select'    => $opt{'query'}->{'select'},
262 %      'table'     => $opt{'query'}->{'table'}, 
263 %      'addl_from' => (exists($opt{'query'}->{'addl_from'}) ? $opt{'query'}->{'addl_from'} : ''),
264 %      'hashref'   => $opt{'query'}->{'hashref'} || {}, 
265 %      'extra_sql' => $opt{'query'}->{'extra_sql'},
266 %      'order_by'  => $opt{'query'}->{'order_by'}. " $limit",
267 %    }) ];
268 %  } else {
269 %    my $sth = dbh->prepare("$opt{'query'} $limit")
270 %      or die "Error preparing $opt{'query'}: ". dbh->errstr;
271 %    $sth->execute
272 %      or die "Error executing $opt{'query'}: ". $sth->errstr;
273 %
274 %    #can get # of rows without fetching them all?
275 %    $rows = $sth->fetchall_arrayref;
276 %
277 %    $header ||= $sth->{NAME};
278 %  }
279 %
280 %  if ( $type eq 'csv' ) {
281 %
282 %    #http_header('Content-Type' => 'text/comma-separated-values' ); #IE chokes
283 %    http_header('Content-Type' => 'text/plain' );
284 %
285 %    my $csv = new Text::CSV_XS { 'always_quote' => 1,
286 %                                 'eol'          => "\n", #"\015\012", #"\012"
287 %                               };
288 %
289 %    $csv->combine(@$header); #or die $csv->status;
290 %    
291 <% $csv->string %>
292 %
293 %
294 %    foreach my $row ( @$rows ) {
295 %
296 %      if ( $opt{'fields'} ) {
297 %
298 %        my @line = ();
299 %
300 %        foreach my $field ( @{$opt{'fields'}} ) {
301 %          if ( ref($field) eq 'CODE' ) {
302 %            push @line, map {
303 %                              ref($_) eq 'ARRAY'
304 %                                ? '(N/A)' #unimplemented
305 %                                : $_;
306 %                            }
307 %                            &{$field}($row);
308 %          } else {
309 %            push @line, $row->$field();
310 %          }
311 %        }
312 %
313 %        $csv->combine(@line); #or die $csv->status;
314 %
315 %      } else {
316 %        $csv->combine(@$row); #or die $csv->status;
317 %      }
318 %
319 %      
320 <% $csv->string %>
321 %
322 %
323 %    }
324 %
325 %  #} elsif ( $type eq 'excel' ) {
326 %  } elsif ( $type =~ /\.xls$/ ) {
327 %
328 %    #http_header('Content-Type' => 'application/excel' ); #eww
329 %    http_header('Content-Type' => 'application/vnd.ms-excel' );
330 %    #http_header('Content-Type' => 'application/msexcel' ); #alas
331 %
332 %    my $data = '';
333 %    my $XLS = new IO::Scalar \$data;
334 %    my $workbook = Spreadsheet::WriteExcel->new($XLS)
335 %      or die "Error opening .xls file: $!";
336 %
337 %    my $worksheet = $workbook->add_worksheet(substr($opt{'title'},0,31));
338 %
339 %    my($r,$c) = (0,0);
340 %
341 %    $worksheet->write($r, $c++, $_) foreach @$header;
342 %
343 %    foreach my $row ( @$rows ) {
344 %      $r++;
345 %      $c = 0;
346 %
347 %      if ( $opt{'fields'} ) {
348 %
349 %        #my $links = $opt{'links'} ? [ @{$opt{'links'}} ] : '';
350 %        #my $aligns = $opt{'align'} ? [ @{$opt{'align'}} ] : '';
351 %
352 %        foreach my $field ( @{$opt{'fields'}} ) {
353 %          #my $align = $aligns ? shift @$aligns : '';
354 %          #$align = " ALIGN=$align" if $align;
355 %          #my $a = '';
356 %          #if ( $links ) {
357 %          #  my $link = shift @$links;
358 %          #  $link = &{$link}($row) if ref($link) eq 'CODE';
359 %          #  if ( $link ) {
360 %          #    my( $url, $method ) = @{$link};
361 %          #    if ( ref($method) eq 'CODE' ) {
362 %          #      $a = $url. &{$method}($row);
363 %          #    } else {
364 %          #      $a = $url. $row->$method();
365 %          #    }
366 %          #    $a = qq(<A HREF="$a">);
367 %          #  }
368 %          #}
369 %          if ( ref($field) eq 'CODE' ) {
370 %            foreach my $value ( &{$field}($row) ) {
371 %              if ( ref($value) eq 'ARRAY' ) { 
372 %                $worksheet->write($r, $c++, '(N/A)' ); #unimplemented
373 %              } else {
374 %                $worksheet->write($r, $c++, $value );
375 %              }
376 %            }
377 %          } else {
378 %            $worksheet->write($r, $c++, $row->$field() );
379 %          }
380 %        }
381 %
382 %      } else {
383 %        $worksheet->write($r, $c++, $_) foreach @$row;
384 %      }
385 %
386 %    }
387 %
388 %    $workbook->close();# or die "Error creating .xls file: $!";
389 %
390 %    http_header('Content-Length' => length($data) );
391 %    
392 <% $data %>
393 %
394 %
395 %  } else { # regular HTML
396 %
397 %    if ( exists($opt{'redirect'}) && scalar(@$rows) == 1 && $total == 1 ) {
398 %      my $redirect = $opt{'redirect'};
399 %      $redirect = &{$redirect}($rows->[0]) if ref($redirect) eq 'CODE';
400 %      my( $url, $method ) = @$redirect;
401 %      redirect( $url. $rows->[0]->$method() );
402 %    } else {
403 %      if ( $opt{'name_singular'} ) {
404 %        $opt{'name'} = PL($opt{'name_singular'});
405 %      }
406 %      ( my $xlsname = $opt{'name'} ) =~ s/\W//g;
407 %      if ( $total == 1 ) {
408 %        if ( $opt{'name_singular'} ) {
409 %          $opt{'name'} = $opt{'name_singular'}
410 %        } else {
411 %          #$opt{'name'} =~ s/s$// if $total == 1;
412 %          $opt{'name'} =~ s/((s)e)?s$/$2/ if $total == 1;
413 %        }
414 %      }                                               
415 %
416 %      my @menubar = ();
417 %      if ( $opt{'menubar'} ) {
418 %        @menubar = @{ $opt{'menubar'} };
419 %      #} else {
420 %      #  @menubar = ( 'Main menu' => $p );
421 %      }
422
423   <% include( '/elements/header.html', $opt{'title'},
424                  include( '/elements/menubar.html', @menubar )
425              )
426   %>
427   <% defined($opt{'html_init'}) 
428         ? ( ref($opt{'html_init'})
429               ? &{$opt{'html_init'}}()
430               : $opt{'html_init'}
431           )
432         : ''
433   %>
434 %  
435 % unless ( $total ) { 
436 % unless ( $opt{'disable_nonefound'} ) { 
437
438       No matching <% $opt{'name'} %> found.<BR>
439 % } 
440 % } else { 
441
442     <TABLE>
443       <TR>
444
445         <TD VALIGN="bottom">
446
447           <FORM>
448
449           <% $total %> total <% $opt{'name'} %>
450
451 %         if ( $confmax && $total > $confmax ) {
452 %           $cgi->delete('maxrecords');
453 %           $cgi->param('_dummy', 1);
454
455 %#           ( show <SELECT NAME="maxrecords" onChange="this.form.submit();">
456             ( show <SELECT NAME="maxrecords" onChange="window.location = '<% $cgi->self_url %>;maxrecords=' + this.options[this.selectedIndex].value;">
457
458 %             foreach my $max ( map { $_ * $confmax } qw( 1 5 10 25 ) ) {
459                 <OPTION VALUE="<% $max %>" <% ( $maxrecords == $max ) ? 'SELECTED' : '' %>><% $max %></OPTION>
460 %             }
461
462             </SELECT> per page )
463
464 %           $cgi->param('maxrecords', $maxrecords);
465 %         }
466
467           <% defined($opt{'html_posttotal'}) 
468                 ? ( ref($opt{'html_posttotal'})
469                       ? &{$opt{'html_posttotal'}}()
470                       : $opt{'html_posttotal'}
471                   )
472                 : ''
473           %>
474           <BR>
475
476 % if ( $opt{'count_addl'} ) { 
477 %   my $n=0; foreach my $count ( @{$opt{'count_addl'}} ) { 
478
479       <% sprintf( $count, $count_arrayref->[++$n] ) %><BR>
480
481 %   } 
482 % } 
483           </FORM>
484
485         </TD>
486
487 % unless ( $opt{'disable_download'} ) { 
488
489           <TD ALIGN="right">
490 % $cgi->param('_type', "$xlsname.xls" ); 
491
492             Download full results<BR>
493             as <A HREF="<% $cgi->self_url %>">Excel spreadsheet</A><BR>
494 % $cgi->param('_type', 'csv'); 
495
496             as <A HREF="<% $cgi->self_url %>">CSV file</A>
497           </TD>
498 % $cgi->param('_type', "html" ); 
499 % } 
500
501       </TR>
502       <TR>
503         <TD COLSPAN=2>
504
505             <% my $pager = include ( '/elements/pager.html',
506                            'offset'     => $offset,
507                            'num_rows'   => scalar(@$rows),
508                            'total'      => $total,
509                            'maxrecords' => $maxrecords,
510             ) %>
511
512             <% defined($opt{'html_form'}) 
513                  ? ( ref($opt{'html_form'})
514                        ? &{$opt{'html_form'}}()
515                        : $opt{'html_form'}
516                    )
517                  : ''
518             %>
519
520             <% include('/elements/table-grid.html') %>
521
522               <TR>
523
524 %                 foreach my $header ( @$header ) { 
525
526                    <TH CLASS="grid" BGCOLOR="#cccccc"><% $header %></TH>
527 % } 
528
529               </TR>
530 % my $bgcolor1 = '#eeeeee';
531 %                 my $bgcolor2 = '#ffffff';
532 %                 my $bgcolor;
533 %                 foreach my $row ( @$rows ) {
534 %                   if ( $bgcolor eq $bgcolor1 ) {
535 %                     $bgcolor = $bgcolor2;
536 %                   } else {
537 %                     $bgcolor = $bgcolor1;
538 %                   }
539 %              
540
541                    <TR>
542 % if ( $opt{'fields'} ) {
543 %
544 %                        my $links  = $opt{'links'} ? [ @{$opt{'links'}} ] : '';
545 %                        my $aligns = $opt{'align'} ? [ @{$opt{'align'}} ] : '';
546 %                        my $colors = $opt{'color'} ? [ @{$opt{'color'}} ] : [];
547 %                        my $sizes  = $opt{'size'}  ? [ @{$opt{'size'}}  ] : [];
548 %                        my $styles = $opt{'style'} ? [ @{$opt{'style'}} ] : [];
549 %
550 %                        foreach my $field (
551 %
552 %                          map {
553 %                                if ( ref($_) eq 'ARRAY' ) {
554 %
555 %                                  my $tableref = $_;
556 %
557 %                                  '<TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0 WIDTH="100%">'.
558 %
559 %                                  join('', map {
560 %
561 %                                    my $rowref = $_;
562 %
563 %                                    '<tr>'.
564 %
565 %                                    join('', map {
566 %
567 %                                      my $e = $_;
568 %
569 %                                      '<TD '.
570 %                                        join(' ', map {
571 %                                          uc($_).'="'. $e->{$_}. '"';
572 %                                        }
573 %                                        grep exists($e->{$_}),
574 %                                             qw( align bgcolor colspan rowspan
575 %                                                 style valign width )
576 %                                        ).
577 %                                      '>'.
578 %
579 %                                      ( $e->{'link'}
580 %                                          ? '<A HREF="'. $e->{'link'}. '">'
581 %                                          : ''
582 %                                      ).
583 %                                      ( $e->{'size'}
584 %                                         ? '<FONT SIZE="'.uc($e->{'size'}).'">'
585 %                                         : ''
586 %                                      ).
587 %                                      ( $e->{'data_style'}
588 %                                          ? '<'. uc($e->{'data_style'}). '>'
589 %                                          : ''
590 %                                      ).
591 %                                      $e->{'data'}.
592 %                                      ( $e->{'data_style'}
593 %                                          ? '</'. uc($e->{'data_style'}). '>'
594 %                                          : ''
595 %                                      ).
596 %                                      ( $e->{'size'} ? '</FONT>' : '' ).
597 %                                      ( $e->{'link'} ? '</A>'    : '' ).
598 %                                      '</td>';
599 %
600 %                                    } @$rowref ).
601 %
602 %                                    '</tr>';
603 %                                  } @$tableref ).
604 %
605 %                                  '</table>';
606 %
607 %                                } else {
608 %                                  $_;
609 %                                }
610 %                              }
611 %
612 %                          map {
613 %                                if ( ref($_) eq 'CODE' ) {
614 %                                  &{$_}($row);
615 %                                } else {
616 %                                  $row->$_();
617 %                                }
618 %                              }
619 %                          @{$opt{'fields'}}
620 %
621 %                        ) {
622 %
623 %                          my $class = ( $field =~ /^<TABLE/i ) ? 'inv' : 'grid';
624 %
625 %                          my $align = $aligns ? shift @$aligns : '';
626 %                          $align = " ALIGN=$align" if $align;
627 %
628 %                          my $a = '';
629 %                          if ( $links ) {
630 %                            my $link = shift @$links;
631 %                            $link = &{$link}($row) if ref($link) eq 'CODE';
632 %                            if ( $link ) {
633 %                              my( $url, $method ) = @{$link};
634 %                              if ( ref($method) eq 'CODE' ) {
635 %                                $a = $url. &{$method}($row);
636 %                              } else {
637 %                                $a = $url. $row->$method();
638 %                              }
639 %                              $a = qq(<A HREF="$a">);
640 %                            }
641 %                          }
642 %
643 %                          my $font = '';
644 %                          my $color = shift @$colors;
645 %                          $color = &{$color}($row) if ref($color) eq 'CODE';
646 %                          my $size = shift @$sizes;
647 %                          $size = &{$size}($row) if ref($size) eq 'CODE';
648 %                          if ( $color || $size ) {
649 %                            $font = '<FONT '.
650 %                                    ( $color ? "COLOR=#$color "   : '' ).
651 %                                    ( $size  ? qq(SIZE="$size" )  : '' ).
652 %                                    '>';
653 %                          }
654 %
655 %                          my($s, $es) = ( '', '' );
656 %                          my $style = shift @$styles;
657 %                          $style = &{$style}($row) if ref($style) eq 'CODE';
658 %                          if ( $style ) {
659 %                            $s = join( '', map "<$_>", split('', $style) );
660 %                            $es = join( '', map "</$_>", split('', $style) );
661 %                          }
662 %
663 %                       
664
665                        <TD CLASS="<% $class %>" BGCOLOR="<% $bgcolor %>"<% $align %>><% $font %><% $a %><% $s %><% $field %><% $es %><% $a ? '</A>' : '' %><% $font ? '</FONT>' : '' %></TD>
666 % } 
667 % } else { 
668 % foreach ( @$row ) { 
669
670                           <TD CLASS="grid" BGCOLOR="$bgcolor"><% $_ %></TD>
671 % } 
672 % } 
673
674                    </TR>
675 % } 
676 % if ( $opt{'footer'} ) { 
677
678                 <TR>
679 % foreach my $footer ( @{ $opt{'footer'} } ) { 
680
681                      <TD CLASS="grid" BGCOLOR="#dddddd" STYLE="border-top: dashed 1px black;"><i><% $footer %></i></TH>
682 % } 
683
684                 </TR>
685 % } 
686
687             
688             </TABLE>
689             <% $pager %>
690   
691           </TD>
692         </TR>
693       </TABLE>
694 % } 
695
696   <% defined($opt{'html_foot'}) 
697         ? ( ref($opt{'html_foot'})
698               ? &{$opt{'html_foot'}}()
699               : $opt{'html_foot'}
700           )
701         : ''
702   %>
703   <% include( '/elements/footer.html' ) %>
704 % } 
705 % }