Rely on layout.mc to pull in xml_encode()
[irspy-moved-to-github.git] / web / htdocs / details / found.mc
index f7f8799..4bdf8d6 100644 (file)
@@ -1,7 +1,28 @@
-%# $Id: found.mc,v 1.7 2006-09-20 13:19:53 mike Exp $
+%# $Id: found.mc,v 1.11 2006-09-25 16:52:30 mike Exp $
 <%once>
 use XML::LibXML;
 use XML::LibXML::XPathContext;
+use URI::Escape;
+
+sub print_navlink {
+    my($params, $cond, $caption, $skip) = @_;
+
+    if ($cond) {
+       print('     <a href="', navlink($params, $caption, $skip),
+             '"', ">$caption</a>\n");
+    } else {
+       print qq[     <span class="disabled">$caption</span>\n];
+    }
+}
+
+sub navlink {
+    my($params, $caption, $skip) = @_;
+    local $params->{_skip} = $skip;
+    my $url = "?" . join("&", map { "$_=" . $params->{$_}  } sort keys %$params);
+    $url = xml_encode($url);
+    return $url;
+}
+
 </%once>
 <%perl>
 my %params = map { ( $_, $r->param($_)) } grep { $r->param($_) } $r->param();
@@ -44,7 +65,7 @@ my $first = $skip+1;
 my $last = $first+$count-1;
 $last = $n if $last > $n;
 </%perl>
-     <h2><% $query %></h2>
+     <h2><% xml_encode($query) %></h2>
      <p>
 % if ($n == 0) {
       No matches
@@ -54,20 +75,8 @@ $last = $n if $last > $n;
 % } else {
       Records <% $first %> to <% $last %> of <% $n %><br/>
 <%perl>
-if ($skip > 0) {
-    $params{_skip} = $count < $skip ? $skip-$count : 0;
-    my $prev = "?" . join("&", map { "$_=" . $params{$_}  } sort keys %params);
-    print qq[     <a href="$prev">Prev</a>\n];
-} else {
-    print qq[     <span class="disabled">Prev</span>\n];
-}
-if ($last < $n) {
-    $params{_skip} = $skip+$count;
-    my $next = "?" . join("&", map { "$_=" . $params{$_}  } sort keys %params);
-    print qq[     <a href="$next">Next</a>\n];
-} else {
-    print qq[     <span class="disabled">Next</span>\n];
-}
+print_navlink(\%params, $skip > 0, "Prev", $count < $skip ? $skip-$count : 0);
+print_navlink(\%params, $last < $n, "Next", $skip+$count);
 </%perl>
 % }
      </p>
@@ -83,6 +92,7 @@ if ($last < $n) {
        <th></th>
        <th></th>
       </tr>
+% my @ids;
 % foreach my $i ($first .. $last) {
 <%perl>
 my $rec = $rs->record($i-1);
@@ -99,17 +109,29 @@ my $db = $xc->find("e:serverInfo/e:database");
 my $id = $xc->find("concat(e:serverInfo/e:host, ':',
                            e:serverInfo/e:port, '/',
                            e:serverInfo/e:database)");
+push @ids, $id;
 </%perl>
       <tr style="background: <% ($i % 2) ? '#ffffc0' : 'white' %>">
        <td><% $i %></td>
-       <td><% $title %></td>
-       <td><% $author %></td>
-       <td><% $host %></td>
-       <td><% $port %></td>
-       <td><% $db %></td>
-       <td><a href="<% "/check.html?id=$id" %>">[Check]</a></td>
-       <td><a href="<% "/raw.html?id=$id" %>">[Raw]</a></td>
+       <td><% xml_encode($title) %></td>
+       <td><% xml_encode($author) %></td>
+       <td><% xml_encode($host) %></td>
+       <td><% xml_encode($port) %></td>
+       <td><% xml_encode($db) %></td>
+       <td><a href="<% xml_encode("/check.html?id=" . uri_escape($id))
+       %>">[Test]</a></td>
+       <td><a href="<% xml_encode("/raw.html?id=" . uri_escape($id))
+       %>">[Raw]</a></td>
       </tr>
-%}
+% }
      </table>
+<%perl>
+print_navlink(\%params, $skip > 0, "Prev", $count < $skip ? $skip-$count : 0);
+print_navlink(\%params, $last < $n, "Next", $skip+$count);
+</%perl>
+     <p>
+      <a href="<% "/check.html?" .
+       xml_encode(join("&", map { "id=" . uri_escape($_) } @ids))
+       %>">[Test all targets on this list]</a>
+     </p>
 % }