14 %#---------- textbox, user enters route as string ----------
15 % if (!$qa->{Dropdowns}) {
17 <h1>Specify route</h1>
19 <form action="<% $quri->() |h %>" method="get">
21 <&| qtextstring, qa => $qa, thingstring => 'routestring' &>
25 % } else { #---------- dropdowns, user selects from menus ----------
31 $islandlistdata{'none'}= [ [ "none", "Select island..." ] ];
33 my $optionlistmap= sub {
34 my ($optlist, $selected) = @_;
36 foreach my $entry (@$optlist) {
37 $out.= sprintf('<option value="%s" %s>%s</option>',
38 encode_entities($entry->[0]),
39 defined $selected && $entry->[0] eq $selected
41 encode_entities($entry->[1]));
46 my $dbh= dbw_connect($qa->{Ocean});
48 $sth= $dbh->prepare("SELECT DISTINCT archipelago FROM islands
49 ORDER BY archipelago;");
52 while ($row=$sth->fetchrow_arrayref) {
54 push @archlistdata, [ $arch, $arch ];
55 $islandlistdata{$arch}= [ [ "none", "Whole arch" ] ];
58 $sth= $dbh->prepare("SELECT islandid,islandname,archipelago
60 ORDER BY islandname;");
63 while ($row=$sth->fetchrow_arrayref) {
65 push @{ $islandlistdata{'none'} }, [ @$row ];
66 push @{ $islandlistdata{$arch} }, [ @$row ];
67 $islandid2{$row->[0]}= { Name => $row->[1], Arch => $arch };
70 my %resetislandlistdata;
71 foreach my $arch (keys %islandlistdata) {
72 $resetislandlistdata{$arch}=
73 $optionlistmap->($islandlistdata{$arch}, '');
78 <input type=hidden name=dropdowns value="<% $qa->{Dropdowns} |h %>">
81 ms_lists= <% to_json_protecttags(\%resetislandlistdata) %>;
82 function ms_Setarch(dd) {
83 debug('ms_SetArch '+dd+' arch='+arch);
84 var arch= document.getElementsByName('archipelago'+dd).item(0).value;
85 var got= ms_lists[arch];
86 if (got == undefined) return; // unknown arch ? hrm
87 debug('ms_SetArch '+dd+' arch='+arch+' got ok');
88 var select= document.getElementsByName('islandid'+dd).item(0);
89 select.innerHTML= got;
90 debug('ms_SetArch '+dd+' arch='+arch+' innerHTML set');
94 <table style="table-layout:fixed; width:90%;">
97 % for my $dd (0..$qa->{Dropdowns}-1) {
99 <select name="archipelago<% $dd %>" onchange="ms_Setarch(<% $dd %>)">
100 <option value="none">Whole ocean</option>
101 <% $optionlistmap->(\@archlistdata, $ARGS{"archipelago$dd"}) %></select></td>
106 % for my $dd (0..$qa->{Dropdowns}-1) {
107 % my $arch= $ARGS{"archipelago$dd"};
108 % $arch= 'none' if !defined $arch;
110 <select name="islandid<% $dd %>">
111 <% $optionlistmap->($islandlistdata{$arch}, $ARGS{"islandid$dd"}) %>
118 % } #---------- end of dropdowns, now common middle of page code ----------
120 <input type=submit name=submit value="Go">
124 #========== result computations ==========
128 print "<h1>Results</h1>\n";
129 $results_head= sub { };
132 #---------- result computation - textstring ----------
133 if (!$qa->{Dropdowns}) {
134 if (length $routestring) {
136 my $rsr= $m->comp('routetextstring',
137 ocean => $qa->{Ocean},
138 string => $routestring,
141 if (length $rsr->{Error}) {
142 print encode_entities($rsr->{Error});
144 foreach my $entry (@{ $rsr->{Results} }) {
146 defined $entry->[1] ? undef : $entry->[0];
147 push @islandids, $entry->[1];
152 } else { #---------- results - dropdowns ----------
154 my $argorundef= sub {
156 my $thing= $ARGS{"${base}${dd}"};
157 $thing= undef if defined $thing and $thing eq 'none';
161 for my $dd (0..$qa->{Dropdowns}-1) {
162 my $arch= $argorundef->($dd,'archipelago');
163 my $island= $argorundef->($dd,'islandid');
164 next unless defined $arch or defined $island;
165 if (defined $island and defined $arch) {
166 my $ii= $islandid2{$island};
167 my $iarch= $ii->{Arch};
168 if ($iarch ne $arch) {
171 Specified archipelago <% $arch %> but
172 island <% $ii->{Name} %>
173 which is in <% $iarch %>; using the island.<br>
178 push @archipelagoes, $arch;
179 push @islandids, $island;
182 }#---------- result processing, common stuff
188 <& routetrade, islandids => \@islandids, archipelagoes => \@archipelagoes &>