Powered by PhantomCart.com
EOD; $CheckOutStr2= <<
EOD; $CheckOutStr3= <<
EOD; $CheckOutStr4= <<
EOD; $CheckOutStr5= <<
After purchase you may specify a different "ship to" address.
EOD; //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- // END OF c_checout.html //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- // BEGIN ADD ITEM HTML //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- $AddItemStr1 = << EOD; //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------- // Just for test $Discount = false; include "sCart_util.php"; $ErrLogFile = "logs/ErrLog"; //$Encrypt = true; SafeExtract(array('any' => array('action', 'type', 'item', 'Caller', 'from', 'email', 'username', 'paymenttype'))); $item = urldecode($item); //ErrLog("======================="); RemoveOldTmpFiles($TmpDownloadDir); $ShoppingCartFile = TagTheCustomer($CustId); // // This is used only for calculating discount (CalculateDiscount() too) // SaveCurrentPage(); // - - - - - - - - - - - - - - - - - - - - - - - - // MAIN LINE // - - - - - - - - - - - - - - - - - - - - - - - - if($action == "add" && $item) { AddItemToShoppingCart($ShoppingCartName, $item, $SecurityCode); } if($action == "del" && $item) { DeleteShoppingCartItem($ShoppingCartName, $item, $SecurityCode, $Caller); } if($action == "checkout") { //$Discount = CalculateDiscount($ShoppingCartFile, $from); $Msg1 = Checkout($ShoppingCartName, $SecurityCode, $ShoppingCartFile); } if($action == "pay") { // // Not likely, but it's possible that someone managed to invoke the "pay" function before the Checkout function. If so, there would be no shopping cart file. To prevent this we to a CheckOut() first // $Discount = CalculateDiscount($ShoppingCartFile, $from); PreCheckout($ShoppingCartName, $SecurityCode, $ShoppingCartFile); if($DHDMedia) { if($email && $username) { switch ($paymenttype) { case "cc": $DHDJoin = $DHDJoinCC; $DHDCurr = "USD"; break; case "ach": $DHDJoin = $DHDJoinACH; $DHDCurr = "USD"; break; case "eu": $DHDJoin = $DHDJoinEU; $DHDCurr = "EUR"; break; default: print "ERROR: Payment Type Invalid ==> '$paymenttype'"; exit; } DHDPay($ShoppingCartFile, $ShoppingCartName, $SecurityCode, $type, $email, $username, $DHDJoin, $DHDCurr); } else { header("Location: sCart_DHDCheckout.php"); exit; } } else { // Pay using CCBill Pay($ShoppingCartFile, $ShoppingCartName, $SecurityCode, $type); } exit; } if($action == "display") { $Discount = CalculateDiscount($ShoppingCartFile, $from); DisplayShoppingCart($ShoppingCartName, $SecurityCode); } if($action == "empty") { $Msg1 = EmptyCart(); } if( !file_exists($MsgWindow) ) print "can't find $MsgWindow"; include $MsgWindow; exit; //------------------------------------------------------------- //------------------------------------------------------------- //------------------------------------------------------------- // F U N C T I O N S //------------------------------------------------------------- //------------------------------------------------------------- //------------------------------------------------------------- function SaveCurrentPage() { $Self = $_SERVER['PHP_SELF']; $HTTP_REFERER = $_SERVER['HTTP_REFERER']; if(!stristr($HTTP_REFERER, "sCart_shop.php")) { //ErrLog("Setting cookie: CurrPage=$HTTP_REFERER"); $ServerName = preg_replace("/www\./", "", $_SERVER['SERVER_NAME']); setcookie("CurrPage", $HTTP_REFERER, 0, "/", ".$ServerName"); } } //----------------------------------------------------------------- // Shopping Cart Rules: There cannot be more that one item of any kind in the shopping cart //----------------------------------------------------------------- function CalculateDiscount($ShoppingCartFile, $from) { global $CartDir; $DiscountFile = "dscnt.php"; if(!is_readable($DiscountFile)) return false; $ShoppingCartItems = file("$CartDir/$ShoppingCartFile"); $ShoppingCartItemsCount = count($ShoppingCartItems); // This is an ugly hack: // When user does a "Remove" from View Cart page, this function is invoked from the "delete item" function using header("Location: xxx)" // As a result the shopping cart item---stored in cookie is not refreshed. So we must subtract one from count. // if(stristr($from, "del")) $ShoppingCartItemsCount--; $DscntArray = file($DiscountFile); foreach($DscntArray as $Rec) { $Rec = trim($Rec); list($DiscountPoint, $Discount) = explode("|", $Rec); //print "DiscountPoint = $DiscountPoint, Discount = $Discount) -- Items In Cart $ShoppingCartItemsCount
"; if($DiscountPoint >= $ShoppingCartItemsCount) { //print "Price Point Found at $DiscountPoint"; return round($Discount/100, 2); } } //print "return false"; return false; } //----------------------------------------------------------------- // //----------------------------------------------------------------- function EmptyCart() { global $MsgWindow, $CartDir, $ShoppingCartFile, $ShoppingCartName; $ServerName = preg_replace("/www\./", "", $_SERVER['SERVER_NAME']); setcookie($ShoppingCartName, "", 0, "/", ".$ServerName"); @unlink("$CartDir/$ShoppingCartFile"); $Msg1 = "Shopping cart has been emptied."; $Link = ""; include $MsgWindow; exit; } //----------------------------------------------------------------- // //----------------------------------------------------------------- function GetCryptedDiscount($ShoppingCartFile, $ShoppingCartName, $SecurityCode) { ErrLog("GetCryptedDiscount('$ShoppingCartFile', '$ShoppingCartName', '$SecurityCode')"); $Discount = 100 * CalculateDiscount($ShoppingCartFile, $from); $CrypterObject = new Crypter(md5($SecurityCode)); $dscnt = $CrypterObject->encrypt($Discount); return $dscnt; } //----------------------------------------------------------------- // //----------------------------------------------------------------- function Pay($ShoppingCartFile, $ShoppingCartName, $SecurityCode, $type) { global $MsgWindow, $CartDir, $formPeriod, $currencyCode, $salt, $clientAccnum, $clientSubacc, $formNameck, $formNamedp, $formName, $CCBillUrl, $ShoppingCartFile, $MinimumOrder, $MaximumOrder; PurgeOldCarts($CartDir); if(!$ShoppingCartArray = GetCryptedCookieArray($ShoppingCartName, $SecurityCode)) { print "





Your shopping cart is empty.
Please click the back button on your browser."; exit; } $dscnt = GetCryptedDiscount($ShoppingCartFile, $ShoppingCartName, $SecurityCode); ErrLog("dscnt: $dscnt"); if(!file("$CartDir/$ShoppingCartFile")) { $Msg1 = "Shopping cart has been emptied"; $Link = "
"; include $MsgWindow; exit; } $formPrice = GetTotalPriceFromShoppingCartFile($ShoppingCartFile); if($MinimumOrder) { if($formPrice < $MinimumOrder) { print "




Sorry

The minimum shopping cart order is: $$MinimumOrder
Your shopping cart order is: $$formPrice

Please close this browser window to continue shopping"; exit; } } if($MaximumOrder) { if($formPrice > $MaximumOrder) { print "




Sorry

The maximum shopping cart order is: $$MaximumOrder
Your shopping cart order is: $$formPrice

Please close this browser window to continue shopping"; exit; } } $formDigest = md5("$formPrice$formPeriod$currencyCode$salt"); switch ($type) { case "cc": // // ------------------------------------------------------------- // CCBILL FLEX FORM vs STANDARD DYNAMIC PRICING // ------------------------------------------------------------- // // The "if($formName)"test below accomodates CCBill's new FlexForm system. // If $formName is not NULL, process with the standard // dynamic pricing URL defind in sCart_conf.php: // // $CCBillUrl = "https://bill.ccbill.com/jpost/signup.cgi"; // // If $forName is NULL process with the FlexForm Url defined // in sCart_conf.php. Warning: the query string's name-value pairs // are different thant those in the standard dynamic pricing query string. // // $CCBillUrl = "https://api.ccbill.com/wap-frontflex/flexforms/15877xxx-xxx4-48xx-x8x7-964833xx7xx1"; // // The last part of the URL is specifci to the dynamic pricing sub-account number and must // be obtained from CCBill: // // 15877xxx-xxx4-48xx-x8x7-964833xx7xx1 // // If using FlexForm be sure to set $formName = false; in sCart_conf.php // // ------------------------------------------------------------- if($formName) // Standard Dynamic Pricing { header("Location: $CCBillUrl?clientAccnum=$clientAccnum&clientSubacc=$clientSubacc&formName=$formName&formPrice=$formPrice&formPeriod=$formPeriod¤cyCode=$currencyCode&formDigest=$formDigest&UserData=$ShoppingCartFile&dscnt=$dscnt"); } else // FlexForm { header("Location: $CCBillUrl?clientSubacc=$clientSubacc&initialPrice=$formPrice&initialPeriod=$formPeriod¤cyCode=$currencyCode&formDigest=$formDigest&UserData=$ShoppingCartFile&dscnt=$dscnt"); } exit; case "ck": header("Location: $CCBillUrl?clientAccnum=$clientAccnum&clientSubacc=$clientSubacc&formName=$formNameck&formPrice=$formPrice&formPeriod=$formPeriod¤cyCode=$currencyCode&formDigest=$formDigest&UserData=$ShoppingCartFile$dscnt=$dscnt"); exit; case "dp": header("Location: $CCBillUrl?clientAccnum=$clientAccnum&clientSubacc=$clientSubacc&formName=$formNamedp&formPrice=$formPrice&formPeriod=$formPeriod¤cyCode=$currencyCode&formDigest=$formDigest&UserData=$ShoppingCartFile&dscnt=$dscnt"); exit; default: print "ERROR: Payment Type Invalid ==> '$type'"; exit; } } //----------------------------------------------------------------- // //----------------------------------------------------------------- function DHDPay($ShoppingCartFile, $ShoppingCartName, $SecurityCode, $type, $email, $username, $DHDJoin, $DHDCurr) { global $DHDJoinLink, $DHDMedia, $DHDJoinCC, $DHDJoinACH, $DHDJoinEU, $MsgWindow, $CartDir, $formPeriod, $currencyCode, $salt, $clientAccnum, $clientSubacc, $formNameck, $formName, $CCBillUrl, $ShoppingCartFile, $MinimumOrder; PurgeOldCarts($CartDir); if(!$ShoppingCartArray = GetCryptedCookieArray($ShoppingCartName, $SecurityCode)) { print "





Your shopping cart is empty.
Please click the back button on your browser."; exit; } if(!file("$CartDir/$ShoppingCartFile")) { $Msg1 = "Shopping cart has been emptied"; $Link = ""; include $MsgWindow; exit; } $formPrice = GetTotalPriceFromShoppingCartFile($ShoppingCartFile); if($MinimumOrder) { if($formPrice < $MinimumOrder) { print "




Sorry

The minimum shopping cart order is: $$MinimumOrder
Your shopping cart order is: $$formPrice

Please close this browser window to continue shopping"; exit; } } if($MaximumOrder) { if($formPrice > $MaximumOrder) { print "




Sorry

The maximum shopping cart order is: $$MaximumOrder
Your shopping cart order is: $$formPrice

Please close this browser window to continue shopping"; exit; } } $IpAddr = $_SERVER['REMOTE_ADDR']; $Date = date("Y-m-d%%H:m:s", time() + (60*60*24)); // Get transaction expiration time. (60*60*24) gives it 24 hours list($Date, $Time) = explode("%%", $Date); // Set data for hash $httl = $Date ."T". $Time ."Z"; // Hash expiration date $cust_email = $email ; // Customer's email $cust_id_ext = "" ; // ID assigned by merchant to a pre-registered customer $hver = 1; // Hash version $inv_id_ext = ""; // Merchant’s invoice ID (time() guarantees unique -- don't want to increment because we would have to save previous) $inv_value_requested = sprintf("%01.2f", $formPrice); // Price of shopping cart $sub_username = $username; // Subscriber’s username from pre-registration with the merchant $curr_id_requested = $DHDCurr; // Currency ID // Build the secret hash from the stuff above $secret = $DHDMedia; // Specific to each webmaster $hash=sha1("$cust_email||$cust_id_ext||$httl||$hver||$inv_id_ext||$inv_value_requested||$sub_username||$curr_id_requested||$secret"); $link=$DHDJoin. "?". "cust_email = " .urlencode($cust_email). "&". "cust_id_ext = " .urlencode($cust_id_ext). "&". "httl = " .urlencode($httl). "&". "hver = " .urlencode($hver). "&". "inv_id_ext = " .urlencode($inv_id_ext). "&". "inv_value_requested = " .urlencode($inv_value_requested). "&". "secret = " .urlencode($hash). "&". "sub_username = " .urlencode($sub_username). "&". "curr_id_requested = " .urlencode($curr_id_requested). "&". "UDF01 = " .urlencode("$formPrice|$IpAddr") ."&". "UDF02 = " .urlencode($ShoppingCartFile); $link = str_replace(" ", "", $link); //print "$link


"; //print "hash in: \ncust_email: '$cust_email'\ncust_id_ext '$cust_id_ext'\nhttl '$httl'\nhver '$hver'\ninv_id_ext '$inv_id_ext'\ninv_value_requested '$inv_value_requested'\nsub_username '$sub_username'\ncurr_id_requested '$curr_id_requested'\nsecret '$secret'


"; //print "hash out: $hash
"; //exit; if(file_exists("diags")) { ErrLog("DHD Link: $link"); ErrLog("hash in: \ncust_email: '$cust_email'\ncust_id_ext '$cust_id_ext'\nhttl '$httl'\nhver '$hver'\ninv_id_ext '$inv_id_ext'\ninv_value_requested '$inv_value_requested'\nsub_username '$sub_username'\ncurr_id_requested '$curr_id_requested'\nsecret '$secret'"); ErrLog("hash out: $hash"); } header("Location: $link"); exit; /* https://payment.dhdmedia.com/merchants/p.1005018/m.1007/buy.cfm?cust_email=billp%40cox.net&cust_id_ext=&hver=1&httl=2010-04-01T09%3A04%3A16Z&inv_id_ext=&inv_value_requested=1.00&sub_username=nudge1&curr_id_requested=USD&UDF01=1%7C72.200.81.73&UDF02=HbUWzaAfUGuu8dEKWinvupJEVte6aePI&secret=728fbe33266ec047d173ebcdc802e8a36e3fe29c hash in: cust_email: 'billp@cox.net' cust_id_ext '' httl '2010-04-01T09:04:16Z' hver '1' inv_id_ext '' inv_value_requested '1.00' sub_username 'nudge1' curr_id_requested 'USD' secret 'PTCXGBv0SzmD4sTfwWDR' hash out: 728fbe33266ec047d173ebcdc802e8a36e3fe29c 728FBE33266EC047D173EBCDC802E8A36E3FE29C Hash Creation Tool https://secure.dhdmedia.com/merchants/p.1005132/m.1007/buy.cfm?cust_email=billp@cox.net& cust_id_ext=&httl=2010-04-01T09:04:16Z&hver=1& inv_id_ext=&inv_value_requested=1.00&sub_username=nudge1&curr_id_requested=USD&secret=728FBE33266EC047D173EBCDC802E8A36E3FE29C Me https://payment.dhdmedia.com/merchants/p.1005018/m.1007/buy.cfm?cust_email=billp%40cox.net&cust_id_ext=&hver=1&httl=2010-04-01T09%3A04%3A16Z&inv_id_ext=&inv_value_requested=1.00&sub_username=nudge1&curr_id_requested=USD&UDF01=1%7C72.200.81.73&UDF02=HbUWzaAfUGuu8dEKWinvupJEVte6aePI&secret=728fbe33266ec047d173ebcdc802e8a36e3fe29c */ } //----------------------------------------------------------------- // //----------------------------------------------------------------- function PurgeOldCarts($CartDir) { global $CookieLife; if ($handle = opendir($CartDir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { //echo "Purge Test: $CartDir/$file
"; $AgeOfFile = filemtime("$CartDir/$file"); $Diff = time() - $AgeOfFile; if($Diff > 60*60*24*2) { @unlink("$CartDir/$file"); } } } closedir($handle); } } //------------------------------------------------------------- // //------------------------------------------------------------- function GetTotalPriceFromShoppingCartFile($ShoppingCartFile) { global $CartDir, $MsgWindow, $Discount; if(!file_exists("$CartDir/$ShoppingCartFile")) { $Msg1 = "Error 001 - Shopping cart empty
"; $Link = ""; include $MsgWindow; exit; } $ShoppingCartItems = file("$CartDir/$ShoppingCartFile"); $ItemPrice = $SubTotal = 0; foreach($ShoppingCartItems as $ContentId) { $ContentId = trim($ContentId); $ItemPrice = GetPriceByContentId($ContentId); $SubTotal = $SubTotal + $ItemPrice; } if($Discount) $SubTotal = round((1 - $Discount)*$SubTotal,2); return sprintf("%01.2f", $SubTotal); } //------------------------------------------------------------- // //------------------------------------------------------------- function GetPriceByContentId($ContentId) { global $Server, $RcvrUrl, $Domain, $ClientAccountId; // // First, check to see if price is stored on client server // if($Price = GetLocalCatalogPrice($ContentId)) return $Price; print "aborting in GetPriceByContentId($ContentId)"; exit; //ErrLog(("ERROR: Catalog Price not available on Client. ContentId: '$ContentId'"); //ErrLog(("GetPriceByContentId($ContentId) from server"); // Comms Data $Msg = "Action=" .urlencode("GetPrice"); // Database Data $Msg .= "&ClientAccountId=" .urlencode($ClientAccountId); $Msg .= "&ContentId=" .urlencode($ContentId); $Msg .= "&Server=" .urlencode($Server); $start_time = microtime(); // Record part of the posting, but not enough to give prying eyes anything important //ErrLog("Posting Message: $Msg"); if(!$Ret = SendMsgToRcvr($Msg, $Domain, $RcvrUrl)) { //ErrLog(("ERROR: SendMsgToRcvr Failed: Msg: $Msg, Domain: $Domain"); } else { //ErrLog(("SUCCESS: SendMsgToRcvr Message Posted"); $Response = parse_response($Ret); //ErrLog(("PhantomFlicks returns token price: $Response[2]"); if(stristr($Response[2], "B A D")) { list($junk, $Error) = explode("::", $Response[2]); include "c_msg1.html"; //ErrLog(("ERROR: $Error"); exit; } //print $Response[2]; return $Response[2]; } } //----------------------------------------------------------------- // //----------------------------------------------------------------- function TagTheCustomer($CustId) { global $CookieLife; if(isset($_COOKIE[$CustId])) { return $_COOKIE[$CustId]; } else { $CustIdCookie = GenerateRandomCustId(32); $ServerName = preg_replace("/www\./", "", $_SERVER['SERVER_NAME']); setcookie($CustId, $CustIdCookie, $CookieLife, "/", ".$ServerName"); return $CustIdCookie; } } //----------------------------------------------------------------- // //----------------------------------------------------------------- function ShowShoppingCartFileContents($ShoppingCartFile) { global $CartDir; print file_get_contents("$CartDir/$ShoppingCartFile"); } //----------------------------------------------------------------- // //----------------------------------------------------------------- function GetBack2ShoppingLink() { if(isset($_COOKIE['CurrPage'])) $Link = ""; else $Link = ""; return $Link; } //----------------------------------------------------------------- // //----------------------------------------------------------------- function Checkout($ShoppingCartName, $SecurityCode, $ShoppingCartFile) { global $Tangible, $CartDir, $MsgWindow, $CheckOutStr1, $SubTotalLine, $CheckOutStr2, $CheckOutStr4, $CheckOutStr3, $CheckOutStr5, $Discount, $formName, $formNameck, $formNamedp; //ErrLog("Checkout($ShoppingCartName, $SecurityCode, $ShoppingCartFile)"); $Link = GetBack2ShoppingLink(); if(!$ShoppingCartArray = GetCryptedCookieArray($ShoppingCartName, $SecurityCode)) { $Msg1 = "Your shopping cart is empty."; include $MsgWindow; exit; } $arr = print_r($ShoppingCartArray, trud); //ErrLog("1=========================================================="); //ErrLog("$arr"); //ErrLog("1=========================================================="); if(!$fd = fopen("$CartDir/$ShoppingCartFile", "w")) { print "Unable to open $CartDir/$ShoppingCartFile"; exit; } // Store permanent version of shopping on disk $Totals = 0; $Self = $_SERVER['PHP_SELF']; $i=0; foreach($ShoppingCartArray as $ContentId => $Val) { $i++; //ErrLog("** $i $ContentId"); fwrite($fd, "$ContentId\n"); $ContentId = trim($ContentId); $Price = GetPriceByContentId($ContentId); if(is_numeric($Price)) { $Totals += $Price; $SubTotalLine .= "
";
	      $SubTotalLine .= "\n";
         $SubTotalLine .= "($i) $ContentId:";
         $SubTotalLine .= "$$Price";
         $SubTotalLine .= "Remove\n";
         $SubTotalLine .= "";
	      $SubTotalLine .= "
"; } else { print "Error in shopping cart"; exit; } } fclose($fd); chmod("$CartDir/$ShoppingCartFile", 0666); $Totals = sprintf("%01.2f", $Totals); $SubTotalLine .= "
";
   $SubTotalLine .= "\n";
   $SubTotalLine .= "Total:  ";
   $SubTotalLine .= "\$$Totals";
   $SubTotalLine .= "";
   $SubTotalLine .= "
"; $Discount = CalculateDiscount($ShoppingCartFile, $from); if($Discount) { $TotalDiscount = round($Totals*(1-$Discount), 2); $TotalDiscount = sprintf("%01.2f", $TotalDiscount); $DisplayDiscount = 100*$Discount; $SubTotalLine .= "
";
   	$SubTotalLine .= "\n";
   	$SubTotalLine .= "With your $DisplayDiscount% discount you pay:  ";
   	$SubTotalLine .= "\$$TotalDiscount";
   	$SubTotalLine .= "";
   	$SubTotalLine .= "
"; } $SubTotalLine .= ""; //include "c_checkout.html"; print $CheckOutStr1; print $SubTotalLine; // Decide whether to display credit card, online check, direct pay if($formNameck && !$formNameck) print $CheckOutStr2; elseif($formNamedp && $formNameck) print $CheckOutStr4; else { if($Tangible) print $CheckOutStr5; else print $CheckOutStr3; } print "$Link Continue shopping
"; print ""; print ""; exit; } //----------------------------------------------------------------- // //----------------------------------------------------------------- function PreCheckout($ShoppingCartName, $SecurityCode, $ShoppingCartFile) { global $CartDir, $MsgWindow; if(!$ShoppingCartArray = GetCryptedCookieArray($ShoppingCartName, $SecurityCode)) { $Msg1 = "Your shopping cart is empty."; $Link = ""; include $MsgWindow; exit; } if(!$fd = fopen("$CartDir/$ShoppingCartFile", "w")) { print "Unable to open $CartDir/$ShoppingCartFile"; exit; } foreach($ShoppingCartArray as $ContentId => $Val) { fwrite($fd, "$ContentId\n"); } fclose($fd); chmod("$CartDir/$ShoppingCartFile", 0666); } //----------------------------------------------------------------- // //----------------------------------------------------------------- function DeleteShoppingCartItem($ShoppingCartName, $Item, $SecurityCode, $Caller) { global $MsgWindow; if(!isset($Item)) { print "Item not set
"; return; } // // Put current shopping cart into an array so we can hunt for Item to delete // $ShoppingCartArray = GetCryptedCookieArray($ShoppingCartName, $SecurityCode); // // To delete an itme, we copy all items from shopping cart array // into new tmp array (BUT NOT ITEM WE WANT TO DELETE_ // $TmpArray = array(); foreach($ShoppingCartArray as $Rec => $Val) { //print "Deleting this? '$Rec' => '$Val' "; if($Rec == $Item) { //print "YES
"; } else { //print "NO
"; $TmpArray[$Rec] = "x"; } } SetCryptedCookieArray($ShoppingCartName, $TmpArray, $SecurityCode); if($Caller == "CO") { $Self = $_SERVER['PHP_SELF']; header("Location: $Self?action=checkout&from=del"); exit; } $Msg1 = "\"$Item\"
removed from your shopping cart.
"; $Link = "
"; include $MsgWindow; exit; } //----------------------------------------------------------------- // //----------------------------------------------------------------- function DisplayShoppingCart($ShoppingCartName, $SecurityCode) { global $MsgWindow; $Msg1 = "Shopping Cart Contents:
"; if(!$ShoppingCartArray = GetCryptedCookieArray($ShoppingCartName, $SecurityCode)) { print "Shopping Cart Empty
"; exit; } foreach($ShoppingCartArray as $Rec => $Val) { print "\"$Rec\"
"; } exit; } //----------------------------------------------------------------- // //----------------------------------------------------------------- function AddItemToShoppingCart($ShoppingCartName, $Item, $SecurityCode) { global $MsgWindow, $AddItemStr1, $AddItemStr2; ErrLog("\n\n============================================="); ErrLog("AddItemToShoppingCart($ShoppingCartName, '$Item'"); $CartArray = GetCryptedCookieArray($ShoppingCartName, $SecurityCode); //$xCartArray = print_r($CartArray, true); //ErrLog("Shopping cart cookie ===> $xCartArray"); if(!is_array($CartArray)) { //print "ShoppingCartName: $ShoppingCartName: creating new array: $Item
"; $StartArray[$Item] = "x"; SetCryptedCookieArray($ShoppingCartName, $StartArray, $SecurityCode); } else { $CartArray[$Item] = "x"; SetCryptedCookieArray($ShoppingCartName, $CartArray, $SecurityCode); } $ItemPrice = GetPriceByContentId($Item); $Msg1 = "
Added To Cart

\"$Item\"

\$$ItemPrice"; //$Link = "
"; print $AddItemStr1; print $Msg1; print $AddItemStr2; //include $MsgWindow; exit; } //----------------------------------------------------------------- // W A R N I N G W A R N I N G W A R N I N G W A R N I N G // W A R N I N G W A R N I N G W A R N I N G W A R N I N G // W A R N I N G W A R N I N G W A R N I N G W A R N I N G // W A R N I N G W A R N I N G W A R N I N G W A R N I N G // W A R N I N G W A R N I N G W A R N I N G W A R N I N G // W A R N I N G W A R N I N G W A R N I N G W A R N I N G // If cookies are not being set add this to a .htaccess file in this directory // ExpiresActive Off //----------------------------------------------------------------- function SetCryptedCookieArray($ShoppingCartName, $Array, $SecurityCode) { global $Encrypt, $CookieLife; $CrypterObject = new Crypter(md5($SecurityCode)); // $xArray = print_r($Array, true); // ErrLog("xArray: $xArray"); // ErrLog("SetCryptedCookieArray(ShoppingCartName=$ShoppingCartName)"); // ErrLog("Serialize1: " .serialize($Array)); //ErrLog("Serialize1: " .$CrypterObject->encrypt(serialize($Array)) ); $ServerName = preg_replace("/www\./", "", $_SERVER['SERVER_NAME']); if($Encrypt) { // ErrLog("ENCRYPT"); setcookie($ShoppingCartName, $CrypterObject->encrypt(serialize($Array)), $CookieLife, "/", ".$ServerName"); } else { //ErrLog("NOT ENCRYPT"); setcookie($ShoppingCartName, serialize($Array), $CookieLife, "/", ".$ServerName"); //ErrLog("setcookie($ShoppingCartName, " .serialize($Array). ", $CookieLife, '/', '.$ServerName"); //$sArray = serialize($Array); //ErrLog("setcookie($ShoppingCartName, $sArray, $CookieLife, '/', '.$ServerName"); } } //------------------------------------------------------------------ // //------------------------------------------------------------------ function GetCryptedCookieArray($ShoppingCartName, $SecurityCode) { global $Encrypt; //ErrLog("GetCryptedCookieArray($ShoppingCartName), Cookie: " . $_COOKIE[$ShoppingCartName]); // // Some servers (MilitaryClassifieds put '\' characters in that do not unserialize(). // Remove back slashes with stripslashes before unserializing // $CookieVal = $_COOKIE[$ShoppingCartName]; $CookieVal = stripslashes($CookieVal); //ErrLog("Before unserialize CookieVal: '$CookieVal'"); if(isset($CookieVal)) { if($Encrypt) { $CrypterObject = new Crypter(md5($SecurityCode)); $unserial = unserialize($CrypterObject->decrypt($CookieVal)); //ErrLog("After decryp and unserialize: " .print_r($unserial, true). "\n\n================="); } else { $unserial = unserialize($CookieVal); //ErrLog("After unserialize (not decrypted): " .print_r($unserial, true). "\n\n================="); } return $unserial; } //ErrLog("Nothing in shopping cart\n\n================="); return false; } //----------------------------------------------------------------- // //----------------------------------------------------------------- function GenerateRandomCustId($nameLength) { $NameChars = 'abcdefghjhijklmnoppqrstuvwxyz1234567890ABCDEFGHJHIJKLMNOPPQRSTUVWXYZ'; $Vouel = 'AEIOUaeiou'; $Name = ""; for ($index = 1; $index <= $nameLength; $index++) { if ($index % 3 == 0) { $randomNumber = rand(1,strlen($Vouel)); $Name .= substr($Vouel,$randomNumber-1,1); } else { $randomNumber = rand(1,strlen($NameChars)); $Name .= substr($NameChars,$randomNumber-1,1); } } return $Name; } //----------------------------------------------------------------- // //----------------------------------------------------------------- class Crypter { var $key; function Crypter($clave){ $this->key = $clave; } function setKey($clave){ $this->key = $clave; } function keyED($txt) { $encrypt_key = md5($this->key); $ctr=0; $tmp = ""; for ($i=0;$ikeyED($tmp)); } function decrypt($txt) { $txt = $this->keyED(base64_decode($txt)); $tmp = ""; for ($i=0;$i