//===============================================================================
// TWB ECommerce Website System - V5.2 (c) web-bureau.com 2004
//-------------------------------------------------------------------------------
// button-wiz.php
// PayPal Button Generator Function
//===============================================================================
// Include this file at the top of the webpages you want 'Buy' buttons on, then
// to create the buy buttons for your products, just put this PHP code where
// you want the button to appear: create_paypal_buttons('PRODUCT');
//===============================================================================
//=============================
// Include DB constants etc.
//=============================
require_once 'twb-constants.php';
//=================================
// FUNCTION: create_paypal_buttons
//----------------------------------------------------------------------------------------------
// This function can be called from anywhere in a webpage using the syntax: create_paypal_buttons('PRODUCT');
// It has to connect to the database itself.
//==============================================================================================
function create_paypal_buttons ($product_name) {
global $use_webaccept, $use_ppcart, $paypal_email, $return_pg, $cancel_pg, $pp_viewcart_text, $pp_viewcart_image, $referrer_id, $web_url, $pp_currency, $pp_btn_text, $pp_cart_text, $pp_subscribe_text, $pp_btn_image, $pp_cart_image, $pp_viewcart_image, $pp_subscribe_image, $ipn_notify_url, $affiliate_variable, $pp_web_image, $db_host, $db_user, $db_passwd, $db_name;
$btn= "\n\n";
//------------
// Connect DB
//------------
$db=mysql_connect($db_host, $db_user, $db_passwd) or die('Cannot connect to database.
'. mysql_error());
mysql_select_db($db_name, $db);
//======================
// Get the product info
//======================
$qry="SELECT * FROM twb_products WHERE pr_name='$product_name'";
$result=mysql_query($qry, $db);
if (mysql_errno()!=0) echo '
SQL Error:
QRY:'. $qry.'
ERR:'. mysql_error().'
No Product Info Found for '$product_name'
\n"; while ($myrow=mysql_fetch_assoc($result)) foreach ($myrow as $myvarname=>$myvarvalue) $$myvarname=$myvarvalue; //--------------------------------------------------------- // Form definitions and fields common to all payment types //--------------------------------------------------------- $frm= "\n"; } //------------------------------------------------ // WEB ACCEPT Enabled - create instant pay button //------------------------------------------------ if ($use_webaccept=='Y' && $pr_recurring!='Y') { (strlen($pp_btn_text)==0) ? $t_btn_text='Buy Now' : $t_btn_text=$pp_btn_text; $btn.= "\n\n"; $btn.= "{$frm}\n{$cmn}"; $btn.= "\n"; //-------------------------------------------------- // If image provided - use that - else use the text //-------------------------------------------------- if (strlen($pp_btn_image)>1) $btn.= "\n"; else $btn.= "\n"; $btn.= "\n"; } //--------------------------------------------------------- // PAYPAL SHOPPING-CART Enabled, create add to cart button //--------------------------------------------------------- if ($use_ppcart=='Y' && $pr_recurring!='Y') { (strlen($pp_cart_text)==0) ? $t_cart_text='Add To Cart' : $t_cart_text=$pp_cart_text; $btn.= "\n\n"; $btn.= "{$frm}\n{$cmn}"; $btn.= "\n"; $btn.= ""; // -- If image available.. -- if (strlen($pp_cart_image)>1) $btn.= "\n"; else $btn.= "\n"; $btn.= "\n"; } //------------------------ // View Cart Button - PP //------------------------ if ($we_c_pp_cart=='Y' && $pr_recurring!='Y') { (strlen($pp_viewcart_text)==0) ? $t_btn_text='Buy Now' : $t_btn_text=$pp_viewcart_text; $btn.= "\n\n"; $btn.= "{$frm}\n{$cmn}"; $btn.= "\n"; // -- If image available.. -- if (strlen($pp_viewcart_image)>1) $btn.= "\n"; else $btn.= "\n"; $btn.= "\n"; } $btn.= "\n"; mysql_close(); echo $btn; //return $btn; } ?>