X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=yarrg%2Fweb%2Flookup;h=448ad6ec3441d38171735cbcbb0546b9a235ed0c;hb=6335baf49c849e16ae7845016d97bcb76d4b7cf6;hp=9c00a65466481bd3e6e1633fa3fe0c7fbf418f9a;hpb=555fcf1a304c5f1aef9384c3c4d07d5255a0f05d;p=ypp-sc-tools.db-test.git diff --git a/yarrg/web/lookup b/yarrg/web/lookup old mode 100644 new mode 100755 index 9c00a65..448ad6e --- a/yarrg/web/lookup +++ b/yarrg/web/lookup @@ -1,17 +1,43 @@ -
+ 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
+<%perl>
+
foreach my $var (@vars) {
my $lname= lc $var->{Name};
next unless exists $ARGS{$lname};
$baseqf{$lname}= $ARGS{$lname};
}
-my %queryqf;
foreach my $var (keys %ARGS) {
next unless $var =~
- m/^(?:routestring|islandid\d|archipelago\d|debug)$/;
+ m/^(?: (?:route|commod|capacity)string |
+ lossperleague |
+ commodid |
+ islandid \d |
+ archipelago \d |
+ debug |
+ [RT]\w+
+ )$/x;
my $val= $ARGS{$var};
next if $val eq 'none';
$queryqf{$var}= $val;
}
-my $uri= URI->new($m->current_comp()->name());
-my $quri= sub { $uri->query_form(@_); $uri->path_query(); };
+my $quri= sub {
+ my $uri= URI->new('lookup');
+ $uri->query_form(@_);
+ $uri->path_query();
+};
-foreach my $var (@vars) {
+my $prselector_core= sub {
+ my ($var)= @_;
my $name= $var->{Name};
my $lname= lc $var->{Name};
my $delim= $var->{Before};
- my $canon= &{$var->{CmpCanon}}($a{$name});
+ my $canon= &{$var->{CmpCanon}}($styles{$name});
my $cvalix= 0;
foreach my $valr (@{ $var->{Values} }) {
print $delim; $delim= "\n|\n";
@@ -82,247 +193,70 @@ foreach my $var (@vars) {
my %qf= (%baseqf,%queryqf);
delete $qf{$lname};
$qf{$lname}= $value if $cvalix;
- print '';
+%perl>
+
+<%perl>
$after= '';
}
print $html, $after;
$cvalix++;
}
print " \n\n";
-}
-
-#---------- initial checks, startup, main entry form ----------
-
-dbw_connect($a{Ocean});
-
-%perl>
-<%args>
-$debug => 0
-$routestring => ''
-%args>
-
-
%#---------- debugging and epilogue ----------
@@ -333,19 +267,25 @@ Debug log:
% }
-
+&script>
+
+<& footer &>
<%init>
use CommodsWeb;
use HTML::Entities;
use URI::Escape;
-use JSON;
%init>
+<%cleanup>
+
+$mydbh->rollback() if $mydbh;
+
+%cleanup>
Specify route
-
-
-<%perl>
-#========== result computations ==========
-
-my $results_head;
-$results_head= sub {
- print "Results
\n";
- $results_head= sub { };
-};
+#---------- initial checks, startup, main entry form ----------
-#---------- result computation - textstring ----------
-if (!$a{Dropdowns}) {
- if (length $routestring) {
- $results_head->();
- 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];
- }
- }
- }
+die if $styles{Query} =~ m/[^a-z]/;
-} else { #---------- results - dropdowns ----------
+my $mydbh;
+my $dbh= ($mydbh= dbw_connect($styles{Ocean}));
-my $argorundef= sub {
- my ($dd,$base) = @_;
- my $thing= $ARGS{"${base}${dd}"};
- $thing= undef if defined $thing and $thing eq 'none';
- return $thing;
+my $results_head_done=0;
+my $someresults= sub {
+ return if $results_head_done;
+ $results_head_done=1;
+ my ($h)= @_;
+ $h= 'Results' if !$h;
+ print "\n$h
\n";
};
-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) {
- $results_head->();
-%perl>
- 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
%perl>
+<%args>
+$debug => 0
+%args>
-% if (@islandids) {
-% $results_head->();
-
-<& routetrade, islandids => \@islandids, archipelagoes => \@archipelagoes &>
+
+
+<& "query_$styles{Query}", %baseqf, %queryqf, %styles,
+ quri => $quri, dbh => $dbh,
+ prselector => $prselector,
+ someresults => $someresults,
+ emsgokorprint => sub {
+ my ($emsg) = @_;
+ return 1 unless defined $emsg and length $emsg;
+ $someresults->();
+ print $emsg;
+ return 0;
+ }
+ &>
-% }
+