Page 1 of 1

Can Somebody help with this paypal cart script?

Posted: Wed Sep 15, 2004 9:13 pm
by sgreen
sorry,invalid post please remove

Posted: Wed Sep 15, 2004 9:17 pm
by John Cartwright
chagned nothing... usiong php tags for readability

Code: Select all

<?php
site_header('Our Products');


/* load products.txt.  */
$fp = fopen($products_path, "r");
$file_contents = fread($fp, filesize($products_path));
fclose($fp);
// Place each line in the products file into an array
$line = explode("\n", $file_contents);
$i = 0;
/* urlencode the PayPal business email address */
$email = urlencode($business_email);

/* loop through the array of products and display the HTML add to cart buttons */
while($i <= sizeof($line)) {
   /* split the line with delimiter used in the file */
   list ($item_number, $item_name ,$item_amount ,$item_link) = split($delimiter, $line[$i],0);
   if($item_amount > 0){
    $number = urlencode($item_number);
     $item_name = str_replace(""", " ", $item_name);
     $name_value = $item_name;
     
   /* remove characters that migh cause problems with the javascript functions */
     $name_value = preg_replace("/[\,\;\`''\|\*\~\^\[\]\{\}\$"]/", " ", $name_value);
   $name_value = preg_replace("/^\s+|\s+$/", "", $name_value);
   $name = urlencode($name_value);
     $amount = urlencode($item_amount);
     $url = "https://www.paypal.com/cart/add=1&business=$email&item_number=$number&item_name=$name&amount=$amount&currency_code=$currency_code&bn=AyerSoft.PerlStudio";
   
   /* create the code for the add to cart buttons for each product */
$html_row=<<<HTML_ROW

<tr>
<td class="cartTD"><img src="$item_number"></td><td class="cartTD"><a href="$item_name">$item_name</a></td><td class="cartTD">$m_symbol$item_amount</td>
<td>
<tr>
<td class="cartTD"><a href="$item_name"></td>$m_symbol$item_amount</a></td>
<td>
<a href="javascript:onclick=window.paypalwinOpen('$url');"><img src="http://images.paypal.com/images/x-click-but22.gif" border="0"></a>
</td></tr>

HTML_ROW;
   /* display the code for the add to cart buttons for each product */ 
    echo $html_row;
  }
  $i++;
}

site_footer();
exit;

/* site header and footer functions */
/* read in a html header file or print out a HTML header section */
//************************************************************************************
function site_header($title) {
  global $DOCUMENT_ROOT,$bgcolor;
 
  $file = $DOCUMENT_ROOT .'/header.html';
  if (!(is_readable($file))){
    $file = "header.html";
  }


$header=<<<HEADER
<HTML>
<HEAD>
<TITLE>$title</TITLE>

<script language="JavaScript">
<!--

var pixels_width = window.screen.width;
var pixels_height = window.screen.height;

var nWidth= "600";
var nHeight="400";

if(pixels_width < 740){
    nWidth = "540";
}
if(pixels_height < 540){
    nHeight = "350";
}

var optionString = "scrollbars,location,resizable,status,";
optionString += "height=" + nHeight + ",width=" + nWidth;
optionString += ",screenX=10,screenY=10,top=10,left=10";

var cartWindow = null;

function paypalwinOpen(url){
    if (!cartWindow || cartWindow.closed) {
    cartWindow = window.open(url,"cart",optionString);
    } else {
    // window already exists, so bring it forward
        cartWindow.location.href=url;
        cartWindow.focus();
    } 
   
}

// -->
</script>
?>
?>

what's not working

Posted: Thu Sep 16, 2004 3:16 am
by phpScott
what's not working?