return unless defined $cmid and @islandids;
foreach my $wf (@warningfs) { $wf->(); }
-</%perl>
+</%perl>
<pre>
NOT YET IMPLEMENTED
-
+bs= <% $qa->{BuySell} %>
cmdid= <% $cmid %>
islandids= <% join ',', map { defined($_) ? $_ : 'U' } @islandids %>
</pre>
+<%perl>
+
+my $locdesc;
+if (@islandids>1) {
+ $locdesc= ' at specified locations';
+} elsif (defined $islandids[0]) {
+ my $sth= $dbh->prepare("SELECT islandname FROM islands
+ WHERE islandid == ?");
+ $sth->execute($islandids[0]);
+ $locdesc= ' at '.($sth->fetchrow_array())[0];
+} else {
+ $locdesc= ' in '.$archipelagoes[0];
+}
+
+my @conds;
+my @condvals;
+push @condvals, $cmid;
+foreach my $ix (0..$#islandids) {
+ my $iid= $islandids[$ix];
+ my $arch= $archipelagoes[$ix];
+ if (defined $iid) {
+ push @conds, 'offers.islandid == ?';
+ push @condvals, $iid;
+ } else {
+ push @conds, 'islands.archipelago == ?';
+ push @condvals, $arch;
+ }
+}
+foreach my $bs (split /_/, $qa->{BuySell}) {
+ die unless grep { $bs eq $_ } qw(buy sell);
+ my $ascdesc= $bs eq 'buy' ? 'DESC' : 'ASC';
+</%perl>
+<h2>Offers to <% uc $bs |h %> <% $commodname |h %> <% $locdesc %></h2>
+<%perl>
+ my $stmt= "
+ SELECT archipelago, islandname, stallname, price, qty, timestamp
+ FROM $bs AS offers
+ JOIN islands ON offers.islandid==islands.islandid
+ JOIN uploads ON offers.islandid==uploads.islandid
+ JOIN stalls ON offers.stallid==stalls.stallid
+ WHERE offers.commodid == ?
+ AND ( ".join("
+ OR ", @conds)."
+ )
+ ORDER BY archipelago, islandname, price $ascdesc, qty ASC,
+ stallname $ascdesc
+";
+ if ($qa->{'debug'}) {
+</%perl>
+<pre>
+<% $stmt %>
+<% join ',', @condvals |h %>
+</pre>
+<%perl>
+ }
+
+ my $sth= $dbh->prepare($stmt);
+ $sth->execute(@condvals);
+</%perl>
+ <& dumptable, sth => $sth &>
+<%perl>
+}
+
+</%perl>