1 %# $Id: edit.mc,v 1.29 2007-03-29 16:19:39 mike Exp $
8 Since this form is used in many different situations, some care is
9 merited in considering the possibilities:
11 Situation Op ID Update
12 ----------------------------------------------------------------------
13 Blank form for adding a new target new
14 New target rejected, changes required new X
15 New target accepted and added new X
16 ---------------------------------------------------------------------
17 Existing target to be edited edit X
18 Edit rejected, changes required edit X X
19 Target successfully updated edit X X
20 ----------------------------------------------------------------------
21 Existing target to be copied copy X
22 New target rejected, changes required copy X X
23 New target accepted and added copy X X
24 ----------------------------------------------------------------------
26 Submissions, whether of new targets, edits or copies, may be rejected
27 due either to missing mandatory fields or host/name/port that form a
32 die "op = new but id defined" if $op eq "new" && defined $id;
33 die "op != new but id undefined" if $op ne "new" && !defined $id;
35 my $conn = new ZOOM::Connection("localhost:8018/IR-Explain---1", 0,
36 user => "admin", password => "fruitbat",
37 elementSetName => "zeerex");
38 my $rec = '<explain xmlns="http://explain.z3950.org/dtd/2.0/"/>';
39 if (defined $id && ($op ne "copy" || !$update)) {
41 my $query = cql_target($id);
42 my $rs = $conn->search(new ZOOM::Query::CQL($query));
43 if ($rs->size() > 0) {
44 $rec = $rs->record(0);
46 ### Is this an error? I don't think the UI will ever provoke it
47 print qq[<p class="error">(New ID specified.)</p>\n];
52 # No ID supplied -- this is a brand new record
53 my $host = $r->param("host");
54 my $port = $r->param("port");
55 my $dbname = $r->param("dbname");
56 if (!defined $host || $host eq "" ||
57 !defined $port || $port eq "" ||
58 !defined $dbname || $dbname eq "") {
59 print qq[<p class="error">
60 You must specify host, port and database name.</p>\n] if $update;
63 my $query = cql_target($host, $port, $dbname);
64 my $rs = $conn->search(new ZOOM::Query::CQL($query));
65 if ($rs->size() > 0) {
66 my $fakeid = xml_encode(uri_escape("$host:$port/$dbname"));
67 print qq[<p class="error">
69 <a href='?op=edit&id=$fakeid'>a record</a>
70 for this host, port and database name.
77 my $xc = irspy_xpath_context($rec);
80 [ title => 0, "Name", "e:databaseInfo/e:title",
82 [ country => $m->comp("country-list.mc"),
83 "Country", "i:status/i:country" ],
84 [ protocol => [ qw(Z39.50 SRW SRU SRW/U) ],
85 "Protocol", "e:serverInfo/\@protocol" ],
86 [ host => 0, "Host", "e:serverInfo/e:host" ],
87 [ port => 0, "Port", "e:serverInfo/e:port" ],
88 [ dbname => 0, "Database Name", "e:serverInfo/e:database",
90 [ type => $m->comp("libtype-list.mc"),
91 "Type of Library", "i:status/i:libraryType" ],
92 [ username => 0, "Username (if needed)", "e:serverInfo/e:authentication/e:user",
94 [ password => 0, "Password (if needed)", "e:serverInfo/e:authentication/e:password",
96 [ description => 5, "Description", "e:databaseInfo/e:description",
98 [ author => 0, "Author", "e:databaseInfo/e:author",
99 qw(e:title e:description) ],
100 [ hosturl => 0, "URL to Hosting Organisation", "i:status/i:hostURL" ],
101 [ contact => 0, "Contact", "e:databaseInfo/e:contact",
102 qw(e:title e:description) ],
103 [ extent => 3, "Extent", "e:databaseInfo/e:extent",
104 qw(e:title e:description) ],
105 [ history => 5, "History", "e:databaseInfo/e:history",
106 qw(e:title e:description) ],
108 # This list was produced by feeding
109 # http://www.loc.gov/standards/iso639-2/ISO-639-2_values_8bits.txt
111 # awk -F'|' '$3 {print$4}'
112 # and shortening some of the longer names by hand
140 "Catalan; Valencian",
144 "Church Slavic; Old Slavonic",
151 "Divehi; Dhivehi; Maldivian",
165 "Gaelic; Scottish Gaelic",
169 "Greek, Modern (1453-)",
172 "Haitian; Haitian Creole",
191 "Kalaallisut; Greenlandic",
203 "Kuanyama; Kwanyama",
208 "Limburgan; Limburger; Limburgish",
211 "Luxembourgish; Letzeburgesch",
226 "Ndebele, South; South Ndebele",
227 "Ndebele, North; North Ndebele",
233 "Chichewa; Chewa; Nyanja",
234 "Occitan (post 1500); Provençal",
254 "Sinhala; Sinhalese",
263 "Spanish; Castilian",
278 "Tonga (Tonga Islands)",
300 "Language of Records", "e:databaseInfo/e:langUsage",
301 qw(e:title e:description) ],
302 [ restrictions => 2, "Restrictions", "e:databaseInfo/e:restrictions",
303 qw(e:title e:description) ],
304 [ subjects => 2, "Subjects", "e:databaseInfo/e:subjects",
305 qw(e:title e:description) ],
308 # Update record with submitted data
309 my %fieldsByKey = map { ( $_->[0], $_) } @fields;
311 foreach my $key ($r->param()) {
312 next if grep { $key eq $_ } qw(op id update);
313 $data{$key} = $r->param($key);
315 my @changedFields = modify_xml_document($xc, \%fieldsByKey, \%data);
316 if ($update && @changedFields) {
317 my @x = modify_xml_document($xc, { dateModified =>
319 "Data/time modified",
320 "e:metaInfo/e:dateModified" ] },
321 { dateModified => isodate(time()) });
322 die "Didn't set dateModified!" if !@x;
323 ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode(), $id);
327 <h2><% xml_encode($xc->find("e:databaseInfo/e:title"), "[Untitled]") %></h2>
328 % if ($update && @changedFields) {
329 % my $nchanges = @changedFields;
330 <p style="font-weight: bold">
331 The record has been <% $op ne "edit" ? "created" : "updated" %>.<br/>
332 Changed <% $nchanges %> field<% $nchanges == 1 ? "" : "s" %>:
333 <% join(", ", map { xml_encode($_->[2]) } @changedFields) %>.
336 <form method="get" action="">
337 <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
339 foreach my $ref (@fields) {
340 my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
343 <th><% $caption %></th>
345 % my $rawval = $xc->findvalue($xpath);
346 % my $val = xml_encode($rawval, "");
348 <select name="<% $name %>" size="1">
349 % foreach my $option (@$nlines) {
350 <option value="<% xml_encode($option) %>"<%
351 ($rawval eq $option ? ' selected="selected"' : "")
352 %>><% xml_encode($option) %></option>
355 % } elsif ($nlines) {
356 <textarea name="<% $name %>" rows="<% $nlines %>" cols="51"><% $val %></textarea>
358 <input name="<% $name %>" type="text" size="60" value="<% $val %>"/>
362 <& /help/link.mc, help => "edit/$name" &>
367 <td align="right" colspan="2">
368 <input type="submit" name="update" value="Update"/>
369 <input type="hidden" name="op" value="<% xml_encode($op) %>"/>
371 <input type="hidden" name="id" value="<% xml_encode($id) %>"/>
378 if (@changedFields && 0) {
379 my $x = $xc->getContextNode()->toString();
381 #$x =~ s/$/<br\/>/gm;
382 print "<pre>$x</pre>\n";