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