c1c1abb129bae388580fba3e00bcfdf1c5f474cd
[irspy-moved-to-github.git] / web / htdocs / details / edit.mc
1 %# $Id: edit.mc,v 1.18 2006-11-16 17:30:25 mike Exp $
2 <%args>
3 $id => undef
4 </%args>
5 <%perl>
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     # Existing record
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);
16     } else {
17         $id = undef;
18     }
19
20 } else {
21     # New record
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);
30     }
31
32     my $query = cql_target($host, $port, $dbname);
33 }
34
35 my $xc = irspy_xpath_context($rec);
36 my @fields =
37     (
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",
43        qw(e:host e:port) ],
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",
48        qw() ],
49      [ password     => 0, "Password (if needed)", "e:serverInfo/e:authentication/e:password",
50        qw(e:user) ],
51      [ title        => 0, "Title", "e:databaseInfo/e:title",
52        qw() ],
53      [ description  => 5, "Description", "e:databaseInfo/e:description",
54        qw(e:title) ],
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) ],
70      );
71
72 my $nchanges = 0;
73 my $update = $r->param("update");
74 if ($update) {
75     # Update record with submitted data
76     my %fieldsByKey = map { ( $_->[0], $_) } @fields;
77     my %data;
78     foreach my $key ($r->param()) {
79         next if grep { $key eq $_ } qw(id update new copy);
80         $data{$key} = $r->param($key);
81     }
82
83     $nchanges = modify_xml_document($xc, \%fieldsByKey, \%data);
84     if ($nchanges) {
85         ### Set e:metaInfo/e:dateModified
86     }
87     ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
88 }
89 </%perl>
90  <h2><% xml_encode($xc->find("e:databaseInfo/e:title"), "[Untitled]") %></h2>
91 % if ($nchanges) {
92  <p style="font-weight: bold">
93   The record has been <% $r->param("new") ? "created" : "updated" %>.<br/>
94   Changed <% $nchanges %> field<% $nchanges == 1 ? "" : "s" %>.
95  </p>
96 % }
97  <form method="get" action="">
98   <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
99 <%perl>
100 foreach my $ref (@fields) {
101     my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
102 </%perl>
103    <tr>
104     <th><% $caption %></th>
105     <td>
106 % my $rawdata = $xc->findvalue($xpath);
107 % my $data = xml_encode($rawdata, "");
108 % if (ref $nlines) {
109      <select name="<% $name %>" size="1">
110 %     foreach my $val (@$nlines) {
111       <option value="<% $val %>"
112 % print ' selected="selected"' if $rawdata eq $val;
113         ><% $val %></option>
114 %     }
115      </select>
116 % } elsif ($nlines) {
117      <textarea name="<% $name %>" rows="<% $nlines %>" cols="51"><% $data %></textarea>
118 % } else {
119      <input name="<% $name %>" type="text" size="60" value="<% $data %>"/>
120 % }
121     </td>
122    </tr>
123 %   }
124    <tr>
125     <td align="right" colspan="2">
126      <input type="submit" name="update" value="Update"/>
127 % if (defined $id) {
128      <input type="hidden" name="id" value="<% xml_encode($id) %>"/>
129 % } else {
130      <input type="hidden" name="new" value="1"/>
131 % }
132     </td>
133    </tr>
134   </table>
135  </form>
136 <%perl>
137     if ($nchanges && 0) {
138         my $x = $xc->getContextNode()->toString();
139         $x = xml_encode($x);
140         #$x =~ s/$/<br\/>/gm;
141         print "<pre>$x</pre>\n";
142     }
143 </%perl>