New
[irspy-moved-to-github.git] / web / htdocs / details / found.mc
1 %# $Id: found.mc,v 1.1 2006-09-15 16:51:51 mike Exp $
2 <%once>
3 use XML::LibXML;
4 use XML::LibXML::XPathContext;
5 </%once>
6 <%perl>
7 my $query = "";
8 foreach my $key ($r->param()) {
9     next if $key =~ /^_/;
10     my $val = $r->param($key);
11     next if $val eq "";
12     $query .= " and " if $query ne "";
13     $query .= "$key = ($val)";
14 }
15
16 ### We can think about keeping the Connection object open to re-use
17 # for multiple requests, but that may not get us much.  Same applies
18 # for the XML parser.
19 my $conn = new ZOOM::Connection("localhost:1313/IR-Explain---1");
20 $conn->option(elementSetName => "zeerex");
21 my $parser = new XML::LibXML();
22
23 my $rs = $conn->search(new ZOOM::Query::CQL($query));
24 my $n = $rs->size();
25
26 my $skip = $r->param("_skip") || 0;
27 my $count = $r->param("_count") || 10;
28
29 my $first = $skip+1;
30 my $last = $first+$count-1;
31 $last = $n if $last > $n;
32 </%perl>
33      <p>
34       <b><% $query %></b>
35       <br/>
36 % if ($n == 0) {
37       No matches
38 % } elsif ($first > $n) {
39       Past end of <% $n %> records
40 % } else {
41       Records <% $first %> to <% $last %> of <% $n %>
42 % }
43      </p>
44 % if ($n > 0 && $first <= $n) {
45      <table width="100%">
46       <tr class="thleft">
47        <th>#</th>
48        <th>Host</th>
49        <th>Port</th>
50        <th>DB</th>
51       </tr>
52 % foreach my $i ($first .. $last) {
53 <%perl>
54 my $rec = $rs->record($i-1);
55 my $xml = $rec->render();
56 my $doc = $parser->parse_string($xml);
57 my $root = $doc->getDocumentElement();
58 my $xc = XML::LibXML::XPathContext->new($root);
59 $xc->registerNs(e => 'http://explain.z3950.org/dtd/2.0/');
60 my $host = $xc->find("e:serverInfo/e:host");
61 my $port = $xc->find("e:serverInfo/e:port");
62 my $db = $xc->find("e:serverInfo/e:database");
63 </%perl>
64       <tr style="background: <% ($i % 2) ? '#ffffc0' : 'white' %>">
65        <td><% $i %></td>
66        <td><% $host %></td>
67        <td><% $port %></td>
68        <td><% $db %></td>
69       </tr>
70 %}
71      </table>
72 % }