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 return unless defined $cmid and @islandids;
92 foreach my $wf (@warningfs) { $wf->(); }
97 bs= <% $qa->{BuySell} %>
99 islandids= <% join ',', map { defined($_) ? $_ : 'U' } @islandids %>
106 $locdesc= ' at specified locations';
107 } elsif (defined $islandids[0]) {
108 my $sth= $dbh->prepare("SELECT islandname FROM islands
109 WHERE islandid == ?");
110 $sth->execute($islandids[0]);
111 $locdesc= ' at '.($sth->fetchrow_array())[0];
113 $locdesc= ' in '.$archipelagoes[0];
120 push @condvals, $cmid;
121 foreach my $ix (0..$#islandids) {
122 my $iid= $islandids[$ix];
123 my $arch= $archipelagoes[$ix];
125 push @conds, 'offers.islandid == ?';
126 push @condvals, $iid;
128 push @conds, 'islands.archipelago == ?';
129 push @condvals, $arch;
132 foreach my $bs (split /_/, $qa->{BuySell}) {
136 die unless grep { $bs eq $_ } qw(buy sell);
137 my $ascdesc= $bs eq 'buy' ? 'DESC' : 'ASC';
139 <h2>Offers to <% uc $bs |h %> <% $commodname |h %> <% $locdesc %></h2>
142 SELECT archipelago, islandname,
143 stallname, price, qty, timestamp,
146 JOIN islands ON offers.islandid==islands.islandid
147 JOIN uploads ON offers.islandid==uploads.islandid
148 JOIN stalls ON offers.stallid==stalls.stallid
149 WHERE offers.commodid == ?
153 ORDER BY archipelago, islandname, price $ascdesc, qty ASC,
156 if ($qa->{'debug'}) {
160 <% join ',', @condvals |h %>
166 my $sth= $dbh->prepare($stmt);
167 $sth->execute(@condvals);
170 % while ($row= $sth->fetchrow_arrayref) {
172 <table class="data" id="<% $bs %>_table" rules=groups>
185 % my $rowid= ${bs}.$row->[6];
186 % my $tscellid= "c$rowid";
187 % my $age= $now - $row->[5];
188 % $da_ages{$rowid}= $age;
190 <tr id=<% $rowid %> class="<% 'datarow'.($rowix & 1) %>" >
191 % foreach my $ci (0..4) {
192 % my $val= $row->[$ci];
193 % $ts_sortkeys{$ci}{$rowid}= $val;
194 <td <% $ci >= 3 ? 'align=right' : '' %> ><% $val |h %>
196 <td id="<% $tscellid %>" align=right><% prettyprint_age($age) %>
203 <&| tabsort, table => "${bs}_table", rowclass => 'datarow', cols => [
205 { Numeric => 1, DoReverse => 1 },
206 { Numeric => 1, DoReverse => 1 },
207 { Numeric => 1, DoReverse => 1, SortKey => "${bs}_ages[rowid]" }],
208 sortkeys => "${bs}_sortkeys"
210 <%$bs%>_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>;
211 <%$bs%>_ages= <% to_json_protecttags(\%da_ages) %>;
222 (Please don't use these pages to scrape data out of the YARRG
223 database. This will be a pain for you to program, slow to run, and
224 pointlessly overload our server. Instead, see our
225 <a href="devel">information for developers</a>
226 to find out how to get testing data or a real-time feed.)