#!/usr/bin/perl -w
# bourne.pl "monkified" v1.0
# bart lines 5 & 29, and theorbtwo for ! delimiters line 36
use strict;
############
## note: six assumptions are made here...
## 1) $USER legal characters are alphanumeric, "_", or "-"
## 2) $USER is between 3 and 16 characters in length
## 3) your default shell is a bourne-like shell (like bash)
## 4) you know enough bourne shell to not get in trouble
## 5) your $HOME directory is /home/$USER
## 6) you accept that you are using this at your own risk
my @cmds = split /\n/, <<'--CMDs--';
############
## edit
whoami
pwd
id
echo \$PATH=$PATH
echo \$PERL5LIB=$PERL5LIB
perl -V
############
## no edit
--CMDs--
my $i=4;
my $size=@cmds;
my $me=`whoami`;
my $dir=`pwd`;
$me=~s/\n//;
$dir=~s/\n//;
$dir=~s!\/home\/[\w-]{3,16}\/!\/!;
my $prompt="$me\@~$dir>";
print "Content-type: text/plain\n\n";
while ($i <= $size - 4) { my $cmd=$cmds[$i]; print $prompt,"$cmd\n",`$
+cmd`,"\n"; $i++; }
sub UpdateCart {
#print "Content-type:text/plain\n\n";
my (@itemquantities, $itemnum, $itemqty, $baseprice, $upsizeamt);
if (&GetCookies('itemprice')) {
+ # if item price, get values
my $rawvalue = pop(@Cookie);
($itemnum, $itemqty, $baseprice, $upsizeamt) = split(/;/, $raw
+value);
@itemquantities = split(/\|/, $itemqty);
} else {
die "Missing Cookie: itemprice! It is required to use the cart
+.";
}
my $number = $query->param("number");
my $i = "0";
my $count = "0";
while ($count <= $number) {
my $update = $query->param($count);
$itemquantities[$i] = $update;
$i++;
$count++;
}
#if ($number eq "0") {
# $itemqty = $itemquantities[0];
# my $new_itemprice = "$itemnum;$itemqty;$baseprice;$upsizeamt"
+;
# &SetCookies("itemprice",$new_itemprice);
#} else {
$itemqty = $itemquantities[0];
$i = "0";
$count = "1";
while ($count <= $number) {
$i++;
my $temp = "$itemqty\|$itemquantities[$i]";
$itemqty = $temp;
$count++;
}
my $new_itemprice = "$itemnum;$itemqty;$baseprice;$upsizeamt";
# print "New Itemprice: $new_itemprice\n";
&SetCookies("itemprice",$new_itemprice);
#}
##################################################################
+############
##################################################################
+############
&GetCookies('total');
my $rawvalue = pop(@Cookie);
+ # get raw totals
my ($itemt, $subt, $grandt, $ouncest, $shippingt) = split(/;/,
+ $rawvalue); # get totals from raw totals
&GetCookies('itemprice');
$rawvalue = pop(@Cookie);
($itemnum, $itemqty, $baseprice, $upsizeamt) = split(/;/, $raw
+value);
my @itemnumbers = split(/\|/, $itemnum);
@itemquantities = split(/\|/, $itemqty);
my @baseprices = split(/\|/, $baseprice);
my @upsizeamounts = split(/\|/, $upsizeamt);
&GetCookies('details');
$rawvalue = pop(@Cookie);
my ($isize, $icolor, $istyle, $iounces) = split(/;/, $rawvalue
+);
my @itemsizes = split(/\|/, $isize);
my @itemcolors = split(/\|/, $icolor);
my @itemstyles = split(/\|/, $istyle);
my @itemounces = split(/\|/, $iounces);
&GetCookies('itemtitle');
my $ititle = pop(@Cookie);
my @itemtitles = split(/;/, $ititle);
##############################################################
+##############
##############################################################
+##############
$i = "0";
my @remove = $query->param("remove");
my %remove;
@remove{@remove} = (1)x@remove;
@itemnumbers = @itemnumbers[ grep !$remove{$_}, 0..$#itemnumbers ]
+;
@itemquantities = @itemquantities[ grep !$remove{$_}, 0..$#itemqua
+ntities ];
@baseprices = @baseprices[ grep !$remove{$_}, 0..$#baseprices ];
@upsizeamounts = @upsizeamounts[ grep !$remove{$_}, 0..$#upsizeamo
+unts ];
@itemsizes = @itemsizes[ grep !$remove{$_}, 0..$#itemsizes ];
@itemcolors = @itemcolors[ grep !$remove{$_}, 0..$#itemcolors ];
@itemstyles = @itemstyles[ grep !$remove{$_}, 0..$#itemstyles ];
@itemounces = @itemounces[ grep !$remove{$_}, 0..$#itemounces ];
@itemtitles = @itemtitles[ grep !$remove{$_}, 0..$#itemtitles ];
if (@remove) {
# foreach my $item (@remove) {
# print "Splice: $item\n";
# $item -= $i;
# $i++;
# splice(@itemnumbers, $item, 1);
# splice(@itemquantities, $item, 1);
# splice(@baseprices, $item, 1);
# splice(@upsizeamounts, $item, 1);
# splice(@itemsizes, $item, 1);
# splice(@itemcolors, $item, 1);
# splice(@itemstyles, $item, 1);
# splice(@itemounces, $item, 1);
# splice(@itemtitles, $item, 1);
# }
$ouncest = "0";
foreach my $item (@itemounces) {
# print "Itemounces: $item\n";
my $temp = ($ouncest + $item);
$ouncest = $temp;
}
&ShippingChart($ouncest);
$shippingt = shift(@NewShipping);
$itemt = "0";
foreach my $item (@itemquantities) {
# print "Itemquantities: $item\n";
my $temp = ($itemt + $item);
$itemt = $temp;
}
my $count = "1";
$subt = "0";
$i = "0";
while ($count <= $number) {
my $temp = sprintf("%.2f",$baseprices[$i] + $upsizeamounts
+[$i]);
my $itemprice = sprintf("%.2f",$temp * $itemquantities[$i]
+);
$temp = sprintf("%.2f",$subt + $itemprice);
$subt = $temp;
# print "Subtotal$i: $subt\n";
$i++;
$count++;
}
$grandt = sprintf("%.2f",$subt + $shippingt);
my $new_total = "$itemt;$subt;$grandt;$ouncest;$shippingt;";
&SetCookies("total",$new_total);
#$count = "1";
$itemnum = $itemnumbers[0];
$itemqty = $itemquantities[0];
$baseprice = $baseprices[0];
$upsizeamt = $upsizeamounts[0];
# print "(0) Itemnumber: $itemnum, Itemquantity: $itemqty, Base
+price: $baseprice, Upsizeamount: $upsizeamt\n";
if ($itemnumbers[1] and $itemquantities[1] and $baseprices[1]
+and $upsizeamounts[1]) {
$i = "1";
# while ($count <= $number) {
for (1..$#itemnumbers) {
my $temp = "$itemnum\|$itemnumbers[$i]";
$itemnum = $temp;
$temp = "$itemqty\|$itemquantities[$i]";
$itemqty = $temp;
$temp = "$baseprice\|$baseprices[$i]";
$baseprice = $temp;
$temp = "$upsizeamt\|$upsizeamounts[$i]";
$upsizeamt = $temp;
# print "($i) Itemnumber: $itemnum, Itemquantity: $item
+qty, Baseprice: $baseprice, Upsizeamount: $upsizeamt\n";
$i++;
# $count++;
}
}
my $new_itemprice = "$itemnum;$itemqty;$baseprice;$upsizeamt";
&SetCookies("itemprice",$new_itemprice);
#$count = "1";
$isize = $itemsizes[0];
$icolor = $itemcolors[0];
$istyle = $itemstyles[0];
$iounces = $itemounces[0];
# print "(0) Itemsize: $isize, Itemcolor: $icolor, Itemstyle: $
+istyle, Itemounces: $iounces\n";
if ($itemsizes[1] and $itemcolors[1] and $itemstyles[1] and $i
+temounces[1]) {
$i = "1";
for (1..$#itemsizes) {
# while ($count <= $number) {
my $temp = "$isize\|$itemsizes[$i]";
$isize = $temp;
$temp = "$icolor\|$itemcolors[$i]";
$icolor = $temp;
$temp = "$istyle\|$itemstyles[$i]";
$istyle = $temp;
$temp = "$iounces\|$itemounces[$i]";
$iounces = $temp;
# print "($i) Itemsize: $isize, Itemcolor: $icolor, Ite
+mstyle: $istyle, Itemounces: $iounces\n";
$i++;
# $count++;
}
}
my $new_details = "$isize;$icolor;$istyle;$iounces";
&SetCookies("details",$new_details);
#$count = "1";
$ititle = $itemtitles[0];
# print "(0) Itemtitle: $ititle\n";
my $new_itemtitle;
if ($itemtitles[1]) {
$i = "1";
for (1..$#itemtitles) {
# while ($count <= $number) {
my $temp = "$ititle;$itemtitles[$i]";
$ititle = $temp;
# print "($i) Itemtitle: $ititle\n";
$i++;
# $count++;
}
$new_itemtitle = $ititle;
}
&SetCookies("itemtitle",$new_itemtitle);
}
my $location = "/cart/action?is=view";
print $query->redirect(-uri=> $location), "\n\n";
exit 0;
}