1 %# $Id: edit.mc,v 1.16 2006-11-16 17:14:46 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 "") {
11 print "Old record '$id'<br/>\n";
13 my $query = 'rec.id="' . cql_quote($id) . '"';
14 my $rs = $conn->search(new ZOOM::Query::CQL($query));
19 $rec = $rs->record(0);
24 print "New record<br/>\n";
25 my $host = $r->param("host");
26 my $port = $r->param("port");
27 my $dbname = $r->param("dbname");
28 if (!defined $host || $host eq "" ||
29 !defined $port || $port eq "" ||
30 !defined $dbname || $dbname eq "") {
31 print qq[<p class="error">You must specify host, port and database name</p>\n];
32 $r->param(update => 0);
35 my $query = cql_target($host, $port, $dbname);
38 my $xc = irspy_xpath_context($rec);
41 [ protocol => [ qw(Z39.50 SRW SRU SRW/U) ],
42 "Protocol", "e:serverInfo/\@protocol" ],
43 [ host => 0, "Host", "e:serverInfo/e:host" ],
44 [ port => 0, "Port", "e:serverInfo/e:port" ],
45 [ dbname => 0, "Database Name", "e:serverInfo/e:database",
47 [ type => [ qw(Academic Public Corporate Special National Education Other) ],
48 "Type of Library", "i:status/i:libraryType" ],
49 [ country => 0, "Country", "i:status/i:country" ],
50 [ username => 0, "Username (if needed)", "e:serverInfo/e:authentication/e:user",
52 [ password => 0, "Password (if needed)", "e:serverInfo/e:authentication/e:password",
54 [ title => 0, "Title", "e:databaseInfo/e:title",
56 [ description => 5, "Description", "e:databaseInfo/e:description",
58 [ author => 0, "Author", "e:databaseInfo/e:author",
59 qw(e:title e:description) ],
60 [ hosturl => 0, "URL to Hosting Organisation", "i:status/i:hostURL" ],
61 [ contact => 0, "Contact", "e:databaseInfo/e:contact",
62 qw(e:title e:description) ],
63 [ extent => 3, "Extent", "e:databaseInfo/e:extent",
64 qw(e:title e:description) ],
65 [ history => 5, "History", "e:databaseInfo/e:history",
66 qw(e:title e:description) ],
67 [ language => 0, "Language of Records", "e:databaseInfo/e:langUsage",
68 qw(e:title e:description) ],
69 [ restrictions => 2, "Restrictions", "e:databaseInfo/e:restrictions",
70 qw(e:title e:description) ],
71 [ subjects => 2, "Subjects", "e:databaseInfo/e:subjects",
72 qw(e:title e:description) ],
76 my $update = $r->param("update");
77 if (defined $update) {
78 # Update record with submitted data
79 my %fieldsByKey = map { ( $_->[0], $_) } @fields;
81 foreach my $key ($r->param()) {
82 next if grep { $key eq $_ } qw(id update new copy);
83 $data{$key} = $r->param($key);
86 $nchanges = modify_xml_document($xc, \%fieldsByKey, \%data);
88 ### Set e:metaInfo/e:dateModified
90 ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
93 <h2><% xml_encode($xc->find("e:databaseInfo/e:title"), "[Untitled]") %></h2>
95 <p style="font-weight: bold">
96 The record has been <% $r->param("new") ? "created" : "updated" %>.<br/>
97 Changed <% $nchanges %> field<% $nchanges == 1 ? "" : "s" %>.
100 <form method="get" action="">
101 <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
103 foreach my $ref (@fields) {
104 my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
107 <th><% $caption %></th>
109 % my $rawdata = $xc->findvalue($xpath);
110 % my $data = xml_encode($rawdata, "");
112 <select name="<% $name %>" size="1">
113 % foreach my $val (@$nlines) {
114 <option value="<% $val %>"
115 % print ' selected="selected"' if $rawdata eq $val;
119 % } elsif ($nlines) {
120 <textarea name="<% $name %>" rows="<% $nlines %>" cols="51"><% $data %></textarea>
122 <input name="<% $name %>" type="text" size="60" value="<% $data %>"/>
128 <td align="right" colspan="2">
129 <input type="submit" name="update" value="Update"/>
131 <input type="hidden" name="id" value="<% xml_encode($id) %>"/>
133 <input type="hidden" name="new" value="1"/>
140 if ($nchanges && 0) {
141 my $x = $xc->getContextNode()->toString();
143 #$x =~ s/$/<br\/>/gm;
144 print "<pre>$x</pre>\n";