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 | eval('require "./gsdlCGI.pm"');
|
---|
12 | if ($@)
|
---|
13 | {
|
---|
14 | print STDOUT "Content-type:text/plain\n\n";
|
---|
15 | print STDOUT "ERROR: $@\n";
|
---|
16 | exit 0;
|
---|
17 | }
|
---|
18 |
|
---|
19 |
|
---|
20 | sub get_infodb_type
|
---|
21 | {
|
---|
22 | my ($collect_home,$collect) = @_;
|
---|
23 |
|
---|
24 | print STDERR "*** Need to implement extracting infodb_type from collect.cfg\n";
|
---|
25 | return "gdbm";
|
---|
26 | }
|
---|
27 |
|
---|
28 |
|
---|
29 | sub oid_to_docxml_filename
|
---|
30 | {
|
---|
31 | my ($collect_home,$collect,$docid) = @_;
|
---|
32 |
|
---|
33 | my $infodb_type = get_infodb_type($collect_home,$collect);
|
---|
34 |
|
---|
35 | # Obtain the collect and archive dir
|
---|
36 | my $archive_dir = &util::filename_cat($collect_home,$collect,"archives");
|
---|
37 |
|
---|
38 | # Obtain the doc.xml path for the specified docID
|
---|
39 | my $arcinfo_doc_filename
|
---|
40 | = &dbutil::get_infodb_file_path($infodb_type, "archiveinf-doc",
|
---|
41 | $archive_dir);
|
---|
42 | my $doc_rec_string
|
---|
43 | = &dbutil::read_infodb_entry($infodb_type, $arcinfo_doc_filename,
|
---|
44 | $docid);
|
---|
45 | my $doc_rec = &dbutil::convert_infodb_string_to_hash($doc_rec_string);
|
---|
46 | my $doc_xml_file = $doc_rec->{'doc-file'}->[0];
|
---|
47 |
|
---|
48 | # The $doc_xml_file is relative to the archives, so now let's get the
|
---|
49 | # full path
|
---|
50 | my $archives_dir = &util::filename_cat($collect_home,$collect,"archives");
|
---|
51 | my $doc_xml_filename = &util::filename_cat($archives_dir,$doc_xml_file);
|
---|
52 |
|
---|
53 | return $doc_xml_filename;
|
---|
54 | }
|
---|
55 |
|
---|
56 | sub main
|
---|
57 | {
|
---|
58 | # Setup greenstone Perl include paths so additional packages can be found
|
---|
59 | my $gsdl_cgi = gsdlCGI->new();
|
---|
60 | $gsdl_cgi->setup_gsdl();
|
---|
61 |
|
---|
62 | my $gsdl_home = $gsdl_cgi->get_gsdl_home();
|
---|
63 | my $collect_home = &util::filename_cat($gsdl_home,"collect");
|
---|
64 |
|
---|
65 | require dbutil;
|
---|
66 | require talkback;
|
---|
67 |
|
---|
68 | my $oid = $gsdl_cgi->{'oid'};
|
---|
69 | my $collect = $gsdl_cgi->{'collect'};
|
---|
70 |
|
---|
71 | # sanity check
|
---|
72 | if (!defined $oid || !defined $collect) {
|
---|
73 | print STDOUT "Content-type:text/plain\n\n";
|
---|
74 | print STDOUT "ERROR: Malformed CGI argments. Neeed to specify 'oid' and 'collect'\n";
|
---|
75 | exit 0;
|
---|
76 | }
|
---|
77 |
|
---|
78 | my $uniq_prefix = "$collect-$oid";
|
---|
79 |
|
---|
80 | my $docxml_filename = oid_to_docxml_filename($collect_home,$collect,$oid);
|
---|
81 |
|
---|
82 | my $talktoUploadURL = $gsdl_cgi->param('talktoUpload');
|
---|
83 |
|
---|
84 | my $browser = LWP::UserAgent->new(agent => 'Perl File Upload');
|
---|
85 |
|
---|
86 | my $response = $browser->post(
|
---|
87 | $talktoUploadURL,
|
---|
88 | [ 'yes_upload' => '1',
|
---|
89 | 'process' => '1',
|
---|
90 | 'uploadedfile' => [$docxml_filename, "$uniq_prefix-doc.xml"]
|
---|
91 | ],
|
---|
92 | 'Content_Type' => 'form-data'
|
---|
93 | );
|
---|
94 |
|
---|
95 | if ($response->is_success) {
|
---|
96 | print "Content-type:text/html\n\n";
|
---|
97 | print $response->content;
|
---|
98 | }
|
---|
99 | else {
|
---|
100 | print $response->error_as_HTML;
|
---|
101 | }
|
---|
102 |
|
---|
103 | }
|
---|
104 |
|
---|
105 | main();
|
---|
106 |
|
---|