74d165b558f7905db897801c77fbaaadd944d766
[irspy-moved-to-github.git] / web / htdocs / details / form.mc
1 %# $Id: form.mc,v 1.4 2006-11-15 13:10:42 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      [ username     => 0, "Username (if needed)", "e:serverInfo/e:authentication/e:user",
18        qw() ],
19      [ password     => 0, "Password (if needed)", "e:serverInfo/e:authentication/e:password",
20        qw(e:user) ],
21      [ title        => 0, "title", "e:databaseInfo/e:title",
22        qw() ],
23      [ description  => 5, "Description", "e:databaseInfo/e:description",
24        qw(e:title) ],
25      [ author       => 0, "Author", "e:databaseInfo/e:author",
26        qw(e:title e:description) ],
27      [ contact      => 0, "Contact", "e:databaseInfo/e:contact",
28        qw(e:title e:description) ],
29      [ extent       => 3, "Extent", "e:databaseInfo/e:extent",
30        qw(e:title e:description) ],
31      [ history      => 5, "History", "e:databaseInfo/e:history",
32        qw(e:title e:description) ],
33      [ language     => 0, "Language of Records", "e:databaseInfo/e:langUsage",
34        qw(e:title e:description) ],
35      [ restrictions => 2, "Restrictions", "e:databaseInfo/e:restrictions",
36        qw(e:title e:description) ],
37      [ subjects     => 2, "Subjects", "e:databaseInfo/e:subjects",
38        qw(e:title e:description) ],
39      );
40
41 my $nchanges = 0;
42 my $update = $r->param("update");
43 if (defined $update) {
44     # Update record with submitted data
45     my %fieldsByKey = map { ( $_->[0], $_) } @fields;
46     my %data;
47     foreach my $key ($r->param()) {
48         next if grep { $key eq $_ } qw(id update);
49         $data{$key} = $r->param($key);
50     }
51
52     $nchanges = modify_xml_document($xc, \%fieldsByKey, \%data);
53     if ($nchanges) {
54         ### Set e:metaInfo/e:dateModified
55     }
56     ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
57 }
58 </%perl>
59  <h2><% xml_encode($xc->find("e:databaseInfo/e:title"), "[Untitled]") %></h2>
60 % if ($nchanges) {
61  <p style="font-weight: bold">
62   The record has been updated.<br/>
63   Changed <% $nchanges %> field<% $nchanges == 1 ? "" : "s" %>.
64  </p>
65 % }
66  <form method="get" action="">
67   <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
68 <%perl>
69 foreach my $ref (@fields) {
70     my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
71 </%perl>
72    <tr>
73     <th><% $caption %></th>
74     <td>
75 % my $data = xml_encode($xc->find($xpath), "");
76 % if (ref $nlines) {
77      <select name="<% $name %>" size="1">
78 %     foreach my $val (@$nlines) {
79       <option value="<% $val %>"><% $val %></option>
80 %     }
81      </select>
82 % } elsif ($nlines) {
83      <textarea name="<% $name %>" rows="<% $nlines %>" cols="61"><% $data %></textarea>
84 % } else {
85      <input name="<% $name %>" type="text" size="60" value="<% $data %>">
86 % }
87     </td>
88    </tr>
89 %   }
90    <tr>
91     <td align="right" colspan="2">
92      <input type="submit" name="update" value="Update"/>
93      <input type="hidden" name="id" value="<% xml_encode($id) %>"/>
94     </td>
95    </tr>
96   </table>
97  </form>
98 <%perl>
99     if ($nchanges && 0) {
100         my $x = $xc->getContextNode()->toString();
101         $x = xml_encode($x);
102         #$x =~ s/$/<br\/>/gm;
103         print "<pre>$x</pre>\n";
104     }
105 </%perl>