1 %# $Id: edit.mc,v 1.21 2006-11-29 18:22:08 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:3313/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 [ protocol => [ qw(Z39.50 SRW SRU SRW/U) ],
81 "Protocol", "e:serverInfo/\@protocol" ],
82 [ host => 0, "Host", "e:serverInfo/e:host" ],
83 [ port => 0, "Port", "e:serverInfo/e:port" ],
84 [ dbname => 0, "Database Name", "e:serverInfo/e:database",
86 [ type => [ qw(Academic Public Corporate Special National Education Other) ],
87 "Type of Library", "i:status/i:libraryType" ],
88 [ country => 0, "Country", "i:status/i:country" ],
89 [ username => 0, "Username (if needed)", "e:serverInfo/e:authentication/e:user",
91 [ password => 0, "Password (if needed)", "e:serverInfo/e:authentication/e:password",
93 [ title => 0, "Title", "e:databaseInfo/e:title",
95 [ description => 5, "Description", "e:databaseInfo/e:description",
97 [ author => 0, "Author", "e:databaseInfo/e:author",
98 qw(e:title e:description) ],
99 [ hosturl => 0, "URL to Hosting Organisation", "i:status/i:hostURL" ],
100 [ contact => 0, "Contact", "e:databaseInfo/e:contact",
101 qw(e:title e:description) ],
102 [ extent => 3, "Extent", "e:databaseInfo/e:extent",
103 qw(e:title e:description) ],
104 [ history => 5, "History", "e:databaseInfo/e:history",
105 qw(e:title e:description) ],
106 [ language => 0, "Language of Records", "e:databaseInfo/e:langUsage",
107 qw(e:title e:description) ],
108 [ restrictions => 2, "Restrictions", "e:databaseInfo/e:restrictions",
109 qw(e:title e:description) ],
110 [ subjects => 2, "Subjects", "e:databaseInfo/e:subjects",
111 qw(e:title e:description) ],
114 # Update record with submitted data
115 my %fieldsByKey = map { ( $_->[0], $_) } @fields;
117 foreach my $key ($r->param()) {
118 next if grep { $key eq $_ } qw(op id update);
119 $data{$key} = $r->param($key);
121 my @changedFields = modify_xml_document($xc, \%fieldsByKey, \%data);
122 if ($update && @changedFields) {
123 my @x = modify_xml_document($xc, { dateModified =>
125 "Data/time modified",
126 "e:metaInfo/e:dateModified" ] },
127 { dateModified => isodate(time()) });
128 die "Didn't set dateModified!" if !@x;
129 ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
133 <h2><% xml_encode($xc->find("e:databaseInfo/e:title"), "[Untitled]") %></h2>
134 % if ($update && @changedFields) {
135 % my $nchanges = @changedFields;
136 <p style="font-weight: bold">
137 The record has been <% $op ne "edit" ? "created" : "updated" %>.<br/>
138 Changed <% $nchanges %> field<% $nchanges == 1 ? "" : "s" %>:
139 <% join(", ", map { xml_encode($_->[2]) } @changedFields) %>.
142 <form method="get" action="">
143 <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
145 foreach my $ref (@fields) {
146 my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
149 <th><% $caption %></th>
151 % my $rawval = $xc->findvalue($xpath);
152 % my $val = xml_encode($rawval, "");
154 <select name="<% $name %>" size="1">
155 % foreach my $option (@$nlines) {
156 <option value="<% xml_encode($option) %>"<%
157 ($rawval eq $option ? ' selected="selected"' : "")
158 %>><% xml_encode($option) %></option>
161 % } elsif ($nlines) {
162 <textarea name="<% $name %>" rows="<% $nlines %>" cols="51"><% $val %></textarea>
164 <input name="<% $name %>" type="text" size="60" value="<% $val %>"/>
170 <td align="right" colspan="2">
171 <input type="submit" name="update" value="Update"/>
172 <input type="hidden" name="op" value="<% xml_encode($op) %>"/>
174 <input type="hidden" name="id" value="<% xml_encode($id) %>"/>
181 if (@changedFields && 0) {
182 my $x = $xc->getContextNode()->toString();
184 #$x =~ s/$/<br\/>/gm;
185 print "<pre>$x</pre>\n";