1 %# $Id: edit.mc,v 1.18 2006-11-16 17:30:25 mike Exp $
6 my $conn = new ZOOM::Connection("localhost:3313/IR-Explain---1", 0,
7 user => "admin", password => "fruitbat",
8 elementSetName => "zeerex");
9 my $rec = '<explain xmlns="http://explain.z3950.org/dtd/2.0/"/>';
10 if (defined $id && $id ne "") {
12 my $query = 'rec.id="' . cql_quote($id) . '"';
13 my $rs = $conn->search(new ZOOM::Query::CQL($query));
14 if ($rs->size() > 0) {
15 $rec = $rs->record(0);
22 my $host = $r->param("host");
23 my $port = $r->param("port");
24 my $dbname = $r->param("dbname");
25 if (!defined $host || $host eq "" ||
26 !defined $port || $port eq "" ||
27 !defined $dbname || $dbname eq "") {
28 print qq[<p class="error">You must specify host, port and database name.</p>\n];
29 $r->param(update => 0);
32 my $query = cql_target($host, $port, $dbname);
35 my $xc = irspy_xpath_context($rec);
38 [ protocol => [ qw(Z39.50 SRW SRU SRW/U) ],
39 "Protocol", "e:serverInfo/\@protocol" ],
40 [ host => 0, "Host", "e:serverInfo/e:host" ],
41 [ port => 0, "Port", "e:serverInfo/e:port" ],
42 [ dbname => 0, "Database Name", "e:serverInfo/e:database",
44 [ type => [ qw(Academic Public Corporate Special National Education Other) ],
45 "Type of Library", "i:status/i:libraryType" ],
46 [ country => 0, "Country", "i:status/i:country" ],
47 [ username => 0, "Username (if needed)", "e:serverInfo/e:authentication/e:user",
49 [ password => 0, "Password (if needed)", "e:serverInfo/e:authentication/e:password",
51 [ title => 0, "Title", "e:databaseInfo/e:title",
53 [ description => 5, "Description", "e:databaseInfo/e:description",
55 [ author => 0, "Author", "e:databaseInfo/e:author",
56 qw(e:title e:description) ],
57 [ hosturl => 0, "URL to Hosting Organisation", "i:status/i:hostURL" ],
58 [ contact => 0, "Contact", "e:databaseInfo/e:contact",
59 qw(e:title e:description) ],
60 [ extent => 3, "Extent", "e:databaseInfo/e:extent",
61 qw(e:title e:description) ],
62 [ history => 5, "History", "e:databaseInfo/e:history",
63 qw(e:title e:description) ],
64 [ language => 0, "Language of Records", "e:databaseInfo/e:langUsage",
65 qw(e:title e:description) ],
66 [ restrictions => 2, "Restrictions", "e:databaseInfo/e:restrictions",
67 qw(e:title e:description) ],
68 [ subjects => 2, "Subjects", "e:databaseInfo/e:subjects",
69 qw(e:title e:description) ],
73 my $update = $r->param("update");
75 # Update record with submitted data
76 my %fieldsByKey = map { ( $_->[0], $_) } @fields;
78 foreach my $key ($r->param()) {
79 next if grep { $key eq $_ } qw(id update new copy);
80 $data{$key} = $r->param($key);
83 $nchanges = modify_xml_document($xc, \%fieldsByKey, \%data);
85 ### Set e:metaInfo/e:dateModified
87 ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
90 <h2><% xml_encode($xc->find("e:databaseInfo/e:title"), "[Untitled]") %></h2>
92 <p style="font-weight: bold">
93 The record has been <% $r->param("new") ? "created" : "updated" %>.<br/>
94 Changed <% $nchanges %> field<% $nchanges == 1 ? "" : "s" %>.
97 <form method="get" action="">
98 <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
100 foreach my $ref (@fields) {
101 my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
104 <th><% $caption %></th>
106 % my $rawdata = $xc->findvalue($xpath);
107 % my $data = xml_encode($rawdata, "");
109 <select name="<% $name %>" size="1">
110 % foreach my $val (@$nlines) {
111 <option value="<% $val %>"
112 % print ' selected="selected"' if $rawdata eq $val;
116 % } elsif ($nlines) {
117 <textarea name="<% $name %>" rows="<% $nlines %>" cols="51"><% $data %></textarea>
119 <input name="<% $name %>" type="text" size="60" value="<% $data %>"/>
125 <td align="right" colspan="2">
126 <input type="submit" name="update" value="Update"/>
128 <input type="hidden" name="id" value="<% xml_encode($id) %>"/>
130 <input type="hidden" name="new" value="1"/>
137 if ($nchanges && 0) {
138 my $x = $xc->getContextNode()->toString();
140 #$x =~ s/$/<br\/>/gm;
141 print "<pre>$x</pre>\n";