chiark / gitweb /
WIP pirate-route selector
[ypp-sc-tools.db-test.git] / yarrg / web / pirate-route
1 <html><head><title>Specify route</title></head><body>
2
3 <%perl>
4 my %a;
5 my @vars;
6
7 @vars= ({       Name => 'Ocean',
8                 Before => 'Ocean: ',
9                 CmpCanon => sub { ucfirst lc $_[0] },
10                 Values => [ qw(Midnight Ice) ]
11         }, {    Name => 'Dropdowns',
12                 Before => 'Interface: ',
13                 CmpCanon => sub { !!$_[0] },
14                 Values => [     [ 0, 'Type in names' ],
15                                 [ 4, 'Select from menus' ] ]
16         });
17
18 foreach my $var (@vars) {
19         my $name= $var->{Name};
20         $var->{Before}= '' unless exists $var->{Before};
21         $var->{CmpCanon}= sub { $_[0]; } unless exists $var->{CmpCanon};
22         foreach my $val (@{ $var->{Values} }) {
23                 next if ref $val;
24                 $val= [ $val, encode_entities($val) ];
25         }
26         if (exists $ARGS{lc $name}) {
27                 $a{$name}= $ARGS{lc $name};
28         } else {
29                 $a{$name}= $var->{Values}[0][0];
30         }
31 }
32
33 foreach my $var (@vars) {
34         my $name= $var->{Name};
35         my $delim= $var->{Before};
36         my $canon= &{$var->{CmpCanon}}($a{$name});
37         my $cvalix= 0;
38         foreach my $valr (@{ $var->{Values} }) {
39                 print $delim;  $delim= "\n|\n";
40                 my ($value,$html) = @$valr;
41                 my $iscurrent= &{$var->{CmpCanon}}($value) eq $canon;
42                 my $after;
43                 if ($iscurrent) {
44                         print '<b>';
45                         $after= '</b>';
46                 } else {
47                         my %qf= ();
48                         foreach my $innerr (@vars) {
49                                 my $n= lc $innerr->{Name};
50                                 if ($n ne lc $name) {
51                                         next unless exists $ARGS{$n};
52                                         $qf{$n}= $ARGS{$n};
53                                 } else {
54                                         next if !$cvalix;
55                                         $qf{$n}= $value;
56                                 }
57                         }
58                         my $uri= URI->new($self_url);
59                         $uri->query_form(%qf);
60                         print '<a href="', $uri->path_query(), '">';
61                         $after= '</a>';
62                 }
63                 print $html, $after;
64                 $cvalix++;
65         }
66         print '<p>';
67 }
68
69 db_setocean($a{'ocean'});
70 db_connect();
71
72 </%perl>
73
74 <h1>Specify route</h1>
75 <form action="/ucgi/~clareb/mason/something" method="get">
76
77 % if (!$a{Dropdowns}) {
78 Enter route (islands, or archipelagoes, separated by commas;
79  abbreviations are OK):<br>
80 <input type="text" name="routestring" size=80><br>
81 <div name="results"></div></br>
82 % } else {
83
84 <%perl>
85 my $sth=$dbh->prepare("SELECT islandid,islandname
86                               FROM islands
87                               ORDER BY islandname;");
88 $sth->execute();
89 my $row;
90 my $islandlistdata='';
91 while ($row=$sth->fetchrow_arrayref) {
92         $islandlistdata.=
93                 sprintf('<option value="%s">%s</option>',
94                         map { encode_entities($_) } @$row);
95 }
96 </%perl>
97
98 <table>
99 <tr>
100 %       for my $dd (0..$a{Dropdowns}-1) {
101 <td><select name="islandid<% $dd %>">
102 <option name="none">Select island...</option>
103 <% $islandlistdata %></select></td>
104 %       }
105 % }
106 </tr>
107 </table>
108
109 <input type=submit name=submit value="Go">
110 </form>
111
112 <%init>
113 use CommodsWeb;
114 use HTML::Entities;
115
116 </%init>