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