chiark / gitweb /
2162e8a8bbf203c7336c561d217374c378d11043
[ypp-sc-tools.web-live.git] / yarrg / web / query_route
1 <%doc>
2
3  This is part of the YARRG website.  YARRG is a tool and website
4  for assisting players of Yohoho Puzzle Pirates.
5
6  Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
7  Copyright (C) 2009 Clare Boothby
8
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
12    download the source.
13
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.
18
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.
23
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/>.
26
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.
30
31
32  This Mason component generates the core of the `trade route' query.
33
34
35 </%doc>
36 <%args>
37 $quri
38 $dbh
39 $prselector
40 $routestring => '';
41 $capacitystring => '';
42 $lossperleague => '';
43 $capitalstring => '';
44 $someresults
45 $emsgokorprint
46 </%args>
47
48 <%perl>
49 my $emsg;
50 my @warningfs;
51 my @archipelagoes;
52 my @islandids;
53 my ($max_volume, $max_mass);
54 my $lossperleaguepct;
55 my $capital;
56
57 my $qa= \%ARGS;
58
59 my $be_post;
60 my $startform= sub {
61         ($be_post)= @_;
62 </%perl>
63 <form action="<% $quri->() |h %>" method="<% $be_post ? 'post' : 'get' %>">
64 <%perl>
65 };
66 my $goupdate= sub { $be_post ? 'Update' : 'Go' };
67
68 </%perl>
69
70 <h1>Specify route</h1>
71
72 % # Sadly we need to do this rather hacky thing to make it be a POST
73 % #  form if the user has already selected some thing(s)
74 % if (!$qa->{Dropdowns}) {
75 %     $startform->($routestring =~ m/\S/);
76 % } else {
77 %     $startform->(grep {
78 %               defined $qa->{"archipelago$_"} ||
79 %               defined $qa->{"islandid$_"}
80 %       } (0..$qa->{Dropdowns}-1));
81 % }
82
83 % $prselector->('ShowStalls');
84
85 <& enter_route, qa => $qa, dbh => $dbh, emsg_r => \$emsg,
86         warningfs_r => \@warningfs,
87         enterwhat => 'Enter route',
88         islandids_r => \@islandids,
89         archipelagoes_r => \@archipelagoes
90  &>
91
92 %#---------- textboxes, user enters details as strings ----------
93 % if (!$qa->{Dropdowns}) {
94
95 <strong>Advanced options - you may leave these blank:</strong>
96 <p>
97 <table>
98 <tr>
99 <td>
100
101 Vessel or capacity:
102 <&| qtextstring, qa => $qa, dbh => $dbh, prefix => 'cs',
103     thingstring => 'capacitystring', emsgstore => \$emsg,
104     helpref => 'capacity',
105     onresults => sub { ($max_mass,$max_volume) = @_; }
106  &>
107  size=40
108 </&>
109
110 <td>
111 &nbsp;
112 &nbsp;
113
114 <td>
115 Expected losses:
116
117 <&| qtextstring, qa => $qa, dbh => $dbh, prefix => 'll',
118     thingstring => 'lossperleague', emsgstore => \$emsg,
119     helpref => 'losses',
120     onresults => sub { ($lossperleaguepct)= @_; }
121  &>
122  size=9
123 </&>
124
125 </table>
126 <table><tr>
127
128 <td>Available capital:
129
130 <&| qtextstring, qa => $qa, dbh => $dbh, prefix => 'ac',
131     thingstring => 'capitalstring', emsgstore => \$emsg,
132     helpref => 'capital',
133     onresults => sub { ($capital)= @_; }
134  &>
135  size=9
136 </&>
137 </td>
138 </tr>
139 </table>
140
141 % } #---------- end of dropdowns, now common middle of page code ----------
142
143 <input type=submit name=submit value="<% $goupdate->() %>">
144 % my $ours= sub { $_[0] =~
145 %  m/^island|^archipelago|^routestring|^capacitystring|^lossperleague|^capitalstring|^[RT]/;
146 % };
147 <& "lookup:formhidden", ours => $ours &>
148
149 <%perl>
150 #========== results ==========
151
152 $emsgokorprint->($emsg) or @islandids=();
153
154 foreach my $warningf (@warningfs) {
155         $someresults->();
156         $warningf->();
157 }
158
159 </%perl>
160
161 % if (@islandids) {
162 %       $someresults->('Relevant trades');
163 <& routetrade,
164    dbh => $dbh,
165    islandids => \@islandids,
166    archipelagoes => \@archipelagoes,
167    qa => $qa,
168    max_mass => $max_mass,
169    max_volume => $max_volume,
170    lossperleaguepct => $lossperleaguepct,
171    max_capital => $capital
172  &>
173 % }
174 </form>