chiark / gitweb /
Better answers for arch queries
[ypp-sc-tools.db-live.git] / yarrg / web / query_route
index 8f6d99c49d29ed353f5f2fcdf6d88dc55180afac..e9e358a433bc928b325a773651441b9ee25971d4 100644 (file)
 </%doc>
 <%args>
 $quri
+$dbh
 $routestring => '';
+$someresults
+$emsgokorprint
 </%args>
-<%perl>
 
+<%perl>
+my $emsg;
 my @archipelagoes;
 my @islandids;
 my %islandid2;
@@ -56,14 +60,21 @@ Enter route (islands, or archipelagoes, separated by |s or commas;
 
 <form action="<% $quri->() |h %>" method="get">
 
-<&| qtextstring, qa => $qa, thingstring => 'routestring' &>
+<&| qtextstring, qa => $qa, dbh => $dbh,
+    thingstring => 'routestring', emsgstore => \$emsg,
+    perresult => sub {
+       my ($canonname, $island, $arch) = @_;
+       push @islandids, $island;
+       push @archipelagoes, defined $island ? undef : $arch;
+    }
+ &>
  size=80
 </&>
 
 % } else { #---------- dropdowns, user selects from menus ----------
 
 <%perl>
-my ($sth,$row);;
+my ($sth,$row);
 my @archlistdata;
 my %islandlistdata;
 $islandlistdata{'none'}= [ [ "none", "Select island..." ] ];
@@ -81,8 +92,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();
@@ -111,8 +120,6 @@ foreach my $arch (keys %islandlistdata) {
                $optionlistmap->($islandlistdata{$arch}, '');
 }
 
-$dbh->rollback();
-
 </%perl>
 
 <&| script &>
@@ -161,36 +168,9 @@ function ms_Setarch(dd) {
 </form>
 
 <%perl>
-#========== result computations ==========
+#========== results ==========
 
-my $results_head;
-$results_head= sub {
-       print "<h1>Results</h1>\n";
-       $results_head= sub { };
-};
-
-#---------- result computation - textstring ----------
-if (!$qa->{Dropdowns}) {
-  if (length $routestring) {
-       $results_head->();
-       my ($emsg,$canonstring,$results)= $m->comp('qtextstringcheck',
-               what => 'routestring',
-               ocean => $qa->{Ocean},
-               string => $routestring,
-               format => 'return'
-       );
-       if (length $emsg) {
-               print encode_entities($emsg);
-       } else {
-               foreach my $entry (@$results) {
-                       push @islandids, $entry->[1];
-                       push @archipelagoes,
-                               defined $entry->[1] ? undef : $entry->[2];
-               } 
-       }
-  }
-
-} else { #---------- results - dropdowns ----------
+$emsgokorprint->($emsg) or @islandids=();
 
 my $argorundef= sub {
        my ($dd,$base) = @_;
@@ -207,7 +187,7 @@ for my $dd (0..$qa->{Dropdowns}-1) {
                my $ii= $islandid2{$island};
                my $iarch= $ii->{Arch};
                if ($iarch ne $arch) {
-                       $results_head->();
+                       $someresults->();
 </%perl>
  Specified archipelago <% $arch %> but
  island <% $ii->{Name} %>
@@ -220,12 +200,12 @@ for my $dd (0..$qa->{Dropdowns}-1) {
        push @islandids, $island;
 }
 
-}#---------- result processing, common stuff
 </%perl>
 
 % if (@islandids) {
-%      $results_head->();
-
-<& routetrade, islandids => \@islandids, archipelagoes => \@archipelagoes &>
-
+%      $someresults->();
+<& routetrade,
+   dbh => $dbh,
+   islandids => \@islandids,
+   archipelagoes => \@archipelagoes &>
 % }