X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=blobdiff_plain;f=yarrg%2Fweb%2Flookup;h=0b6466e3f6a4fc53a61fc4202643fddc67f3b438;hp=0106684af46e5ba515d69b9b3aa4a92be2fc9d19;hb=608bc9e07b5c8a961325fd1b8d5b92f65418b949;hpb=38e2919be138f8a77eef7a2fc93d34eff8897f5e diff --git a/yarrg/web/lookup b/yarrg/web/lookup index 0106684..0b6466e 100755 --- a/yarrg/web/lookup +++ b/yarrg/web/lookup @@ -35,9 +35,9 @@ <%perl> -my %a; my %ahtml; my @vars; +my %styles; #---------- "mode" argument parsing and mode menu at top of page ---------- @@ -58,6 +58,14 @@ my @vars; Values => [ [ 'route', 'Trades for route' ], [ 'commod', 'Prices for commodity' ], [ 'age', 'Data age' ] ] + }, { Name => 'BuySell', + Before => '', + Values => [ [ 'buy_sell', 'Buy and sell' ], + [ 'sell_buy', 'Sell and buy' ], + [ 'buy', 'Buy offers only' ], + [ 'sell', 'Sell offers only' ], + ], + QuerySpecific => 1, }); foreach my $var (@vars) { @@ -70,16 +78,34 @@ foreach my $var (@vars) { $val= [ $val, encode_entities($val) ]; } if (exists $ARGS{$lname}) { - $a{$name}= $ARGS{$lname}; - my @html= grep { $_->[0] eq $a{$name} } @{ $var->{Values} }; + $styles{$name}= $ARGS{$lname}; + my @html= grep { $_->[0] eq $styles{$name} } + @{ $var->{Values} }; $ahtml{$name}= @html==1 ? $html[0][1] : '???'; } else { - $a{$name}= $var->{Values}[0][0]; + $styles{$name}= $var->{Values}[0][0]; $ahtml{$name}= $var->{Values}[0][1]; } } + +<%shared> +my %baseqf; +my %queryqf; + + +<%method formhidden> +<%args> +$ours + +% foreach my $n (keys %baseqf, keys %queryqf) { +% next if $ours->($n); +% my $v= exists $baseqf{$n} ? $baseqf{$n} : $queryqf{$n}; + value="<% $v |h %>"> +% } + + <% ucfirst $ahtml{Query} %> - YARRG YARRG - @@ -89,17 +115,15 @@ foreach my $var (@vars) {

<%perl> -my %baseqf; foreach my $var (@vars) { my $lname= lc $var->{Name}; next unless exists $ARGS{$lname}; $baseqf{$lname}= $ARGS{$lname}; } -my %queryqf; foreach my $var (keys %ARGS) { next unless $var =~ - m/^(?:routestring|islandid\d|archipelago\d|debug)$/; + m/^(?:(?:route|commod)string|islandid\d|archipelago\d|debug)$/; my $val= $ARGS{$var}; next if $val eq 'none'; $queryqf{$var}= $val; @@ -111,11 +135,12 @@ my $quri= sub { $uri->path_query(); }; -foreach my $var (@vars) { +my $prselector_core= sub { + my ($var)= @_; my $name= $var->{Name}; my $lname= lc $var->{Name}; my $delim= $var->{Before}; - my $canon= &{$var->{CmpCanon}}($a{$name}); + my $canon= &{$var->{CmpCanon}}($styles{$name}); my $cvalix= 0; foreach my $valr (@{ $var->{Values} }) { print $delim; $delim= "\n|\n"; @@ -138,13 +163,37 @@ foreach my $var (@vars) { $cvalix++; } print "

\n\n"; +}; + +my $prselector= sub { + my ($name)= @_; + foreach my $var (@vars) { + if ($var->{Name} eq $name) { + $prselector_core->($var); + return; + } + } + die $name; +}; + +foreach my $var (@vars) { + next if $var->{QuerySpecific}; + $prselector_core->($var); } #---------- initial checks, startup, main entry form ---------- -die if $a{Query} =~ m/[^a-z]/; +die if $styles{Query} =~ m/[^a-z]/; + +my $mydbh; +my $dbh= ($mydbh= dbw_connect($styles{Ocean})); -dbw_connect($a{Ocean}); +my $results_head_done=0; +my $someresults= sub { + return if $results_head_done; + $results_head_done=1; + print "\n

Results

\n"; +}; <%args> @@ -153,7 +202,18 @@ $debug => 0
-<& "query_$a{Query}", %baseqf, %queryqf, quri => $quri, qa => \%a &> +<& "query_$styles{Query}", %baseqf, %queryqf, %styles, + quri => $quri, dbh => $dbh, + prselector => $prselector, + someresults => $someresults, + emsgokorprint => sub { + my ($emsg) = @_; + return 1 unless defined $emsg and length $emsg; + $someresults->(); + print $emsg; + return 0; + } + &>

@@ -183,3 +243,8 @@ use HTML::Entities; use URI::Escape; +<%cleanup> + +$mydbh->rollback() if $mydbh; + +