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