#!/usr/bin/perl -T # Doreva Belfiore/John Joergensen # Rutgers University Law Library # Camden, NJ # multivp2.cgi = #2 of 2 #N.B. – This file was edited by John Joergensen to reduce redundancy and improve functionality. #The author wishes to thank Mr. Joergensen for his assistance with this script. # This script allows user (Law Library staff member) to navigate between # pages of a multi-volume document and then enter pagination data # to be submitted to a final CGI that writes the data out to a text file. # Revision date: 11/14/2011 #1 Set environment, path, & remote directories $ENV{"PATH"} = "/bin:/usr/bin:/usr/local/bin"; use CGI qw(param); use strict; #set remote directories and parameters my $bdir = "/ INSERT SERVER PATH HERE /gdoc/PROBLEM"; my $rdir = "/ INSERT SERVER PATH HERE /gdoc/MULTIV"; my $gdir = "/ INSERT SERVER PATH HERE/gdoc"; my $doc = param("lccn"); my $pnum = param("preface"); my $firstpage = param("firstpage"); my $lastpage = param("lastpage"); my $preface = param("preface"); my $action = param("action"); my $npage = param("npage"); my $ppage = param("ppage"); my ($filey, $fnumber); my $page = param("page"); my $fpage = param("fpage"); my $lpage = param("lpage"); my $confirm = param("confirmation"); #######example test params############# #$doc = "70601813d"; #$firstpage = 1; #$lastpage = 773; #$pnum = 4; #$action = "SUBMIT"; ############################# # Checking the parameters if($npage =~ /(\d+)/){ $npage = $1; } if($ppage =~ /(\d+)/){ $ppage = $1; } if($action =~ /(\w+)/){ $action = $1; } if($firstpage =~ /(\d+)/){ $firstpage = $1; } if($lastpage =~ /(\d+)/){ $lastpage = $1; } if($preface =~ /(\d+)/){ $preface = $1; } if($doc =~ /(\w+)/){ $doc = $1; } # action determinations if($action eq "SUBMIT"){ &write_out; exit; }elsif($action =~ /Next/i){ $page = $npage; }elsif($action =~ /First/i){ $page = "0001"; }elsif($action =~ /Prev/i){ $page = $ppage; }elsif($action =~ /Last/i){ $page = $lpage; } #2 set parameters and variables # source file = multivp.cgi if($confirm =~ /[0-9]{1}/){ $confirm = $1; } $page = sprintf("%04d", $page); #2 opens directory and greps the files opendir DIR2, "$rdir/$doc"; my @files = grep /\.tif/, readdir DIR2; closedir DIR2; @files = sort(@files); $fnumber = @files; $filey = $files[0]; #3 Page calculations if ($ppage =~ /(\d+)/) { $ppage = $1; } if ($page == 1) { $ppage = $page; }else{ $ppage = ($page - 1); } $ppage = sprintf("%04s", $ppage); $npage = ($page + 1); #print "npage after addition = $npage \n"; $npage = sprintf("%04s", $npage); $fpage = 1; $fpage = sprintf("%04s", $fpage); $lpage = $fnumber; $lpage = sprintf("%04s", $lpage); if ($confirm == 0) { &convert1; &countpage; }elsif ($confirm == 1) { &goback; } # subroutines sub countpage { print < Government Document Quality Control Check

Government Document Quality Check

Multivolume Page Confirmation Check

Please confirm the pages for: $doc:
Pages of prefatory material
(Enter arabic numeral!):
Page number, FIRST numbered page:
Page number, LAST numbered page:

Go to page:


END_of_HTML } #end sub countpage sub goback { #move bad directory system "mv $rdir/$doc $bdir/$doc"; #move to next directory to process print < Government Document Quality Control Check

Government Document Quality Control Check

Multivolume Page Confirmation Check

Skipping to next multipage-set document.

END_of_HTML } #end sub goback sub convert1 { chdir "$rdir/$doc"; #Calls tifftopnm converter program to convert TIFF images to JPG images on the fly # for web presentation #Set quality to 50% to save server space and processing time system "tifftopnm '$doc-$lpage.tif' |pnmtojpeg -quality=50 >'$doc-$lpage.jpg'"; system "tifftopnm '$doc-$npage.tif' |pnmtojpeg -quality=50 >'$doc-$npage.jpg'"; system "tifftopnm '$doc-$ppage.tif' |pnmtojpeg -quality=50 >'$doc-$ppage.jpg'"; system "tifftopnm '$doc-$fpage.tif' |pnmtojpeg -quality=50 >'$doc-$fpage.jpg'"; } #end sub convert1 sub write_out { open(PAGER,">$rdir/$doc/$doc.out") || die "could not open out file:$!\n"; my $govdir = "/INSERT SERVER PATH HERE/gdoc"; print PAGER "$doc,"; print PAGER "$pnum,"; print PAGER "$firstpage,"; print PAGER "$lastpage"; print PAGER "\n"; close PAGER; #chdir "$govdir/$doc"; system "rm $rdir/$doc/*.jpg"; #chdir ".."; system "mv $rdir/$doc $govdir/$doc"; #says thanks print < Government Document Quality Control Check

Government Document Quality Control Check

Multivolume Page Confirmation Check

Thank you for your assistance with document $doc.

END_of_HTML } # end sub write_out.