chiark / gitweb /
Merge branch 'master' of ../ypp-sc-tools
[ypp-sc-tools.db-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 $minprofitstring => '';
45 $someresults
46 $emsgokorprint
47 $allargs
48 </%args>
49
50 <%perl>
51 my $emsg;
52 my @warningfs;
53 my @archipelagoes;
54 my @islandids;
55
56 my $qa= \%ARGS;
57
58 my $be_post;
59 my $startform= sub {
60         ($be_post)= @_;
61 </%perl>
62 <form action="<% $quri->() |h %>" method="<% $be_post ? 'post' : 'get' %>">
63 <%perl>
64 };
65 my $goupdate= sub { $be_post ? 'Update' : 'Go' };
66
67 </%perl>
68
69 % # Sadly we need to do this rather hacky thing to make it be a POST
70 % #  form if the user has already selected some thing(s)
71 % if (!$qa->{Dropdowns}) {
72 %     $startform->($routestring =~ m/\S/);
73 % } else {
74 %     $startform->(grep {
75 %               defined $qa->{"archipelago$_"} ||
76 %               defined $qa->{"islandid$_"}
77 %       } (0..$qa->{Dropdowns}-1));
78 % }
79
80 <div class="query">
81
82 <h1>Specify route</h1>
83
84 % $prselector->('ShowStalls');
85
86 <& enter_route, qa => $qa, dbh => $dbh, emsg_r => \$emsg,
87         warningfs_r => \@warningfs,
88         enterwhat => 'Enter route',
89         islandids_r => \@islandids,
90         archipelagoes_r => \@archipelagoes
91  &>
92
93 %#---------- textboxes, user enters details as strings ----------
94 % my $routeparams= { EmsgRef => \$emsg };
95 % if (!$qa->{Dropdowns}) {
96
97 <input type=submit name=submit value="<% $goupdate->() %>">
98 <p>
99
100 <& enter_advrouteopts, qa=>$qa, dbh=>$dbh,
101    minprofit_needs_apply => $be_post,
102    routeparams=>$routeparams &>
103
104 % } #---------- end of dropdowns, now common middle of page code ----------
105
106 % my $ours= sub { $_[0] =~
107 %  m/^island|^archipelago|^routestring|^capacitystring|^lossperleague|^capitalstring|^minprofitstring|^[RT]/;
108 % };
109 <& "lookup:formhidden", ours => $ours &>
110
111 </div>
112 <div class="results">
113 <%perl>
114 #========== results ==========
115
116 $emsgokorprint->($emsg) or @islandids=();
117
118 foreach my $warningf (@warningfs) {
119         $someresults->();
120         $warningf->();
121 }
122
123 </%perl>
124
125 % if (@islandids) {
126 %       $someresults->();
127 <& routetrade,
128    dbh => $dbh,
129    islandids => \@islandids,
130    archipelagoes => \@archipelagoes,
131    qa => $qa, quri => $quri,
132    routeparams => $routeparams,
133    reset_suppressions => !!$allargs->{'apply_minprofit'}
134  &>
135 % }
136 </div>
137 </form>