Display value of Multiple OPAC Records test.
[irspy-moved-to-github.git] / web / htdocs / details / full.mc
1 <%args>
2 $id
3 </%args>
4 <%perl>
5 my $db = ZOOM::IRSpy::connect_to_registry();
6 my $conn = new ZOOM::Connection($db);
7 $conn->option(elementSetName => "zeerex");
8 my $query = cql_target($id);
9 my $rs = $conn->search(new ZOOM::Query::CQL($query));
10 my $n = $rs->size();
11 if ($n == 0) {
12     $m->comp("/details/error.mc",
13              title => "Error", message => "No such ID '$id'");
14 } else {
15     my $xc = irspy_xpath_context($rs->record(0));
16     my @fields = (
17                   [ Name => "e:databaseInfo/e:title",
18                     lang => "en", primary => "true" ],
19                   [ Country => "i:status/i:country" ],
20                   [ "Last Checked" => "i:status/i:probe[last()]" ],
21                   [ Protocol => "e:serverInfo/\@protocol" ],
22                   [ Host => "e:serverInfo/e:host" ],
23                   [ Port => "e:serverInfo/e:port" ],
24                   [ "Database Name" => "e:serverInfo/e:database" ],
25                   [ "Type of Library" => "i:status/i:libraryType" ],
26 #                 [ "Username (if needed)" => "e:serverInfo/e:authentication/e:user" ],
27 #                 [ "Password (if needed)" => "e:serverInfo/e:authentication/e:password" ],
28                   [ "Server ID" => 'i:status/i:serverImplementationId/@value' ],
29                   [ "Server Name" => 'i:status/i:serverImplementationName/@value' ],
30                   [ "Server Version" => 'i:status/i:serverImplementationVersion/@value' ],
31                   [ Description => "e:databaseInfo/e:description",
32                     lang => "en", primary => "true" ],
33                   [ Author => "e:databaseInfo/e:author" ],
34                   [ Contact => "e:databaseInfo/e:contact" ],
35                   [ "URL to Hosting Organisation" => "i:status/i:hostURL" ],
36                   [ Extent => "e:databaseInfo/e:extent" ],
37                   [ History => "e:databaseInfo/e:history" ],
38                   [ "Language of Records" => "e:databaseInfo/e:langUsage" ],
39                   [ Restrictions => "e:databaseInfo/e:restrictions" ],
40                   [ Subjects => "e:databaseInfo/e:subjects" ],
41                   [ "Implementation ID" => "i:status/i:implementationId" ],
42                   [ "Implementation Name" => "i:status/i:implementationName" ],
43                   [ "Implementation Version" => "i:status/i:implementationVersion" ],
44                   [ "Reliability/reliability" => \&calc_reliability_wrapper, $xc ],
45                   [ "Services" => \&calc_init_options, $xc ],
46                   [ "Bib-1 Use attributes" => \&calc_ap, $xc, "bib-1" ],
47                   [ "Dan-1 Use attributes" => \&calc_ap, $xc, "dan-1" ],
48                   [ "Operators" => \&calc_boolean, $xc ],
49                   [ "Named Result Sets" => \&calc_nrs, $xc ],
50                   [ "Record syntaxes" => \&calc_recsyn, $xc ],
51                   [ "Explain" => \&calc_explain, $xc ],
52                   [ "Multiple OPAC records" => \&calc_mor, $xc ],
53                   );
54     my $title = $xc->find("e:databaseInfo/e:title");
55 </%perl>
56      <h2><% xml_encode($title, "") %></h2>
57      <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
58 <%perl>
59     foreach my $ref (@fields) {
60         my($caption, $xpath, @args) = @$ref;
61         my($data, $linkURL);
62         if (ref $xpath && ref($xpath) eq "CODE") {
63             ($data, $linkURL) = &$xpath($id, @args);
64         } else {
65             $data = $xc->find($xpath);
66         }
67         if ($data) {
68             print "      <tr>\n";
69             $caption =~ s/\/(.*)//;
70             my $help = $1;
71             my($linkstart, $linkend) = ("", "");
72             if (defined $linkURL) {
73                 $linkstart = '<a href="' . xml_encode($linkURL) . '">';
74                 $linkend = "</a>";
75             }
76 </%perl>
77        <th><% xml_encode($caption) %><%
78         !defined $help ? "" : $m->comp("/help/link.mc", help =>"info/$help")
79         %></th>
80        <td><% $linkstart . xml_encode($data) . $linkend %></td>
81       </tr>
82 %       }
83 %   }
84      </table>
85      <p>
86 % my $target = irspy_identifier2target($id);
87 % $target =~ s/^tcp://; # Apparently ZAP can't handle the leading "tcp:"
88       <a href="<% xml_encode("http://targettest.indexdata.com/targettest/search/index.zap?" .
89         join("&",
90              "target=" . uri_escape_utf8($target),
91              "name=" . uri_escape_utf8($title),
92              "attr=" . join(" ", _list_ap($xc, "bib-1")),
93              "formats=" . calc_recsyn($id, $xc, " ")))
94         %>">Search this target.</a>
95      </p>
96 % }
97 <%perl>
98
99 sub calc_reliability_wrapper {
100     my($id, $xc) = @_;
101     return calc_reliability_string($xc);
102 }
103
104 sub calc_init_options {
105     my($id, $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($id, $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             "/ap.html?id=$id&set=$set");
151 }
152
153 sub _list_ap {
154     my($xc, $set) = @_;
155
156     my $expr = 'e:indexInfo/e:index[@search = "true"]/e:map/e:attr[
157         @set = "'.$set.'" and @type = "1"]';
158     my @nodes = $xc->findnodes($expr);
159     return sort { $a <=> $b } map { $_->findvalue(".") } @nodes;
160 }
161
162 sub calc_boolean {
163     my($id, $xc) = @_;
164
165     ### Note that we are currently interrogating an IRSpy extension.
166     #   The standard ZeeRex record should be extended with a
167     #   "supports" type for this.
168     my @nodes = $xc->findnodes('i:status/i:boolean[@ok = "1"]');
169     my $res = join(", ", map { $_->findvalue('@operator') } @nodes);
170     $res = "[none]" if $res eq "";
171     return $res;
172 }
173
174 sub calc_nrs { _calc_boolean(@_, 'i:status/i:named_resultset[@ok = "1"]') }
175 sub calc_mor { _calc_boolean(@_, 'i:status/i:multiple_opac[@ok = "1"]') }
176
177 sub _calc_boolean {
178     my($id, $xc, $xpath) = @_;
179
180     my @nodes = $xc->findnodes($xpath);
181     return @nodes ? "Yes" : "No";
182 }
183
184 sub calc_recsyn {
185     my($id, $xc, $sep) = @_;
186     $sep = ", " if !defined $sep;
187
188     my @nodes = $xc->findnodes('e:recordInfo/e:recordSyntax');
189     my $res = join($sep, map { $_->findvalue('@name') } @nodes);
190     $res = "[none]" if $res eq "";
191     return $res;
192 }
193
194 sub calc_explain {
195     my($id, $xc) = @_;
196
197     my @nodes = $xc->findnodes('i:status/i:explain[@ok = "1"]');
198     my $res = join(", ", map { $_->findvalue('@category') } @nodes);
199     $res = "[none]" if $res eq "";
200     return $res;
201 }
202 </%perl>