Add new elements "type", "country" and "hosturl" requested by Per.
[irspy-moved-to-github.git] / web / htdocs / details / form.mc
1 %# $Id: form.mc,v 1.6 2006-11-15 13:20:32 mike Exp $
2 <%args>
3 $id => undef
4 $conn
5 $rec
6 </%args>
7 <%perl>
8 my $xc = irspy_xpath_context($rec);
9 my @fields =
10     (
11      [ protocol     => [ qw(Z39.50 SRW SRU SRW/U) ],
12        "Protocol", "e:serverInfo/\@protocol" ],
13      [ host         => 0, "Host", "e:serverInfo/e:host" ],
14      [ port         => 0, "Port", "e:serverInfo/e:port" ],
15      [ dbname       => 0, "Database Name", "e:serverInfo/e:database",
16        qw(e:host e:port) ],
17      [ type         => [ qw(Academic Public Corporate Special National Education Other) ],
18        "Type of Library", "i:status/i:libraryType" ],
19      [ country      => 0, "Country", "i:status/i:country" ],
20      [ username     => 0, "Username (if needed)", "e:serverInfo/e:authentication/e:user",
21        qw() ],
22      [ password     => 0, "Password (if needed)", "e:serverInfo/e:authentication/e:password",
23        qw(e:user) ],
24      [ title        => 0, "Title", "e:databaseInfo/e:title",
25        qw() ],
26      [ description  => 5, "Description", "e:databaseInfo/e:description",
27        qw(e:title) ],
28      [ author       => 0, "Author", "e:databaseInfo/e:author",
29        qw(e:title e:description) ],
30      [ hosturl       => 0, "URL to Hosting Organisation", "i:status/i:hostURL",
31        qw(e:title e:description) ],
32      [ contact      => 0, "Contact", "e:databaseInfo/e:contact",
33        qw(e:title e:description) ],
34      [ extent       => 3, "Extent", "e:databaseInfo/e:extent",
35        qw(e:title e:description) ],
36      [ history      => 5, "History", "e:databaseInfo/e:history",
37        qw(e:title e:description) ],
38      [ language     => 0, "Language of Records", "e:databaseInfo/e:langUsage",
39        qw(e:title e:description) ],
40      [ restrictions => 2, "Restrictions", "e:databaseInfo/e:restrictions",
41        qw(e:title e:description) ],
42      [ subjects     => 2, "Subjects", "e:databaseInfo/e:subjects",
43        qw(e:title e:description) ],
44      );
45
46 my $nchanges = 0;
47 my $update = $r->param("update");
48 if (defined $update) {
49     # Update record with submitted data
50     my %fieldsByKey = map { ( $_->[0], $_) } @fields;
51     my %data;
52     foreach my $key ($r->param()) {
53         next if grep { $key eq $_ } qw(id update);
54         $data{$key} = $r->param($key);
55     }
56
57     $nchanges = modify_xml_document($xc, \%fieldsByKey, \%data);
58     if ($nchanges) {
59         ### Set e:metaInfo/e:dateModified
60     }
61     ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
62 }
63 </%perl>
64  <h2><% xml_encode($xc->find("e:databaseInfo/e:title"), "[Untitled]") %></h2>
65 % if ($nchanges) {
66  <p style="font-weight: bold">
67   The record has been updated.<br/>
68   Changed <% $nchanges %> field<% $nchanges == 1 ? "" : "s" %>.
69  </p>
70 % }
71  <form method="get" action="">
72   <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
73 <%perl>
74 foreach my $ref (@fields) {
75     my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
76 </%perl>
77    <tr>
78     <th><% $caption %></th>
79     <td>
80 % my $data = xml_encode($xc->find($xpath), "");
81 % if (ref $nlines) {
82      <select name="<% $name %>" size="1">
83 %     foreach my $val (@$nlines) {
84       <option value="<% $val %>"><% $val %></option>
85 %     }
86      </select>
87 % } elsif ($nlines) {
88      <textarea name="<% $name %>" rows="<% $nlines %>" cols="61"><% $data %></textarea>
89 % } else {
90      <input name="<% $name %>" type="text" size="60" value="<% $data %>">
91 % }
92     </td>
93    </tr>
94 %   }
95    <tr>
96     <td align="right" colspan="2">
97      <input type="submit" name="update" value="Update"/>
98      <input type="hidden" name="id" value="<% xml_encode($id) %>"/>
99     </td>
100    </tr>
101   </table>
102  </form>
103 <%perl>
104     if ($nchanges && 0) {
105         my $x = $xc->getContextNode()->toString();
106         $x = xml_encode($x);
107         #$x =~ s/$/<br\/>/gm;
108         print "<pre>$x</pre>\n";
109     }
110 </%perl>