1 %# $Id: edit.mc,v 1.19 2006-11-16 17:52:06 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">
29 You must specify host, port and database name.</p>\n];
30 $r->param(update => 0);
32 my $query = cql_target($host, $port, $dbname);
33 my $rs = $conn->search(new ZOOM::Query::CQL($query));
34 if ($rs->size() > 0) {
35 my $fakeid = xml_encode(uri_escape("$host:$port/$dbname"));
36 print qq[<p class="error">
38 <a href='?id=$fakeid'>a record</a>
39 for this host, port and database name.
45 my $xc = irspy_xpath_context($rec);
48 [ protocol => [ qw(Z39.50 SRW SRU SRW/U) ],
49 "Protocol", "e:serverInfo/\@protocol" ],
50 [ host => 0, "Host", "e:serverInfo/e:host" ],
51 [ port => 0, "Port", "e:serverInfo/e:port" ],
52 [ dbname => 0, "Database Name", "e:serverInfo/e:database",
54 [ type => [ qw(Academic Public Corporate Special National Education Other) ],
55 "Type of Library", "i:status/i:libraryType" ],
56 [ country => 0, "Country", "i:status/i:country" ],
57 [ username => 0, "Username (if needed)", "e:serverInfo/e:authentication/e:user",
59 [ password => 0, "Password (if needed)", "e:serverInfo/e:authentication/e:password",
61 [ title => 0, "Title", "e:databaseInfo/e:title",
63 [ description => 5, "Description", "e:databaseInfo/e:description",
65 [ author => 0, "Author", "e:databaseInfo/e:author",
66 qw(e:title e:description) ],
67 [ hosturl => 0, "URL to Hosting Organisation", "i:status/i:hostURL" ],
68 [ contact => 0, "Contact", "e:databaseInfo/e:contact",
69 qw(e:title e:description) ],
70 [ extent => 3, "Extent", "e:databaseInfo/e:extent",
71 qw(e:title e:description) ],
72 [ history => 5, "History", "e:databaseInfo/e:history",
73 qw(e:title e:description) ],
74 [ language => 0, "Language of Records", "e:databaseInfo/e:langUsage",
75 qw(e:title e:description) ],
76 [ restrictions => 2, "Restrictions", "e:databaseInfo/e:restrictions",
77 qw(e:title e:description) ],
78 [ subjects => 2, "Subjects", "e:databaseInfo/e:subjects",
79 qw(e:title e:description) ],
83 my $update = $r->param("update");
85 # Update record with submitted data
86 my %fieldsByKey = map { ( $_->[0], $_) } @fields;
88 foreach my $key ($r->param()) {
89 next if grep { $key eq $_ } qw(id update new copy);
90 $data{$key} = $r->param($key);
92 my $mynchanges = modify_xml_document($xc, \%fieldsByKey, \%data);
95 $nchanges = $mynchanges;
97 ### Set e:metaInfo/e:dateModified
99 ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
102 <h2><% xml_encode($xc->find("e:databaseInfo/e:title"), "[Untitled]") %></h2>
104 <p style="font-weight: bold">
105 The record has been <% $r->param("new") ? "created" : "updated" %>.<br/>
106 Changed <% $nchanges %> field<% $nchanges == 1 ? "" : "s" %>.
109 <form method="get" action="">
110 <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
112 foreach my $ref (@fields) {
113 my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
116 <th><% $caption %></th>
118 % my $rawdata = $xc->findvalue($xpath);
119 % my $data = xml_encode($rawdata, "");
121 <select name="<% $name %>" size="1">
122 % foreach my $val (@$nlines) {
123 <option value="<% $val %>"
124 % print ' selected="selected"' if $rawdata eq $val;
128 % } elsif ($nlines) {
129 <textarea name="<% $name %>" rows="<% $nlines %>" cols="51"><% $data %></textarea>
131 <input name="<% $name %>" type="text" size="60" value="<% $data %>"/>
137 <td align="right" colspan="2">
138 <input type="submit" name="update" value="Update"/>
140 <input type="hidden" name="id" value="<% xml_encode($id) %>"/>
142 <input type="hidden" name="new" value="1"/>
149 if ($nchanges && 0) {
150 my $x = $xc->getContextNode()->toString();
152 #$x =~ s/$/<br\/>/gm;
153 print "<pre>$x</pre>\n";