ada79e23abc5e8d22674a45d8b1e3f551cbce6fe
[irspy-moved-to-github.git] / web / htdocs / details / full.mc
1 %# $Id: full.mc,v 1.27 2007-04-27 14:04:40 mike Exp $
2 <%args>
3 $id
4 </%args>
5 <%perl>
6 my $conn = new ZOOM::Connection("localhost:8018/IR-Explain---1");
7 $conn->option(elementSetName => "zeerex");
8 my $qid = $id;
9 $qid =~ s/"/\\"/g;
10 my $query = qq[rec.id="$qid"];
11 my $rs = $conn->search(new ZOOM::Query::CQL($query));
12 my $n = $rs->size();
13 if ($n == 0) {
14     $m->comp("/details/error.mc",
15              title => "Error", message => "No such ID '$id'");
16 } else {
17     my $xc = irspy_xpath_context($rs->record(0));
18     my @fields = (
19                   [ Name => "e:databaseInfo/e:title",
20                     lang => "en", primary => "true" ],
21                   [ Country => "i:status/i:country" ],
22                   [ "Last Checked" => "i:status/i:probe[last()]" ],
23                   [ Protocol => "e:serverInfo/\@protocol" ],
24                   [ Host => "e:serverInfo/e:host" ],
25                   [ Port => "e:serverInfo/e:port" ],
26                   [ "Database Name" => "e:serverInfo/e:database" ],
27                   [ "Type of Library" => "i:status/i:libraryType" ],
28 #                 [ "Username (if needed)" => "e:serverInfo/e:authentication/e:user" ],
29 #                 [ "Password (if needed)" => "e:serverInfo/e:authentication/e:password" ],
30                   [ "Server ID" => 'i:status/i:serverImplementationId/@value' ],
31                   [ "Server Name" => 'i:status/i:serverImplementationName/@value' ],
32                   [ "Server Version" => 'i:status/i:serverImplementationVersion/@value' ],
33                   [ Description => "e:databaseInfo/e:description",
34                     lang => "en", primary => "true" ],
35                   [ Author => "e:databaseInfo/e:author" ],
36                   [ Contact => "e:databaseInfo/e:contact" ],
37                   [ "URL to Hosting Organisation" => "i:status/i:hostURL" ],
38                   [ Extent => "e:databaseInfo/e:extent" ],
39                   [ History => "e:databaseInfo/e:history" ],
40                   [ "Language of Records" => "e:databaseInfo/e:langUsage" ],
41                   [ Restrictions => "e:databaseInfo/e:restrictions" ],
42                   [ Subjects => "e:databaseInfo/e:subjects" ],
43                   [ "Implementation ID" => "i:status/i:implementationId" ],
44                   [ "Implementation Name" => "i:status/i:implementationName" ],
45                   [ "Implementation Version" => "i:status/i:implementationVersion" ],
46                   [ "Reliability/reliability" => \&calc_reliability, $xc ],
47                   [ "Services" => \&calc_init_options, $xc ],
48                   [ "Bib-1 Use attributes" => \&calc_ap, $xc, "bib-1" ],
49                   [ "Dan-1 Use attributes" => \&calc_ap, $xc, "dan-1" ],
50                   [ "Operators" => \&calc_boolean, $xc ],
51                   [ "Named Result Sets" => \&calc_nrs, $xc ],
52                   [ "Record syntaxes" => \&calc_recsyn, $xc ],
53                   [ "Explain" => \&calc_explain, $xc ],
54                   );
55     my $title = $xc->find("e:databaseInfo/e:title");
56 </%perl>
57      <h2><% xml_encode($title, "") %></h2>
58      <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
59 <%perl>
60     foreach my $ref (@fields) {
61         my($caption, $xpath, @args) = @$ref;
62         my $data;
63         if (ref $xpath && ref($xpath) eq "CODE") {
64             $data = &$xpath(@args);
65         } else {
66             $data = $xc->find($xpath);
67         }
68         if ($data) {
69 </%perl>
70       <tr>
71 % $caption =~ s/\/(.*)//;
72 % my $help = $1;
73        <th><% xml_encode($caption) %><%
74         !defined $help ? "" : $m->comp("/help/link.mc", help =>"info/$help")
75         %></th>
76        <td><% xml_encode($data) %></td>
77       </tr>
78 %       }
79 %   }
80      </table>
81      <p>
82       <a href="<% xml_encode("http://targettest.indexdata.com/targettest/search/index.zap?" .
83         join("&",
84              "target=" . uri_escape_utf8(irspy_identifier2target($id)),
85              "name=" . uri_escape_utf8($title),
86              "attr=" . join(" ", list_ap($xc, "bib-1")),
87              "formats=" . calc_recsyn($xc, " ")))
88         %>">Search this target.</a>
89      </p>
90 % }
91 <%perl>
92
93 sub calc_reliability {
94     my($xc) = @_;
95
96     my @allpings = $xc->findnodes("i:status/i:probe");
97     my $nall = @allpings;
98     return "[untested]" if $nall == 0;
99     my @okpings = $xc->findnodes('i:status/i:probe[@ok = "1"]');
100     my $nok = @okpings;
101     return "$nok/$nall = " . int(100*$nok/$nall) . "%";
102 }
103
104 sub calc_init_options {
105     my($xc) = @_;
106
107     my @ops;
108     my @nodes = $xc->findnodes('e:configInfo/e:supports/@type');
109     foreach my $node (@nodes) {
110         my $type = $node->value();
111         if ($type =~ s/^z3950_//) {
112             push @ops, $type;
113         }
114     }
115
116     return join(", ", @ops);
117 }
118
119 sub calc_ap {
120     my($xc, $set) = @_;
121
122     my @aps = list_ap($xc, $set);
123     my $n = @aps;
124     return "[none]" if $n == 0;
125
126     my $res = "";
127     my($first, $last);
128     foreach my $ap (@aps) {
129         if (!defined $first) {
130             $first = $last = $ap;
131         } elsif ($ap == $last+1) {
132             $last++;
133         } else {
134             # Got a complete range
135             $res .= ", " if $res ne "";
136             $res .= "$first";
137             $res .= "-$last" if $last > $first;
138             $first = $last = $ap;
139         }
140     }
141
142     # Leftovers
143     if (defined $first) {
144         $res .= ", " if $res ne "";
145         $res .= "$first";
146         $res .= "-$last" if $last > $first;
147     }
148
149     return "$n access points: $res";
150 }
151
152 sub list_ap {
153     my($xc, $set) = @_;
154
155     my $expr = 'e:indexInfo/e:index[@search = "true"]/e:map/e:attr[
156         @set = "'.$set.'" and @type = "1"]';
157     my @nodes = $xc->findnodes($expr);
158     return sort { $a <=> $b } map { $_->findvalue(".") } @nodes;
159 }
160
161 sub calc_boolean {
162     my($xc) = @_;
163
164     ### Note that we are currently interrogating an IRSpy extension.
165     #   The standard ZeeRex record should be extended with a
166     #   "supports" type for this.
167     my @nodes = $xc->findnodes('i:status/i:boolean[@ok = "1"]');
168     my $res = join(", ", map { $_->findvalue('@operator') } @nodes);
169     $res = "[none]" if $res eq "";
170     return $res;
171 }
172
173 sub calc_nrs {
174     my($xc) = @_;
175
176     my @nodes = $xc->findnodes('i:status/i:named_resultset[@ok = "1"]');
177     return @nodes ? "Yes" : "No";
178 }
179
180 sub calc_recsyn {
181     my($xc, $sep) = @_;
182     $sep = ", " if !defined $sep;
183
184     my @nodes = $xc->findnodes('e:recordInfo/e:recordSyntax');
185     my $res = join($sep, map { $_->findvalue('@name') } @nodes);
186     $res = "[none]" if $res eq "";
187     return $res;
188 }
189
190 sub calc_explain {
191     my($xc) = @_;
192
193     my @nodes = $xc->findnodes('i:status/i:explain[@ok = "1"]');
194     my $res = join(", ", map { $_->findvalue('@category') } @nodes);
195     $res = "[none]" if $res eq "";
196     return $res;
197 }
198 </%perl>