<%doc> This is part of the YARRG website. YARRG is a tool and website for assisting players of Yohoho Puzzle Pirates. Copyright (C) 2009 Ian Jackson Copyright (C) 2009 Clare Boothby YARRG's client code etc. is covered by the ordinary GNU GPL (v3 or later). The YARRG website is covered by the GNU Affero GPL v3 or later, which basically means that every installation of the website will let you download the source. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . Yohoho and Puzzle Pirates are probably trademarks of Three Rings and are used without permission. This program is not endorsed or sponsored by Three Rings. This Mason component generates the main `lookup' page, including all the entry boxes etc. for every query. <%perl> my %ahtml; my @vars; my %styles; #---------- "mode" argument parsing and mode menu at top of page ---------- # for debugging, invoke as # http://www.chiark.greenend.org.uk/ucgi/~clareb/mason/pirates/pirate-route?debug=1 @vars= ({ Name => 'Ocean', Before => 'Ocean: ', CmpCanon => sub { ucfirst lc $_[0] }, Values => [ ocean_list() ] }, { Name => 'Dropdowns', Before => 'Interface: ', CmpCanon => sub { !!$_[0] }, Values => [ [ 0, 'Type in names' ], [ 4, 'Select from menus' ] ] }, { Name => 'Query', Before => 'Query: ', Values => [ [ 'route', 'Trades for route' ], [ 'commod', 'Prices for commodity' ], [ 'offers', 'Offers at location' ], [ 'routesearch', 'Find profitable route' ], [ 'age', 'Data age' ] ] }, { Name => 'BuySell', Before => '', Values => [ [ 'buy_sell', 'Buy and sell' ], [ 'sell_buy', 'Sell and buy' ], [ 'buy', 'Buy offers only' ], [ 'sell', 'Sell offers only' ], ], QuerySpecific => 1, }, { Name => 'ShowBlank', Before => '', Values => [ [ 0, 'Omit islands with no offers' ], [ 'show', 'Show all islands' ], ], QuerySpecific => 1, }, { Name => 'ShowStalls', Before => '', Values => [ [ 0, 'Show total quantity at each price' ], [ 1, 'Show individual stalls' ], ], QuerySpecific => 1, }, { Name => 'RouteSearchType', Before => 'Type of routes to search for: ', Values => [ [ 0, 'Open-ended' ], [ 1, 'Circular' ], ], QuerySpecific => 1, }); foreach my $var (@vars) { my $name= $var->{Name}; my $lname= lc $name; $var->{Before}= '' unless exists $var->{Before}; $var->{CmpCanon}= sub { $_[0]; } unless exists $var->{CmpCanon}; foreach my $val (@{ $var->{Values} }) { next if ref $val; $val= [ $val, encode_entities($val) ]; } if (exists $ARGS{$lname}) { $styles{$name}= $ARGS{$lname}; my @html= grep { $_->[0] eq $styles{$name} } @{ $var->{Values} }; $ahtml{$name}= @html==1 ? $html[0][1] : '???'; } else { $styles{$name}= $var->{Values}[0][0]; $ahtml{$name}= $var->{Values}[0][1]; } } <%shared> my %baseqf; my %queryqf; <%method formhidden> <%args> $ours % foreach my $n (keys %baseqf, keys %queryqf) { % next if $ours->($n); % my $v= exists $baseqf{$n} ? $baseqf{$n} : $queryqf{$n}; value="<% $v |h %>"> % } <% ucfirst $ahtml{Query} %> - YARRG <&| script &> function register_onload(f) { var previous_onload= window.onload; window.onload= function() { if (previous_onload) previous_onload(); f(); }; } % if (!printable($m)) {
% } <& "query_$styles{Query}", %baseqf, %queryqf, %styles, quri => $quri, dbh => $dbh, baseqf => \%baseqf, queryqf => \%queryqf, allargs => \%ARGS, prselector => $prselector, someresults => $someresults, emsgokorprint => sub { my ($emsg) = @_; return 1 unless defined $emsg and length $emsg; $someresults->(); print $emsg; return 0; } &> %#---------- debugging and epilogue ---------- % if ($debug) {
Debug log:
% } <&| script &> function debug (m) { % if ($debug) { var node= document.getElementById('debug_log'); node.innerHTML += "\n" + m + "\n"; % } } <& footer &> <%init> use CommodsWeb; use HTML::Entities; use URI::Escape; <%cleanup> $mydbh->rollback() if $mydbh;