Display supported Bath-profile searches.
[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                   [ "Bath Profile searches" => \&calc_bath, $xc ],
49                   [ "Operators" => \&calc_boolean, $xc ],
50                   [ "Named Result Sets" => \&calc_nrs, $xc ],
51                   [ "Record syntaxes" => \&calc_recsyn, $xc ],
52                   [ "Explain" => \&calc_explain, $xc ],
53                   [ "Multiple OPAC records" => \&calc_mor, $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, $linkURL);
63         if (ref $xpath && ref($xpath) eq "CODE") {
64             ($data, $linkURL) = &$xpath($id, @args);
65         } else {
66             $data = $xc->find($xpath);
67         }
68         if ($data) {
69             print "      <tr>\n";
70             $caption =~ s/\/(.*)//;
71             my $help = $1;
72             my($linkstart, $linkend) = ("", "");
73             if (defined $linkURL) {
74                 $linkstart = '<a href="' . xml_encode($linkURL) . '">';
75                 $linkend = "</a>";
76             }
77 </%perl>
78        <th><% xml_encode($caption) %><%
79         !defined $help ? "" : $m->comp("/help/link.mc", help =>"info/$help")
80         %></th>
81        <td><% $linkstart . xml_encode($data) . $linkend %></td>
82       </tr>
83 %       }
84 %   }
85      </table>
86      <p>
87 % my $target = irspy_identifier2target($id);
88 % $target =~ s/^tcp://; # Apparently ZAP can't handle the leading "tcp:"
89       <a href="<% xml_encode("http://targettest.indexdata.com/targettest/search/index.zap?" .
90         join("&",
91              "target=" . uri_escape_utf8($target),
92              "name=" . uri_escape_utf8($title),
93              "attr=" . join(" ", _list_ap($xc, "bib-1")),
94              "formats=" . calc_recsyn($id, $xc, " ")))
95         %>">Search this target.</a>
96      </p>
97 % }
98 <%perl>
99
100 sub calc_reliability_wrapper {
101     my($id, $xc) = @_;
102     return calc_reliability_string($xc);
103 }
104
105 sub calc_init_options {
106     my($id, $xc) = @_;
107
108     my @ops;
109     my @nodes = $xc->findnodes('e:configInfo/e:supports/@type');
110     foreach my $node (@nodes) {
111         my $type = $node->value();
112         if ($type =~ s/^z3950_//) {
113             push @ops, $type;
114         }
115     }
116
117     return join(", ", @ops);
118 }
119
120 sub calc_ap {
121     my($id, $xc, $set) = @_;
122
123     my @aps = _list_ap($xc, $set);
124     my $n = @aps;
125     return "[none]" if $n == 0;
126
127     my $res = "";
128     my($first, $last);
129     foreach my $ap (@aps) {
130         if (!defined $first) {
131             $first = $last = $ap;
132         } elsif ($ap == $last+1) {
133             $last++;
134         } else {
135             # Got a complete range
136             $res .= ", " if $res ne "";
137             $res .= "$first";
138             $res .= "-$last" if $last > $first;
139             $first = $last = $ap;
140         }
141     }
142
143     # Leftovers
144     if (defined $first) {
145         $res .= ", " if $res ne "";
146         $res .= "$first";
147         $res .= "-$last" if $last > $first;
148     }
149
150     return ("$n access points: $res",
151             "/ap.html?id=$id&set=$set");
152 }
153
154 sub _list_ap {
155     my($xc, $set) = @_;
156
157     my $expr = 'e:indexInfo/e:index[@search = "true"]/e:map/e:attr[
158         @set = "'.$set.'" and @type = "1"]';
159     my @nodes = $xc->findnodes($expr);
160     return sort { $a <=> $b } map { $_->findvalue(".") } @nodes;
161 }
162
163 sub calc_bath {
164     my($id, $xc) = @_;
165
166     my @nodes = $xc->findnodes('i:status/i:search_bath[@ok = "1"]');
167     my $res = join(", ", map { $_->findvalue('@name') } @nodes);
168     $res = "[none]" if $res eq "";
169     return $res;
170 }
171
172 sub calc_boolean {
173     my($id, $xc) = @_;
174
175     ### Note that we are currently interrogating an IRSpy extension.
176     #   The standard ZeeRex record should be extended with a
177     #   "supports" type for this.
178     my @nodes = $xc->findnodes('i:status/i:boolean[@ok = "1"]');
179     my $res = join(", ", map { $_->findvalue('@operator') } @nodes);
180     $res = "[none]" if $res eq "";
181     return $res;
182 }
183
184 sub calc_nrs { _calc_boolean(@_, 'i:status/i:named_resultset[@ok = "1"]') }
185 sub calc_mor { _calc_boolean(@_, 'i:status/i:multiple_opac[@ok = "1"]') }
186
187 sub _calc_boolean {
188     my($id, $xc, $xpath) = @_;
189
190     my @nodes = $xc->findnodes($xpath);
191     return @nodes ? "Yes" : "No";
192 }
193
194 sub calc_recsyn {
195     my($id, $xc, $sep) = @_;
196     $sep = ", " if !defined $sep;
197
198     my @nodes = $xc->findnodes('e:recordInfo/e:recordSyntax');
199     my $res = join($sep, map { $_->findvalue('@name') } @nodes);
200     $res = "[none]" if $res eq "";
201     return $res;
202 }
203
204 sub calc_explain {
205     my($id, $xc) = @_;
206
207     my @nodes = $xc->findnodes('i:status/i:explain[@ok = "1"]');
208     my $res = join(", ", map { $_->findvalue('@category') } @nodes);
209     $res = "[none]" if $res eq "";
210     return $res;
211 }
212 </%perl>