1 %# $Id: edit.mc,v 1.5 2006-10-31 09:26:59 mike Exp $
9 my $conn = new ZOOM::Connection("localhost:3313/IR-Explain---1", 0,
10 user => "admin", password => "fruitbat");
11 $conn->option(elementSetName => "zeerex");
14 my $query = qq[rec.id="$qid"];
15 my $rs = $conn->search(new ZOOM::Query::CQL($query));
18 $m->comp("/details/error.mc",
19 title => "Error", message => "No such ID '$id'");
21 my $rec = $rs->record(0);
22 my $xc = irspy_xpath_context($rec);
25 [ protocol => 0, "Protocol", "e:serverInfo/\@protocol" ],
26 [ host => 0, "Host", "e:serverInfo/e:host" ],
27 [ port => 0, "Port", "e:serverInfo/e:port" ],
28 [ dbname => 0, "Database Name", "e:serverInfo/e:database",
30 [ username => 0, "Username (if needed)", "e:serverInfo/e:authentication/e:user",
32 [ password => 0, "Password (if needed)", "e:serverInfo/e:authentication/e:password",
34 [ title => 0, "title", "e:databaseInfo/e:title",
36 [ description => 5, "Description", "e:databaseInfo/e:description",
38 [ author => 0, "Author", "e:databaseInfo/e:author",
39 qw(e:title e:description) ],
40 [ contact => 0, "Contact", "e:databaseInfo/e:contact",
41 qw(e:title e:description) ],
42 [ extent => 3, "Extent", "e:databaseInfo/e:extent",
43 qw(e:title e:description) ],
44 [ history => 5, "History", "e:databaseInfo/e:history",
45 qw(e:title e:description) ],
46 [ language => 0, "Language of Records", "e:databaseInfo/e:langUsage",
47 qw(e:title e:description) ],
48 [ restrictions => 2, "Restrictions", "e:databaseInfo/e:restrictions",
49 qw(e:title e:description) ],
50 [ subjects => 2, "Subjects", "e:databaseInfo/e:subjects",
51 qw(e:title e:description) ],
52 ### Remember to set e:metaInfo/e:dateModified
54 my %fieldsByKey = map { ( $_->[0], $_) } @fields;
55 my $update = $r->param("update");
56 if (defined $update) {
57 # Update record with submitted data
58 foreach my $key ($r->param()) {
59 next if grep { $key eq $_ } qw(id update);
60 my $value = $r->param($key);
61 my $ref = $fieldsByKey{$key} or die "no field '$key'";
62 my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
63 my @nodes = $xc->findnodes($xpath);
65 warn scalar(@nodes), " nodes match '$xpath'" if @nodes > 1;
67 if ($node->isa("XML::LibXML::Attr")) {
68 $node->setValue($value);
69 #print "Attr $key <- '$value' ($xpath)<br/>\n";
70 } elsif ($node->isa("XML::LibXML::Element")) {
71 my $child = $node->firstChild();
72 die "element child $child is not text"
73 if !ref $child || !$child->isa("XML::LibXML::Text");
74 $child->setData($value);
75 #print "Elem $key <- '$value' ($xpath)<br/>\n";
77 warn "unexpected node type $node";
81 my($ppath, $element) = $xpath =~ /(.*)\/(.*)/;
82 dom_add_element($xc, $ppath, $element, $value, @addAfter);
85 ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
88 <h2><% xml_encode($id) %></h2>
89 % print " <p><b>The record has been updated.</b></p>\n" if defined $update;
90 <form method="get" action="">
91 <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
93 foreach my $ref (@fields) {
94 my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
97 <th><% $caption %></th>
99 % my $data = xml_encode($xc->find($xpath));
101 <textarea name="<% $name %>" rows="<% $nlines %>" cols="61"><% $data %></textarea>
103 <input name="<% $name %>" type="text" size="60" value="<% $data %>">
109 <td align="right" colspan="2">
110 <input type="submit" name="update" value="Update"/>
111 <input type="hidden" name="id" value="<% xml_encode($id) %>"/>