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 %>
103 $locdesc= ' at specified locations';
104 } elsif (defined $islandids[0]) {
105 my $sth= $dbh->prepare("SELECT islandname FROM islands
106 WHERE islandid == ?");
107 $sth->execute($islandids[0]);
108 $locdesc= ' at '.($sth->fetchrow_array())[0];
110 $locdesc= ' in '.$archipelagoes[0];
117 push @condvals, $cmid;
118 foreach my $ix (0..$#islandids) {
119 my $iid= $islandids[$ix];
120 my $arch= $archipelagoes[$ix];
122 push @conds, 'offers.islandid == ?';
123 push @condvals, $iid;
125 push @conds, 'islands.archipelago == ?';
126 push @condvals, $arch;
129 foreach my $bs (split /_/, $qa->{BuySell}) {
133 die unless grep { $bs eq $_ } qw(buy sell);
134 my $ascdesc= $bs eq 'buy' ? 'DESC' : 'ASC';
136 <h2>Offers to <% uc $bs |h %> <% $commodname |h %> <% $locdesc %></h2>
139 SELECT archipelago, islandname,
140 stallname, price, qty, timestamp,
143 JOIN islands ON offers.islandid==islands.islandid
144 JOIN uploads ON offers.islandid==uploads.islandid
145 JOIN stalls ON offers.stallid==stalls.stallid
146 WHERE offers.commodid == ?
150 ORDER BY archipelago, islandname, price $ascdesc, qty ASC,
153 if ($qa->{'debug'}) {
157 <% join ',', @condvals |h %>
163 my $sth= $dbh->prepare($stmt);
164 $sth->execute(@condvals);
167 % while ($row= $sth->fetchrow_arrayref) {
169 <table id="<% $bs %>_table" rules=groups>
182 % my $rowid= ${bs}.$row->[6];
183 % my $tscellid= "c$rowid";
184 % my $age= $now - $row->[5];
185 % $da_ages{$rowid}= $age;
187 <tr id=<% $rowid %> class="<% 'datarow'.($rowix & 1) %>" >
188 % foreach my $ci (0..4) {
189 % my $val= $row->[$ci];
190 % $ts_sortkeys{$ci}{$rowid}= $val;
191 <td <% $ci >= 3 ? 'align=right' : '' %> ><% $val |h %>
193 <td id="<% $tscellid %>" align=right><% prettyprint_age($age) %>
200 <&| tabsort, table => "${bs}_table", rowclass => 'datarow', cols => [
202 { Numeric => 1, DoReverse => 1 },
203 { Numeric => 1, DoReverse => 1 },
204 { Numeric => 1, DoReverse => 1, SortKey => "${bs}_ages[rowid]" }],
205 sortkeys => "${bs}_sortkeys"
207 <%$bs%>_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>;
208 <%$bs%>_ages= <% to_json_protecttags(\%da_ages) %>;
219 (Please don't use these pages to scrape data out of the YARRG
220 database. This will be a pain for you to program, slow to run, and
221 pointlessly overload our server. Instead, see our
222 <a href="devel">information for developers</a>
223 to find out how to get testing data or a real-time feed.)