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 main `lookup' page, including
33 all the entry boxes etc. for every query.
42 #---------- "mode" argument parsing and mode menu at top of page ----------
44 # for debugging, invoke as
45 # http://www.chiark.greenend.org.uk/ucgi/~clareb/mason/pirates/pirate-route?debug=1
47 @vars= ({ Name => 'Ocean',
49 CmpCanon => sub { ucfirst lc $_[0] },
50 Values => [ ocean_list() ]
51 }, { Name => 'Dropdowns',
52 Before => 'Interface: ',
53 CmpCanon => sub { !!$_[0] },
54 Values => [ [ 0, 'Type in names' ],
55 [ 4, 'Select from menus' ] ]
58 Values => [ [ 'route', 'Trades for route' ],
59 [ 'commod', 'Prices for commodity' ],
60 [ 'age', 'Data age' ] ]
61 }, { Name => 'BuySell',
63 Values => [ [ 'buy_sell', 'Buy and sell' ],
64 [ 'sell_buy', 'Sell and buy' ],
65 [ 'buy', 'Buy offers only' ],
66 [ 'sell', 'Sell offers only' ],
69 }, { Name => 'ShowBlank',
71 Values => [ [ 0, 'Omit islands with no offers' ],
72 [ 'show', 'Show all islands' ],
75 }, { Name => 'ShowStalls',
77 Values => [ [ 0, 'Show total quantity at each price' ],
78 [ 1, 'Show individual stalls' ],
83 foreach my $var (@vars) {
84 my $name= $var->{Name};
86 $var->{Before}= '' unless exists $var->{Before};
87 $var->{CmpCanon}= sub { $_[0]; } unless exists $var->{CmpCanon};
88 foreach my $val (@{ $var->{Values} }) {
90 $val= [ $val, encode_entities($val) ];
92 if (exists $ARGS{$lname}) {
93 $styles{$name}= $ARGS{$lname};
94 my @html= grep { $_->[0] eq $styles{$name} }
96 $ahtml{$name}= @html==1 ? $html[0][1] : '???';
98 $styles{$name}= $var->{Values}[0][0];
99 $ahtml{$name}= $var->{Values}[0][1];
114 % foreach my $n (keys %baseqf, keys %queryqf) {
115 % next if $ours->($n);
116 % my $v= exists $baseqf{$n} ? $baseqf{$n} : $queryqf{$n};
117 <input type=hidden name=<% $n %> value="<% $v |h %>">
121 <html><head><title><% ucfirst $ahtml{Query} %> - YARRG</title>
122 <style type="text/css">
127 tr.datarow0 { background: #e3e3e3; }
128 tr.datarow1 { background: #ffffff; }
131 function register_onload(f) {
132 var previous_onload= window.onload;
133 window.onload= function() {
134 if (previous_onload) previous_onload();
141 <a href="<% $m->current_comp()->name() |u %>">YARRG</a> -
142 Yet Another Revenue Research Gatherer
144 <a href="devel">development</a>
146 <a href="intro">introduction</a>
148 <a href="docs">documentation</a>
152 foreach my $var (@vars) {
153 my $lname= lc $var->{Name};
154 next unless exists $ARGS{$lname};
155 $baseqf{$lname}= $ARGS{$lname};
158 foreach my $var (keys %ARGS) {
160 m/^(?: (?:route|commod|capacity)string |
168 my $val= $ARGS{$var};
169 next if $val eq 'none';
170 $queryqf{$var}= $val;
174 my $uri= URI->new('lookup');
175 $uri->query_form(@_);
179 my $prselector_core= sub {
181 my $name= $var->{Name};
182 my $lname= lc $var->{Name};
183 my $delim= $var->{Before};
184 my $canon= &{$var->{CmpCanon}}($styles{$name});
186 foreach my $valr (@{ $var->{Values} }) {
187 print $delim; $delim= "\n|\n";
188 my ($value,$html) = @$valr;
189 my $iscurrent= &{$var->{CmpCanon}}($value) eq $canon;
195 my %qf= (%baseqf,%queryqf);
197 $qf{$lname}= $value if $cvalix;
199 <a href="<% $quri->(%qf) |h %>">
209 my $prselector= sub {
211 foreach my $var (@vars) {
212 if ($var->{Name} eq $name) {
213 $prselector_core->($var);
220 foreach my $var (@vars) {
221 next if $var->{QuerySpecific};
222 $prselector_core->($var);
225 #---------- initial checks, startup, main entry form ----------
227 die if $styles{Query} =~ m/[^a-z]/;
230 my $dbh= ($mydbh= dbw_connect($styles{Ocean}));
232 my $results_head_done=0;
233 my $someresults= sub {
234 return if $results_head_done;
235 $results_head_done=1;
237 $h= 'Results' if !$h;
238 print "\n<h1>$h</h1>\n";
248 <& "query_$styles{Query}", %baseqf, %queryqf, %styles,
249 quri => $quri, dbh => $dbh,
250 prselector => $prselector,
251 someresults => $someresults,
252 emsgokorprint => sub {
254 return 1 unless defined $emsg and length $emsg;
263 %#---------- debugging and epilogue ----------
275 var node= document.getElementById('debug_log');
276 node.innerHTML += "\n" + m + "\n";
291 $mydbh->rollback() if $mydbh;