1e19a8b6e41672fac8b902c6a68eef6069eaf573
[irspy-moved-to-github.git] / web / htdocs / details / full.mc
1 %# $Id: full.mc,v 1.19 2006-12-06 13:00:40 mike Exp $
2 <%args>
3 $id
4 </%args>
5 <%perl>
6 my $conn = new ZOOM::Connection("localhost:3313/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                   [ Description => "e:databaseInfo/e:description",
33                     lang => "en", primary => "true" ],
34                   [ Author => "e:databaseInfo/e:author" ],
35                   [ Contact => "e:databaseInfo/e:contact" ],
36                   [ "URL to Hosting Organisation" => "i:status/i:hostURL" ],
37                   [ Extent => "e:databaseInfo/e:extent" ],
38                   [ History => "e:databaseInfo/e:history" ],
39                   [ "Language of Records" => "e:databaseInfo/e:langUsage" ],
40                   [ Restrictions => "e:databaseInfo/e:restrictions" ],
41                   [ Subjects => "e:databaseInfo/e:subjects" ],
42                   [ "Implementation ID" => "i:status/i:implementationId" ],
43                   [ "Implementation Name" => "i:status/i:implementationName" ],
44                   [ "Implementation Version" => "i:status/i:implementationVersion" ],
45                   [ "Reliability" => \&calc_reliability, $xc ],
46                   [ "Services" => \&calc_init_options, $xc ],
47                   [ "Bib-1 Use attributes" => \&calc_ap, $xc, "bib-1" ],
48                   [ "Dan-1 Use attributes" => \&calc_ap, $xc, "dan-1" ],
49                   [ "Operators" => \&calc_boolean, $xc ],
50                   [ "Named Result Sets" => \&calc_nrs, $xc ],
51                   [ "Record syntaxes" => \&calc_recsyn, $xc ],
52                   [ "Explain" => \&calc_explain, $xc ],
53                   );
54 </%perl>
55      <h2><% xml_encode($xc->find("e:databaseInfo/e:title"), "") %></h2>
56      <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
57 <%perl>
58     foreach my $ref (@fields) {
59         my($caption, $xpath, @args) = @$ref;
60         my $data;
61         if (ref $xpath && ref($xpath) eq "CODE") {
62             $data = &$xpath(@args);
63         } else {
64             $data = $xc->find($xpath);
65         }
66         if ($data) {
67 </%perl>
68       <tr>
69        <th><% xml_encode($caption) %></th>
70        <td><% xml_encode($data) %></td>
71       </tr>
72 %       }
73 %   }
74      </table>
75 % }
76 <%perl>
77
78 sub calc_reliability {
79     my($xc) = @_;
80
81     my @allpings = $xc->findnodes("i:status/i:probe");
82     my $nall = @allpings;
83     return "[untested]" if $nall == 0;
84     my @okpings = $xc->findnodes('i:status/i:probe[@ok = "1"]');
85     my $nok = @okpings;
86     return "$nok/$nall = " . int(100*$nok/$nall) . "%";
87 }
88
89 sub calc_init_options {
90     my($xc) = @_;
91
92     my @ops;
93     my @nodes = $xc->findnodes('e:configInfo/e:supports/@type');
94     foreach my $node (@nodes) {
95         my $type = $node->value();
96         if ($type =~ s/^z3950_//) {
97             push @ops, $type;
98         }
99     }
100
101     return join(", ", @ops);
102 }
103
104 sub calc_ap {
105     my($xc, $set) = @_;
106
107     my $expr = 'e:indexInfo/e:index/e:map/e:attr[
108         @set = "'.$set.'" and @type = "1"]';
109     my @bib1nodes = $xc->findnodes($expr);
110     my $nbib1 = @bib1nodes;
111     return "[none]" if $nbib1 == 0;
112
113     my $res = "";
114     my($first, $last);
115     @bib1nodes = sort { $a->findvalue(".") <=> $b->findvalue(".") } @bib1nodes;
116     foreach my $node (@bib1nodes) {
117         my $ap .= $node->findvalue(".");
118         if (!defined $first) {
119             $first = $ap;
120         } elsif (!defined $last || $last == $ap-1) {
121             $last = $ap;
122         } else {
123             # Got a complete range
124             $res .= ", " if $res ne "";
125             $res .= "$first";
126             $res .= "-$last" if defined $last;
127             $first = $ap;
128             $last = undef;
129         }
130     }
131
132     # Leftovers
133     if (defined $first) {
134         $res .= ", " if $res ne "";
135         $res .= "$first";
136         $res .= "-$last" if defined $last;
137     }
138
139     return "$nbib1 access points: $res";
140 }
141
142 sub calc_boolean {
143     my($xc) = @_;
144
145     ### Note that we are currently interrogating an IRSpy extension.
146     #   The standard ZeeRex record should be extended with a
147     #   "supports" type for this.
148     my @nodes = $xc->findnodes('i:status/i:boolean[@ok = "1"]');
149     my $res = join(", ", map { $_->findvalue('@operator') } @nodes);
150     $res = "[none]" if $res eq "";
151     return $res;
152 }
153
154 sub calc_nrs {
155     my($xc) = @_;
156
157     my @nodes = $xc->findnodes('i:status/i:named_resultset[@ok = "1"]');
158     return @nodes ? "Yes" : "No";
159 }
160
161 sub calc_recsyn {
162     my($xc) = @_;
163
164     my @nodes = $xc->findnodes('e:recordInfo/e:recordSyntax');
165     my $res = join(", ", map { $_->findvalue('@name') } @nodes);
166     $res = "[none]" if $res eq "";
167     return $res;
168 }
169
170 sub calc_explain {
171     my($xc) = @_;
172
173     my @nodes = $xc->findnodes('i:status/i:explain[@ok = "1"]');
174     my $res = join(", ", map { $_->findvalue('@category') } @nodes);
175     $res = "[none]" if $res eq "";
176     return $res;
177 }
178
179 </%perl>