chiark / gitweb /
Better title for commodity enquiries
[ypp-sc-tools.db-live.git] / yarrg / web / query_commod
index 5a7497bac9d3d8d042bf40c031d565bf952607d2..aeee3cee83d0bf8288ee79903ec005e20b36f4fc 100644 (file)
 </%doc>
 <%args>
 $quri
+$dbh
 $commodstring => '';
+$prselector
+$someresults
+$emsgokorprint
 </%args>
 
-% my $qa= \%ARGS;
+<%perl>
+my $emsg;
+my ($commodname,$commodid);
+
+my $qa= \%ARGS;
+</%perl>
+
+<h1>Commodity enquiry</h1>
+
+% $prselector->('BuySell');
 
 %#---------- textbox, user enters route as string ----------
 % if (!$qa->{Dropdowns}) {
 
-<h1>Select commodity</h1>
+Enter commodity (abbreviations are OK):<br>
 
 <form action="<% $quri->() |h %>" method="get">
 
-<&| qtextstring, qa => $qa, thingstring => 'commodstring' &>
+<&| qtextstring, qa => $qa, dbh => $dbh,
+    thingstring => 'commodstring', emsgstore => \$emsg,
+    perresult => sub { ($commodname,$commodid)= @_; }
+ &>
  size=80
 </&>
 
 % } else { #---------- dropdowns, user selects from menus ----------
 
+Not yet implemented.
+
 % } #---------- end of dropdowns, now common middle of page code ----------
+
+<input type=submit name=submit value="Go">
+% my $ours= sub { $_[0] =~ m/^commodstring|^commodid/; };
+<& "lookup:formhidden", ours => $ours &>
+
+</form>
+
+%#========== results ==========
+<%perl>
+
+$emsgokorprint->($emsg) or $commodid=undef;
+return unless defined $commodid;
+$someresults->();
+
+#---------- actually compute the results and print them ----------
+
+foreach my $bs (split /_/, $ARGS{BuySell}) {
+       $bs =~ m/^(buy|sell)$/ or die;
+       $bs= $1;
+
+       my $sth= $dbh->prepare(
+       "SELECT archipelago, islandname, stallname, price, qty
+               FROM $bs NATURAL JOIN stalls NATURAL JOIN islands
+               WHERE commodid = ?"
+               );
+       # fixme this query is utterly wrong
+
+       $sth->execute($commodid);
+
+</%perl>
+
+<h2>Offers to <% uc $bs |h %> <% $commodname |h %></h2>
+
+<table>
+<tr>
+<th>Archipelago
+<th>Island
+<th>Best stall
+<th>Best price
+<th>Qty at best
+</tr>
+%      my $row;
+%      while ($row=$sth->fetchrow_hashref) {
+<tr> <td><% $row->{'archipelago'} %>
+     <td><% $row->{'islandname'} %>
+     <td><% $row->{'stallname'} %>
+     <td><% $row->{'price'} %>
+     <td><% $row->{'qty'} %>
+</tr>
+%      }
+</table>
+
+<%perl>
+}
+</%perl>