1 %# $Id: edit.mc,v 1.20 2006-11-17 22:39:17 mike Exp $
3 Since this form is used in many different situations, some care is
4 merited in considering the possibilities:
6 New? Copy ID? Situation
7 --------------------------------------------------------------------------
8 Y Blank form for adding a new target.
9 Y New target submitted successfully.
10 Y Partial new target submitted, requiring more
12 Y Existing target to be edited.
13 Y Existing target has been updated.
15 Y Y Existing target to be copied.
16 Y New or copied target rejected due to duplicate ID.
17 --------------------------------------------------------------------------
25 my $conn = new ZOOM::Connection("localhost:3313/IR-Explain---1", 0,
26 user => "admin", password => "fruitbat",
27 elementSetName => "zeerex");
28 my $rec = '<explain xmlns="http://explain.z3950.org/dtd/2.0/"/>';
29 if (defined $id && $id ne "") {
31 my $query = 'rec.id="' . cql_quote($id) . '"';
32 my $rs = $conn->search(new ZOOM::Query::CQL($query));
33 if ($rs->size() > 0) {
34 $rec = $rs->record(0);
41 my $host = $r->param("host");
42 my $port = $r->param("port");
43 my $dbname = $r->param("dbname");
44 if (!defined $host || $host eq "" ||
45 !defined $port || $port eq "" ||
46 !defined $dbname || $dbname eq "") {
47 print qq[<p class="error">
48 You must specify host, port and database name.</p>\n];
49 $r->param(update => 0);
51 my $query = cql_target($host, $port, $dbname);
52 my $rs = $conn->search(new ZOOM::Query::CQL($query));
53 if ($rs->size() > 0) {
54 my $fakeid = xml_encode(uri_escape("$host:$port/$dbname"));
55 print qq[<p class="error">
57 <a href='?id=$fakeid'>a record</a>
58 for this host, port and database name.
64 my $xc = irspy_xpath_context($rec);
67 [ protocol => [ qw(Z39.50 SRW SRU SRW/U) ],
68 "Protocol", "e:serverInfo/\@protocol" ],
69 [ host => 0, "Host", "e:serverInfo/e:host" ],
70 [ port => 0, "Port", "e:serverInfo/e:port" ],
71 [ dbname => 0, "Database Name", "e:serverInfo/e:database",
73 [ type => [ qw(Academic Public Corporate Special National Education Other) ],
74 "Type of Library", "i:status/i:libraryType" ],
75 [ country => 0, "Country", "i:status/i:country" ],
76 [ username => 0, "Username (if needed)", "e:serverInfo/e:authentication/e:user",
78 [ password => 0, "Password (if needed)", "e:serverInfo/e:authentication/e:password",
80 [ title => 0, "Title", "e:databaseInfo/e:title",
82 [ description => 5, "Description", "e:databaseInfo/e:description",
84 [ author => 0, "Author", "e:databaseInfo/e:author",
85 qw(e:title e:description) ],
86 [ hosturl => 0, "URL to Hosting Organisation", "i:status/i:hostURL" ],
87 [ contact => 0, "Contact", "e:databaseInfo/e:contact",
88 qw(e:title e:description) ],
89 [ extent => 3, "Extent", "e:databaseInfo/e:extent",
90 qw(e:title e:description) ],
91 [ history => 5, "History", "e:databaseInfo/e:history",
92 qw(e:title e:description) ],
93 [ language => 0, "Language of Records", "e:databaseInfo/e:langUsage",
94 qw(e:title e:description) ],
95 [ restrictions => 2, "Restrictions", "e:databaseInfo/e:restrictions",
96 qw(e:title e:description) ],
97 [ subjects => 2, "Subjects", "e:databaseInfo/e:subjects",
98 qw(e:title e:description) ],
102 my $update = $r->param("update");
104 # Update record with submitted data
105 my %fieldsByKey = map { ( $_->[0], $_) } @fields;
107 foreach my $key ($r->param()) {
108 next if grep { $key eq $_ } qw(id update new copy);
109 $data{$key} = $r->param($key);
111 my $mynchanges = modify_xml_document($xc, \%fieldsByKey, \%data);
114 $nchanges = $mynchanges;
116 ### Set e:metaInfo/e:dateModified
118 ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
121 <h2><% xml_encode($xc->find("e:databaseInfo/e:title"), "[Untitled]") %></h2>
123 <p style="font-weight: bold">
124 The record has been <% $new ? "created" : "updated" %>.<br/>
125 Changed <% $nchanges %> field<% $nchanges == 1 ? "" : "s" %>.
128 <form method="get" action="">
129 <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
131 foreach my $ref (@fields) {
132 my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
135 <th><% $caption %></th>
137 % my $rawdata = $xc->findvalue($xpath);
138 % my $data = xml_encode($rawdata, "");
140 <select name="<% $name %>" size="1">
141 % foreach my $val (@$nlines) {
142 <option value="<% $val %>"
143 % print ' selected="selected"' if $rawdata eq $val;
147 % } elsif ($nlines) {
148 <textarea name="<% $name %>" rows="<% $nlines %>" cols="51"><% $data %></textarea>
150 <input name="<% $name %>" type="text" size="60" value="<% $data %>"/>
156 <td align="right" colspan="2">
157 <input type="submit" name="update" value="Update"/>
159 <input type="hidden" name="id" value="<% xml_encode($id) %>"/>
161 <input type="hidden" name="new" value="1"/>
163 % if (defined $copy) {
164 <input type="hidden" name="copy" value="<% xml_encode($copy) %>"/>
171 if ($nchanges && 0) {
172 my $x = $xc->getContextNode()->toString();
174 #$x =~ s/$/<br\/>/gm;
175 print "<pre>$x</pre>\n";