Error! this program is running in folder: $thisDir
ZippyCart must be installed in folder: $req\n"; exit;
}
if(!is_writable($thisDir)){
print "
Error! the folder: $thisDir is not writable by this script\n";
exit;
}
if($_POST['emptycart']){
foreach($_COOKIE as $n =>$v){if(!strpos($n,"ustomer_")){
setcookie( $n, '', -10000, $cookie_path, ".$server");
}}
header("Location: zpdemo.php"); exit;
} ####################################################################
if($_POST['destChange']){
foreach($_COOKIE as $n =>$v){if(strpos($n,"ustomer_")){
setcookie( $n, '', -10000, $cookie_path, ".$server");
}}
header("Location: zpdemo.php"); exit;
} ####################################################################
if($_POST['update']){
$neworder=""; $separator="";
foreach($_POST as $n => $v){
if(strpos($n,"ata_")){
list ($x,$y)=split("_",$n);
if($_POST['sel_'.$y]){continue;}
if($neworder){$separator='][';}
$neworder.=$separator.$_POST['qty_'.$y]."|".$_POST['data_'.$y];
}
}
setcookie( "order", $neworder, $cookie_life, $cookie_path, ".$server");
if($_POST['customer_country']){
setcookie( "customer_country", $_POST['customer_country'],
$cookie_life,$cookie_path, ".$server");
}
if($_POST['customer_state']){
setcookie( "customer_state", $_POST['customer_state'],
$cookie_life,$cookie_path, ".$server");
}
if($_POST['customer_zip']){
setcookie( "customer_zip", $_POST['customer_zip'],
$cookie_life,$cookie_path, ".$server");
}
if($_POST['expedite']){
setcookie( "expedite", "1", $cookie_life, $cookie_path, ".$server");
}else{
setcookie( "expedite", "0", $cookie_life, $cookie_path, ".$server");
}
header("Location: zpdemo.php"); exit;
} ####################################################################
if($_POST['cmd']){ ## cmd field means this is an order
$item=$_POST['item_number']; $separator=']['; $opts="";
if(! $item){$item=substr(time(),5);} ## must have unique item number
$title=$_POST['item_name'];
$price=$_POST['amount'];
$class=$_POST['item_class']; ## class is reserved for user
$price=str_replace("$","",$price); ## remove leading dollar sign
$qty= $_POST['add']; ## quantity is required or exit
if(!$qty){ header("Location: zpdemo.php"); exit;}
$ounces=round($_POST['ounces']+.01); ## convert to ounces
$ounces+=round(($_POST['pounds'] * 16)+.01);
foreach($_POST as $n =>$v){ ## build options list
if(false !==strpos($n, "on") || false !==strpos($n, "os")){$opts.="$v ";}
}
$orderline=$_COOKIE['order'];
if($orderline){$separator='][';}else{$separator='';}
$orderline.=$separator;
$orderline.="$qty|$item|$title|$price|$opts|$class|$ounces";
setcookie( "order", $orderline, $cookie_life, $cookie_path, ".$server");
header("Location: zpdemo.php");
} ####################################################################
if($_COOKIE['order']){
$ctr=0; $prodtotal=0; $ounces=0; $comparescript="";
$itm_count=0; $itemtax=0; $separator='\]\[';
$rows=split($separator,$_COOKIE['order']);
foreach($rows as $row){
$dta=split("\|",$row); ## parts of row
$ounces+=($dta[6] * $dta[0]); ## qty times weight each
$amt=fmtDec( $dta[0] * $dta[3]); ## price time qty
$itm_count+=$dta[0]; ## total items
$prodtotal+=($dta[0] * $dta[3]); ## running total amount
$comparescript.='oval["qty_'.$ctr.'"]="'.$dta[0].'";';
if($clr=="#EBF1E7"){$clr="#EBE2DD";}else{$clr="#EBF1E7";}
$orderTableRows.=<<
$dta[2] no. $dta[1]
$dta[4]
$amt
ROW;
$invoiceRows.=<<
$dta[0]
$dta[3]
$dta[2] #$dta[1]
#$dta[4]
$amt
INV;
$ctr++;
} ################################### end loop through orderlines
}else{
$cartempty=1;
$orderTableRows="
Cart is empty!
";
} ######################################## end test for order cookie
$orderlines=$ctr-1; $Fprodtotal=fmtDec($prodtotal);
if($clr=="#EBF1E7"){$clr="#EBE2DD";}else{$clr="#EBF1E7";}
if($clr=="#EBF1E7"){$shipclr="#EBE2DD";}else{$shipclr="#EBF1E7";}
################################## shipping calculation begins here
$overweight=""; $disableco="disabled";
if($_COOKIE['customer_country'] && $_COOKIE['customer_zip']){
$disableco="";
// list($ctry,$code)=split(",",$_COOKIE['customer_country']);
if(!$cartempty){
$orderweight = $ounces;
if($_COOKIE['customer_country']=="United States"){
$shpchg=getDomSH($_COOKIE['customer_zip'],
$_COOKIE['expedite'], $orderweight);
$invshiptext=" *S&H charge for delivery to zip ";
$invshiptext.=$_COOKIE['customer_zip']." - US/".$_COOKIE['customer_state'];
}else{
$shpchg=getIntSH($_COOKIE['customer_country'],
$_COOKIE['expedite'], $orderweight);
$invshiptext=" *S&H charge for delivery to ".$_COOKIE['customer_country'];
}
}else{
$invshiptext="Shipping to: $ctry ";
if($ctry=="United States"){
$invshiptext.=$_COOKIE['customer_state'].", ".$_COOKIE['customer_zip'];
}
}
$shRowContent='
';
$shRowContent.=$invshiptext;
}else{
$countries=getCountries();
$options="";
if($countries){
foreach($countries as $ctry){
$options.="";
}
}
$shpchg="";
$shRowContent=<< $options
State
Zip Code
IMPORTANT!! You must indicate the destination before continuing!
** The zip code is required for US destinations. ZippyCart™ requires
this information to accurately calculate shipping charges for the order.
SEL;
$shipScript='
document.forms[0].update.disabled=false
var nz=Number(document.forms[0].customer_zip.value);
var c=document.forms[0].customer_country.selectedIndex;
var z=document.forms[0].customer_zip.value;
var s=document.forms[0].customer_state.value;
if(c==0 && (z=="" || z=="N/A" || s=="" || nz<10 || nz >99999)){
document.forms[0].update.disabled=true
document.forms[0].checkout.disabled=true
alert("Please provide accurate delivery information!");
return false;
}';
}
$shpchg=fmtDec($shpchg); $shtotShow=$shpchg;
$grandtotal=fmtDec($tax + $prodtotal + $shpchg);
if($_POST['checkout']){
if(!$_COOKIE['customer_country']){ ## avoid checkout without destination
header("Location: zpdemo.php");
exit;
}
sendHeader();
print invoice($invoiceRows);
exit;
}
########################################### MAIN CART PAGE BEGINS HERE
if($cartempty){$disableco="disabled";}
$style=style();
$javascript1=getScript1($orderlines, $comparescript,$shipScript);
sendHeader();
$testpart=testcart();
print << $javascript1 $style
ZippyCart Demo
ZippyCart™ Demo
You are using the demo version of ZippyCart. Once the active version is installed,
you may wish to use this area to describe your shipping policies or provide links
to other features of your website. Any valid HTML and/or script may be used.
Simply edit the zippycart code to match your specific needs.