Add new elements "type", "country" and "hosturl" requested by Per.
[irspy-moved-to-github.git] / web / htdocs / details / full.mc
1 %# $Id: full.mc,v 1.15 2006-11-15 13:23:05 mike Exp $
2 <%args>
3 $id
4 </%args>
5 <%once>
6 use ZOOM;
7 </%once>
8 <%perl>
9 my $conn = new ZOOM::Connection("localhost:3313/IR-Explain---1");
10 $conn->option(elementSetName => "zeerex");
11 my $qid = $id;
12 $qid =~ s/"/\\"/g;
13 my $query = qq[rec.id="$qid"];
14 my $rs = $conn->search(new ZOOM::Query::CQL($query));
15 my $n = $rs->size();
16 if ($n == 0) {
17     $m->comp("/details/error.mc",
18              title => "Error", message => "No such ID '$id'");
19 } else {
20     my $rec = $rs->record(0);
21     my $xc = irspy_xpath_context($rec);
22     my @fields = (
23                   [ "Last Checked" => "i:status/i:probe[last()]" ],
24                   [ Protocol => "e:serverInfo/\@protocol" ],
25                   [ Host => "e:serverInfo/e:host" ],
26                   [ Port => "e:serverInfo/e:port" ],
27                   [ "Database Name" => "e:serverInfo/e:database" ],
28                   [ "Type of Library" => "i:status/i:libraryType" ],
29                   [ Country => "i:status/i:country" ],
30                   [ "Username (if needed)" =>
31                     "e:serverInfo/e:authentication/e:user" ],
32                   [ "Password (if needed)" =>
33                     "e:serverInfo/e:authentication/e:password" ],
34                   [ Title => "e:databaseInfo/e:title",
35                     lang => "en", primary => "true" ],
36                   [ Description => "e:databaseInfo/e:description",
37                     lang => "en", primary => "true" ],
38                   [ Author => "e:databaseInfo/e:author" ],
39                   [ Contact => "e:databaseInfo/e:contact" ],
40                   [ "URL to Hosting Organisation" => "i:status/i:hostURL" ],
41                   [ Extent => "e:databaseInfo/e:extent" ],
42                   [ History => "e:databaseInfo/e:history" ],
43                   [ "Language of Records" => "e:databaseInfo/e:langUsage" ],
44                   [ Restrictions => "e:databaseInfo/e:restrictions" ],
45                   [ Subjects => "e:databaseInfo/e:subjects" ],
46                   [ "Implementation ID" => "i:status/i:implementationId" ],
47                   [ "Implementation Name" => "i:status/i:implementationName" ],
48                   [ "Implementation Version" => "i:status/i:implementationVersion" ],
49                   [ "Reliability" => \&calc_reliability, $xc ],
50                   [ "Services" => sub { "
51 ### IRSpy does not yet check for search, present, delSet,
52 concurrentOperations, namedResultSets, etc. and store the information
53 is a usable form.  This information should probably be harvested from
54 the Init Response.
55 " } ],
56                   [ "Bib-1 Use attributes" => \&calc_ap, $xc, "bib-1" ],
57                   [ "Dan-1 Use attributes" => \&calc_ap, $xc, "dan-1" ],
58                   [ "Operators" => \&calc_boolean, $xc ],
59                   [ "Named Result Sets" => \&calc_nrs, $xc ],
60                   [ "Record syntaxes" => \&calc_recsyn, $xc ],
61                   [ "Explain" => \&calc_explain, $xc ],
62                   );
63 </%perl>
64      <h2><% xml_encode($xc->find("e:databaseInfo/e:title"), "") %></h2>
65      <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
66 <%perl>
67     foreach my $ref (@fields) {
68         my($caption, $xpath, @args) = @$ref;
69         my $data;
70         if (ref $xpath && ref($xpath) eq "CODE") {
71             $data = &$xpath(@args);
72         } else {
73             $data = $xc->find($xpath);
74         }
75         if ($data) {
76 </%perl>
77       <tr>
78        <th><% xml_encode($caption) %></th>
79        <td><% xml_encode($data) %></td>
80       </tr>
81 %       }
82 %   }
83      </table>
84 % }
85 <%perl>
86
87 sub calc_reliability {
88     my($xc) = @_;
89
90     my @allpings = $xc->findnodes("i:status/i:probe");
91     my $nall = @allpings;
92     return "[untested]" if $nall == 0;
93     my @okpings = $xc->findnodes('i:status/i:probe[@ok = "1"]');
94     my $nok = @okpings;
95     return "$nok/$nall = " . int(100*$nok/$nall) . "%";
96 }
97
98 sub calc_ap {
99     my($xc, $set) = @_;
100
101     my $expr = 'e:indexInfo/e:index/e:map/e:attr[
102         @set = "'.$set.'" and @type = "1"]';
103     my @bib1nodes = $xc->findnodes($expr);
104     my $nbib1 = @bib1nodes;
105     return "[none]" if $nbib1 == 0;
106
107     my $res = "";
108     my($first, $last);
109     @bib1nodes = sort { $a->findvalue(".") <=> $b->findvalue(".") } @bib1nodes;
110     foreach my $node (@bib1nodes) {
111         my $ap .= $node->findvalue(".");
112         if (!defined $first) {
113             $first = $ap;
114         } elsif (!defined $last || $last == $ap-1) {
115             $last = $ap;
116         } else {
117             # Got a complete range
118             $res .= ", " if $res ne "";
119             $res .= "$first";
120             $res .= "-$last" if defined $last;
121             $first = $ap;
122             $last = undef;
123         }
124     }
125
126     # Leftovers
127     if (defined $first) {
128         $res .= ", " if $res ne "";
129         $res .= "$first";
130         $res .= "-$last" if defined $last;
131     }
132
133     return "$nbib1 access points: $res";
134 }
135
136 sub calc_boolean {
137     my($xc) = @_;
138
139     ### Note that we are currently interrogating an IRSpy extension.
140     #   The standard ZeeRex record should be extended with a
141     #   "supports" type for this.
142     my @nodes = $xc->findnodes('i:status/i:boolean[@ok = "1"]');
143     my $res = join(", ", map { $_->findvalue('@operator') } @nodes);
144     $res = "[none]" if $res eq "";
145     return $res;
146 }
147
148 sub calc_nrs {
149     my($xc) = @_;
150
151     my @nodes = $xc->findnodes('i:status/i:named_resultset[@ok = "1"]');
152     return @nodes ? "Yes" : "No";
153 }
154
155 sub calc_recsyn {
156     my($xc) = @_;
157
158     my @nodes = $xc->findnodes('e:recordInfo/e:recordSyntax');
159     my $res = join(", ", map { $_->findvalue('@name') } @nodes);
160     $res = "[none]" if $res eq "";
161     return $res;
162 }
163
164 sub calc_explain {
165     my($xc) = @_;
166
167     my @nodes = $xc->findnodes('i:status/i:explain[@ok = "1"]');
168     my $res = join(", ", map { $_->findvalue('@category') } @nodes);
169     $res = "[none]" if $res eq "";
170     return $res;
171 }
172
173 </%perl>