Move lists of countries and library-types into their own new little
[irspy-moved-to-github.git] / web / htdocs / details / edit.mc
1 %# $Id: edit.mc,v 1.29 2007-03-29 16:19:39 mike Exp $
2 <%args>
3 $op
4 $id => undef
5 $update => undef
6 </%args>
7 <%doc>
8 Since this form is used in many different situations, some care is
9 merited in considering the possibilities:
10
11 Situation                                       Op      ID      Update
12 ----------------------------------------------------------------------
13 Blank form for adding a new target              new
14 New target rejected, changes required           new             X
15 New target accepted and added                   new             X
16 ---------------------------------------------------------------------
17 Existing target to be edited                    edit    X
18 Edit rejected, changes required                 edit    X       X
19 Target successfully updated                     edit    X       X
20 ----------------------------------------------------------------------
21 Existing target to be copied                    copy    X
22 New target rejected, changes required           copy    X       X
23 New target accepted and added                   copy    X       X
24 ----------------------------------------------------------------------
25
26 Submissions, whether of new targets, edits or copies, may be rejected
27 due either to missing mandatory fields or host/name/port that form a
28 duplicate ID.
29 </%doc>
30 <%perl>
31 # Sanity checking
32 die "op = new but id defined" if $op eq "new" && defined $id;
33 die "op != new but id undefined" if $op ne "new" && !defined $id;
34
35 my $conn = new ZOOM::Connection("localhost:8018/IR-Explain---1", 0,
36                                 user => "admin", password => "fruitbat",
37                                 elementSetName => "zeerex");
38 my $rec = '<explain xmlns="http://explain.z3950.org/dtd/2.0/"/>';
39 if (defined $id && ($op ne "copy" || !$update)) {
40     # Existing record
41     my $query = cql_target($id);
42     my $rs = $conn->search(new ZOOM::Query::CQL($query));
43     if ($rs->size() > 0) {
44         $rec = $rs->record(0);
45     } else {
46         ### Is this an error?  I don't think the UI will ever provoke it
47         print qq[<p class="error">(New ID specified.)</p>\n];
48         $id = undef;
49     }
50
51 } else {
52     # No ID supplied -- this is a brand new record
53     my $host = $r->param("host");
54     my $port = $r->param("port");
55     my $dbname = $r->param("dbname");
56     if (!defined $host || $host eq "" ||
57         !defined $port || $port eq "" ||
58         !defined $dbname || $dbname eq "") {
59         print qq[<p class="error">
60 You must specify host, port and database name.</p>\n] if $update;
61         undef $update;
62     } else {
63         my $query = cql_target($host, $port, $dbname);
64         my $rs = $conn->search(new ZOOM::Query::CQL($query));
65         if ($rs->size() > 0) {
66             my $fakeid = xml_encode(uri_escape("$host:$port/$dbname"));
67             print qq[<p class="error">
68 There is already
69 <a href='?op=edit&amp;id=$fakeid'>a record</a>
70 for this host, port and database name.
71 </p>\n];
72             undef $update;
73         }
74     }
75 }
76
77 my $xc = irspy_xpath_context($rec);
78 my @fields =
79     (
80      [ title        => 0, "Name", "e:databaseInfo/e:title",
81        qw() ],
82      [ country      => $m->comp("country-list.mc"),
83        "Country", "i:status/i:country" ],
84      [ protocol     => [ qw(Z39.50 SRW SRU SRW/U) ],
85        "Protocol", "e:serverInfo/\@protocol" ],
86      [ host         => 0, "Host", "e:serverInfo/e:host" ],
87      [ port         => 0, "Port", "e:serverInfo/e:port" ],
88      [ dbname       => 0, "Database Name", "e:serverInfo/e:database",
89        qw(e:host e:port) ],
90      [ type         => $m->comp("libtype-list.mc"),
91        "Type of Library", "i:status/i:libraryType" ],
92      [ username     => 0, "Username (if needed)", "e:serverInfo/e:authentication/e:user",
93        qw() ],
94      [ password     => 0, "Password (if needed)", "e:serverInfo/e:authentication/e:password",
95        qw(e:user) ],
96      [ description  => 5, "Description", "e:databaseInfo/e:description",
97        qw(e:title) ],
98      [ author       => 0, "Author", "e:databaseInfo/e:author",
99        qw(e:title e:description) ],
100      [ hosturl       => 0, "URL to Hosting Organisation", "i:status/i:hostURL" ],
101      [ contact      => 0, "Contact", "e:databaseInfo/e:contact",
102        qw(e:title e:description) ],
103      [ extent       => 3, "Extent", "e:databaseInfo/e:extent",
104        qw(e:title e:description) ],
105      [ history      => 5, "History", "e:databaseInfo/e:history",
106        qw(e:title e:description) ],
107      [ language     => [
108 # This list was produced by feeding
109 #       http://www.loc.gov/standards/iso639-2/ISO-639-2_values_8bits.txt
110 # through the filter
111 #       awk -F'|' '$3 {print$4}'
112 # and shortening some of the longer names by hand
113                         "",
114                         "English",
115                         "Afar",
116                         "Abkhazian",
117                         "Afrikaans",
118                         "Akan",
119                         "Albanian",
120                         "Amharic",
121                         "Arabic",
122                         "Aragonese",
123                         "Armenian",
124                         "Assamese",
125                         "Avaric",
126                         "Avestan",
127                         "Aymara",
128                         "Azerbaijani",
129                         "Bashkir",
130                         "Bambara",
131                         "Basque",
132                         "Belarusian",
133                         "Bengali",
134                         "Bihari",
135                         "Bislama",
136                         "Bosnian",
137                         "Breton",
138                         "Bulgarian",
139                         "Burmese",
140                         "Catalan; Valencian",
141                         "Chamorro",
142                         "Chechen",
143                         "Chinese",
144                         "Church Slavic; Old Slavonic",
145                         "Chuvash",
146                         "Cornish",
147                         "Corsican",
148                         "Cree",
149                         "Czech",
150                         "Danish",
151                         "Divehi; Dhivehi; Maldivian",
152                         "Dutch; Flemish",
153                         "Dzongkha",
154                         "Esperanto",
155                         "Estonian",
156                         "Ewe",
157                         "Faroese",
158                         "Fijian",
159                         "Finnish",
160                         "French",
161                         "Western Frisian",
162                         "Fulah",
163                         "Georgian",
164                         "German",
165                         "Gaelic; Scottish Gaelic",
166                         "Irish",
167                         "Galician",
168                         "Manx",
169                         "Greek, Modern (1453-)",
170                         "Guarani",
171                         "Gujarati",
172                         "Haitian; Haitian Creole",
173                         "Hausa",
174                         "Hebrew",
175                         "Herero",
176                         "Hindi",
177                         "Hiri Motu",
178                         "Hungarian",
179                         "Igbo",
180                         "Icelandic",
181                         "Ido",
182                         "Sichuan Yi",
183                         "Inuktitut",
184                         "Interlingue",
185                         "Interlingua",
186                         "Indonesian",
187                         "Inupiaq",
188                         "Italian",
189                         "Javanese",
190                         "Japanese",
191                         "Kalaallisut; Greenlandic",
192                         "Kannada",
193                         "Kashmiri",
194                         "Kanuri",
195                         "Kazakh",
196                         "Khmer",
197                         "Kikuyu; Gikuyu",
198                         "Kinyarwanda",
199                         "Kirghiz",
200                         "Komi",
201                         "Kongo",
202                         "Korean",
203                         "Kuanyama; Kwanyama",
204                         "Kurdish",
205                         "Lao",
206                         "Latin",
207                         "Latvian",
208                         "Limburgan; Limburger; Limburgish",
209                         "Lingala",
210                         "Lithuanian",
211                         "Luxembourgish; Letzeburgesch",
212                         "Luba-Katanga",
213                         "Ganda",
214                         "Macedonian",
215                         "Marshallese",
216                         "Malayalam",
217                         "Maori",
218                         "Marathi",
219                         "Malay",
220                         "Malagasy",
221                         "Maltese",
222                         "Moldavian",
223                         "Mongolian",
224                         "Nauru",
225                         "Navajo; Navaho",
226                         "Ndebele, South; South Ndebele",
227                         "Ndebele, North; North Ndebele",
228                         "Ndonga",
229                         "Nepali",
230                         "Norwegian Nynorsk",
231                         "Norwegian Bokmål",
232                         "Norwegian",
233                         "Chichewa; Chewa; Nyanja",
234                         "Occitan (post 1500); Provençal",
235                         "Ojibwa",
236                         "Oriya",
237                         "Oromo",
238                         "Ossetian; Ossetic",
239                         "Panjabi; Punjabi",
240                         "Persian",
241                         "Pali",
242                         "Polish",
243                         "Portuguese",
244                         "Pushto",
245                         "Quechua",
246                         "Raeto-Romance",
247                         "Romanian",
248                         "Rundi",
249                         "Russian",
250                         "Sango",
251                         "Sanskrit",
252                         "Serbian",
253                         "Croatian",
254                         "Sinhala; Sinhalese",
255                         "Slovak",
256                         "Slovenian",
257                         "Northern Sami",
258                         "Samoan",
259                         "Shona",
260                         "Sindhi",
261                         "Somali",
262                         "Sotho, Southern",
263                         "Spanish; Castilian",
264                         "Sardinian",
265                         "Swati",
266                         "Sundanese",
267                         "Swahili",
268                         "Swedish",
269                         "Tahitian",
270                         "Tamil",
271                         "Tatar",
272                         "Telugu",
273                         "Tajik",
274                         "Tagalog",
275                         "Thai",
276                         "Tibetan",
277                         "Tigrinya",
278                         "Tonga (Tonga Islands)",
279                         "Tswana",
280                         "Tsonga",
281                         "Turkmen",
282                         "Turkish",
283                         "Twi",
284                         "Uighur; Uyghur",
285                         "Ukrainian",
286                         "Urdu",
287                         "Uzbek",
288                         "Venda",
289                         "Vietnamese",
290                         "Volapük",
291                         "Welsh",
292                         "Walloon",
293                         "Wolof",
294                         "Xhosa",
295                         "Yiddish",
296                         "Yoruba",
297                         "Zhuang; Chuang",
298                         "Zulu",
299                         ],
300        "Language of Records", "e:databaseInfo/e:langUsage",
301        qw(e:title e:description) ],
302      [ restrictions => 2, "Restrictions", "e:databaseInfo/e:restrictions",
303        qw(e:title e:description) ],
304      [ subjects     => 2, "Subjects", "e:databaseInfo/e:subjects",
305        qw(e:title e:description) ],
306      );
307
308 # Update record with submitted data
309 my %fieldsByKey = map { ( $_->[0], $_) } @fields;
310 my %data;
311 foreach my $key ($r->param()) {
312     next if grep { $key eq $_ } qw(op id update);
313     $data{$key} = $r->param($key);
314 }
315 my @changedFields = modify_xml_document($xc, \%fieldsByKey, \%data);
316 if ($update && @changedFields) {
317     my @x = modify_xml_document($xc, { dateModified =>
318                                            [ dateModified => 0,
319                                              "Data/time modified",
320                                              "e:metaInfo/e:dateModified" ] },
321                                 { dateModified => isodate(time()) });
322     die "Didn't set dateModified!" if !@x;
323     ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode(), $id);
324 }
325
326 </%perl>
327  <h2><% xml_encode($xc->find("e:databaseInfo/e:title"), "[Untitled]") %></h2>
328 % if ($update && @changedFields) {
329 %     my $nchanges = @changedFields;
330  <p style="font-weight: bold">
331   The record has been <% $op ne "edit" ? "created" : "updated" %>.<br/>
332   Changed <% $nchanges %> field<% $nchanges == 1 ? "" : "s" %>:
333   <% join(", ", map { xml_encode($_->[2]) } @changedFields) %>.
334  </p>
335 % }
336  <form method="get" action="">
337   <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
338 <%perl>
339 foreach my $ref (@fields) {
340     my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
341 </%perl>
342    <tr>
343     <th><% $caption %></th>
344     <td>
345 % my $rawval = $xc->findvalue($xpath);
346 % my $val = xml_encode($rawval, "");
347 % if (ref $nlines) {
348      <select name="<% $name %>" size="1">
349 %     foreach my $option (@$nlines) {
350       <option value="<% xml_encode($option) %>"<%
351         ($rawval eq $option ? ' selected="selected"' : "")
352         %>><% xml_encode($option) %></option>
353 %     }
354      </select>
355 % } elsif ($nlines) {
356      <textarea name="<% $name %>" rows="<% $nlines %>" cols="51"><% $val %></textarea>
357 % } else {
358      <input name="<% $name %>" type="text" size="60" value="<% $val %>"/>
359 % }
360     </td>
361     <td>
362      <& /help/link.mc, help => "edit/$name" &>
363     </td>
364    </tr>
365 %   }
366    <tr>
367     <td align="right" colspan="2">
368      <input type="submit" name="update" value="Update"/>
369      <input type="hidden" name="op" value="<% xml_encode($op) %>"/>
370 % if (defined $id) {
371      <input type="hidden" name="id" value="<% xml_encode($id) %>"/>
372 % }
373     </td>
374    </tr>
375   </table>
376  </form>
377 <%perl>
378     if (@changedFields && 0) {
379         my $x = $xc->getContextNode()->toString();
380         $x = xml_encode($x);
381         #$x =~ s/$/<br\/>/gm;
382         print "<pre>$x</pre>\n";
383     }
384 </%perl>