#!/usr/local/bin/perl

##
# Do some init set-up
##
$MyPID = $$;
$Bookstore = "iacovou@boombox.micro.umn.edu";


##
# Do Some init.

$Instructor = "\n"; $Phone = "\n"; $Email = "\n"; $Year1 = "\n"; 
$Quarter1 = "\n"; $Campus = "\n"; $Dept = "\n"; $Course = "\n"; 
$Joint = "\n"; $Section = "\n"; $Required = "\n"; $Estimated = "\n"; 
$Actual = "\n"; $Year2 = "\n"; $Quarter2 = "\n"; 
@Author = "\n"; @Title = "\n"; @Publisher = "\n"; 
$ISBN = "\n"; $Price = "\n"; $Paperback = "\n"; $Edition = "\n"; 
$Volume = "\n";

#
##
# Get the values the user supplied via STDIN
##

$Instructor = <>;
$Phone = <>;
$Email = <>;
$Year1 = <>;
$Quarter1 = <>;
$Campus = <>;
$Dept = <>;
$Course = <>;
$Joint = <>;
$Section = <>;
$Required = <>;
$Estimated = <>;
$Actual = <>;
$Year2 = <>;
$Quarter2 = <>;

$Line1 = <>;
while ($Line1 != 0 ) 
{
	$entry = <>;
	push( @Author, $entry );
	$Line1--;
}

$Line2 = <>;
while ($Line2 != 0 ) 
{
	$entry = <>;
	push( @Title, $entry );
	$Line2--;
}

$Line3 = <>;
while ($Line3 != 0 ) 
{
	$entry = <>;
	push( @Publisher,  $entry );
	$Line3--;
}

$ISBN = <>;
$Price = <>;
$Paperback = <>;
$Edition = <>;
$Volume = <>;

##
# Open a tmp file and generate the body of the mesage
##

open ( RABOOF, ">> /tmp/textbook.$MyPID" ) || die "error\n";

    print RABOOF "\n";
    print RABOOF "\n";
    print RABOOF "TextBook Information Request";
    print RABOOF "\n";
    print RABOOF "\n";
	print RABOOF "\n";
	print RABOOF "Instructor:\t\t$Instructor";
	print RABOOF "Phone No:\t\t$Phone";
	print RABOOF "E-Mail Address:\t\t$Email";
	print RABOOF "\n";
    print RABOOF "Year:\t\t\t$Year1";
    print RABOOF "Quarter:\t\t$Quarter1";
    print RABOOF "Campus:\t\t\t$Campus";
    print RABOOF "Dept:\t\t\t$Dept";
    print RABOOF "Course No:\t\t$Course";
    print RABOOF "Joint Day/Ext:\t\t$Joint";
    print RABOOF "Section:\t\t$Section";
    print RABOOF "Required:\t\t$Required";
    print RABOOF "\n";
    print RABOOF "Estimated Enrollment This Quarter:\t\t$Estimated";
    print RABOOF "Actual Enrollment This Quarter Last Year:\t$Actual";
    print RABOOF "Year This Book Will Be Used Again:\t\t$Year2";
    print RABOOF "Quarter This Book Will Be Used Again:\t\t$Quarter2";
    print RABOOF "\n";
    print RABOOF "Author:\t\t@Author";
    print RABOOF "Title:\t\t@Title";
    print RABOOF "Publisher:\t@Publisher";
	print RABOOF "\n";
    print RABOOF "ISBN:\t\t$ISBN";
    print RABOOF "Price:\t\t$Price";
    print RABOOF "Paperback:\t$Paperback";
    print RABOOF "Edition:\t$Edition";
    print RABOOF "Volume:\t\t$Volume";
    print RABOOF "\n";

close (RABOOF);

##
# Send out the Mail
##

system "/usr/ucb/mail -s \"TextBook Information Request\" $Bookstore < /tmp/textbook.$MyPID";
 

##
# Decide which closing message to display
##
if ( ($Joint eq "Yes\r\n") || ($Joint eq "Yes\n") )
{
    print "Requirements for Extension classes should NOT be reported\r\n";
    print "on the same sheet as the day classes. They each have their\r\n";
    print "own forms and need to be reported separately.\r\n";
    print "\r\n";
    print "EVEN JOINT DAY/EXTENSION OR CONCURRENT CLASSES\r\n";
    print "\r\n";
    print "Your order has been sent to the bookstore. Please\r\n";
    print "remember to fill another form for the Extension class\r\n";
	print "To cancel an order or to contact the text book ordering\r\n";
	print "section of the bookstore call XXX-XXXX or send e-mail to\r\n";
	print "     yyy@xxxx.umn.edu\r\n";
	print "\r\n";
	print "Here is the order as it stands:\r\n";
	print "\r\n";
}
else
{
	print "Your order has been sent to the bookstore.\r\n";
	print "To cancel an order or to contact the text book ordering\r\n";
	print "section of the bookstore call XXX-XXXX or send e-mail to\r\n";
	print "		yyy@xxxx.umn.edu\r\n";
	print "\r\n";
	print "Here is the order as it stands:\r\n";
	print "\r\n";
}


open (foo, "< /tmp/textbook.$MyPID" ) || die "error\n";
while (<foo>)
{
	print;
}
close (foo);


unlink ( "/tmp/textbook.$MyPID" );

