<%args>
$quri
$dbh
+$commodid => undef;
$commodstring => '';
$prselector
$someresults
<%perl>
my $emsg;
-my ($commodname,$commodid);
+my ($commodname,$cmid);
my $qa= \%ARGS;
</%perl>
% $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 ----------
%#========== 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 ----------
-my $onloads= "";
-
foreach my $bs (split /_/, $ARGS{BuySell}) {
$bs =~ m/^(buy|sell)$/ or die;
$bs= $1;
my ($ascdesc) = ($bs eq 'buy')
? ('DESC')
: ('ASC');
- my $joinkind= $ARGS{ShowBlank} eq 'show'
- ? 'LEFT OUTER JOIN' : 'INNER JOIN';
+ my $joinkind= $ARGS{ShowBlank} ? 'LEFT OUTER JOIN' : 'INNER JOIN';
my $islands= $dbh->prepare(
"SELECT islands.islandid AS islandid, archipelago, islandname,
sum(qty) as tqty
FROM islands $joinkind $bs offers
ON islands.islandid == offers.islandid AND commodid == ?
- GROUP BY islands.islandid,
+ GROUP BY islands.islandid
ORDER BY archipelago, islandname"
);
WHERE commodid = ? AND islandid = ?
ORDER BY price $ascdesc"
);
- # fixme this query is utterly wrong
</%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>
<th>+/-10%
<th>Any
</tr>
-% $islands->execute($commodid);
-% my $island;
-% my %ts_sortkeys;
-% 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= '';
% $stallname= sprintf "%d offers", scalar @beststalls;
% }
%
-% $cqty == $tqty or die "$bs $cqty $tqty $commodid $islandid ";
-<tr id=<% $rowid %> >
+% $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 %>
<td><% $stallname |h %>
% for my $cix (0..$#$s) {
% $ts_sortkeys{$cix}{$rowid}= $s->[$cix];
% }
+% $rowix++;
% }
+% if ($rowix) {
</table>
-<& tabsort, table => "${bs}_table", sortkeys => "${bs}_sortkeys",
- throw => "${bs}_table_thr", cols => [
+<&| tabsort, table => "${bs}_table", sortkeys => "${bs}_sortkeys",
+ throw => "${bs}_table_thr", rowclass => 'datarow', cols => [
{}, {},
{ DoReverse => 1 },
{ DoReverse => 1, Numeric => 1, MapFn => "ts_Pricemap_${bs}" },
{ DoReverse => 1, Numeric => 1 },
{ DoReverse => 1, Numeric => 1 },
] &>
-<&| script &>
<% $bs %>_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>;
function ts_Pricemap_<% $bs %>(price) {
if (price=='-') { return <% $bs eq 'buy' ? '-1' : '99999999' %>; }
return price;
}
-</&>
-% $onloads .= " ts_onload__${bs}_table();\n";
+</&tabsort>
+% } else {
+No offers.
+% }
<%perl>
}
</%perl>
-
-<&| script &>
- function all_onload() {
-<% $onloads %>
- }
- window.onload= all_onload;
-</&>