chiark / gitweb /
yarrg database code: eliminate all NATURAL JOINs and turn them into JOIN USING
[ypp-sc-tools.main.git] / yarrg / web / query_commod
index c87b4400fdf9c8b690a274f9f5ce3242e53f9c32..c801a631e65855d4e762aa247bb702bf883ecfc1 100644 (file)
@@ -50,6 +50,7 @@ my ($commodname,$cmid);
 my $qa= \%ARGS;
 </%perl>
 
+<div class="query">
 <h1>Commodity enquiry</h1>
 
 % $prselector->('BuySell');
@@ -57,34 +58,10 @@ my $qa= \%ARGS;
 
 <form action="<% $quri->() |h %>" method="get">
 
-%#---------- textbox, user enters route as string ----------
-% if (!$qa->{Dropdowns}) {
-
-Enter commodity (abbreviations are OK):<br>
-
-<&| qtextstring, qa => $qa, dbh => $dbh,
-    thingstring => 'commodstring', emsgstore => \$emsg,
-    perresult => sub { ($commodname,$cmid)= @_; }
+<& enter_commod, qa => $qa, dbh => $dbh, emsg_r => \$emsg,
+       commodname_r => \$commodname,
+       cmid_r => \$cmid
  &>
- size=80
-</&>
-
-% } else { #---------- dropdowns, user selects from menus ----------
-
-%      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 ----------
 
 <input type=submit name=submit value="Go">
 % my $ours= sub { $_[0] =~ m/^commodstring|^commodid/; };
@@ -93,10 +70,13 @@ Enter commodity (abbreviations are OK):<br>
 </form>
 
 %#========== results ==========
+</div>
+<div class="results">
 <%perl>
 
 $emsgokorprint->($emsg) or $cmid=undef;
-return unless defined $cmid;
+print("</div>"), return
+       unless defined $cmid;
 $someresults->();
 
 #---------- actually compute the results and print them ----------
@@ -119,7 +99,7 @@ foreach my $bs (split /_/, $ARGS{BuySell}) {
 
        my $offers= $dbh->prepare(
        "SELECT stallname, price, qty
-               FROM $bs NATURAL JOIN stalls
+               FROM $bs JOIN stalls USING (stallid, islandid)
                WHERE commodid = ? AND islandid = ?
                ORDER BY price $ascdesc"
                );
@@ -127,10 +107,20 @@ foreach my $bs (split /_/, $ARGS{BuySell}) {
 </%perl>
 
 <h2>Offers to <% uc $bs |h %> <% $commodname |h %></h2>
-
-<table id="<% $bs %>_table">
+%      $islands->execute($cmid);
+%      my $island;
+%      my %ts_sortkeys;
+%      my $rowix= 0;
+%      while ($island= $islands->fetchrow_hashref) {
+%              if (!$rowix) {
+<table class="data" id="<% $bs %>_table" rules=groups>
+<colgroup span=2>
+<colgroup span=1>
+<colgroup span=2>
+<colgroup span=3>
 <tr>
-<th colspan=3>
+<th colspan=2>
+<th colspan=1>
 <th colspan=2>Prices
 <th colspan=3>Quantity at price
 <tr id="<% $bs %>_table_thr">
@@ -143,11 +133,7 @@ foreach my $bs (split /_/, $ARGS{BuySell}) {
 <th>+/-10%
 <th>Any
 </tr>
-%      $islands->execute($cmid);
-%      my $island;
-%      my %ts_sortkeys;
-%      my $rowix= 0;
-%      while ($island= $islands->fetchrow_hashref) {
+%              }
 %              my $islandid= $island->{'islandid'};
 %              $offers->execute($cmid, $islandid);
 %              my ($offer, $bestprice, $marginal, @beststalls);
@@ -193,17 +179,18 @@ foreach my $bs (split /_/, $ARGS{BuySell}) {
      <td><% $s->[0]= $island->{'archipelago'} |h %>
      <td><% $s->[1]= $island->{'islandname'} |h %>
      <td><%          $stallname |h %>
-     <td><% $s->[3]= (length $bestqty ? $bestprice : '-') %>
-     <td><% $s->[4]= $median %>
-     <td><% $s->[5]= $bestqty %>
-     <td><% $s->[6]= $approxqty %>
-     <td><% $s->[7]= $cqty %>
+     <td align=right><% $s->[3]= (length $bestqty ? $bestprice : '-') %>
+     <td align=right><% $s->[4]= $median %>
+     <td align=right><% $s->[5]= $bestqty %>
+     <td align=right><% $s->[6]= $approxqty %>
+     <td align=right><% $s->[7]= $cqty %>
 </tr>
 %              for my $cix (0..$#$s) {
 %                      $ts_sortkeys{$cix}{$rowid}= $s->[$cix];
 %              }
 %              $rowix++;
 %      }
+%      if ($rowix) {
 </table>
 
 <&| tabsort,   table => "${bs}_table", sortkeys => "${bs}_sortkeys",
@@ -222,7 +209,11 @@ foreach my $bs (split /_/, $ARGS{BuySell}) {
     return price;
   }
 </&tabsort>
+%      } else {
+No offers.
+%      }
 
 <%perl>
 }
 </%perl>
+</div>