1 %# $Id: edit.mc,v 1.30 2007-04-27 14:04:40 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 $protocol = $r->param("protocol");
54 my $host = $r->param("host");
55 my $port = $r->param("port");
56 my $dbname = $r->param("dbname");
57 if (!defined $protocol || $protocol eq "" ||
58 !defined $host || $host eq "" ||
59 !defined $port || $port eq "" ||
60 !defined $dbname || $dbname eq "") {
61 print qq[<p class="error">
62 You must specify protocol, host, port and database name.</p>\n] if $update;
65 ### Should use a utility function for this
66 my $query = cql_target($protocol, $host, $port, $dbname);
67 my $rs = $conn->search(new ZOOM::Query::CQL($query));
68 if ($rs->size() > 0) {
70 xml_encode(uri_escape(irspy_make_identifier($protocol, $host,
72 print qq[<p class="error">
74 <a href='?op=edit&id=$fakeid'>a record</a>
75 for this host, port and database name.
82 my $xc = irspy_xpath_context($rec);
85 [ title => 0, "Name", "e:databaseInfo/e:title",
87 [ country => $m->comp("country-list.mc"),
88 "Country", "i:status/i:country" ],
89 [ protocol => [ qw(Z39.50 SRW SRU SRW/U) ],
90 "Protocol", "e:serverInfo/\@protocol" ],
91 [ host => 0, "Host", "e:serverInfo/e:host" ],
92 [ port => 0, "Port", "e:serverInfo/e:port" ],
93 [ dbname => 0, "Database Name", "e:serverInfo/e:database",
95 [ type => $m->comp("libtype-list.mc"),
96 "Type of Library", "i:status/i:libraryType" ],
97 [ username => 0, "Username (if needed)", "e:serverInfo/e:authentication/e:user",
99 [ password => 0, "Password (if needed)", "e:serverInfo/e:authentication/e:password",
101 [ description => 5, "Description", "e:databaseInfo/e:description",
103 [ author => 0, "Author", "e:databaseInfo/e:author",
104 qw(e:title e:description) ],
105 [ hosturl => 0, "URL to Hosting Organisation", "i:status/i:hostURL" ],
106 [ contact => 0, "Contact", "e:databaseInfo/e:contact",
107 qw(e:title e:description) ],
108 [ extent => 3, "Extent", "e:databaseInfo/e:extent",
109 qw(e:title e:description) ],
110 [ history => 5, "History", "e:databaseInfo/e:history",
111 qw(e:title e:description) ],
113 # This list was produced by feeding
114 # http://www.loc.gov/standards/iso639-2/ISO-639-2_values_8bits.txt
116 # awk -F'|' '$3 {print$4}'
117 # and shortening some of the longer names by hand
145 "Catalan; Valencian",
149 "Church Slavic; Old Slavonic",
156 "Divehi; Dhivehi; Maldivian",
170 "Gaelic; Scottish Gaelic",
174 "Greek, Modern (1453-)",
177 "Haitian; Haitian Creole",
196 "Kalaallisut; Greenlandic",
208 "Kuanyama; Kwanyama",
213 "Limburgan; Limburger; Limburgish",
216 "Luxembourgish; Letzeburgesch",
231 "Ndebele, South; South Ndebele",
232 "Ndebele, North; North Ndebele",
238 "Chichewa; Chewa; Nyanja",
239 "Occitan (post 1500); Provençal",
259 "Sinhala; Sinhalese",
268 "Spanish; Castilian",
283 "Tonga (Tonga Islands)",
305 "Language of Records", "e:databaseInfo/e:langUsage",
306 qw(e:title e:description) ],
307 [ restrictions => 2, "Restrictions", "e:databaseInfo/e:restrictions",
308 qw(e:title e:description) ],
309 [ subjects => 2, "Subjects", "e:databaseInfo/e:subjects",
310 qw(e:title e:description) ],
313 # Update record with submitted data
314 my %fieldsByKey = map { ( $_->[0], $_) } @fields;
316 foreach my $key ($r->param()) {
317 next if grep { $key eq $_ } qw(op id update);
318 $data{$key} = $r->param($key);
320 my @changedFields = modify_xml_document($xc, \%fieldsByKey, \%data);
321 if ($update && @changedFields) {
322 my @x = modify_xml_document($xc, { dateModified =>
324 "Data/time modified",
325 "e:metaInfo/e:dateModified" ] },
326 { dateModified => isodate(time()) });
327 die "Didn't set dateModified!" if !@x;
328 ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode(), $id);
332 <h2><% xml_encode($xc->find("e:databaseInfo/e:title"), "[Untitled]") %></h2>
333 % if ($update && @changedFields) {
334 % my $nchanges = @changedFields;
335 <p style="font-weight: bold">
336 The record has been <% $op ne "edit" ? "created" : "updated" %>.<br/>
337 Changed <% $nchanges %> field<% $nchanges == 1 ? "" : "s" %>:
338 <% join(", ", map { xml_encode($_->[2]) } @changedFields) %>.
341 <form method="get" action="">
342 <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
344 foreach my $ref (@fields) {
345 my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
348 <th><% $caption %></th>
350 % my $rawval = $xc->findvalue($xpath);
351 % my $val = xml_encode($rawval, "");
353 <select name="<% $name %>" size="1">
354 % foreach my $option (@$nlines) {
355 <option value="<% xml_encode($option) %>"<%
356 ($rawval eq $option ? ' selected="selected"' : "")
357 %>><% xml_encode($option) %></option>
360 % } elsif ($nlines) {
361 <textarea name="<% $name %>" rows="<% $nlines %>" cols="51"><% $val %></textarea>
363 <input name="<% $name %>" type="text" size="60" value="<% $val %>"/>
367 <& /help/link.mc, help => "edit/$name" &>
372 <td align="right" colspan="2">
373 <input type="submit" name="update" value="Update"/>
374 <input type="hidden" name="op" value="<% xml_encode($op) %>"/>
376 <input type="hidden" name="id" value="<% xml_encode($id) %>"/>
383 if (@changedFields && 0) {
384 my $x = $xc->getContextNode()->toString();
386 #$x =~ s/$/<br\/>/gm;
387 print "<pre>$x</pre>\n";