| 1 | package CGI::OptimalQuery::SimpleQuery; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | no warnings qw( uninitialized ); | ||
| 6 | use base 'CGI::OptimalQuery::Base'; | ||
| 7 | |||
| 8 | sub escapeHTML { CGI::OptimalQuery::Base::escapeHTML(@_) } | ||
| 9 | |||
| 10 | sub output { | ||
| 11 | my ($o) = @_; | ||
| 12 | |||
| 13 | my $tbody; | ||
| 14 | my $typeMap = $o->{oq}->get_col_types('select'); | ||
| 15 | while (my $r = $o->fetch()) { | ||
| 16 | $tbody .= "<tr data-uid='".escapeHTML($$r{U_ID})."'>"; | ||
| 17 | |||
| 18 | foreach my $col (@{ $o->get_usersel_cols }) { | ||
| 19 | my $val = $o->get_html_val($col); | ||
| 20 | my $type = $$typeMap{$col} || 'char'; | ||
| 21 | $tbody .= "<td".(($type ne 'char')?" class=$type":"").">$val</td>"; | ||
| 22 | } | ||
| 23 | $tbody .= "</tr>\n"; | ||
| 24 | } | ||
| 25 | $o->finish(); | ||
| 26 | |||
| 27 | my $buf = $$o{httpHeader}->(-type=>'text/html',-expires=>'now')."<!DOCTYPE html>\n<html>\n<body>"; | ||
| 28 | |||
| 29 | if ($tbody) { | ||
| 30 | $buf .= "<table class=grid><thead><tr>\n"; | ||
| 31 | |||
| 32 | foreach my $colAlias (@{ $o->get_usersel_cols }) { | ||
| 33 | my $colOpts = $$o{schema}{select}{$colAlias}[3]; | ||
| 34 | $buf .= "<td data-col='".escapeHTML($colAlias)."'"; | ||
| 35 | $buf .= ">".escapeHTML($o->get_nice_name($colAlias))."</td>"; | ||
| 36 | } | ||
| 37 | $buf .= "\n</tr></thead><tbody>\n$tbody</tbody></table>"; | ||
| 38 | } | ||
| 39 | else { | ||
| 40 | $buf .= "<em>none found</em>"; | ||
| 41 | } | ||
| 42 | |||
| 43 | $buf .= "</body></html>"; | ||
| 44 | |||
| 45 | $$o{output_handler}->($buf); | ||
| 46 | return undef; | ||
| 47 | } | ||
| 48 | |||
| 49 | 1; |