<%attr>
multiple => 0
+maxambig => 4
</%attr>
<%method sqlstmt>
ambiguous commodity "<% $ARGS{spec} |h %>",
could be <% $ARGS{couldbe} |h %>
</%method>
+
+<%method manyambig>
+ Many matching commodities.
+</%method>
<%attr>
multiple => 1
+maxambig => 5
</%attr>
<%method sqlstmt>
ambiguous island or arch "<% $ARGS{spec} |h %>",
could be <% $ARGS{couldbe} |h %>
</%method>
+
+<%method manyambig>
+
+</%method>
<%perl>
my %ahtml;
my @vars;
-my %styleqf;
+my %styles;
#---------- "mode" argument parsing and mode menu at top of page ----------
$val= [ $val, encode_entities($val) ];
}
if (exists $ARGS{$lname}) {
- $styleqf{$name}= $ARGS{$lname};
- my @html= grep { $_->[0] eq $styleqf{$name} }
+ $styles{$name}= $ARGS{$lname};
+ my @html= grep { $_->[0] eq $styles{$name} }
@{ $var->{Values} };
$ahtml{$name}= @html==1 ? $html[0][1] : '???';
} else {
- $styleqf{$name}= $var->{Values}[0][0];
+ $styles{$name}= $var->{Values}[0][0];
$ahtml{$name}= $var->{Values}[0][1];
}
}
</%perl>
+
+<%shared>
+my %baseqf;
+my %queryqf;
+</%shared>
+
+<%method formhidden>
+<%args>
+$ours
+</%args>
+% foreach my $n (keys %baseqf, keys %queryqf) {
+% next if $ours->($n);
+% my $v= exists $baseqf{$n} ? $baseqf{$n} : $queryqf{$n};
+<input type=hidden name=<% $n %> value="<% $v |h %>">
+% }
+</%method>
+
<html><head><title><% ucfirst $ahtml{Query} %> - YARRG</title></head><body>
<a href="<% $m->current_comp()->name() |u %>">YARRG</a> -
<p>
<%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;
my $name= $var->{Name};
my $lname= lc $var->{Name};
my $delim= $var->{Before};
- my $canon= &{$var->{CmpCanon}}($styleqf{$name});
+ my $canon= &{$var->{CmpCanon}}($styles{$name});
my $cvalix= 0;
foreach my $valr (@{ $var->{Values} }) {
print $delim; $delim= "\n|\n";
#---------- initial checks, startup, main entry form ----------
-die if $styleqf{Query} =~ m/[^a-z]/;
+die if $styles{Query} =~ m/[^a-z]/;
-dbw_connect($styleqf{Ocean});
+dbw_connect($styles{Ocean});
</%perl>
<%args>
<hr>
-<& "query_$styleqf{Query}", %baseqf, %queryqf, %styleqf, quri => $quri &>
+<& "query_$styles{Query}", %baseqf, %queryqf, %styles, quri => $quri &>
<p>
$stringval='' if !defined $stringval;
</%perl>
-Enter route (islands, or archipelagoes, separated by |s or commas;
- abbreviations are OK):<br>
-
<&| script &>
ts_uri= "qtextstringcheck?format=application/json&ctype=text/xml"
+ "&what=<% $thingstring %>"
use CommodsWeb;
die if $what =~ m/[^a-z]/;
-my $specifics= "check_${what}";
-my $specific= $m->fetch_comp($specifics);
+my $chk= $m->fetch_comp("check_${what}");
my $dbh= dbw_connect($ocean);
-my $sqlstmt= $specific->scall_method("sqlstmt");
+
+my $sqlstmt= $chk->scall_method("sqlstmt");
my $sth= $dbh->prepare($sqlstmt);
my @sqlstmt_qs= $sqlstmt =~ m/\?/g;
my $emsg= '';
my @results;
-my @specs= $specific->attr('multiple') ? (split m#[/|,]#, $string) : ($string);
+my @specs= $chk->attr('multiple') ? (split m#[/|,]#, $string) : ($string);
+
+no warnings qw(exiting);
foreach my $each (@specs) {
$each =~ s/^\s*//; $each =~ s/\s*$//; $each =~ s/\s+/ /g;
}
if (!$results) {
if (!%m) {
- $err->($specific->scall_method("nomatch",
+ $err->($chk->scall_method("nomatch",
spec => $each));
- } elsif (keys(%m) > 5) {
- $err->(' ');
+ } elsif (keys(%m) > $chk->attr('maxambig')) {
+ $err->($chk->scall_method("manyambig"));
} else {
- $err->($specific->scall_method("ambiguous",
+ $err->($chk->scall_method("ambiguous",
spec => $each,
couldbe => join(', ', sort keys %m)));
}
<h1>Select commodity</h1>
+Enter commodity (abbreviations are OK):<br>
+
<form action="<% $quri->() |h %>" method="get">
<&| qtextstring, qa => $qa, thingstring => 'commodstring' &>
size=80
</&>
+<input type=submit name=submit value="Go">
+% my $ours= sub { $_[0] =~ m/^commodstring/; };
+<& "lookup:formhidden", ours => $ours &>
+
+</form>
+
% } else { #---------- dropdowns, user selects from menus ----------
% } #---------- end of dropdowns, now common middle of page code ----------
<h1>Specify route</h1>
+Enter route (islands, or archipelagoes, separated by |s or commas;
+ abbreviations are OK):<br>
+
<form action="<% $quri->() |h %>" method="get">
<&| qtextstring, qa => $qa, thingstring => 'routestring' &>
</%perl>
-<input type=hidden name=dropdowns value="<% $qa->{Dropdowns} |h %>">
-
<&| script &>
ms_lists= <% to_json_protecttags(\%resetislandlistdata) %>;
function ms_Setarch(dd) {
% } #---------- end of dropdowns, now common middle of page code ----------
<input type=submit name=submit value="Go">
+% my $ours= sub { $_[0] =~ m/^island|^archipelago|^routestring/; };
+<& "lookup:formhidden", ours => $ours &>
</form>
<%perl>