3 This is part of the YARRG website. YARRG is a tool and website
4 for assisting players of Yohoho Puzzle Pirates.
6 Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
7 Copyright (C) 2009 Clare Boothby
9 YARRG's client code etc. is covered by the ordinary GNU GPL (v3 or later).
10 The YARRG website is covered by the GNU Affero GPL v3 or later, which
11 basically means that every installation of the website will let you
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU Affero General Public License as
16 published by the Free Software Foundation, either version 3 of the
17 License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU Affero General Public License for more details.
24 You should have received a copy of the GNU Affero General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
28 are used without permission. This program is not endorsed or
29 sponsored by Three Rings.
32 This Mason component generates the core of the `offers' query.
52 my ($commodname,$cmid);
57 <h1>Prices for commodity at location(s)</h1>
59 % $prselector->('BuySell');
61 <form action="<% $quri->() |h %>" method="get">
63 <& enter_commod, qa => $qa, dbh => $dbh, emsg_r => \$emsg,
64 commodname_r => \$commodname,
68 <& enter_route, qa => $qa, dbh => $dbh, emsg_r => \$emsg,
69 warningfs_r => \@warningfs,
70 enterwhat => 'Enter location',
71 islandids_r => \@islandids,
72 archipelagoes_r => \@archipelagoes
75 <input type=submit name=submit value="Go">
76 % my $ours= sub { $_[0] =~
77 % m/^commodstring|^commodid|^routestring|^archipelago|^island/;
79 <& "lookup:formhidden", ours => $ours &>
83 %#========== results ==========
86 $emsgokorprint->($emsg) or $cmid=undef;
87 return unless defined $cmid and @islandids;
89 foreach my $wf (@warningfs) { $wf->(); }
94 bs= <% $qa->{BuySell} %>
96 islandids= <% join ',', map { defined($_) ? $_ : 'U' } @islandids %>
102 $locdesc= ' at specified locations';
103 } elsif (defined $islandids[0]) {
104 my $sth= $dbh->prepare("SELECT islandname FROM islands
105 WHERE islandid == ?");
106 $sth->execute($islandids[0]);
107 $locdesc= ' at '.($sth->fetchrow_array())[0];
109 $locdesc= ' in '.$archipelagoes[0];
114 push @condvals, $cmid;
115 foreach my $ix (0..$#islandids) {
116 my $iid= $islandids[$ix];
117 my $arch= $archipelagoes[$ix];
119 push @conds, 'offers.islandid == ?';
120 push @condvals, $iid;
122 push @conds, 'islands.archipelago == ?';
123 push @condvals, $arch;
126 foreach my $bs (split /_/, $qa->{BuySell}) {
127 die unless grep { $bs eq $_ } qw(buy sell);
128 my $ascdesc= $bs eq 'buy' ? 'DESC' : 'ASC';
130 <h2>Offers to <% uc $bs |h %> <% $commodname |h %> <% $locdesc %></h2>
133 SELECT archipelago, islandname, stallname, price, qty, timestamp
135 JOIN islands ON offers.islandid==islands.islandid
136 JOIN uploads ON offers.islandid==uploads.islandid
137 JOIN stalls ON offers.stallid==stalls.stallid
138 WHERE offers.commodid == ?
142 ORDER BY archipelago, islandname, price $ascdesc, qty ASC,
145 if ($qa->{'debug'}) {
149 <% join ',', @condvals |h %>
154 my $sth= $dbh->prepare($stmt);
155 $sth->execute(@condvals);
157 <& dumptable, sth => $sth &>