1 %# $Id: edit.mc,v 1.34 2007-05-03 12:54:18 mike Exp $
4 $id => undef ### should be extracted using utf8param()
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");
39 my $protocol = utf8param($r, "protocol");
40 my $host = utf8param($r, "host");
41 my $port = utf8param($r, "port");
42 my $dbname = utf8param($r, "dbname");
44 if (defined $protocol && $protocol ne "" &&
45 defined $host && $host ne "" &&
46 defined $port && $port ne "" &&
47 defined $dbname && $dbname ne "") {
48 $newid = irspy_make_identifier($protocol, $host, $port, $dbname);
51 my $rec = '<explain xmlns="http://explain.z3950.org/dtd/2.0/"/>';
55 # About to enter data for a new record
56 # Nothing to do at this stage
57 } elsif (!defined $newid) {
58 # Tried to create new record but data is insufficient
59 print qq[<p class="error">
60 Please specify protocol, host, port and database name.</p>\n];
63 # Creating new record, all necessary data is present. Check
64 # that the new record is not a duplicate of an existing one.
65 my $rs = $conn->search(new ZOOM::Query::CQL(cql_target($newid)));
66 if ($rs->size() > 0) {
67 my $qnewid = xml_encode(uri_escape($newid));
68 print qq[<p class="error">
70 <a href='?op=edit&id=$newid'>a record</a>
71 for this protocol, host, port and database name.
77 # assert(defined $id);
78 # Copying or editing an existing record: fetch it for editing
79 my $query = cql_target($id);
80 my $rs = $conn->search(new ZOOM::Query::CQL($query));
81 if ($rs->size() > 0) {
82 $rec = $rs->record(0);
84 ### Is this an error? I don't think the UI will ever provoke it
85 print qq[<p class="error">(New ID specified.)</p>\n];
90 my $xc = irspy_xpath_context($rec);
93 [ title => 0, "Name", "e:databaseInfo/e:title",
95 [ country => $m->comp("country-list.mc"),
96 "Country", "i:status/i:country" ],
97 [ protocol => [ qw(Z39.50 SRW SRU) ],
98 "Protocol", "e:serverInfo/\@protocol" ],
99 [ host => 0, "Host", "e:serverInfo/e:host" ],
100 [ port => 0, "Port", "e:serverInfo/e:port" ],
101 [ dbname => 0, "Database Name", "e:serverInfo/e:database",
103 [ type => $m->comp("libtype-list.mc"),
104 "Type of Library", "i:status/i:libraryType" ],
105 [ username => 0, "Username (if needed)", "e:serverInfo/e:authentication/e:user",
107 [ password => 0, "Password (if needed)", "e:serverInfo/e:authentication/e:password",
109 [ description => 5, "Description", "e:databaseInfo/e:description",
111 [ author => 0, "Author", "e:databaseInfo/e:author",
112 qw(e:title e:description) ],
113 [ hosturl => 0, "URL to Hosting Organisation", "i:status/i:hostURL" ],
114 [ contact => 0, "Contact", "e:databaseInfo/e:contact",
115 qw(e:title e:description) ],
116 [ extent => 3, "Extent", "e:databaseInfo/e:extent",
117 qw(e:title e:description) ],
118 [ history => 5, "History", "e:databaseInfo/e:history",
119 qw(e:title e:description) ],
121 # This list was produced by feeding
122 # http://www.loc.gov/standards/iso639-2/ISO-639-2_values_8bits.txt
124 # awk -F'|' '$3 {print$4}'
125 # and shortening some of the longer names by hand
153 "Catalan; Valencian",
157 "Church Slavic; Old Slavonic",
164 "Divehi; Dhivehi; Maldivian",
178 "Gaelic; Scottish Gaelic",
182 "Greek, Modern (1453-)",
185 "Haitian; Haitian Creole",
204 "Kalaallisut; Greenlandic",
216 "Kuanyama; Kwanyama",
221 "Limburgan; Limburger; Limburgish",
224 "Luxembourgish; Letzeburgesch",
239 "Ndebele, South; South Ndebele",
240 "Ndebele, North; North Ndebele",
246 "Chichewa; Chewa; Nyanja",
247 "Occitan (post 1500); Provençal",
267 "Sinhala; Sinhalese",
276 "Spanish; Castilian",
291 "Tonga (Tonga Islands)",
313 "Language of Records", "e:databaseInfo/e:langUsage",
314 qw(e:title e:description) ],
315 [ restrictions => 2, "Restrictions", "e:databaseInfo/e:restrictions",
316 qw(e:title e:description) ],
317 [ subjects => 2, "Subjects", "e:databaseInfo/e:subjects",
318 qw(e:title e:description) ],
321 # Update record with submitted data
322 my %fieldsByKey = map { ( $_->[0], $_) } @fields;
324 foreach my $key ($r->param()) {
325 next if grep { $key eq $_ } qw(op id update);
326 $data{$key} = utf8param($r, $key);
328 my @changedFields = modify_xml_document($xc, \%fieldsByKey, \%data);
329 if ($update && @changedFields) {
330 my @x = modify_xml_document($xc, { dateModified =>
332 "Data/time modified",
333 "e:metaInfo/e:dateModified" ] },
334 { dateModified => isodate(time()) });
335 die "Didn't set dateModified!" if !@x;
336 ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode(),
337 $op eq "edit" ? $id : undef);
341 <h2><% xml_encode($xc->find("e:databaseInfo/e:title"), "[Untitled]") %></h2>
342 % if ($update && @changedFields) {
343 % my $nchanges = @changedFields;
344 <p style="font-weight: bold">
345 The record has been <% $op ne "edit" ? "created" : "updated" %>.<br/>
346 Changed <% $nchanges %> field<% $nchanges == 1 ? "" : "s" %>:
347 <% join(", ", map { xml_encode($_->[2]) } @changedFields) %>.
350 <form method="get" action="">
351 <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
353 foreach my $ref (@fields) {
354 my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
357 <th><% $caption %></th>
359 % my $rawval = $xc->findvalue($xpath);
360 % my $val = xml_encode($rawval, "");
362 <select name="<% $name %>" size="1">
363 % foreach my $option (@$nlines) {
364 <option value="<% xml_encode($option) %>"<%
365 ($rawval eq $option ? ' selected="selected"' : "")
366 %>><% xml_encode($option) %></option>
369 % } elsif ($nlines) {
370 <textarea name="<% $name %>" rows="<% $nlines %>" cols="51"><% $val %></textarea>
372 <input name="<% $name %>" type="text" size="60" value="<% $val %>"/>
376 <& /help/link.mc, help => "edit/$name" &>
381 <td align="right" colspan="2">
382 <input type="submit" name="update" value="Update"/>
383 % $op = "edit" if $op eq "new" && defined $update;
384 <input type="hidden" name="op" value="<% xml_encode($op) %>"/>
385 % $id = $newid if defined $newid;
387 <input type="hidden" name="id" value="<% xml_encode($id) %>"/>
394 if (@changedFields && 0) {
395 my $x = $xc->getContextNode()->toString();
397 #$x =~ s/$/<br\/>/gm;
398 print "<pre>$x</pre>\n";