X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.web-live.git;a=blobdiff_plain;f=yarrg%2Fweb%2Froute;h=595976f8293a7cde6b6cbe56871ba5e90f47595b;hp=1366345c44ab2d0e2361c7779ae589192919ac47;hb=4a7daddbd09806e47fc3b6df9cfc42ed5eb84758;hpb=598b6371434047312704df43e69cab629e1f3a3d diff --git a/yarrg/web/route b/yarrg/web/route index 1366345..595976f 100644 --- a/yarrg/web/route +++ b/yarrg/web/route @@ -4,6 +4,11 @@ my %a; my @vars; +# for output: +my @archipelagoes; +my @islandids; +my %islandid2; + #---------- "mode" argument parsing and mode menu at top of page ---------- # for debugging, invoke as @@ -141,6 +146,7 @@ function tr_Ready() { tr_request= false; tr_Request(); } +window.onload= tr_Needed;
 

-% if (length $routestring) { - -
-DATA FOR 
-<% $routestring |h %>
-WOULD GO HERE
-
- -% } - % } else { #---------- dropdowns, user selects from menus ---------- <%perl> @@ -199,6 +195,7 @@ while ($row=$sth->fetchrow_arrayref) { my $arch= $row->[2]; push @{ $islandlistdata{'none'} }, [ @$row ]; push @{ $islandlistdata{$arch} }, [ @$row ]; + $islandid2{$row->[0]}= { Name => $row->[1], Arch => $arch }; } my %resetislandlistdata; @@ -249,11 +246,73 @@ function ms_Setarch(dd) { -% } #---------- end of dropdowns, now common code ---------- +% } #---------- end of dropdowns, now common middle of page code ---------- +

Results

+ +<%perl> +#========== result computations ========== + +#---------- result computation - textstring ---------- +if (!$a{Dropdowns}) { + if (length $routestring) { + my $rsr= $m->comp('routetextstring', + ocean => $a{Ocean}, + string => $routestring, + format => 'return' + ); + if (length $rsr->{Error}) { + print encode_entities($rsr->{Error}); + } else { + foreach my $entry (@{ $rsr->{Results} }) { + push @archipelagoes, + defined $entry->[1] ? undef : $entry->[0]; + push @islandids, $entry->[1]; + } + } + } + +} else { #---------- results - dropdowns ---------- + +my $argorundef= sub { + my ($dd,$base) = @_; + my $thing= $ARGS{"${base}${dd}"}; + $thing= undef if defined $thing and $thing eq 'none'; + return $thing; +}; + +for my $dd (0..$a{Dropdowns}-1) { + my $arch= &$argorundef($dd,'archipelago'); + my $island= &$argorundef($dd,'islandid'); + next unless defined $arch or defined $island; + if (defined $island and defined $arch) { + my $ii= $islandid2{$island}; + my $iarch= $ii->{Arch}; + if ($iarch ne $arch) { + + Specified archipelago <% $arch %> but + island <% $ii->{Name} %> + which is in <% $iarch %>; using the island.
+<%perl> + } + $arch= undef; + } + push @archipelagoes, $arch; + push @islandids, $island; +} + +}#---------- result processing, common stuff + + +% if (@islandids) { + +<& routetrade, islandids => \@islandids, archipelagoes => \@archipelagoes &> + +% } + %#---------- debugging and epilogue ---------- % if ($debug) {