1 %# $Id: edit.mc,v 1.26 2007-01-24 09:28:02 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 = 'rec.id="' . cql_quote($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",
92 "Antigua and Barbuda",
110 "Bosnia and Herzegowina",
114 "British Indian Ocean Terr.",
124 "Central African Republic",
129 "Cocos (Keeling) Islands",
136 "Croatia (Hrvatska)",
143 "Dominican Republic",
152 "Falkland Islands/Malvinas",
157 "France, Metropolitan",
160 "French Southern Terr.",
177 "Heard & McDonald Is.",
199 "Lao People's Dem. Rep.",
204 "Libyan Arab Jamahiriya",
234 "Netherlands Antilles",
242 "Northern Mariana Is.",
259 "Russian Federation",
261 "S.Georgia & S.Sandwich Is.",
262 "Saint Kitts and Nevis",
266 "Sao Tome & Principe",
272 "Slovakia (Slovak Republic)",
280 "St. Pierre & Miquelon",
281 "St. Vincent & Grenadines",
284 "Svalbard & Jan Mayen Is.",
288 "Syrian Arab Republic",
296 "Trinidad and Tobago",
300 "Turks & Caicos Islands",
302 "U.S. Minor Outlying Is.",
305 "United Arab Emirates",
311 "Vatican (Holy See)",
314 "Virgin Islands (British)",
315 "Virgin Islands (U.S.)",
316 "Wallis & Futuna Is.",
324 "Country", "i:status/i:country" ],
325 [ protocol => [ qw(Z39.50 SRW SRU SRW/U) ],
326 "Protocol", "e:serverInfo/\@protocol" ],
327 [ host => 0, "Host", "e:serverInfo/e:host" ],
328 [ port => 0, "Port", "e:serverInfo/e:port" ],
329 [ dbname => 0, "Database Name", "e:serverInfo/e:database",
331 [ type => [ "", qw(Academic Public Corporate Special National Education Other) ],
332 "Type of Library", "i:status/i:libraryType" ],
333 [ username => 0, "Username (if needed)", "e:serverInfo/e:authentication/e:user",
335 [ password => 0, "Password (if needed)", "e:serverInfo/e:authentication/e:password",
337 [ description => 5, "Description", "e:databaseInfo/e:description",
339 [ author => 0, "Author", "e:databaseInfo/e:author",
340 qw(e:title e:description) ],
341 [ hosturl => 0, "URL to Hosting Organisation", "i:status/i:hostURL" ],
342 [ contact => 0, "Contact", "e:databaseInfo/e:contact",
343 qw(e:title e:description) ],
344 [ extent => 3, "Extent", "e:databaseInfo/e:extent",
345 qw(e:title e:description) ],
346 [ history => 5, "History", "e:databaseInfo/e:history",
347 qw(e:title e:description) ],
349 # This list was produced by feeding
350 # http://www.loc.gov/standards/iso639-2/ISO-639-2_values_8bits.txt
352 # awk -F'|' '$3 {print$4}'
353 # and shortening some of the longer names by hand
380 "Catalan; Valencian",
384 "Church Slavic; Old Slavonic",
391 "Divehi; Dhivehi; Maldivian",
406 "Gaelic; Scottish Gaelic",
410 "Greek, Modern (1453-)",
413 "Haitian; Haitian Creole",
432 "Kalaallisut; Greenlandic",
444 "Kuanyama; Kwanyama",
449 "Limburgan; Limburger; Limburgish",
452 "Luxembourgish; Letzeburgesch",
467 "Ndebele, South; South Ndebele",
468 "Ndebele, North; North Ndebele",
474 "Chichewa; Chewa; Nyanja",
475 "Occitan (post 1500); Provençal",
495 "Sinhala; Sinhalese",
504 "Spanish; Castilian",
519 "Tonga (Tonga Islands)",
541 "Language of Records", "e:databaseInfo/e:langUsage",
542 qw(e:title e:description) ],
543 [ restrictions => 2, "Restrictions", "e:databaseInfo/e:restrictions",
544 qw(e:title e:description) ],
545 [ subjects => 2, "Subjects", "e:databaseInfo/e:subjects",
546 qw(e:title e:description) ],
549 # Update record with submitted data
550 my %fieldsByKey = map { ( $_->[0], $_) } @fields;
552 foreach my $key ($r->param()) {
553 next if grep { $key eq $_ } qw(op id update);
554 $data{$key} = $r->param($key);
556 my @changedFields = modify_xml_document($xc, \%fieldsByKey, \%data);
557 if ($update && @changedFields) {
558 my @x = modify_xml_document($xc, { dateModified =>
560 "Data/time modified",
561 "e:metaInfo/e:dateModified" ] },
562 { dateModified => isodate(time()) });
563 die "Didn't set dateModified!" if !@x;
564 ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
568 <h2><% xml_encode($xc->find("e:databaseInfo/e:title"), "[Untitled]") %></h2>
569 % if ($update && @changedFields) {
570 % my $nchanges = @changedFields;
571 <p style="font-weight: bold">
572 The record has been <% $op ne "edit" ? "created" : "updated" %>.<br/>
573 Changed <% $nchanges %> field<% $nchanges == 1 ? "" : "s" %>:
574 <% join(", ", map { xml_encode($_->[2]) } @changedFields) %>.
577 <form method="get" action="">
578 <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
580 foreach my $ref (@fields) {
581 my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
584 <th><% $caption %></th>
586 % my $rawval = $xc->findvalue($xpath);
587 % my $val = xml_encode($rawval, "");
589 <select name="<% $name %>" size="1">
590 % foreach my $option (@$nlines) {
591 <option value="<% xml_encode($option) %>"<%
592 ($rawval eq $option ? ' selected="selected"' : "")
593 %>><% xml_encode($option) %></option>
596 % } elsif ($nlines) {
597 <textarea name="<% $name %>" rows="<% $nlines %>" cols="51"><% $val %></textarea>
599 <input name="<% $name %>" type="text" size="60" value="<% $val %>"/>
603 <& /help/link.mc, help => "edit/$name" &>
608 <td align="right" colspan="2">
609 <input type="submit" name="update" value="Update"/>
610 <input type="hidden" name="op" value="<% xml_encode($op) %>"/>
612 <input type="hidden" name="id" value="<% xml_encode($id) %>"/>
619 if (@changedFields && 0) {
620 my $x = $xc->getContextNode()->toString();
622 #$x =~ s/$/<br\/>/gm;
623 print "<pre>$x</pre>\n";