#!**PERLBIN** -w # Need to specify the full path of Perl above use strict; use File::Basename; no strict 'subs'; no strict 'refs'; # allow filehandles to be variables and viceversa # Set this to 1 to work around IIS 6 craziness my $iis6_mode = 0; # IIS 6: for some reason, IIS runs this script with the working directory set to the Greenstone # directory rather than the cgi-bin directory, causing lots of stuff to fail if ($iis6_mode) { # Change into cgi-bin directory chdir("cgi"); } # We use require and an eval here (instead of "use") to catch any errors loading the module (for IIS) eval("require \"rbCGI.pm\""); if ($@) { print STDOUT "Content-type:text/plain\n\n"; print STDOUT "ERROR: $@\n"; exit 0; } sub main { my $rb_cgi = new rbCGI(); $rb_cgi->{'xml'} = 0; $rb_cgi->setup_rb(); my $rbhome = $ENV{'REALISTIC_BOOKS_HOME'}; $rb_cgi->checked_chdir($rbhome); my $action = $rb_cgi->param("a"); my $pdf_filename = $rb_cgi->param("upload"); #$rb_cgi->generate_message("action = $action, pdf file = $pdf_filename"); #exit 0; if ($action eq "import-pdf") { my $pdf_filename = $rb_cgi->param("upload"); my ($fname, $fpath, $ext) = fileparse ( $pdf_filename, '\..*' ); $pdf_filename = "$fname$ext"; $pdf_filename =~ tr/ /_/; my $full_pdf_filename = &util::filename_cat($rbhome,"pdfs",$pdf_filename); my $upload_filehandle = $rb_cgi->upload("upload"); ##open (UPLOADFILE, ">$rbhome/pdfs/$pdf_filename") open (UPLOADFILE, ">full_pdf_filename") || $rb_cgi->generate_error("$!"); binmode UPLOADFILE; while ( <$upload_filehandle> ){ print UPLOADFILE; } close UPLOADFILE; my $old_handle = select (STDOUT); $| = 1; # perform flush after each write to STDOUT ##my $cmd = "perl -S pdf2realbook.pl \"$rbhome/pdfs/$pdf_filename\""; my $cmd = "perl -S pdf2realbook.pl \"$full_pdf_filename\""; if (open(PIN,"$cmd|")) { print STDOUT "Content-type:text/html\n\n"; print STDOUT "

Processing ...

"; my $line; while (defined ($line=)) { next if ($line =~ m/^Realistic book generated/); chomp $line; print STDOUT "$line
\n"; } close(PIN); } else { $rb_cgi->generate_error("Failed to cmd: $cmd"); } select ($old_handle); print STDOUT "Done\n"; my $viewbookurl = $rb_cgi->param("viewbookurl"); my $viewthisbookurl = "$viewbookurl/$fname/index.html"; print STDOUT "

View this Realistic Book

\n"; print STDOUT "

View Realistic Library

\n"; ##$rb_cgi->generate_message("Success: $output"); } else { $rb_cgi->generate_error("Unrecognized action"); } } &main();