chiark / gitweb /
Merge branch 'test-install'
[ypp-sc-tools.db-live.git] / yarrg / web / query_route
index 66dee1dd08135de011871b15d71d963f7db235af..393e7a668755145d05262a56b56ed005330669c1 100644 (file)
@@ -35,6 +35,8 @@
 </%doc>
 <%args>
 $quri
+$dbh
+$prselector
 $routestring => '';
 $someresults
 $emsgokorprint
@@ -47,19 +49,32 @@ my @islandids;
 my %islandid2;
 
 my $qa= \%ARGS;
+
+my $be_post;
+my $startform= sub {
+       ($be_post)= @_;
 </%perl>
+<form action="<% $quri->() |h %>" method="<% $be_post ? 'post' : 'get' %>">
+<%perl>
+};
+my $goupdate= sub { $be_post ? 'Update' : 'Go' };
 
-%#---------- textbox, user enters route as string ----------
-% if (!$qa->{Dropdowns}) {
+</%perl>
 
 <h1>Specify route</h1>
 
+% $prselector->('ShowStalls');
+
+%#---------- textbox, user enters route as string ----------
+% if (!$qa->{Dropdowns}) {
+
 Enter route (islands, or archipelagoes, separated by |s or commas;
  abbreviations are OK):<br>
 
-<form action="<% $quri->() |h %>" method="get">
+% $startform->($routestring =~ m/\S/);
 
-<&| qtextstring, qa => $qa, thingstring => 'routestring', emsgstore => \$emsg,
+<&| qtextstring, qa => $qa, dbh => $dbh,
+    thingstring => 'routestring', emsgstore => \$emsg,
     perresult => sub {
        my ($canonname, $island, $arch) = @_;
        push @islandids, $island;
@@ -71,6 +86,11 @@ Enter route (islands, or archipelagoes, separated by |s or commas;
 
 % } else { #---------- dropdowns, user selects from menus ----------
 
+% $startform->(grep {
+%              defined $ARGS{"archipelago$_"} ||
+%              defined $ARGS{"islandid$_"}
+%      } (0..$qa->{Dropdowns}-1));
+
 <%perl>
 my ($sth,$row);
 my @archlistdata;
@@ -90,8 +110,6 @@ my $optionlistmap= sub {
        return $out;
 };
 
-my $dbh= dbw_connect($qa->{Ocean});
-
 $sth= $dbh->prepare("SELECT DISTINCT archipelago FROM islands
                            ORDER BY archipelago;");
 $sth->execute();
@@ -120,8 +138,6 @@ foreach my $arch (keys %islandlistdata) {
                $optionlistmap->($islandlistdata{$arch}, '');
 }
 
-$dbh->rollback();
-
 </%perl>
 
 <&| script &>
@@ -164,10 +180,9 @@ 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/; };
+<input type=submit name=submit value="<% $goupdate->() %>">
+% my $ours= sub { $_[0] =~ m/^island|^archipelago|^routestring|^[RT]/; };
 <& "lookup:formhidden", ours => $ours &>
-</form>
 
 <%perl>
 #========== results ==========
@@ -205,6 +220,12 @@ for my $dd (0..$qa->{Dropdowns}-1) {
 </%perl>
 
 % if (@islandids) {
-%      $someresults->();
-<& routetrade, islandids => \@islandids, archipelagoes => \@archipelagoes &>
+%      $someresults->('Relevant trades');
+<& routetrade,
+   dbh => $dbh,
+   islandids => \@islandids,
+   archipelagoes => \@archipelagoes,
+   qa => $qa
+ &>
+</form>
 % }