#!/usr/bin/perl require('cgi-lib.pl'); &ReadParse(*INPUT); $memberfile="../data/member.dat"; $image=int(rand(5)); $image="../CIS89B/images2/image".$image.".jpg"; $mailprog = "/usr/lib/sendmail"; $myEmail = "xz040650\@voyager.atc.fhda.edu"; if ($ENV{'REQUEST_METHOD'} eq "POST") { &Select_Option(%INPUT); } else { print "Location: ../CIS89B/shopcatalog.html \n\n"; } # Select Option ====================================================== sub Select_Option { local (%INPUT) = @_; &View_Cart(%INPUT) if ($INPUT{'submit'} eq "View Cart"); &Add_to_Cart(%INPUT) if ($INPUT{'submit'} eq "Add to Cart"); &Modify_Cart(%INPUT) if ($INPUT{'submit'} eq "Modify Cart"); &Checkout(%INPUT) if ($INPUT{'submit'} eq "Checkout"); &Confirm(%INPUT) if ($INPUT{'submit'} eq "Confirm"); &Get_Invoice(%INPUT) if ($INPUT{'submit'} eq "Get Invoice"); &Login(%INPUT) if ($INPUT{'submit'} eq "Login"); print "Location: ../CIS89B/shopcatalog.html \n\n" if ($INPUT{'submit'} eq "Go Back for More"); } # Add to Cart ====================================================== sub Add_to_Cart { local (%INPUT) = @_; foreach $key(%INPUT) { if (($INPUT{$key} > 0) && ($key ne "submit")) { $INPUT{'new_item'} .= "; " if $INPUT{'new_item'}; $INPUT{'new_item'} .= "$key=$INPUT{$key}"; print "Set-Cookie: $key=$INPUT{$key}; path=/\n"; } } &View_Cart (%INPUT); } # Modify Cart ====================================================== sub Modify_Cart { local (%INPUT) = @_; foreach $key(%INPUT) { if ($key ne "submit") { if ($INPUT{$key} > 0 ) { $INPUT{'items'} .= "; " if $INPUT{'items'}; $INPUT{'items'} .= "$key=$INPUT{$key}"; print "Set-Cookie: $key=$INPUT{$key}; path=/\n"; } else { print "Set-Cookie: $key=$INPUT{$key}; path=/; expires=Sunday, 01-Feb-98 00:00:01\n"; } } } &View_Cart (%INPUT); } # View Cart ====================================================== sub View_Cart { local (%INPUT) = @_; local ($fundname, $share, $nav, $subtotal, $total); if ($INPUT{'new_item'}) { $ENV{'HTTP_COOKIE'} .= "; " if $ENV{'HTTP_COOKIE'}; $ENV{'HTTP_COOKIE'} .= $INPUT{'new_item'}; } $ENV{'HTTP_COOKIE'} = $INPUT{'items'} if $INPUT{'items'}; @cart_raw = split (/;/, $ENV{'HTTP_COOKIE'}); $total = 0; print "Content-type: text/html\n\n"; print <<"EOF"; View Shopping Cart

Current Contents of Your Shopping Cart

SharesFund NameNavSubtotal EOF foreach (@cart_raw) { ($fund_item, $share) = split(/=/); ($itemshare, $fundname, $nav) = split(/:/, $fund_item); $subtotal = $nav*$share; $total += $subtotal; if ($share > 0) { print <<"EOF";
$fundname $nav \$$subtotal EOF } } print <<"EOF";
total \$$total
EOF } # Checkout ====================================================== sub Checkout { print "Content-type: text/html\n\n"; print <<"EOF"; Member login

Member Login

Name:
Membership Number:
If you are new, just leave "Membership Number" blank, we'll asign one for you.
EOF } # Login ====================================================== sub Login { local (%INPUT) = @_; local($id, $customer, $address1, $address2, $paymethod, $cardname, $cardnumber, $cardexpire); if (!$INPUT{'id'}) { $id = "LLS".int(rand(1000)); $customer = $INPUT{'customer'}; $msg = "Welcome new member. A new id is assigned to you."; $cardnumber = "Card Number"; $cardexpire = "Expiration Date"; } else { open(MEMBER, $memberfile) || die ( "Content-type:text/html\n\nCan't open $memberfile\n" ); @member = ; for($i=0;$i<@member;$i++){ ($id, $customer)=split(/:/, $member[$i]); if (($id eq $INPUT{'id'}) && ($customer eq $INPUT{'customer'})) { ($id, $customer, $address1, $address2, $paymethod, $cardname, $cardnumber, $cardexpire) = split(/:/, $member[$i]); $found=1; $msg = "You can modify the member information except id."; last; } } if (!$found) { $cardnumber = "Card Number"; $cardexpire = "Expiration Date"; $msg = "Member ID $INPUT{'id'} did not match Member Name $INPUT{'customer'}. Will assign a new id."; $id = "LLS".int(rand(1000)); $customer = $INPUT{'customer'}; } } if ($cardname) { $cardselected = "checked"; if ($cardname eq "VISA") { $vsselected = "selected"; } elsif ($cardname eq "Master Card") { $mcselected = "selected"; } elsif ($cardname eq "Discover") { $dcselected = "selected"; } elsif ($cardname eq "American Express") { $exselected = "selected"; } } print "Content-type: text/html\n\n"; print <<"EOF"; Member Information

Member Information

$msg
$name
Membership Number:
Name:
Address:
Payment Method: Credit Card
Check or Money Order
if Credit Card, Enter select card type, enter Card Number and Expiration Date

EOF } # Get Invoice ====================================================== sub Get_Invoice { local (%INPUT) = @_; local ($fundname, $share, $nav, $subtotal, $total); $member=join(":", $INPUT{'id'}, $INPUT{'customer'}, $INPUT{'address1'}, $INPUT{'address2'}, $INPUT{'paymethod'}, $INPUT{'cardname'}, $INPUT{'cardnumber'}, $INPUT{'cardexpire'}); $member.= "\n"; open(MEMBER, $memberfile) || die ( "Content-type:text/html\n\nCan't open $memberfile\n" ); @member = ; close(MEMBER); for($i=0;$i<@member;$i++){ ($id, $customer)=split(/:/, $member[$i]); if ($id eq $INPUT{'id'}) { $member[$i]=$member; $found = 1; last; } } if ( !$found ) { push(@member, $member); } open(MEMBER, ">$memberfile") || die ( "Content-type:text/html\n\nCan't open $memberfile\n" ); print MEMBER @member; @cart_raw = split (/;/, $ENV{'HTTP_COOKIE'}); $total = 0; $customer = "Sir/Madam"; $customer = $INPUT{'customer'} if $INPUT{'customer'}; print "Content-type: text/html\n\n"; print <<"EOF"; Invoice

Invoice


Dear $customer, You have bought

EOF foreach (@cart_raw) { ($fund_item, $share) = split(/=/); ($itemshare, $fundname, $nav) = split(/:/, $fund_item); $subtotal = $nav*$share; $total += $subtotal; if ($share > 0) { print "
$share Share $fundname at \$$nav per share for a sub total of \$$subtotal
"; } } print "Total payment due: \$$total
"; if ($INPUT{'paymethod'}='creditcard' && $INPUT{'cardname'} && $INPUT{'cardnumber'} && ($INPUT{'cardnumber'}!="Card Number") && ($INPUT{'cardexpire'}!="Expiration Date")) { print "It'll be charged to your $INPUT{'cardname'} $INPUT{'cardnumber'}.
"; } else { print "Please send check or money order to :
Long Life Insurance,
P.O.Box 2000,
Virtual City, Cyber 2000
"; } print <<"EOF";

EOF } # Confirm ====================================================== sub Confirm { local (%INPUT) = @_; @cart_raw = split (/;/, $ENV{'HTTP_COOKIE'}); open (MAIL, "|$mailprog -t -n -oi") || die ("Content-type:text/html\n\nCan't run $mailprog!\n"); print MAIL "To: $myEmail\nSubject: Mutual Funds Order by $INPUT{'id'}\n\n"; print MAIL $INPUT{'id'}."\n"; print MAIL @cart_raw; close (MAIL); foreach (@cart_raw) { ($key, $value) = split(/=/); print "Set-Cookie: $key=$value; path=/; expires=Sunday, 01-Feb-98 00:00:01\n"; } print "Content-type: text/html \n\n"; print <<"EOF"; Confirm Shopping Cart Checkout

Long Life Insurance Financial Services


Thanks $INPUT{'customer'} for your order
Please come back again
Have a nice day!


EOF print &HtmlBot; }