Language of records now chosen from a dropdown.
[irspy-moved-to-github.git] / web / htdocs / details / edit.mc
1 %# $Id: edit.mc,v 1.25 2006-12-06 10:47:27 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:3313/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 = 'rec.id="' . cql_quote($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      => [
83                         "",
84                         "Afghanistan",
85                         "Albania",
86                         "Algeria",
87                         "American Samoa",
88                         "Andorra",
89                         "Angola",
90                         "Anguilla",
91                         "Antarctica",
92                         "Antigua and Barbuda",
93                         "Argentina",
94                         "Armenia",
95                         "Aruba",
96                         "Australia",
97                         "Austria",
98                         "Azerbaijan",
99                         "Bahamas",
100                         "Bahrain",
101                         "Bangladesh",
102                         "Barbados",
103                         "Belarus",
104                         "Belgium",
105                         "Belize",
106                         "Benin",
107                         "Bermuda",
108                         "Bhutan",
109                         "Bolivia",
110                         "Bosnia and Herzegowina",
111                         "Botswana",
112                         "Bouvet Island",
113                         "Brazil",
114                         "British Indian Ocean Terr.",
115                         "Brunei Darussalam",
116                         "Bulgaria",
117                         "Burkina Faso",
118                         "Burundi",
119                         "Cambodia",
120                         "Cameroon",
121                         "Canada",
122                         "Cape Verde",
123                         "Cayman Islands",
124                         "Central African Republic",
125                         "Chad",
126                         "Chile",
127                         "China",
128                         "Christmas Island",
129                         "Cocos (Keeling) Islands",
130                         "Colombia",
131                         "Comoros",
132                         "Congo",
133                         "Cook Islands",
134                         "Costa Rica",
135                         "Cote d'Ivoire",
136                         "Croatia (Hrvatska)",
137                         "Cuba",
138                         "Cyprus",
139                         "Czech Republic",
140                         "Denmark",
141                         "Djibouti",
142                         "Dominica",
143                         "Dominican Republic",
144                         "East Timor",
145                         "Ecuador",
146                         "Egypt",
147                         "El Salvador",
148                         "Equatorial Guinea",
149                         "Eritrea",
150                         "Estonia",
151                         "Ethiopia",
152                         "Falkland Islands/Malvinas",
153                         "Faroe Islands",
154                         "Fiji",
155                         "Finland",
156                         "France",
157                         "France, Metropolitan",
158                         "French Guiana",
159                         "French Polynesia",
160                         "French Southern Terr.",
161                         "Gabon",
162                         "Gambia",
163                         "Georgia",
164                         "Germany",
165                         "Ghana",
166                         "Gibraltar",
167                         "Greece",
168                         "Greenland",
169                         "Grenada",
170                         "Guadeloupe",
171                         "Guam",
172                         "Guatemala",
173                         "Guinea",
174                         "Guinea-Bissau",
175                         "Guyana",
176                         "Haiti",
177                         "Heard & McDonald Is.",
178                         "Honduras",
179                         "Hong Kong",
180                         "Hungary",
181                         "Iceland",
182                         "India",
183                         "Indonesia",
184                         "Iran",
185                         "Iraq",
186                         "Ireland",
187                         "Israel",
188                         "Italy",
189                         "Jamaica",
190                         "Japan",
191                         "Jordan",
192                         "Kazakhstan",
193                         "Kenya",
194                         "Kiribati",
195                         "Korea, North",
196                         "Korea, South",
197                         "Kuwait",
198                         "Kyrgyzstan",
199                         "Lao People's Dem. Rep.",
200                         "Latvia",
201                         "Lebanon",
202                         "Lesotho",
203                         "Liberia",
204                         "Libyan Arab Jamahiriya",
205                         "Liechtenstein",
206                         "Lithuania",
207                         "Luxembourg",
208                         "Macau",
209                         "Macedonia",
210                         "Madagascar",
211                         "Malawi",
212                         "Malaysia",
213                         "Maldives",
214                         "Mali",
215                         "Malta",
216                         "Marshall Islands",
217                         "Martinique",
218                         "Mauritania",
219                         "Mauritius",
220                         "Mayotte",
221                         "Mexico",
222                         "Micronesia",
223                         "Moldova",
224                         "Monaco",
225                         "Mongolia",
226                         "Montserrat",
227                         "Morocco",
228                         "Mozambique",
229                         "Myanmar",
230                         "Namibia",
231                         "Nauru",
232                         "Nepal",
233                         "Netherlands",
234                         "Netherlands Antilles",
235                         "New Caledonia",
236                         "New Zealand",
237                         "Nicaragua",
238                         "Niger",
239                         "Nigeria",
240                         "Niue",
241                         "Norfolk Island",
242                         "Northern Mariana Is.",
243                         "Norway",
244                         "Oman",
245                         "Pakistan",
246                         "Palau",
247                         "Panama",
248                         "Papua New Guinea",
249                         "Paraguay",
250                         "Peru",
251                         "Philippines",
252                         "Pitcairn",
253                         "Poland",
254                         "Portugal",
255                         "Puerto Rico",
256                         "Qatar",
257                         "Reunion",
258                         "Romania",
259                         "Russian Federation",
260                         "Rwanda",
261                         "S.Georgia & S.Sandwich Is.",
262                         "Saint Kitts and Nevis",
263                         "Saint Lucia",
264                         "Samoa",
265                         "San Marino",
266                         "Sao Tome & Principe",
267                         "Saudi Arabia",
268                         "Senegal",
269                         "Seychelles",
270                         "Sierra Leone",
271                         "Singapore",
272                         "Slovakia (Slovak Republic)",
273                         "Slovenia",
274                         "Solomon Islands",
275                         "Somalia",
276                         "South Africa",
277                         "Spain",
278                         "Sri Lanka",
279                         "St. Helena",
280                         "St. Pierre & Miquelon",
281                         "St. Vincent & Grenadines",
282                         "Sudan",
283                         "Suriname",
284                         "Svalbard & Jan Mayen Is.",
285                         "Swaziland",
286                         "Sweden",
287                         "Switzerland",
288                         "Syrian Arab Republic",
289                         "Taiwan",
290                         "Tajikistan",
291                         "Tanzania",
292                         "Thailand",
293                         "Togo",
294                         "Tokelau",
295                         "Tonga",
296                         "Trinidad and Tobago",
297                         "Tunisia",
298                         "Turkey",
299                         "Turkmenistan",
300                         "Turks & Caicos Islands",
301                         "Tuvalu",
302                         "U.S. Minor Outlying Is.",
303                         "Uganda",
304                         "Ukraine",
305                         "United Arab Emirates",
306                         "United Kingdom",
307                         "United States",
308                         "Uruguay",
309                         "Uzbekistan",
310                         "Vanuatu",
311                         "Vatican (Holy See)",
312                         "Venezuela",
313                         "Viet Nam",
314                         "Virgin Islands (British)",
315                         "Virgin Islands (U.S.)",
316                         "Wallis & Futuna Is.",
317                         "Western Sahara",
318                         "Yemen",
319                         "Yugoslavia",
320                         "Zaire",
321                         "Zambia",
322                         "Zimbabwe",
323                          ],
324        "Country", "i:status/i:country" ],
325      [ protocol     => [ qw(Z39.50 SRW SRU SRW/U) ],
326        "Protocol", "e:serverInfo/\@protocol" ],
327      [ host         => 0, "Host", "e:serverInfo/e:host" ],
328      [ port         => 0, "Port", "e:serverInfo/e:port" ],
329      [ dbname       => 0, "Database Name", "e:serverInfo/e:database",
330        qw(e:host e:port) ],
331      [ type         => [ "", qw(Academic Public Corporate Special National Education Other) ],
332        "Type of Library", "i:status/i:libraryType" ],
333      [ username     => 0, "Username (if needed)", "e:serverInfo/e:authentication/e:user",
334        qw() ],
335      [ password     => 0, "Password (if needed)", "e:serverInfo/e:authentication/e:password",
336        qw(e:user) ],
337      [ description  => 5, "Description", "e:databaseInfo/e:description",
338        qw(e:title) ],
339      [ author       => 0, "Author", "e:databaseInfo/e:author",
340        qw(e:title e:description) ],
341      [ hosturl       => 0, "URL to Hosting Organisation", "i:status/i:hostURL" ],
342      [ contact      => 0, "Contact", "e:databaseInfo/e:contact",
343        qw(e:title e:description) ],
344      [ extent       => 3, "Extent", "e:databaseInfo/e:extent",
345        qw(e:title e:description) ],
346      [ history      => 5, "History", "e:databaseInfo/e:history",
347        qw(e:title e:description) ],
348      [ language     => [
349 # This list was produced by feeding
350 #       http://www.loc.gov/standards/iso639-2/ISO-639-2_values_8bits.txt
351 # through the filter
352 #       awk -F'|' '$3 {print$4}'
353 # and shortening some of the longer names by hand
354                         "",
355                         "Afar",
356                         "Abkhazian",
357                         "Afrikaans",
358                         "Akan",
359                         "Albanian",
360                         "Amharic",
361                         "Arabic",
362                         "Aragonese",
363                         "Armenian",
364                         "Assamese",
365                         "Avaric",
366                         "Avestan",
367                         "Aymara",
368                         "Azerbaijani",
369                         "Bashkir",
370                         "Bambara",
371                         "Basque",
372                         "Belarusian",
373                         "Bengali",
374                         "Bihari",
375                         "Bislama",
376                         "Bosnian",
377                         "Breton",
378                         "Bulgarian",
379                         "Burmese",
380                         "Catalan; Valencian",
381                         "Chamorro",
382                         "Chechen",
383                         "Chinese",
384                         "Church Slavic; Old Slavonic",
385                         "Chuvash",
386                         "Cornish",
387                         "Corsican",
388                         "Cree",
389                         "Czech",
390                         "Danish",
391                         "Divehi; Dhivehi; Maldivian",
392                         "Dutch; Flemish",
393                         "Dzongkha",
394                         "English",
395                         "Esperanto",
396                         "Estonian",
397                         "Ewe",
398                         "Faroese",
399                         "Fijian",
400                         "Finnish",
401                         "French",
402                         "Western Frisian",
403                         "Fulah",
404                         "Georgian",
405                         "German",
406                         "Gaelic; Scottish Gaelic",
407                         "Irish",
408                         "Galician",
409                         "Manx",
410                         "Greek, Modern (1453-)",
411                         "Guarani",
412                         "Gujarati",
413                         "Haitian; Haitian Creole",
414                         "Hausa",
415                         "Hebrew",
416                         "Herero",
417                         "Hindi",
418                         "Hiri Motu",
419                         "Hungarian",
420                         "Igbo",
421                         "Icelandic",
422                         "Ido",
423                         "Sichuan Yi",
424                         "Inuktitut",
425                         "Interlingue",
426                         "Interlingua",
427                         "Indonesian",
428                         "Inupiaq",
429                         "Italian",
430                         "Javanese",
431                         "Japanese",
432                         "Kalaallisut; Greenlandic",
433                         "Kannada",
434                         "Kashmiri",
435                         "Kanuri",
436                         "Kazakh",
437                         "Khmer",
438                         "Kikuyu; Gikuyu",
439                         "Kinyarwanda",
440                         "Kirghiz",
441                         "Komi",
442                         "Kongo",
443                         "Korean",
444                         "Kuanyama; Kwanyama",
445                         "Kurdish",
446                         "Lao",
447                         "Latin",
448                         "Latvian",
449                         "Limburgan; Limburger; Limburgish",
450                         "Lingala",
451                         "Lithuanian",
452                         "Luxembourgish; Letzeburgesch",
453                         "Luba-Katanga",
454                         "Ganda",
455                         "Macedonian",
456                         "Marshallese",
457                         "Malayalam",
458                         "Maori",
459                         "Marathi",
460                         "Malay",
461                         "Malagasy",
462                         "Maltese",
463                         "Moldavian",
464                         "Mongolian",
465                         "Nauru",
466                         "Navajo; Navaho",
467                         "Ndebele, South; South Ndebele",
468                         "Ndebele, North; North Ndebele",
469                         "Ndonga",
470                         "Nepali",
471                         "Norwegian Nynorsk",
472                         "Norwegian Bokmål",
473                         "Norwegian",
474                         "Chichewa; Chewa; Nyanja",
475                         "Occitan (post 1500); Provençal",
476                         "Ojibwa",
477                         "Oriya",
478                         "Oromo",
479                         "Ossetian; Ossetic",
480                         "Panjabi; Punjabi",
481                         "Persian",
482                         "Pali",
483                         "Polish",
484                         "Portuguese",
485                         "Pushto",
486                         "Quechua",
487                         "Raeto-Romance",
488                         "Romanian",
489                         "Rundi",
490                         "Russian",
491                         "Sango",
492                         "Sanskrit",
493                         "Serbian",
494                         "Croatian",
495                         "Sinhala; Sinhalese",
496                         "Slovak",
497                         "Slovenian",
498                         "Northern Sami",
499                         "Samoan",
500                         "Shona",
501                         "Sindhi",
502                         "Somali",
503                         "Sotho, Southern",
504                         "Spanish; Castilian",
505                         "Sardinian",
506                         "Swati",
507                         "Sundanese",
508                         "Swahili",
509                         "Swedish",
510                         "Tahitian",
511                         "Tamil",
512                         "Tatar",
513                         "Telugu",
514                         "Tajik",
515                         "Tagalog",
516                         "Thai",
517                         "Tibetan",
518                         "Tigrinya",
519                         "Tonga (Tonga Islands)",
520                         "Tswana",
521                         "Tsonga",
522                         "Turkmen",
523                         "Turkish",
524                         "Twi",
525                         "Uighur; Uyghur",
526                         "Ukrainian",
527                         "Urdu",
528                         "Uzbek",
529                         "Venda",
530                         "Vietnamese",
531                         "Volapük",
532                         "Welsh",
533                         "Walloon",
534                         "Wolof",
535                         "Xhosa",
536                         "Yiddish",
537                         "Yoruba",
538                         "Zhuang; Chuang",
539                         "Zulu",
540                         ],
541        "Language of Records", "e:databaseInfo/e:langUsage",
542        qw(e:title e:description) ],
543      [ restrictions => 2, "Restrictions", "e:databaseInfo/e:restrictions",
544        qw(e:title e:description) ],
545      [ subjects     => 2, "Subjects", "e:databaseInfo/e:subjects",
546        qw(e:title e:description) ],
547      );
548
549 # Update record with submitted data
550 my %fieldsByKey = map { ( $_->[0], $_) } @fields;
551 my %data;
552 foreach my $key ($r->param()) {
553     next if grep { $key eq $_ } qw(op id update);
554     $data{$key} = $r->param($key);
555 }
556 my @changedFields = modify_xml_document($xc, \%fieldsByKey, \%data);
557 if ($update && @changedFields) {
558     my @x = modify_xml_document($xc, { dateModified =>
559                                            [ dateModified => 0,
560                                              "Data/time modified",
561                                              "e:metaInfo/e:dateModified" ] },
562                                 { dateModified => isodate(time()) });
563     die "Didn't set dateModified!" if !@x;
564     ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
565 }
566
567 </%perl>
568  <h2><% xml_encode($xc->find("e:databaseInfo/e:title"), "[Untitled]") %></h2>
569 % if ($update && @changedFields) {
570 %     my $nchanges = @changedFields;
571  <p style="font-weight: bold">
572   The record has been <% $op ne "edit" ? "created" : "updated" %>.<br/>
573   Changed <% $nchanges %> field<% $nchanges == 1 ? "" : "s" %>:
574   <% join(", ", map { xml_encode($_->[2]) } @changedFields) %>.
575  </p>
576 % }
577  <form method="get" action="">
578   <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
579 <%perl>
580 foreach my $ref (@fields) {
581     my($name, $nlines, $caption, $xpath, @addAfter) = @$ref;
582 </%perl>
583    <tr>
584     <th><% $caption %></th>
585     <td>
586 % my $rawval = $xc->findvalue($xpath);
587 % my $val = xml_encode($rawval, "");
588 % if (ref $nlines) {
589      <select name="<% $name %>" size="1">
590 %     foreach my $option (@$nlines) {
591       <option value="<% xml_encode($option) %>"<%
592         ($rawval eq $option ? ' selected="selected"' : "")
593         %>><% xml_encode($option) %></option>
594 %     }
595      </select>
596 % } elsif ($nlines) {
597      <textarea name="<% $name %>" rows="<% $nlines %>" cols="51"><% $val %></textarea>
598 % } else {
599      <input name="<% $name %>" type="text" size="60" value="<% $val %>"/>
600 % }
601     </td>
602     <td>
603      <& /help/link.mc, help => "edit/$name" &>
604     </td>
605    </tr>
606 %   }
607    <tr>
608     <td align="right" colspan="2">
609      <input type="submit" name="update" value="Update"/>
610      <input type="hidden" name="op" value="<% xml_encode($op) %>"/>
611 % if (defined $id) {
612      <input type="hidden" name="id" value="<% xml_encode($id) %>"/>
613 % }
614     </td>
615    </tr>
616   </table>
617  </form>
618 <%perl>
619     if (@changedFields && 0) {
620         my $x = $xc->getContextNode()->toString();
621         $x = xml_encode($x);
622         #$x =~ s/$/<br\/>/gm;
623         print "<pre>$x</pre>\n";
624     }
625 </%perl>