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