#!/usr/local/bin/perl use CGI qw(:standard); $addr = $ENV{'REMOTE_ADDR'}; $command = param('command'); $mailprog = '/usr/sbin/sendmail'; &display_order if ($command eq 'Order Now'); # Get the input $buffer = query_string(); @pairs = map ("$_\n",split(/&/, $buffer)); @pairs = grep(/^pn/i,@pairs); if (($command eq 'change')||(!(@stat = stat($addr)))||(time - $stat[8] > 7200)) { open FILE, ">$addr"; } else { open FILE, ">>$addr"; } print FILE @pairs; close FILE; &display_cart; &display_form if ($command eq 'Check Out'); sub display_cart { open FILE, $addr; @pairs = ; close FILE; chop @pairs; foreach $pair (@pairs) { ($product, $value) = split(/=/, $pair); $product =~ s/ //g; $product =~ s/pn//g; if ($product !~ /_size|_color/) { $value =~ s/[^0-9]+//g; next if ($value == 0); $order{$product} += $value; } else { $order{$product} = "($value)";} } open FILE, "costdata.txt"; @data = ; close FILE; chop @data; print header(), start_html(-title=>"Adfree4u Shopping Cart", -BGCOLOR=>"#ffffc0"); open FILE, "shipdata.txt"; @ship = ; close FILE; chop @ship; ##### ??? how to take care of color size ... print start_form("post", "cart.cgi"); print h1("Here is the context of your shopping cart"); print "\n"; while (($product, $value) = each %order) { if ($product =~ /_size|_color|_length/) { next;} $data = (grep(/^$product/, @data))[0]; ($pro_num,$desc,$price,$ship,$vendor) = split(/,,,/, $data); $vendor =~ s/[\s\n\t\f\r]//g; $shipdata = (grep(/^$ship,,,/i,@ship))[0]; ($ship,$ship_desc,$ship_price) = split(/,,,/,$shipdata); if ($desc =~ /<([\d]+)off>/i) { $price = int ($price * (100 - $1)/100);} $desc =~ s/\[[^\]]*\]//g; $desc .= " ".$order{$product."_size"}; $desc .= " ".$order{$product."_color"}; $desc .= " ".$order{$product."_length"}; $desc =~ tr/+/ /; # Un-Webify plus signs and %-encoding $desc =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $price =~ s/¸U/0000/; $price =~ s/[^\.\d]//g; $ship_price =~ s/[^\.\d]//g if (($ship ne 's853')&&($ship ne 's118')); if ($value) { print "\n"; $total += $price*$value; $total_ship += $ship_price*$value; $order_msg .= "$product $desc $price $value\n"; } } if (($ship eq 's853')||($ship eq 's118')) { $total_ship = $ship_price; } else { $total += $total_ship;} $order_msg .= "Shipping & Handling charge : $total_ship\n"; $order_msg .= "\nTotal : $total\n\n"; print "
$product$desc$price
Shipping & Handling charge<\/td>$total_ship<\/td><\/tr>\n"; print "
\n"; print "Note: California residents will be charged 7.75% State Sales Tax.",br,br; open FILE, "cart.tem"; @line = ; close FILE; print @line; } sub display_form { print start_form("post", "cart.cgi"); print "Please fill in the following information",p; print "E-mail : ", textfield('email'),p; print "Name :", textfield('name'),p; print "Address1 : ", textfield('address1','',60),p; print "Address2 : ", textfield('address2','',60),p; print "Phone : ", textfield('phone'),p; print "Card Type : ", popup_menu('card_type', ['VISA', 'Master Card', 'American Express']),p; print "Card number : ", textfield('card_number'); print " Expire date (mm/yy) : ", textfield('expire','',10), p; print "Shipping Information (if diferent from the above)", p; print "Receiver's name : ", textfield('ship_name'),p; print "Shipping address1 : ", textfield('ship_address1','',60),p; print "Shipping address2 : ", textfield('ship_address2','',60),p; $order_msg =~ s/<[^>]+>//g; print hidden('order',$order_msg); print hidden('vendor',$vendor); print submit('command','Order Now'), reset; print end_form, end_html; } sub display_order { if (($email=param('email'))&&($name=param('name'))&&($address1=param('address1'))&&($phone=param('phone'))&&($card_type=param('card_type'))&&($card_number=param('card_number'))&&($expire=param('expire'))&&($order=param('order'))&&($vendor=param('vendor'))) { open (MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n"; print MAIL "Subject: Order refered by Admcity America Mall\n"; print MAIL "From: $email\n"; if ($vendor ne 'Multi') { open FILE, "vendor.txt"; @vendor = ; close FILE; chop @vendor; $line = (grep(/^$vendor,,,/i,@vendor))[0]; if (!$line) {$vendor_email = "miss_vender\@adfree4u.com"; } else {($vendor,$vendor_email,$vendor_desc) = split(/,,,/,$line);} print MAIL "CC: $vendor_email\n"; } print MAIL "To: mall\@adfree4u.com\n\n"; print MAIL $order,"Name : $name\nEmail : $email\nAddress : $address1 "; print MAIL param('address2'), "\nTelephone : $phone\n"; print MAIL "Card Type : $card_type\n"; print MAIL "Card Number : $card_number\n"; print MAIL "Expire Date : $expire\n"; print MAIL "Ship To : ", param('ship_name'), "\n"; print MAIL "Shipping address", param('ship_address1'), " ", param('ship_address2'), "\n"; close (MAIL); open FILE, ">$addr"; close FILE; print header(), start_html("Admcity America mall check out"); print h1("Thank you for shopping at Admcity America Mall"); print h2("Your goods will be shipped to you as soon as possible"); print br,br,br,br,"Admcity America Mall"; } else { print header(), start_html("Admcity America mall check out"); print h1("Data Imcomplete! Please click 'Back' button of your brower"); # print "$email:$name:$vendor:$order\n"; } print end_html; exit; }