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);
58 <h1>Prices for commodity at location(s)</h1>
60 % $prselector->('BuySell');
62 <form action="<% $quri->() |h %>" method="get">
64 <& enter_commod, qa => $qa, dbh => $dbh, emsg_r => \$emsg,
65 commodname_r => \$commodname,
69 <& enter_route, qa => $qa, dbh => $dbh, emsg_r => \$emsg,
70 warningfs_r => \@warningfs,
71 enterwhat => 'Enter location',
72 islandids_r => \@islandids,
73 archipelagoes_r => \@archipelagoes
76 <input type=submit name=submit value="Go">
77 % my $ours= sub { $_[0] =~
78 % m/^commodstring|^commodid|^routestring|^archipelago|^island/;
80 <& "lookup:formhidden", ours => $ours &>
86 %#========== results ==========
89 $emsgokorprint->($emsg) or $cmid=undef;
90 print("</div>"), return
91 unless defined $cmid and @islandids;
93 foreach my $wf (@warningfs) { $wf->(); }
98 bs= <% $qa->{BuySell} %>
100 islandids= <% join ',', map { defined($_) ? $_ : 'U' } @islandids %>
107 $locdesc= ' at specified locations';
108 } elsif (defined $islandids[0]) {
109 my $sth= $dbh->prepare("SELECT islandname FROM islands
110 WHERE islandid == ?");
111 $sth->execute($islandids[0]);
112 $locdesc= ' at '.($sth->fetchrow_array())[0];
114 $locdesc= ' in '.$archipelagoes[0];
121 push @condvals, $cmid;
122 foreach my $ix (0..$#islandids) {
123 my $iid= $islandids[$ix];
124 my $arch= $archipelagoes[$ix];
126 push @conds, 'offers.islandid == ?';
127 push @condvals, $iid;
129 push @conds, 'islands.archipelago == ?';
130 push @condvals, $arch;
133 foreach my $bs (split /_/, $qa->{BuySell}) {
137 die unless grep { $bs eq $_ } qw(buy sell);
138 my $ascdesc= $bs eq 'buy' ? 'DESC' : 'ASC';
140 <h2>Offers to <% uc $bs |h %> <% $commodname |h %> <% $locdesc %></h2>
143 SELECT archipelago, islandname,
144 stallname, price, qty, timestamp,
147 JOIN islands ON offers.islandid==islands.islandid
148 JOIN uploads ON offers.islandid==uploads.islandid
149 JOIN stalls ON offers.stallid==stalls.stallid
150 WHERE offers.commodid == ?
154 ORDER BY archipelago, islandname, price $ascdesc, qty ASC,
157 if ($qa->{'debug'}) {
161 <% join ',', @condvals |h %>
167 my $sth= $dbh->prepare($stmt);
168 $sth->execute(@condvals);
171 % while ($row= $sth->fetchrow_arrayref) {
173 <table class="data" id="<% $bs %>_table" rules=groups>
186 % my $rowid= ${bs}.$row->[6];
187 % my $tscellid= "c$rowid";
188 % my $age= $now - $row->[5];
189 % $da_ages{$rowid}= $age;
191 <tr id=<% $rowid %> class="<% 'datarow'.($rowix & 1) %>" >
192 % foreach my $ci (0..4) {
193 % my $val= $row->[$ci];
194 % $ts_sortkeys{$ci}{$rowid}= $val;
195 <td <% $ci >= 3 ? 'align=right' : '' %> ><% $val |h %>
197 <td id="<% $tscellid %>" align=right><% prettyprint_age($age) %>
204 <&| tabsort, table => "${bs}_table", rowclass => 'datarow', cols => [
206 { Numeric => 1, DoReverse => 1 },
207 { Numeric => 1, DoReverse => 1 },
208 { Numeric => 1, DoReverse => 1, SortKey => "${bs}_ages[rowid]" }],
209 sortkeys => "${bs}_sortkeys"
211 <%$bs%>_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>;
212 <%$bs%>_ages= <% to_json_protecttags(\%da_ages) %>;
223 (Please don't use these pages to scrape data out of the YARRG
224 database. This will be a pain for you to program, slow to run, and
225 pointlessly overload our server. Instead, see our
226 <a href="devel">information for developers</a>
227 to find out how to get testing data or a real-time feed.)