#!/usr/local/bin/perl

##
# Do some init set-up
##
$MyPID = $$;
#$Bookstore = "someuser@store.dingdong.edu";

##
# Get the values the user supplied via STDIN
##
$Instructor = <>; chop ($Instructor); 
$Phone = <>; chop ($Phone);
$Email = <>; chop ($Email);

$Year = <>; chop ($Year);
$Quarter = <>; chop ($Quarter);
$Dept = <>; chop ($Dept);
$Course = <>; chop ($Course);

$Line1 = <>;
while ($Line1 != 0 )
{
    $entry = <>; chop($entry);
    $entry=~ s/[^A-Za-z0-9. ]//g;
    push( @Author, $entry );
    $Line1--;
}

$Line2 = <>;
while ($Line2 != 0 )
{
    $entry = <>; chop($entry);
    $entry=~ s/[^A-Za-z0-9. ]//g;
    push( @Title, $entry );
    $Line2--;
}

$Line3 = <>;
while ($Line3 != 0 )
{
    $entry = <>; chop($entry);
    $entry=~ s/[^A-Za-z0-9. ]//g;
    push( @Publisher,  $entry );
    $Line3--;
}

$ISBN = <>;
$Price = <>;

$Hard = <>; chop($Hard);
$Latest = <>; chop($Latest);
$Snotes = <>; chop($Snotes);

##
# Security precautions
##
$Instructor =~ s/[^A-Za-z0-9. ]//g;
$Phone =~ s/[^A-Za-z0-9.()\- ]//g;
$Email =~ s/[^A-Za-z0-9.@ ]//g;

$Year =~ s/[^A-Za-z0-9 ]//g;
$Quarter =~ s/[^A-Za-z0-9 ]//g;
$Dept =~ s/[^A-Za-z0-9 ]//g;
$Course =~ s/[^A-Za-z0-9 ]//g;

$ISBN =~ s/[^A-Za-z0-9\- ]//g;
$Price =~ s/[^A-Za-z0-9\$\. ]//g;

$Hard =~ s/[^01]//g;
$Latest =~ s/[^01]//g;
$Snotes =~ s/[^01]//g;


if ($Hard eq "1") 
{
    $Hard = "Yes";
}
else
{
    $Hard = "No";        
}

if ($Latest eq "1")
{
    $Latest = "Yes";
}
else
{
    $Latest = "No";
}

if ($Snotes eq "1")
{
    $Snotes = "Yes";
}
else
{
    $Snotes = "No";
}


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

print RABOOF "\r\n";
    print RABOOF "\r\n";
    print RABOOF "TextBook Information Request\r\n";
    print RABOOF "\r\n";
    print RABOOF "\r\n";
    print RABOOF "\r\n";
    print RABOOF "Instructor:\t\t$Instructor\r\n";
    print RABOOF "Phone No:\t\t$Phone\r\n";
    print RABOOF "E-Mail Address:\t\t$Email\r\n";
    print RABOOF "\r\n";
    print RABOOF "Year:\t\t\t$Year\r\n";
    print RABOOF "Quarter:\t\t$Quarter\r\n";
    print RABOOF "Dept:\t\t\t$Dept\r\n";
    print RABOOF "Course No:\t\t$Course\r\n";
    print RABOOF "\r\n";
    print RABOOF "Author:\t\t@Author\r\n";
    print RABOOF "Title:\t\t@Title\r\n";
    print RABOOF "Publisher:\t@Publisher\r\n";
    print RABOOF "\r\n";
    print RABOOF "ISBN:\t\t$ISBN\r\n";
    print RABOOF "Price:\t\t$Price\r\n";
    print RABOOF "\r\n";
    print RABOOF "Hard Cover?\t$Hard\r\n";
    print RABOOF "Latest Edition?\t$Latest\r\n";
    print RABOOF "With Supplement Notes?\t$Snotes\r\n";
close (RABOOF);


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

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


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

