1 | #!/usr/bin/perl -w
|
---|
2 |
|
---|
3 | use strict;
|
---|
4 |
|
---|
5 | use LWP::UserAgent;
|
---|
6 | use HTTP::Request::Common;
|
---|
7 |
|
---|
8 | use CGI::Carp qw(fatalsToBrowser);
|
---|
9 | use CGI;
|
---|
10 |
|
---|
11 | BEGIN {
|
---|
12 | eval('require "./gsdlCGI.pm"');
|
---|
13 | if ($@)
|
---|
14 | {
|
---|
15 | print STDOUT "Content-type:text/plain\n\n";
|
---|
16 | print STDOUT "ERROR: $@\n";
|
---|
17 | exit 0;
|
---|
18 | }
|
---|
19 |
|
---|
20 | # Line to stop annoying child DOS CMD windows from appearing
|
---|
21 | Win32::SetChildShowWindow(0)
|
---|
22 | if defined &Win32::SetChildShowWindow;
|
---|
23 | }
|
---|
24 |
|
---|
25 |
|
---|
26 |
|
---|
27 |
|
---|
28 | sub get_infodb_type
|
---|
29 | {
|
---|
30 | my ($opt_site,$collect_home,$collect) = @_;
|
---|
31 |
|
---|
32 | my $out = "STDERR";
|
---|
33 |
|
---|
34 | $collect = &colcfg::use_collection($opt_site, $collect, $collect_home);
|
---|
35 |
|
---|
36 | if ($collect eq "") {
|
---|
37 | print STDERR "Error: failed to find collection $collect in $collect_home\n";
|
---|
38 | print STDOUT "Content-type:text/plain\n\n";
|
---|
39 | print STDOUT "ERROR: Failed to find collection $collect\n";
|
---|
40 | exit 0;
|
---|
41 |
|
---|
42 | }
|
---|
43 |
|
---|
44 | # Read in the collection configuration file.
|
---|
45 | my ($config_filename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
|
---|
46 | my $collectcfg = &colcfg::read_collection_cfg ($config_filename, $gs_mode);
|
---|
47 |
|
---|
48 | return $collectcfg->{'infodbtype'};
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | sub oid_to_docxml_filename
|
---|
53 | {
|
---|
54 | my ($opt_site,$collect_home,$collect,$docid) = @_;
|
---|
55 |
|
---|
56 | my $infodb_type = get_infodb_type($opt_site,$collect_home,$collect);
|
---|
57 |
|
---|
58 | # Obtain the collect and archives dir
|
---|
59 | my $archives_dir = &util::filename_cat($collect_home,$collect,"archives");
|
---|
60 |
|
---|
61 | # Obtain the doc.xml path for the specified docID
|
---|
62 | my $arcinfo_doc_filename
|
---|
63 | = &dbutil::get_infodb_file_path($infodb_type, "archiveinf-doc",
|
---|
64 | $archives_dir);
|
---|
65 | my $doc_rec_string
|
---|
66 | = &dbutil::read_infodb_entry($infodb_type, $arcinfo_doc_filename,
|
---|
67 | $docid);
|
---|
68 | my $doc_rec = &dbutil::convert_infodb_string_to_hash($doc_rec_string);
|
---|
69 | my $doc_xml_file = $doc_rec->{'doc-file'}->[0];
|
---|
70 |
|
---|
71 | # The $doc_xml_file is relative to the archives, so now let's get the
|
---|
72 | # full path
|
---|
73 | my $doc_xml_filename = &util::filename_cat($archives_dir,$doc_xml_file);
|
---|
74 |
|
---|
75 | return $doc_xml_filename;
|
---|
76 | }
|
---|
77 |
|
---|
78 | sub main
|
---|
79 | {
|
---|
80 | # Setup greenstone Perl include paths so additional packages can be found
|
---|
81 | my $gsdl_cgi = gsdlCGI->new();
|
---|
82 | $gsdl_cgi->setup_gsdl();
|
---|
83 |
|
---|
84 | my $gsdl_home = $gsdl_cgi->get_gsdl_home();
|
---|
85 | my $collect_home = &util::filename_cat($gsdl_home,"collect");
|
---|
86 |
|
---|
87 | require dbutil;
|
---|
88 | require talkback;
|
---|
89 | require colcfg;
|
---|
90 |
|
---|
91 | my $oid = $gsdl_cgi->param('oid');
|
---|
92 | my $collect = $gsdl_cgi->param('collect');
|
---|
93 | my $site = $gsdl_cgi->param('site');
|
---|
94 |
|
---|
95 | # sanity check
|
---|
96 | if (!defined $oid || !defined $collect) {
|
---|
97 | print STDOUT "Content-type:text/plain\n\n";
|
---|
98 | print STDOUT "ERROR: Malformed CGI argments. Need to specify 'oid' and 'collect'\n";
|
---|
99 | exit 0;
|
---|
100 | }
|
---|
101 |
|
---|
102 | my $uniq_prefix = "$collect-$oid";
|
---|
103 |
|
---|
104 | my $docxml_filename = oid_to_docxml_filename($site,$collect_home,$collect,$oid);
|
---|
105 |
|
---|
106 | my $talktoUploadURL = $gsdl_cgi->param('talktoUpload');
|
---|
107 |
|
---|
108 | my $browser = LWP::UserAgent->new(agent => 'Perl File Upload');
|
---|
109 |
|
---|
110 | my $response = $browser->post(
|
---|
111 | $talktoUploadURL,
|
---|
112 | [ 'yes_upload' => '1',
|
---|
113 | 'process' => '1',
|
---|
114 | 'oid' => $oid,
|
---|
115 | 'collect' => $collect,
|
---|
116 | 'uploadedfile' => [$docxml_filename, "$uniq_prefix-doc.xml"]
|
---|
117 | ],
|
---|
118 | 'Content_Type' => 'form-data'
|
---|
119 | );
|
---|
120 |
|
---|
121 | if ($response->is_success) {
|
---|
122 | print "Content-type:text/html\n\n";
|
---|
123 | print $response->content;
|
---|
124 | }
|
---|
125 | else {
|
---|
126 | print $response->error_as_HTML;
|
---|
127 | }
|
---|
128 |
|
---|
129 | }
|
---|
130 |
|
---|
131 | main();
|
---|
132 |
|
---|