Add link to test all targets in searchlist.
[irspy-moved-to-github.git] / web / htdocs / details / found.mc
1 %# $Id: found.mc,v 1.8 2006-09-20 16:37:15 mike Exp $
2 <%once>
3 use XML::LibXML;
4 use XML::LibXML::XPathContext;
5 </%once>
6 <%perl>
7 my %params = map { ( $_, $r->param($_)) } grep { $r->param($_) } $r->param();
8 my $query = "";
9 foreach my $key (keys %params) {
10     next if $key =~ /^_/;
11     my $val = $params{$key};
12     next if $val eq "";
13     $query .= " and " if $query ne "";
14     $query .= "$key = ($val)";
15 }
16 $query = 'cql.allRecords=x' if $query eq "";
17
18 my $sort = $params{"_sort"};
19 if ($sort) {
20     my $modifiers = "";
21     if ($sort =~ s/(\/.*)//) {
22         $modifiers = $1;
23     }
24     $query .= " or $sort=/sort";
25     $query .= "-desc" if $params{_desc};
26     $query .= $modifiers;
27     $query .= " 0";
28 }
29
30 ### We can think about keeping the Connection object open to re-use
31 # for multiple requests, but that may not get us much.  Same applies
32 # for the XML parser.
33 my $conn = new ZOOM::Connection("localhost:3313/IR-Explain---1");
34 $conn->option(elementSetName => "zeerex");
35 my $parser = new XML::LibXML();
36
37 my $rs = $conn->search(new ZOOM::Query::CQL($query));
38 my $n = $rs->size();
39
40 my $skip = $params{"_skip"} || 0;
41 my $count = $params{"_count"} || 10;
42
43 my $first = $skip+1;
44 my $last = $first+$count-1;
45 $last = $n if $last > $n;
46 </%perl>
47      <h2><% $query %></h2>
48      <p>
49 % if ($n == 0) {
50       No matches
51 % } elsif ($first > $n) {
52 %# "Can't happen"
53       Past end of <% $n %> records
54 % } else {
55       Records <% $first %> to <% $last %> of <% $n %><br/>
56 <%perl>
57 if ($skip > 0) {
58     $params{_skip} = $count < $skip ? $skip-$count : 0;
59     my $prev = "?" . join("&", map { "$_=" . $params{$_}  } sort keys %params);
60     print qq[     <a href="$prev">Prev</a>\n];
61 } else {
62     print qq[     <span class="disabled">Prev</span>\n];
63 }
64 if ($last < $n) {
65     $params{_skip} = $skip+$count;
66     my $next = "?" . join("&", map { "$_=" . $params{$_}  } sort keys %params);
67     print qq[     <a href="$next">Next</a>\n];
68 } else {
69     print qq[     <span class="disabled">Next</span>\n];
70 }
71 </%perl>
72 % }
73      </p>
74 % if ($n > 0 && $first <= $n) {
75      <table width="100%">
76       <tr class="thleft">
77        <th>#</th>
78        <th>Title</th>
79        <th>Author</th>
80        <th>Host</th>
81        <th>Port</th>
82        <th>DB</th>
83        <th></th>
84        <th></th>
85       </tr>
86 % my @ids;
87 % foreach my $i ($first .. $last) {
88 <%perl>
89 my $rec = $rs->record($i-1);
90 my $xml = $rec->render();
91 my $doc = $parser->parse_string($xml);
92 my $root = $doc->getDocumentElement();
93 my $xc = XML::LibXML::XPathContext->new($root);
94 $xc->registerNs(e => 'http://explain.z3950.org/dtd/2.0/');
95 my $title = $xc->find("e:databaseInfo/e:title");
96 my $author = $xc->find("e:databaseInfo/e:author");
97 my $host = $xc->find("e:serverInfo/e:host");
98 my $port = $xc->find("e:serverInfo/e:port");
99 my $db = $xc->find("e:serverInfo/e:database");
100 my $id = $xc->find("concat(e:serverInfo/e:host, ':',
101                            e:serverInfo/e:port, '/',
102                            e:serverInfo/e:database)");
103 push @ids, $id;
104 </%perl>
105       <tr style="background: <% ($i % 2) ? '#ffffc0' : 'white' %>">
106        <td><% $i %></td>
107        <td><% $title %></td>
108        <td><% $author %></td>
109        <td><% $host %></td>
110        <td><% $port %></td>
111        <td><% $db %></td>
112        <td><a href="<% "/check.html?id=$id" %>">[Test]</a></td>
113        <td><a href="<% "/raw.html?id=$id" %>">[Raw]</a></td>
114       </tr>
115 % }
116      </table>
117      <p>
118       <a href="<% "/check.html?id=" . join(" ", @ids)
119         %>">[Test all targets on this list]</a>
120      </p>
121 % }