[AppWrap-cvs] AppWrap/Apache/AppWrap Search.pm,1.5,1.6
Status: Beta
Brought to you by:
planetman
From: <pla...@us...> - 2002-12-30 09:27:02
|
Update of /cvsroot/appwrap/AppWrap/Apache/AppWrap In directory sc8-pr-cvs1:/tmp/cvs-serv11882 Modified Files: Search.pm Log Message: i18n recoding Index: Search.pm =================================================================== RCS file: /cvsroot/appwrap/AppWrap/Apache/AppWrap/Search.pm,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Search.pm 10 Dec 2002 07:03:57 -0000 1.5 --- Search.pm 30 Dec 2002 09:26:59 -0000 1.6 *************** *** 16,24 **** use Apache::Util (); ! use Apache::AppWrap::Subs qw($HNL); use AppWrap qw(%config); use vars qw($VERSION); ! $Apache::AppWrap::Search::VERSION = '0.02'; # 10Dec02. CSS, warnings pragma. --- 16,25 ---- use Apache::Util (); ! use Apache::AppWrap::Subs qw($dbh $HNL); use AppWrap qw(%config); use vars qw($VERSION); ! $Apache::AppWrap::Search::VERSION = '0.04'; ! # 28Dec02. i18n # 10Dec02. CSS, warnings pragma. *************** *** 30,33 **** --- 31,38 ---- my $my_defaults = $opts->{my_defaults}; + my %args = ( + 'caller' => 'search', + ); + # store output in @rows; my (@rows, $results); *************** *** 48,52 **** } # body of search results ! my $ref = &search_results($opts); push @rows, join("", @$ref) if $ref && scalar(@$ref); --- 53,57 ---- } # body of search results ! my $ref = search_results($opts); push @rows, join("", @$ref) if $ref && scalar(@$ref); *************** *** 56,67 **** # try it as a string my $unpacked = eval $eval; ! $opts->{Title} = 'Search Results for <br />' . $unpacked; } else { # Args were not present so run the default code to display the # key_type popup menus ! my $rows = &search_form($opts); push @rows, join("", @$rows) if $rows && scalar(@$rows); ! $opts->{Title} = 'Search this Site'; } --- 61,78 ---- # try it as a string my $unpacked = eval $eval; ! unless ($unpacked) { ! } ! $args{'caller'} = 'search_results'; ! $args{element} = 'title'; ! my $text = Apache::AppWrap::Subs::chk_txt($opts, \%args); ! $opts->{Title} = $text . '<br />' . $unpacked; } else { # Args were not present so run the default code to display the # key_type popup menus ! my $rows = search_form($opts); push @rows, join("", @$rows) if $rows && scalar(@$rows); ! $args{element} = 'title'; ! $opts->{Title} = Apache::AppWrap::Subs::chk_txt($opts, \%args); } *************** *** 129,136 **** my $my_tables = $opts->{my_tables}; my $my_columns = $opts->{my_columns}; ! my $log = Apache->request->log; my @rows; # get all values of 'key_type', excluding 'idnum' my (@key_types, $test); # $test = join(", ", @$valid_tables); --- 140,149 ---- my $my_tables = $opts->{my_tables}; my $my_columns = $opts->{my_columns}; ! my $r = Apache->request; ! my $log = $r->log; my @rows; # get all values of 'key_type', excluding 'idnum' my (@key_types, $test); + my %args; # $test = join(", ", @$valid_tables); *************** *** 145,159 **** } ! #start the <div> ! push @rows, '<div id="pager">' . $HNL; ! # start a table for holding this whole bot ! my $display = ' <table border="1" width="95%" align="center"'; ! $display .= ' class="vbar">' . $HNL; ! push @rows, $display; ! $display = ' <tr valign="bottom">' . $HNL; ! $display .= ' <th align="center">Search</th>' . $HNL; ! $display .= ' </tr>' . $HNL; ! push @rows, $display; # this loop generates a popup menu and form for each key_type --- 158,174 ---- } ! #start the <div> ! push @rows, '<div id="pager">' . $HNL; ! # start a table for holding this whole bit ! my $display = ' <table>'; ! push @rows, $display . $HNL; ! ! # get another label ! $args{'caller'} = 'search'; ! $args{element} = 'title'; ! my $label = Apache::AppWrap::Subs::chk_txt($opts, \%args); ! $display = qq{<tr><th>$label</th></tr>}; ! push @rows, '' . $display . $HNL; # this loop generates a popup menu and form for each key_type *************** *** 162,165 **** --- 177,186 ---- $opts->{column} = 'key_value'; my $eval_sub = $my_tables->{$tablename}{search}; + unless ($eval_sub) { + my $msg = 'Search::search_form: no defined'; + $msg .= qq{ my_tables->{$tablename}{search} function}; + $r->log_error($msg); + return SERVER_ERROR; + } $display = eval $eval_sub; if ($display) { *************** *** 167,171 **** # skip 'idnum's my $label = $my_tables->{$tablename}{label}; ! my $text = ' <tr valign="top">'; $text .= '<td align="left">' . $label; push @rows, $text; --- 188,192 ---- # skip 'idnum's my $label = $my_tables->{$tablename}{label}; ! my $text = ' <tr valign="top">'; $text .= '<td align="left">' . $label; push @rows, $text; *************** *** 178,182 **** push @rows, $text; ! $text = ' <input type="hidden" name="key_type" value="'; $text .= $key_type . '" />' . $HNL; push @rows, $text; --- 199,203 ---- push @rows, $text; ! $text = ' <input type="hidden" name="key_type" value="'; $text .= $key_type . '" />' . $HNL; push @rows, $text; *************** *** 184,201 **** push @rows, join("", @$display) if scalar(@$display); ! $text = '<input type="submit" name="submit" value="Go" />' . $HNL; ! push @rows, $text; ! $text = ' </form>' . $HNL; ! $text .= ' </td>' . $HNL; ! $text .= ' </tr>' . $HNL; push @rows, $text; } } # end %key_data loop ! push @rows, ' </table>' . $HNL; #close the <div> push @rows, '</div>' . $HNL; - # push @rows, ' <br />' . $HNL; return \@rows; } # end search_form --- 205,222 ---- push @rows, join("", @$display) if scalar(@$display); ! $text = '<input type="submit" name="submit"'; ! $text .= ' name="submit" value="Go" />'; ! push @rows, ' ' . $text . $HNL; ! $text = ' </form>' . $HNL; ! $text .= ' </td>' . $HNL; ! $text .= ' </tr>' . $HNL; push @rows, $text; } } # end %key_data loop ! push @rows, ' </table>' . $HNL; #close the <div> push @rows, '</div>' . $HNL; return \@rows; } # end search_form *************** *** 213,329 **** my $my_defaults = $opts->{my_defaults}; my $valid_tables = $opts->{valid_tables}; ! my $log = Apache->request->log; ! my @rows; ! my $kt = $opts->{args}{key_type}; ! my $kv = $opts->{args}{key_value}; ! # get the list of tables and the parent for the selected key_type ! my ($tables, $parent) = &table_list($opts, $kt); #my $test = join(", ", @$tables); #$log->debug("\nkt=$kt, tables=$test, parent=$parent"); ! my ($select, $from, $where, $ref, $results); ! foreach my $tablename (@$tables) { ! $select = 'idnum,' . $kt; ! $from = $tablename; ! $where = $kt . '=' . $kv; ! $ref = Apache::AppWrap::Subs::sqlSelectHashRef($select, $from, $where); ! foreach my $row (@$ref) { ! $row->{tablename} = $tablename; ! push @$results, $row; ! } ! } ! ! # scan the parent table ! $select = '*'; ! $from = $parent; ! $where = 'idnum=' . $kv; ! $ref = Apache::AppWrap::Subs::sqlSelectHashRef($select, $from, $where); ! my $parent_result = $ref->[0]; ! #start the <div> ! push @rows, '<div id="pager">' . $HNL; ! # build tabular output ! my $text = ' <table align="center" border="1" width="'; ! $text .= $my_defaults->{main_table_width} . '">'; ! push @rows, $text . $HNL; ! $text = ' <tr valign="bottom">'; ! push @rows, $text . $HNL; ! $text = ' <th>Table</th><th>Link to Focus page</th>'; ! push @rows, $text . $HNL; ! $text = ' </tr>'; ! push @rows, $text . $HNL; ! # count table entries ! my %tablecount; ! grep ($_->{tablename} && $tablecount{$_->{tablename}}++, @$results); ! # start with the parent table ! $text = ' <tr valign="top">'; ! push @rows, $text . $HNL; ! my $label = $my_tables->{$parent}{label}; ! $text = ' <td>' . $label . '</td>'; ! push @rows, $text . $HNL; ! # this is the hyperlink ! $text = ' <td><a href="' . $config{homeurl}; ! $text .= '/' . $parent . '/focus?idnum=' . $kv . '">'; ! $text .= $kv . '</a></td>'; push @rows, $text . $HNL; ! $text = ' </tr>'; push @rows, $text . $HNL; ! # foreach my $row ($parent_result, @$results) { ! foreach my $row (@$results) { ! my $tablename = $row->{tablename}; ! my $idnum = $row->{idnum}; ! # the sub to eval requires this ! $opts->{column} = 'idnum'; ! ! $text = ' <tr valign="top">'; ! push @rows, $text . $HNL; ! my $label = $my_tables->{$tablename}{label}; ! # if >1 record per table, show a link to &display ! if ($tablecount{$row->{tablename}} >1) { ! # $display is the link to an all records ! my $display = $config{homeurl} . '/'; ! $display .= $tablename . '/display?kv=' . $kv . '">'; ! $text = ' <td><a href="' . $display . $label . '</a></td>'; ! } ! else { ! $text = ' <td>' . $label . '</td>'; ! } ! push @rows, $text . $HNL; ! # get the label for this idnum ! # get the page_list function to display a label for the focus link ! my $eval = $my_columns->{$tablename}{idnum}{func_list}; ! my $ref = eval $eval; ! my $name = join("", @$ref) if $ref && scalar(@$ref); ! # skip this table if there are no records ! next unless $name; ! # $focus is the link to an individual record ! my $focus = $config{homeurl} . '/' . $tablename; ! # my $focus = $my_defaults->{homeurl} . $tablename; ! $text = ' <td>' . $name; ! $text .= '</td>'; ! push @rows, $text . $HNL; ! $text = ' </tr>'; ! push @rows, $text . $HNL; ! } ! $text = ' </table>'; ! push @rows, $text . $HNL; ! #close the <div> ! push @rows, '</div>' . $HNL; ! return \@rows; } # end search_results --- 234,369 ---- my $my_defaults = $opts->{my_defaults}; my $valid_tables = $opts->{valid_tables}; ! my $r = Apache->request; ! my $log = $r->log; ! my (@rows, $text, $sth); ! my $kt = $opts->{args}{key_type}; ! my $kv = $opts->{args}{key_value}; ! # get the list of tables and the parent for the selected key_type ! my ($tables, $parent) = table_list($opts, $kt); #my $test = join(", ", @$tables); #$log->debug("\nkt=$kt, tables=$test, parent=$parent"); ! my ($select, $from, $where, $ref, $results); ! foreach my $tablename (@$tables) { ! my $sql = qq{SeLecT idnum, $kt frOm $tablename}; ! $sql .= qq{ WHERE $kt=?}; ! $sth = $dbh->prepare($sql); ! $sth->execute($kv); ! ! # populate the results ref to an array of hashes ! while (my $row = $sth->fetchrow_hashref) { ! $row->{tablename} = $tablename; ! push @$results, $row; ! } ! } ! $sth->finish; ! # scan the parent table ! my $sql = qq{SeLect * frOm $parent WHERE idnum=?}; ! $sth = $dbh->prepare_cached($sql); ! $sth->execute($kv); ! # expect only a single row to be returned ! if ($sth->rows > 1) { ! my $msg = qq{Subs::search_results: "$sql" returned more}; ! $msg .= ' than 1 idnum'; ! $r->log_error($msg); ! return SERVER_ERROR; ! } ! my $parent_result; ! while (my $row = $sth->fetchrow_hashref) { ! $parent_result = $row; ! } ! $sth->finish; ! #start the <div> ! push @rows, '<div id="pager">' . $HNL; ! # build tabular output ! push @rows, ' <table>' . $HNL; ! push @rows, ' <tr>' . $HNL; ! # get the label for the results table columns ! my %args = ( ! 'caller' => 'DEFAULT', ! element => 'table', ! ); ! my $label = Apache::AppWrap::Subs::chk_txt($opts, \%args); ! $text = '<th>'; ! $text .= ucfirst($label); ! $text .= '</th>'; ! #$log->debug("\nsearch_results: label=$label, text=$text"); ! ! # get the label for other column ! $args{'caller'} = 'search_results'; ! $args{element} = 'subtitle'; ! $label = Apache::AppWrap::Subs::chk_txt($opts, \%args); ! $text .= qq{<th>$label</th></tr>}; ! push @rows, ' ' . $text . $HNL; ! ! # count table entries ! my %tablecount; ! grep ($_->{tablename} && $tablecount{$_->{tablename}}++, @$results); ! ! # start with the parent table ! $text = ' <tr>'; push @rows, $text . $HNL; ! $label = $my_tables->{$parent}{label}; ! $text = ' <td>' . $label . '</td>'; push @rows, $text . $HNL; ! # this is the hyperlink ! $text = '<td><a href="/' . $parent; ! $text .= '/focus?idnum=' . $kv . '">' . $kv . '</a></td></tr>'; ! push @rows, ' ' . $text . $HNL; ! foreach my $row (@$results) { ! my $tablename = $row->{tablename}; ! my $idnum = $row->{idnum}; ! # the sub to eval requires this ! $opts->{column} = 'idnum'; ! $text = ' <tr>'; ! my $label = $my_tables->{$tablename}{label}; ! # if >1 record per table, show a link to &display ! if ($tablecount{$row->{tablename}} >1) { ! # $display is the link to an all records ! my $display = $config{homeurl} . '/'; ! $display .= $tablename . '/display?kv=' . $kv . '">'; ! $text = '<td><a href="' . $display . $label . '</a></td>'; ! } ! else { ! $text = '<td>' . $label . '</td>'; ! } ! push @rows, ' ' . $text . $HNL; ! # get the page_list function to display a label ! # for the focus link ! my $eval = $my_columns->{$tablename}{idnum}{func_list}; ! my $ref = eval $eval; ! my $name = join("", @$ref) if $ref && scalar(@$ref); ! # skip this table if there are no records ! next unless $name; ! # $focus is the link to an individual record ! my $focus = $config{homeurl} . '/' . $tablename; ! $text = ' <td>' . $name; ! $text .= '</td>'; ! push @rows, $text . $HNL; ! $text = ' </tr>'; ! push @rows, $text . $HNL; ! } ! $text = ' </table>'; ! push @rows, $text . $HNL; ! #close the <div> ! push @rows, '</div>' . $HNL; ! ! return \@rows; } # end search_results |