Move Zebra for port 3313 to 8018 (which is visible on test through its firewall)
[irspy-moved-to-github.git] / web / htdocs / details / full.mc
1 %# $Id: full.mc,v 1.21 2007-01-24 09:28:02 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 </%perl>
58      <h2><% xml_encode($xc->find("e:databaseInfo/e: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;
64         if (ref $xpath && ref($xpath) eq "CODE") {
65             $data = &$xpath(@args);
66         } else {
67             $data = $xc->find($xpath);
68         }
69         if ($data) {
70 </%perl>
71       <tr>
72        <th><% xml_encode($caption) %></th>
73        <td><% xml_encode($data) %></td>
74       </tr>
75 %       }
76 %   }
77      </table>
78 % }
79 <%perl>
80
81 sub calc_reliability {
82     my($xc) = @_;
83
84     my @allpings = $xc->findnodes("i:status/i:probe");
85     my $nall = @allpings;
86     return "[untested]" if $nall == 0;
87     my @okpings = $xc->findnodes('i:status/i:probe[@ok = "1"]');
88     my $nok = @okpings;
89     return "$nok/$nall = " . int(100*$nok/$nall) . "%";
90 }
91
92 sub calc_init_options {
93     my($xc) = @_;
94
95     my @ops;
96     my @nodes = $xc->findnodes('e:configInfo/e:supports/@type');
97     foreach my $node (@nodes) {
98         my $type = $node->value();
99         if ($type =~ s/^z3950_//) {
100             push @ops, $type;
101         }
102     }
103
104     return join(", ", @ops);
105 }
106
107 sub calc_ap {
108     my($xc, $set) = @_;
109
110     my $expr = 'e:indexInfo/e:index/e:map/e:attr[
111         @set = "'.$set.'" and @type = "1"]';
112     my @bib1nodes = $xc->findnodes($expr);
113     my $nbib1 = @bib1nodes;
114     return "[none]" if $nbib1 == 0;
115
116     my $res = "";
117     my($first, $last);
118     @bib1nodes = sort { $a->findvalue(".") <=> $b->findvalue(".") } @bib1nodes;
119     foreach my $node (@bib1nodes) {
120         my $ap .= $node->findvalue(".");
121         if (!defined $first) {
122             $first = $ap;
123         } elsif (!defined $last || $last == $ap-1) {
124             $last = $ap;
125         } else {
126             # Got a complete range
127             $res .= ", " if $res ne "";
128             $res .= "$first";
129             $res .= "-$last" if defined $last;
130             $first = $ap;
131             $last = undef;
132         }
133     }
134
135     # Leftovers
136     if (defined $first) {
137         $res .= ", " if $res ne "";
138         $res .= "$first";
139         $res .= "-$last" if defined $last;
140     }
141
142     return "$nbib1 access points: $res";
143 }
144
145 sub calc_boolean {
146     my($xc) = @_;
147
148     ### Note that we are currently interrogating an IRSpy extension.
149     #   The standard ZeeRex record should be extended with a
150     #   "supports" type for this.
151     my @nodes = $xc->findnodes('i:status/i:boolean[@ok = "1"]');
152     my $res = join(", ", map { $_->findvalue('@operator') } @nodes);
153     $res = "[none]" if $res eq "";
154     return $res;
155 }
156
157 sub calc_nrs {
158     my($xc) = @_;
159
160     my @nodes = $xc->findnodes('i:status/i:named_resultset[@ok = "1"]');
161     return @nodes ? "Yes" : "No";
162 }
163
164 sub calc_recsyn {
165     my($xc) = @_;
166
167     my @nodes = $xc->findnodes('e:recordInfo/e:recordSyntax');
168     my $res = join(", ", map { $_->findvalue('@name') } @nodes);
169     $res = "[none]" if $res eq "";
170     return $res;
171 }
172
173 sub calc_explain {
174     my($xc) = @_;
175
176     my @nodes = $xc->findnodes('i:status/i:explain[@ok = "1"]');
177     my $res = join(", ", map { $_->findvalue('@category') } @nodes);
178     $res = "[none]" if $res eq "";
179     return $res;
180 }
181
182 </%perl>