source: main/tags/2.40/gsdl/bin/script/picklanguage.pl@ 21085

Last change on this file since 21085 was 4232, checked in by jrm21, 21 years ago

now return codes when an error occurs, so that the receptionist can tell!

  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# picklanguage.pl
6#
7# A component of the Greenstone digital library software
8# from the New Zealand Digital Library Project at the
9# University of Waikato, New Zealand.
10#
11# Copyright (C) 1999 New Zealand Digital Library Project
12#
13# This program is free software; you can redistribute it and/or modify
14# it under the terms of the GNU General Public License as published by
15# the Free Software Foundation; either version 2 of the License, or
16# (at your option) any later version.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26#
27###########################################################################
28
29# This code generates the front page of the Greenstone Interface Translation Agency
30# which asks the user to pick their base language and translating language before
31# proceeding into the translation pages
32
33BEGIN {
34 if (!defined($ENV{'GSDLHOME'})) {
35 print STDERR "GSDLHOME not set\n";
36 return 1;
37 }
38 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
39}
40
41
42use util;
43use CGI;
44
45
46sub main
47{
48 my $gsdldir = "$ENV{'GSDLHOME'}";
49 # Read the languages available from etc/main.cfg
50 my $maincfg_fname = util::filename_cat($gsdldir, "etc", "main.cfg");
51 if (!open(MCFILE, "<$maincfg_fname")) {
52 print STDERR "Error: Could not open $maincfg_fname: $!\n";
53 return 2;
54 }
55
56 my @languages;
57 my $line;
58 while (defined ($line=<MCFILE>)) {
59 chomp($line);
60 if ($line =~ m/^Language\s+/i) {
61 my @args = split(/ +/,$line);
62 my ($lang_abbr) = ($args[1] =~ m/^shortname=(.*)$/);
63 my ($lang_long) = ($args[2] =~ m/^longname=(.*)$/);
64 push(@languages, $lang_long);
65 }
66 }
67 close MCFILE;
68
69 # Write the HTML content of the page to tmp/lang/picklanguage.lang
70 my $dir = util::filename_cat($gsdldir, "tmp", "lang");
71 # creates directory if it doesn't already exist
72 my $currentmask = umask;
73 umask(0000);
74 if (!-e $dir) {
75 if (! mkdir($dir, 0777)) {
76 print STDERR "Couldn't create directory $dir\n";
77 return 3;
78 }
79 }
80 my $picklang_fname = util::filename_cat($dir, "picklanguage.lang");
81
82 # Make the file world writeable
83 if (! open(HTMLFILE,">$picklang_fname")) {
84 umask($currentmask);
85 print STDERR "Error: Could not create $picklang_fname: $!\n";
86 return 4;
87 }
88 umask($currentmask);
89
90 # Writes to file the instructions on how to use the interface (_textinitial_)
91 # and then displays a table at the end with menu options from which the user
92 # selects their base and translation languages, and submits these choices
93 # to proceed into the interface translation agency
94 my $query = new CGI;
95 print HTMLFILE (" _textinitial_ <br>\n",
96 "<table border=\"2\" cellpadding=\"8\"><tr><td><center>",
97 "_textselectbase_ <p>\n",
98 $query->popup_menu(-name=>"bl",
99 -values=>\@languages,
100 -default=>'English'),
101 "<p></center></td><td><center>\n",
102 "_textselectforeign_ <p>\n",
103 $query->popup_menu(-name=>"tlng",
104 -values=>\@languages),
105 "<p>\n",
106 "_textselectnew_ <p>\n",
107 $query->textfield(-name=>"ownchoice",
108 -default=>"",
109 -size=>50),
110 "<p></center></td></tr></table>\n",
111 $query->submit("submitlanguage","_textenter_"),
112 "</center><p>\n",
113 "<center><img src=\"_httpimg_/divb.gif\"></center><p>");
114 close HTMLFILE;
115 return 0;
116}
117
118
119exit &main();
Note: See TracBrowser for help on using the repository browser.