[AppWrap-cvs] AppWrap/Apache/AppWrap Focus.pm,1.9,1.10
Status: Beta
Brought to you by:
planetman
From: <pla...@us...> - 2002-12-26 01:35:50
|
Update of /cvsroot/appwrap/AppWrap/Apache/AppWrap In directory sc8-pr-cvs1:/tmp/cvs-serv32269 Modified Files: Focus.pm Log Message: More i18n tweaks Index: Focus.pm =================================================================== RCS file: /cvsroot/appwrap/AppWrap/Apache/AppWrap/Focus.pm,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Focus.pm 21 Dec 2002 11:09:25 -0000 1.9 --- Focus.pm 26 Dec 2002 01:35:47 -0000 1.10 *************** *** 56,60 **** my $sql = qq{SeLEcT * FrOm $table WHERE idnum=?}; ! my $sth = $dbh->prepare($sql); $sth->execute($idnum); # should only return a single row; we only want the first --- 56,60 ---- my $sql = qq{SeLEcT * FrOm $table WHERE idnum=?}; ! my $sth = $dbh->prepare_cached($sql); $sth->execute($idnum); # should only return a single row; we only want the first *************** *** 69,89 **** # assign messages for alt tags. this is how we get display text ! my $msgs = $opts->{display_text}; ! $msgs ||= Apache::AppWrap::Subs::get_display_text($opts); ! $opts->{display_text} ||= $msgs; ! my $title = eval $msgs->{title} if $msgs->{title}; ! # this may be a fudge to regret later ! $title ||= $opts->{Title}; ! unless ($title) { ! $r->log_error("Pager: no title eval'd: $msgs->{title}"); ! return SERVER_ERROR; ! } ! $opts->{Title} = $title; - # subtitles are not mandatory: some tables have none. - my $subtitle = eval $msgs->{subtitle} if $msgs->{subtitle}; - $subtitle ||= $opts->{SubTitle}; - $opts->{SubTitle} = $subtitle if $subtitle; # get the data_header section --- 69,83 ---- # assign messages for alt tags. this is how we get display text ! $args{'caller'} = $opts->{phase}; ! $args{element} = 'title'; ! $args{idnum} = $idnum; ! my $title = Apache::AppWrap::Subs::chk_txt($opts, \%args); ! $opts->{Title} = $title; ! $args{element} = 'subtitle'; ! $args{label} = $link_vars->{label}; ! my $subtitle = Apache::AppWrap::Subs::chk_txt($opts, \%args); ! $opts->{SubTitle} = $subtitle; # get the data_header section *************** *** 175,179 **** my @subs = split(/\s*;\s*/, $menu_func ); foreach my $sub (@subs) { ! #$log->debug("\nFocus: eval_sub=$sub"); my $ref = eval $sub; if ($ref && scalar(@$ref)) { --- 169,173 ---- my @subs = split(/\s*;\s*/, $menu_func ); foreach my $sub (@subs) { ! $log->debug("\nFocus: eval_sub=$sub"); my $ref = eval $sub; if ($ref && scalar(@$ref)) { *************** *** 193,196 **** --- 187,328 ---- return OK; } # end handler + + + ############################################################## + # $ref = &focus_stats2(\%opts) + # A list of all unique entries of the selected control, and + # a count of records having that control value. + # 28 Dec 01. Removed CGI dependency. + # 10 Jun 01. Fixed logic to handle varied input including dates, and + # utilize my_columns func_focus subroutine. + # 09 Jun 01. Squashed bug - extra space between query string args. + ############################################################## + sub focus_stats2 { + my $opts = shift; + my $by = $opts->{args}{by}; + my $table = $opts->{table}; + my @rows; + my ($select, $from, $where, $other); + my $my_columns = $opts->{my_columns}; + my ($result); + my $log = Apache->request->log; + + $log->debug("\nfocus_stats2: here."); + # list distict db entries for this control except if + # control = (idnum|date). We make these 2 exceptions + # because an itemized list of them would not be meaningful. + # Naming convention for date fields in the db is 'date' + # or ends with '_date' + if ( $by ne 'idnum' && $by ne 'date' && $by !~ /_date$/) { + + # get the column name. + my $column = $by; + # make a header row + my $label = $my_columns->{$table}{$column}{label}; + push @rows, '<table>' . $HNL; + # my $text = ' <tr><th>' . $label; + # $text .= '</th><th>Count</th></tr>'; + my %args = ( + 'caller' => 'focus_stats2', + element => 'table_heading', + label => $label, + ); + my $show = ' '; + my $text = Apache::AppWrap::Subs::chk_txt($opts, \%args); + $show .= $text if $text; + push @rows, $show . $HNL; + + # my $text = '<tr><th>' . $args->{label} . '</th><th>Count</th></tr>'; + # push @rows, $text . $HNL; + + my $sql = qq{SeLecT disTInct($by),MAX(idnum),COUNT($by)}; + $sql .= qq{ FROM $table GROUP BY $by}; + my $sth = $dbh->prepare_cached($sql); + my $rc = $sth-execute(); + + # make a link (idnum & $by) for each distinct db entry + while (my $row = $sth->fetchrow_hashref) { + # Handle the varied column inputs by processing with the + # func_focus subroutine in my_columns. This is a bit ugly + # now so needs work. But it functions correctly. + my ($ary, $val); + # get the func_focus sub + my $func_focus; + if ($my_columns->{$table}{$column}{func_focus}) { + $func_focus = $my_columns->{$table}{$column}{func_focus}; + } + # if it exists, run it. if not, use the input value directly + if ($func_focus) { + $ary = eval $func_focus; + if ($ary && scalar(@$ary)) { + $val = join("", @$ary); + } + } + else { + $val = $row->{$column}; + } + # could be some newlines in the data, so delete them + $val =~ s/\n/<br \/>/g if $val; + $result = html_blank($val); + # this hash element key is a messy string with the + # column embedded. + my $count = 'COUNT(' . $by . ')'; + # now fromat the html output + my $stat = ' <tr><td class="first"><a href="/' . $table; + $stat .= '/focus?idnum=' . $row->{'MAX(idnum)'} . '&by='; + $stat .= $by . '">' . $result . '</a></td><td>'; + $stat .= $row->{$count} . '</td></tr>' . $HNL; + push @rows, $stat; + } # close the WHILE + push @rows, '</table>' . $HNL; + } # close the IF + return \@rows; + } # end &focus_stats2 + + + ############################################################## + # my $ref = &focus_stats1(\%opts) + # Summarize the data in the app's db + # 03Dec02. Removed table cruft, replaced with CSS + # 13Jan 02. Simplified logic. + # 11 Aug 01. Modified for color coded links + # 10 Jun 01. Fixed logic to utilize my_columns func_focus subroutine. + ############################################################## + sub focus_stats1 { + my $opts = shift; + my $table = $opts->{table}; + my $my_tables = $opts->{my_tables}; + my $my_columns = $opts->{my_columns}; + my (@rows, @fields); + + ### color coded links + my $link_vars = cclinks($opts); + my $label = $link_vars->{label}; + + # push the header + # get count of distinct entries in each sortable field + foreach my $by (@{ $opts->{col_order} }) { + next unless $my_columns->{$table}{$by}{page_sort}; + my $sql = qq{SeLecT DisTInct($by) From $table}; + my $sth = $dbh->prepare_cached($sql); + my $rc = $sth->execute; + my $i = $sth->rows; + $sth->finish; + if ($by eq 'idnum') { + my $text = ' <p class="bodyheader">' . $label; + $text .= ' records.</p>' . $HNL; + push @rows, $text; + next; + } + my $unit = ' value'; + $i > 1 ? $unit .= 's</p>' : $unit .= '</p>'; + my $label = $my_columns->{$table}{$by}{label}; + push @rows, ' <p>' . $i . ' unique '; + push @rows, $label . $unit . $HNL; + } + ### + return \@rows; + } # end &focus_stats1 + |