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 `trade route' query.
41 $capacitystring => '';
52 my ($max_volume, $max_mass);
61 <form action="<% $quri->() |h %>" method="<% $be_post ? 'post' : 'get' %>">
64 my $goupdate= sub { $be_post ? 'Update' : 'Go' };
68 <h1>Specify route</h1>
70 % $prselector->('ShowStalls');
72 %#---------- textbox, user enters route as string ----------
73 % if (!$qa->{Dropdowns}) {
75 Enter route (islands, or archipelagoes, separated by |s or commas;
76 abbreviations are OK):<br>
78 % $startform->($routestring =~ m/\S/);
80 <&| qtextstring, qa => $qa, dbh => $dbh,
81 thingstring => 'routestring', emsgstore => \$emsg,
83 my ($canonname, $island, $arch) = @_;
84 push @islandids, $island;
85 push @archipelagoes, defined $island ? undef : $arch;
91 <strong>Advanced options - you may leave these blank:</strong>
98 <&| qtextstring, qa => $qa, dbh => $dbh, prefix => 'cs',
99 thingstring => 'capacitystring', emsgstore => \$emsg,
100 helpref => 'capacity',
102 ($max_mass,$max_volume) = @_;
115 <&| qtextstring, qa => $qa, dbh => $dbh, prefix => 'll',
116 thingstring => 'lossperleague', emsgstore => \$emsg,
118 perresult => sub { ($lossperleaguepct)= @_; }
125 % } else { #---------- dropdowns, user selects from menus ----------
127 % $startform->(grep {
128 % defined $ARGS{"archipelago$_"} ||
129 % defined $ARGS{"islandid$_"}
130 % } (0..$qa->{Dropdowns}-1));
136 $islandlistdata{'none'}= [ [ "none", "Select island..." ] ];
138 my $optionlistmap= sub {
139 my ($optlist, $selected) = @_;
141 foreach my $entry (@$optlist) {
142 $out.= sprintf('<option value="%s" %s>%s</option>',
143 encode_entities($entry->[0]),
144 defined $selected && $entry->[0] eq $selected
146 encode_entities($entry->[1]));
151 $sth= $dbh->prepare("SELECT DISTINCT archipelago FROM islands
152 ORDER BY archipelago;");
155 while ($row=$sth->fetchrow_arrayref) {
157 push @archlistdata, [ $arch, $arch ];
158 $islandlistdata{$arch}= [ [ "none", "Whole arch" ] ];
161 $sth= $dbh->prepare("SELECT islandid,islandname,archipelago
163 ORDER BY islandname;");
166 while ($row=$sth->fetchrow_arrayref) {
168 push @{ $islandlistdata{'none'} }, [ @$row ];
169 push @{ $islandlistdata{$arch} }, [ @$row ];
170 $islandid2{$row->[0]}= { Name => $row->[1], Arch => $arch };
173 my %resetislandlistdata;
174 foreach my $arch (keys %islandlistdata) {
175 $resetislandlistdata{$arch}=
176 $optionlistmap->($islandlistdata{$arch}, '');
182 ms_lists= <% to_json_protecttags(\%resetislandlistdata) %>;
183 function ms_Setarch(dd) {
184 debug('ms_SetArch '+dd+' arch='+arch);
185 var arch= document.getElementsByName('archipelago'+dd).item(0).value;
186 var got= ms_lists[arch];
187 if (got == undefined) return; // unknown arch ? hrm
188 debug('ms_SetArch '+dd+' arch='+arch+' got ok');
189 var select= document.getElementsByName('islandid'+dd).item(0);
190 select.innerHTML= got;
191 debug('ms_SetArch '+dd+' arch='+arch+' innerHTML set');
195 <table style="table-layout:fixed; width:90%;">
198 % for my $dd (0..$qa->{Dropdowns}-1) {
200 <select name="archipelago<% $dd %>" onchange="ms_Setarch(<% $dd %>)">
201 <option value="none">Whole ocean</option>
202 <% $optionlistmap->(\@archlistdata, $ARGS{"archipelago$dd"}) %></select></td>
207 % for my $dd (0..$qa->{Dropdowns}-1) {
208 % my $arch= $ARGS{"archipelago$dd"};
209 % $arch= 'none' if !defined $arch;
211 <select name="islandid<% $dd %>">
212 <% $optionlistmap->($islandlistdata{$arch}, $ARGS{"islandid$dd"}) %>
219 % } #---------- end of dropdowns, now common middle of page code ----------
221 <input type=submit name=submit value="<% $goupdate->() %>">
222 % my $ours= sub { $_[0] =~
223 % m/^island|^archipelago|^routestring|^capacitystring|^lossperleague|^[RT]/;
225 <& "lookup:formhidden", ours => $ours &>
228 #========== results ==========
230 $emsgokorprint->($emsg) or @islandids=();
232 my $argorundef= sub {
234 my $thing= $ARGS{"${base}${dd}"};
235 $thing= undef if defined $thing and $thing eq 'none';
239 for my $dd (0..$qa->{Dropdowns}-1) {
240 my $arch= $argorundef->($dd,'archipelago');
241 my $island= $argorundef->($dd,'islandid');
242 next unless defined $arch or defined $island;
243 if (defined $island and defined $arch) {
244 my $ii= $islandid2{$island};
245 my $iarch= $ii->{Arch};
246 if ($iarch ne $arch) {
249 Specified archipelago <% $arch %> but
250 island <% $ii->{Name} %>
251 which is in <% $iarch %>; using the island.<br>
256 push @archipelagoes, $arch;
257 push @islandids, $island;
263 % $someresults->('Relevant trades');
266 islandids => \@islandids,
267 archipelagoes => \@archipelagoes,
269 max_mass => $max_mass,
270 max_volume => $max_volume,
271 lossperleaguepct => $lossperleaguepct