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