chiark / gitweb /
Trying Hunter but it failed
[ypp-sc-tools.db-live.git] / yarrg / web / query_commod
index 957526037a81b5107ad30f20ba805ceaf924d5e0..b37fa39001e25ec966f234e4ff84735c340c18b7 100644 (file)
@@ -36,6 +36,7 @@
 <%args>
 $quri
 $dbh
+$commodid => undef;
 $commodstring => '';
 $prselector
 $someresults
@@ -44,7 +45,7 @@ $emsgokorprint
 
 <%perl>
 my $emsg;
-my ($commodname,$commodid);
+my ($commodname,$cmid);
 
 my $qa= \%ARGS;
 </%perl>
@@ -54,23 +55,34 @@ my $qa= \%ARGS;
 % $prselector->('BuySell');
 % $prselector->('ShowBlank');
 
+<form action="<% $quri->() |h %>" method="get">
+
 %#---------- textbox, user enters route as string ----------
 % if (!$qa->{Dropdowns}) {
 
 Enter commodity (abbreviations are OK):<br>
 
-<form action="<% $quri->() |h %>" method="get">
-
 <&| qtextstring, qa => $qa, dbh => $dbh,
     thingstring => 'commodstring', emsgstore => \$emsg,
-    perresult => sub { ($commodname,$commodid)= @_; }
+    perresult => sub { ($commodname,$cmid)= @_; }
  &>
  size=80
 </&>
 
 % } else { #---------- dropdowns, user selects from menus ----------
 
-Not yet implemented.
+%      my $sth= $dbh->prepare("SELECT commodname,commodid FROM commods
+%                                      ORDER BY commodname");
+%      $sth->execute();
+%      my $row;
+<select name="commodid">
+<option value="">Select commodity...</option>
+%      while ($row= $sth->fetchrow_arrayref) {
+%              my $selected= $commodid eq $row->[1] ? 'selected' : '';
+<option value="<% $row->[1] %>" <% $selected %>><% $row->[0] |h %></option>
+%              ($commodname,$cmid) = @$row if $selected;
+%      }
+</select>
 
 % } #---------- end of dropdowns, now common middle of page code ----------
 
@@ -83,8 +95,8 @@ Not yet implemented.
 %#========== results ==========
 <%perl>
 
-$emsgokorprint->($emsg) or $commodid=undef;
-return unless defined $commodid;
+$emsgokorprint->($emsg) or $cmid=undef;
+return unless defined $cmid;
 $someresults->();
 
 #---------- actually compute the results and print them ----------
@@ -115,7 +127,12 @@ foreach my $bs (split /_/, $ARGS{BuySell}) {
 </%perl>
 
 <h2>Offers to <% uc $bs |h %> <% $commodname |h %></h2>
-
+%      $islands->execute($cmid);
+%      my $island;
+%      my %ts_sortkeys;
+%      my $rowix= 0;
+%      while ($island= $islands->fetchrow_hashref) {
+%              if (!$rowix) {
 <table id="<% $bs %>_table">
 <tr>
 <th colspan=3>
@@ -131,13 +148,9 @@ foreach my $bs (split /_/, $ARGS{BuySell}) {
 <th>+/-10%
 <th>Any
 </tr>
-%      $islands->execute($commodid);
-%      my $island;
-%      my %ts_sortkeys;
-%      my $rowix= 0;
-%      while ($island= $islands->fetchrow_hashref) {
+%              }
 %              my $islandid= $island->{'islandid'};
-%              $offers->execute($commodid, $islandid);
+%              $offers->execute($cmid, $islandid);
 %              my ($offer, $bestprice, $marginal, @beststalls);
 %              my $tqty= $island->{'tqty'};
 %              my $cqty= '';
@@ -176,7 +189,7 @@ foreach my $bs (split /_/, $ARGS{BuySell}) {
 %                      $stallname= sprintf "%d offers", scalar @beststalls;
 %              }
 %
-%              $cqty == $tqty or die "$bs $cqty $tqty $commodid $islandid ";
+%              $cqty == $tqty or die "$bs $cqty $tqty $cmid $islandid ";
 <tr id=<% $rowid %> class="<% 'datarow'.($rowix & 1) %>">
      <td><% $s->[0]= $island->{'archipelago'} |h %>
      <td><% $s->[1]= $island->{'islandname'} |h %>
@@ -192,6 +205,7 @@ foreach my $bs (split /_/, $ARGS{BuySell}) {
 %              }
 %              $rowix++;
 %      }
+%      if ($rowix) {
 </table>
 
 <&| tabsort,   table => "${bs}_table", sortkeys => "${bs}_sortkeys",
@@ -210,6 +224,9 @@ foreach my $bs (split /_/, $ARGS{BuySell}) {
     return price;
   }
 </&tabsort>
+%      } else {
+No offers.
+%      }
 
 <%perl>
 }