Category Archives: eCommerce

PHP CGI Auction Scripts for E-Commerce

CGI Auction Script! allows you to create auction sites with unlimited categories, and set the price you wish to charge! There is only 1 file to upload to your CGI-Bin! Make a few changes, and WOW! You’ve got your own Auction website! E-Commerce.

<?php
include('variables.php');

$connect = mysql_connect($host,$username,$password);
if (!$connect) {
   die('Could not connect: ' . mysql_error());
}
@mysql_select_db($database) or die( "Unable to select database");

function doTheCurl ()
{
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value)
{
$value = urlencode(stripslashes($value));
$req .= "&amp;$key=$value";
}
$ch = curl_init();

// check to see if this is sandbox or not
if ($_POST["test_ipn"] == 1)
{
curl_setopt($ch, CURLOPT_URL, "https://www.sandbox.paypal.com/cgi-bin/webscr");
}
else
{
curl_setopt($ch, CURLOPT_URL, "https://www.paypal.com/cgi-bin/webscr");
}

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$paypal_response = curl_exec ($ch);
curl_close($ch);
return $paypal_response;
}

function doTheHttp ()
{
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value)
{
$value = urlencode(stripslashes($value));
$req .= "&amp;$key=$value";
}
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

// check to see if this is sandbox or not.
if ($_POST["test_ipn"] == 1)
{
$paypal_response = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
}
else
{
$paypal_response = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
}

if (!$paypal_response) {
return "ERROR";
}
else
{
fputs ($paypal_response, $header . $req);
while (!feof($paypal_response))
{
$res = fgets ($paypal_response, 1024);
if (strcmp ($res, "VERIFIED") == 0)
{
return "VERIFIED";
}
else if (strcmp ($res, "INVALID") == 0)
{
return "INVALID";
}
}
fclose ($paypal_response);
}
return "ERROR";
}

$paypal_response = doTheCurl();
if (!$paypal_response)
{

$paypal_response = doTheHttp();

}
else
{

}

//get variables
$receiver_email = $_POST['receiver_email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$payer_email = $_POST['payer_email'];
$item_name = $_POST['item_name'];
$amount = $_POST['mc_gross'];
$payment_status = $_POST['payment_status'];
$txn_type = $_POST['txn_type'];

if ($first_name != "")
$message = "Customer First Name: " . $first_name . "\n";
if ($last_name != "")
$message .= "Customer Last Name: " . $last_name . "\n";
if ($payer_email != "")
$message .= "Customer Email: " . $payer_email . "\n";
if ($item_name != "")
$message .= "Item: " . $item_name . "\n";
if ($amount != "")
$message .= "Amount: " . $amount . "\n";
if ($txn_type != "")
$message .= "Transaction Type: " . $txn_type . "\n";
if ($payer_status != "")
$message .= "Payment Status: " . $payment_status . "\n";

if (ereg('VERIFIED',$paypal_response)) {
$response_verified = 1;
$ipn_result = 'VERIFIED';
if ($payment_status == "Completed")
{

$checkquery = "SELECT * FROM files WHERE paypalname = '$item_name'";
$checkresult = mysql_query($checkquery);

$checkrow=mysql_fetch_assoc($checkresult);

$price = $checkrow["price"];
$filename = $checkrow["filename"];

if ($price == $amount)
{
//send email to buyer
$random = rand();
$string = md5($random);

$query = "INSERT INTO links (getfilename, link, dltimes) VALUES ('$filename', '$string', '3')";
mysql_query($query);
mysql_close($connect);

$to = $payer_email;
$subject = $storename . " Order";
$body = "Your download url:\n" . $scriptpath . "send_url.php?q=" . $string . "\n\nIf you cannot download, please contact us at " . $email . ".";

mail($to, $subject, $body,
    "To: " . $to . "\n" .
    "From: ". $email ."\n" .
    "X-Mailer: PHP 4.x");

mail($email, "Order Received", $message, "From: ". $email);

}
else
{
mail($email, "Order Payment Amount Invalid", $message, "From: ". $email);

}
}

} else if (ereg('INVALID',$paypal_response)) {
$response_invalid = 1;
$ipn_result = 'INVALID';

$message .= "IPN returned invalid\n";

mail($email, "Order Received - Invalid IPN", $message, "From: ". $email);

$to = $payer_email;
$subject = $storename . " Order";
$body = "Your download was not completed, please contact us at " . $email . ".";

mail($to, $subject, $body,
    "To: " . $to . "\n" .
    "From: " . $email . "\n" .
    "X-Mailer: PHP 4.x");

} else {
echo 'Error: no valid $paypal_response received.';

$message .= "No response from Paypal\n";

mail($email, "Order Received - No IPN Response", $message, "From: " . $email);

$to = $payer_email;
$subject = $storename . " Order";
$body = "Your download was not completed, please contact us at " . $email . ".";

mail($to, $subject, $body,
    "To: " . $to . "\n" .
    "From: " . $email . "\n" .
    "X-Mailer: PHP 4.x");
}

?>

PHP DHTML shopping cart module E-Commerce

This script is a DHTML shopping cart module.The products will fly to the shopping basket when you click on the “Add to basket” button. Ajax is used to dynamically update the content of the basket. E-Commerce.

 

 

<?php
include('../variables.php');

$lang_file = "../languages/$lang.php";
include($lang_file);

$connect = mysql_connect($host,$username,$password);
if (!$connect) {
 die('Could not connect: ' . mysql_error());
}
@mysql_select_db($database) or die( "Unable to select database");
?>
<html>
<head>
 <link href="../css/default.css" rel="stylesheet" type="text/css" />
<title>
<? echo $lang_admin_header;?>
</title>
</head>
<body>
<?php include("../includes/header.php"); ?>

 <a href="add.php"><? echo $lang_add_file;?></a>


<ol>
<?
$query = " SELECT * FROM files ORDER BY id DESC";
$result = mysql_query($query) or die('Error, query failed');

if (mysql_num_rows($result) > 0)
{
 // iterate through resultset
 // print title with links to edit and delete scripts
 while($row = mysql_fetch_object($result))
 {
 ?>
 <li><strong>
 <? echo $row->paypalname; ?></strong>
 [<a href="../myfiles/<? echo $row->filename; ?>" target="_blank" title="<? echo $lang_view_file;?>"><? echo $row->filename; ?></a>]
 <? echo $lang_currency;?> <? echo $row->price; ?>

 <br>
 <font size="-2"><a href="edit.php?id=<? echo $row->id; ?>"><? echo $lang_edit;?></a>
| <a
href="delete.php?id=<? echo $row->id; ?>"><? echo $lang_delete;?></a></font>
 <p>
 </li>
 <?
 } echo "</ol>";
}
// if no records present
// display message
else
{
?>
 <font size="-1"><? echo $lang_no_downloads;?></font><p>
<?
}

// close connection
mysql_close($connect);

?>
</body>
</html>

&amp;nbsp;

PHP IBiz E-Payment Integrator E-Commerce

Internet E-Commerce simplified. IBiz E-Payment Integrator (formerly IP*Works! CC ICharge) includes components for Credit Card & Electronic Check (ACH) processing via major Internet payment gteways. Rock-solid E-Commerce components trusted by thousands of developers worldwide.Now with direct QuickBooks integration and support for more than 50 major Internet Payment gateways. This release includes support for new Internet payment gateways for credit card processing.

 

 

<?php
include('../variables.php');

$lang_file = "../languages/$lang.php";
include($lang_file);

$connect = mysql_connect($host,$username,$password);
if (!$connect) {
 die('Could not connect: ' . mysql_error());
}
@mysql_select_db($database) or die( "Unable to select database");



?>
<html>
<head>
 <link href="../css/default.css" rel="stylesheet" type="text/css" />
<title><? echo $lang_add_product;?></title>
</head>
<body>
<?php include("../includes/header.php"); ?>
<?

if (!isset($_POST['submit']))
{
?>

<table cellspacing="5" cellpadding="5">
<form action="<? echo $PHP_SELF; ?>" method="POST" enctype="multipart/form-data">

<tr>
 <td valign="top" align="right"><b><font size="-1"><? echo $lang_name_of_item;?></font></b></td>
 <td><input size="50" maxlength="250" type="text" name="paypalname"></td>
</tr>
<tr>
 <td valign="top" align="right"><b><font size="-1"><? echo $lang_price;?></font></b></td>
 <td><input size="10" maxlength="250" type="text" name="price"></td>
</tr>


<tr>
 <td valign="top" align="right"><b><font size="-1"><? echo $lang_file;?><br></font></b></td>
 <td>
 <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="thefile" type="file" id="thefile">


</td>
</tr>

<tr>
 <td colspan=2><input type="Submit" name="submit" value="<? echo $lang_add;?>"></td>
</tr>
</form>
</table>
<?
}
else
{

$uploadDir = '../myfiles/';

$fileName = $_FILES['thefile']['name'];
$paypalname = $_POST['paypalname'];
$price = $_POST['price'];

if ($fileName != "")
{


$filename = $_FILES['thefile']['name'];
$tmpname = $_FILES['thefile']['tmp_name'];
$fileSize = $_FILES['thefile']['size'];
$fileType = $_FILES['thefile']['type'];




$ext = substr(strrchr($filename, "."), 1);

$filePath = $uploadDir . $filename;

$result = move_uploaded_file(stripslashes($tmpname), stripslashes($filePath));
chmod(stripslashes($filePath), 0777);
}
else
{

}

if (!result)
{
echo "File upload error.";
}

 // generate and execute query
 $query = "INSERT INTO files SET filename = '$filename', paypalname = '$paypalname', price = '$price'";
 $result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());

 // print result
echo "<div class=\"alert\">$lang_insert_succesful</div>";

 // close database connection
 mysql_close($connect);
 }

?>
</body>
</html>

&amp;nbsp;

Digital Product Manager PHP Scripts E-Commerce

Digital Product Manager script helps you to manipulate and sell digital products on line.Features: – Stores all product information in database – Auto file upload – Edit file prices and properties once added to database – Automatically sends customer purchased files – All files protected and not directly accessible – PayPal IPN integration – Complete Admin Center.

 

 

<?php
include('../variables.php');

$lang_file = "../languages/$lang.php";
include($lang_file);

$connect = mysql_connect($host,$username,$password);
if (!$connect) {
 die('Could not connect: ' . mysql_error());
}
@mysql_select_db($database) or die( "Unable to select database");

$id = $_GET['id'];

 // generate and execute query
 $query = "SELECT * FROM files WHERE id = '$id'";
 $result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());

 // if a result is returned
 if (mysql_num_rows($result) > 0)
 {
 // turn it into an object
 $row = mysql_fetch_object($result);

?>
<html>
<head>
 <link href="../css/default.css" rel="stylesheet" type="text/css" />
<title><? echo $lang_edit_file;?></title>
</head>
<body>
<?php include("../includes/header.php"); ?>
<?

$paypalname = $row->paypalname;
$filename = $row->filename;
$origfilename = $row->filename;
$price = $row->price;

$paypalname = htmlspecialchars($paypalname, ENT_QUOTES);
$filename = htmlspecialchars($filename, ENT_QUOTES);
$origfilename = htmlspecialchars($origfilename, ENT_QUOTES);

if (!isset($_POST['submit']))
{
?>

<table cellspacing="5" cellpadding="5">
<form action="<? echo $PHP_SELF; ?>" method="POST" enctype="multipart/form-data">
<input type="hidden" name="id"  value="<? echo $id; ?>">
<tr>
 <td valign="top" align="right"><b><font size="-1"><? echo $lang_name_of_item;?></font></b></td>
 <td><input size="50" maxlength="250" type="text" name="paypalname" value='<?
echo $paypalname; ?>'></td>
</tr>
<tr>
 <td valign="top" align="right"><b><font size="-1"><? echo $lang_price;?></font></b></td>
 <td><input size="10" maxlength="250" type="text" name="price" value='<?
echo $price; ?>'></td>
</tr>


<tr>
 <td valign="top" align="right"><b><font size="-1"><? echo $lang_file;?><br></font></b></td>
 <td>
 <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="thefile" type="file" id="thefile">


</td>
</tr>

<tr>
 <td colspan=2><input type="Submit" name="submit" value="<? echo $lang_update;?>"></td>
</tr>
</form>
</table>
<?
}
else
{

$uploadDir = '../myfiles/';

$fileName = $_FILES['thefile']['name'];
$paypalname = $_POST['paypalname'];
$price = $_POST['price'];

if ($fileName != "")
{

$myFile = $uploadDir . $origfilename;
unlink($myFile);

$filename = $_FILES['thefile']['name'];
$tmpname = $_FILES['thefile']['tmp_name'];
$fileSize = $_FILES['thefile']['size'];
$fileType = $_FILES['thefile']['type'];




$ext = substr(strrchr($filename, "."), 1);

$filePath = $uploadDir . $filename;

$result = move_uploaded_file(stripslashes($tmpname), stripslashes($filePath));
chmod(stripslashes($filePath), 0777);
}
else
{
$filename = $origfilename;
}

if (!result)
{
echo "File upload error.";
}

 // generate and execute query
 $query = "UPDATE files SET filename = '$filename', paypalname = '$paypalname', price = '$price' WHERE id = '$id'";
 $result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());

 // print result
echo "<div class=\"alert\">$lang_update_succesful</div>";

 // close database connection
 mysql_close($connect);
 }
 }
?>
</body>
</html>

PHP script for Language Features

Currently for backward-compatibility purposes, most internal functions
do not throw exceptions. However, new extensions make use of this capability,
and you can use it in your own source code. Also, similar to the already existing
set_error_handler()
, you may use
set_exception_handler()
to catch an
unhandled exception before the script terminates

 

class SQLException extends Exception {
public $problem;
function __construct($problem) {
$this->problem = $problem;
}
}
try {
...
throw new SQLException("Couldn't connect to database");
...
} catch (SQLException $e) {
print "Caught an SQLException with problem $obj->problem";
} catch (Exception $e) {
print "Caught unrecognized exception";

&amp;nbsp;

PHP script for Object-Oriented Model

The OO model
also had support for inheritance and allowed a class (and object) to aggregate
both methods and properties, but not much more. When Zeev and Andi Gutmans
rewrote the scripting engine for PHP 4, it was a completely new engine;
it ran much faster, was more stable, and boasted more features. However, the
OO model first introduced in PHP 3 was barely touched.

class Person {
var $name;
function getName()
{
return $this->name;
}
function setName($name)
{
$this->name = $name;
}
function Person($name)
{
$this->setName($name);
}
}
function changeName($person, $name)
{
$person->setName($name);
}
$person = new Person("Andi");
changeName($person, "Stig");
print $person->getName();

&amp;nbsp;

 

PHP Scripts for xtCommerce E-Commerce

Xt:Commerce is developed as a powerful ecommerce webcart shop system for small, medium and full-sized merchants as well as wholesalers. Its full functionality enables you to strengthen your position in the fast growing ecommerce shopping cart market. xt:Commerce is released as a free opensource shopping cart software (GNU/GPL) with a broad spectrum of ecommerce functions, as dynamic and powerfull as expensive ecommerce shopping cart systems.

 

<?php
/* -----------------------------------------------------------------------------------------
 $Id: application_top.php,v 1.20 2004/04/25 16:30:44 fanta2k Exp $

 XT-Commerce - community made shopping
 http://www.xt-commerce.com

 Copyright (c) 2003 XT-Commerce
 -----------------------------------------------------------------------------------------
 based on:
 (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
 (c) 2002-2003 osCommerce(application_top.php,v 1.273 2003/05/19); www.oscommerce.com
 (c) 2003     nextcommerce (application_top.php,v 1.54 2003/08/25); www.nextcommerce.org

 Released under the GNU General Public License
 -----------------------------------------------------------------------------------------
 Third Party contribution:
 Add A Quickie v1.0 Autor  Harald Ponce de Leon

 Credit Class/Gift Vouchers/Discount Coupons (Version 5.10)
 http://www.oscommerce.com/community/contributions,282
 Copyright (c) Strider | Strider@oscworks.com
 Copyright (c  Nick Stanko of UkiDev.com, nick@ukidev.com
 Copyright (c) Andre ambidex@gmx.net
 Copyright (c) 2001,2002 Ian C Wilson http://www.phesis.org


 Released under the GNU General Public License
 ---------------------------------------------------------------------------------------*/


 // start the timer for the page parse time log
 define('PAGE_PARSE_START_TIME', microtime());

 // set the level of error reporting
 error_reporting(E_ALL &amp; ~E_NOTICE);
//  error_reporting(E_ALL);

 // Set the local configuration parameters - mainly for developers - if exists else the mainconfigure
 if (file_exists('includes/local/configure.php')) {
 include('includes/local/configure.php');
 } else {
 include('includes/configure.php');
 }



 // define the project version
 define('PROJECT_VERSION', 'XT-Commerce v2.0 RC1.2');

 // set the type of request (secure or not)
 $request_type = (getenv('HTTPS') == 'on') ? 'SSL' : 'NONSSL';

 // set php_self in the local scope
 $PHP_SELF = $_SERVER['PHP_SELF'];

 // include the list of project filenames
 require(DIR_WS_INCLUDES . 'filenames.php');

 // include the list of project database tables
 require(DIR_WS_INCLUDES . 'database_tables.php');


 // Below are some defines which affect the way the discount coupon/gift voucher system work
// Be careful when editing them.
//
// Set the length of the redeem code, the longer the more secure
 define('SECURITY_CODE_LENGTH', '10');
//
// The settings below determine whether a new customer receives an incentive when they first signup
//
// Set the amount of a Gift Voucher that the new signup will receive, set to 0 for none
//  define('NEW_SIGNUP_GIFT_VOUCHER_AMOUNT', '10');  // placed in the admin configuration mystore
//
// Set the coupon ID that will be sent by email to a new signup, if no id is set then no email :)
//  define('NEW_SIGNUP_DISCOUNT_COUPON', '3'); // placed in the admin configuration mystore

 // Store DB-Querys in a Log File
 define('STORE_DB_TRANSACTIONS', 'false');

 // include used functions
 require_once(DIR_FS_INC . 'xtc_db_connect.inc.php');
 require_once(DIR_FS_INC . 'xtc_db_close.inc.php');
 require_once(DIR_FS_INC . 'xtc_db_error.inc.php');
 require_once(DIR_FS_INC . 'xtc_db_perform.inc.php');
 require_once(DIR_FS_INC . 'xtc_db_query.inc.php');
 require_once(DIR_FS_INC . 'xtc_db_fetch_array.inc.php');
 require_once(DIR_FS_INC . 'xtc_db_num_rows.inc.php');
 require_once(DIR_FS_INC . 'xtc_db_data_seek.inc.php');
 require_once(DIR_FS_INC . 'xtc_db_insert_id.inc.php');
 require_once(DIR_FS_INC . 'xtc_db_free_result.inc.php');
 require_once(DIR_FS_INC . 'xtc_db_fetch_fields.inc.php');
 require_once(DIR_FS_INC . 'xtc_db_output.inc.php');
 require_once(DIR_FS_INC . 'xtc_db_input.inc.php');
 require_once(DIR_FS_INC . 'xtc_db_prepare_input.inc.php');
 require_once(DIR_FS_INC . 'xtc_get_top_level_domain.inc.php');
 require_once(DIR_FS_INC . 'xtc_not_null.inc.php');
 require_once(DIR_FS_INC . 'xtc_update_whos_online.inc.php');

 require_once(DIR_FS_INC . 'xtc_activate_banners.inc.php');
 require_once(DIR_FS_INC . 'xtc_expire_banners.inc.php');
 require_once(DIR_FS_INC . 'xtc_expire_specials.inc.php');
 require_once(DIR_FS_INC . 'xtc_href_link.inc.php');
 require_once(DIR_FS_INC . 'xtc_parse_category_path.inc.php');
 require_once(DIR_FS_INC . 'xtc_get_product_path.inc.php');
 require_once(DIR_FS_INC . 'xtc_get_parent_categories.inc.php');
 require_once(DIR_FS_INC . 'xtc_redirect.inc.php');
 require_once(DIR_FS_INC . 'xtc_get_uprid.inc.php');
 require_once(DIR_FS_INC . 'xtc_get_all_get_params.inc.php');
 require_once(DIR_FS_INC . 'xtc_has_product_attributes.inc.php');
 require_once(DIR_FS_INC . 'xtc_image.inc.php');
 require_once(DIR_FS_INC . 'xtc_get_products_attribute_price.inc.php');
 require_once(DIR_FS_INC . 'xtc_check_stock_attributes.inc.php');
 require_once(DIR_FS_INC . 'xtc_currency_exists.inc.php');
 require_once(DIR_FS_INC . 'xtc_draw_separator.inc.php');
 require_once(DIR_FS_INC . 'xtc_remove_non_numeric.inc.php');
 require_once(DIR_FS_INC . 'xtc_get_ip_address.inc.php');
 require_once(DIR_FS_INC . 'xtc_setcookie.inc.php');
 require_once(DIR_FS_INC . 'xtc_check_agent.inc.php');
 require_once(DIR_FS_INC . 'xtc_count_cart.inc.php');
 require_once(DIR_FS_INC . 'xtc_get_qty.inc.php');
 require_once(DIR_FS_INC . 'create_coupon_code.inc.php');
 require_once(DIR_FS_INC . 'xtc_gv_account_update.inc.php');
 require_once(DIR_FS_INC . 'xtc_get_tax_rate_from_desc.inc.php');


 // make a connection to the database... now
 xtc_db_connect() or die('Unable to connect to database server!');

 // set the application parameters
 $configuration_query = xtc_db_query('select configuration_key as cfgKey, configuration_value as cfgValue from ' . TABLE_CONFIGURATION);
 while ($configuration = xtc_db_fetch_array($configuration_query)) {
 define($configuration['cfgKey'], $configuration['cfgValue']);
 }

 // if gzip_compression is enabled, start to buffer the output
 if ( (GZIP_COMPRESSION == 'true') &amp;&amp; ($ext_zlib_loaded = extension_loaded('zlib')) &amp;&amp; (PHP_VERSION >= '4') ) {
 if (($ini_zlib_output_compression = (int)ini_get('zlib.output_compression')) < 1) {
 ob_start('ob_gzhandler');
 } else {
 ini_set('zlib.output_compression_level', GZIP_LEVEL);
 }
 }

 // set the HTTP GET parameters manually if search_engine_friendly_urls is enabled
 if (SEARCH_ENGINE_FRIENDLY_URLS == 'true') {
 if (strlen(getenv('PATH_INFO')) > 1) {
 $GET_array = array();
 $PHP_SELF = str_replace(getenv('PATH_INFO'), '', $PHP_SELF);
 $vars = explode('/', substr(getenv('PATH_INFO'), 1));
 for ($i=0, $n=sizeof($vars); $i<$n; $i++) {
 if (strpos($vars[$i], '[]')) {
 $GET_array[substr($vars[$i], 0, -2)][] = $vars[$i+1];
 } else {
 $_GET[$vars[$i]] = $vars[$i+1];
 }
 $i++;
 }

 if (sizeof($GET_array) > 0) {
 while (list($key, $value) = each($GET_array)) {
 $_GET[$key] = $value;
 }
 }
 }
 }

 // set the top level domains
 $http_domain = xtc_get_top_level_domain(HTTP_SERVER);
 $https_domain = xtc_get_top_level_domain(HTTPS_SERVER);
 $current_domain = (($request_type == 'NONSSL') ? $http_domain : $https_domain);

 // include cache functions if enabled
 // if (USE_CACHE == 'true') include(DIR_WS_FUNCTIONS . 'cache.php');

 // include shopping cart class
 require(DIR_WS_CLASSES . 'shopping_cart.php');

 // include navigation history class
 require(DIR_WS_CLASSES . 'navigation_history.php');

 // some code to solve compatibility issues
 require(DIR_WS_FUNCTIONS . 'compatibility.php');

 // define how the session functions will be used
 require(DIR_WS_FUNCTIONS . 'sessions.php');

 // set the session name and save path
 session_name('XTCsid');
 session_save_path(SESSION_WRITE_DIRECTORY);

 // set the session cookie parameters
 if (function_exists('session_set_cookie_params')) {
 session_set_cookie_params(0, '/', (xtc_not_null($current_domain) ? '.' . $current_domain : ''));
 } elseif (function_exists('ini_set')) {
 ini_set('session.cookie_lifetime', '0');
 ini_set('session.cookie_path', '/');
 ini_set('session.cookie_domain', (xtc_not_null($current_domain) ? '.' . $current_domain : ''));
 }

 // set the session ID if it exists
 if (isset($_POST[session_name()])) {
 session_id($_POST[session_name()]);
 } elseif ( ($request_type == 'SSL') &amp;&amp; isset($_GET[session_name()]) ) {
 session_id($_GET[session_name()]);
 }

 // start the session
 $session_started = false;
 if (SESSION_FORCE_COOKIE_USE == 'True') {
 xtc_setcookie('cookie_test', 'please_accept_for_session', time()+60*60*24*30, '/', $current_domain);

 if (isset($HTTP_COOKIE_VARS['cookie_test'])) {
 session_start();
 $session_started = true;
 }
 } elseif (SESSION_BLOCK_SPIDERS == 'True') {
 $user_agent = strtolower(getenv('HTTP_USER_AGENT'));
 $spider_flag = false;

 if (xtc_not_null($user_agent)) {
 $spiders = file(DIR_WS_INCLUDES . 'spiders.txt');

 for ($i=0, $n=sizeof($spiders); $i<$n; $i++) {
 if (xtc_not_null($spiders[$i])) {
 if (is_integer(strpos($user_agent, trim($spiders[$i])))) {
 $spider_flag = true;
 break;
 }
 }
 }
 }

 if ($spider_flag == false) {
 session_start();
 $session_started = true;
 }
 } else {
 session_start();
 $session_started = true;
 }

 // verify the ssl_session_id if the feature is enabled
 if ( ($request_type == 'SSL') &amp;&amp; (SESSION_CHECK_SSL_SESSION_ID == 'True') &amp;&amp; (ENABLE_SSL == true) &amp;&amp; ($session_started == true) ) {
 $ssl_session_id = getenv('SSL_SESSION_ID');
 if (!session_is_registered('SSL_SESSION_ID')) {
 $_SESSION['SESSION_SSL_ID'] = $ssl_session_id;
 }

 if ($_SESSION['SESSION_SSL_ID'] != $ssl_session_id) {
 session_destroy();
 xtc_redirect(xtc_href_link(FILENAME_SSL_CHECK));
 }
 }

 // verify the browser user agent if the feature is enabled
 if (SESSION_CHECK_USER_AGENT == 'True') {
 $http_user_agent = getenv('HTTP_USER_AGENT');
 if (!session_is_registered('SESSION_USER_AGENT')) {
 $_SESSION['SESSION_USER_AGENT'] = $http_user_agent;
 }

 if ($_SESSION['SESSION_USER_AGENT'] != $http_user_agent) {
 session_destroy();
 xtc_redirect(xtc_href_link(FILENAME_LOGIN));
 }
 }

 // verify the IP address if the feature is enabled
 if (SESSION_CHECK_IP_ADDRESS == 'True') {
 $ip_address = xtc_get_ip_address();
 if (!isset($_SESSION['SESSION_IP_ADDRESS'])) {
 $_SESSION['SESSION_IP_ADDRESS'] = $ip_address;
 }

 if ($_SESSION['SESSION_IP_ADDRESS'] != $ip_address) {
 session_destroy();
 xtc_redirect(xtc_href_link(FILENAME_LOGIN));
 }
 }

 // create the shopping cart &amp; fix the cart if necesary
 if (!is_object($_SESSION['cart'])) {
 $_SESSION['cart'] = new shoppingCart;
 }

 // include currencies class and create an instance
 require(DIR_WS_CLASSES . 'currencies.php');
 $currencies = new currencies();

 // include the mail classes
 if (EMAIL_TRANSPORT == 'sendmail') include(DIR_WS_CLASSES . 'class.phpmailer.php');
 if (EMAIL_TRANSPORT == 'smtp') include(DIR_WS_CLASSES . 'class.smtp.php');


 // set the language
 if (!isset($_SESSION['language']) || isset($_GET['language'])) {

 include(DIR_WS_CLASSES . 'language.php');
 $lng = new language($_GET['language']);

 if (!isset($_GET['language'])) $lng->get_browser_language();

 $_SESSION['language'] = $lng->language['directory'];
 $_SESSION['languages_id'] = $lng->language['id'];
 $_SESSION['language_charset'] = $lng->language['language_charset'];
 }

 // include the language translations
 require(DIR_WS_LANGUAGES . $_SESSION['language'].'/'.$_SESSION['language'] . '.php');

 // currency
 if (!isset($_SESSION['currency']) || isset($_GET['currency']) || ( (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') &amp;&amp; (LANGUAGE_CURRENCY != $_SESSION['currency']) ) ) {

 if (isset($_GET['currency'])) {
 if (!$_SESSION['currency'] = xtc_currency_exists($_GET['currency'])) $_SESSION['currency'] = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;
 } else {
 $_SESSION['currency'] = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;
 }
 }
 if (isset($_SESSION['currency']) &amp;&amp; $_SESSION['currency'] == '') {
 $_SESSION['currency'] = DEFAULT_CURRENCY;
 }



 // Shopping cart actions
 if (isset($_GET['action'])) {
 // redirect the customer to a friendly cookie-must-be-enabled page if cookies are disabled
 if ($session_started == false) {
 xtc_redirect(xtc_href_link(FILENAME_COOKIE_USAGE));
 }

 if (DISPLAY_CART == 'true') {
 $goto =  FILENAME_SHOPPING_CART;
 $parameters = array('action', 'cPath', 'products_id', 'pid');
 } else {
 $goto = basename($PHP_SELF);
 if ($_GET['action'] == 'buy_now') {
 $parameters = array('action', 'pid', 'products_id');
 } else {
 $parameters = array('action', 'pid');
 }
 }
 switch ($_GET['action']) {
 // customer wants to update the product quantity in their shopping cart
 case 'update_product':
 for ($i = 0, $n = sizeof($_POST['products_id']); $i < $n; $i++) {
 if (in_array($_POST['products_id'][$i], (is_array($_POST['cart_delete']) ? $_POST['cart_delete'] : array()))) {
 $_SESSION['cart']->remove($_POST['products_id'][$i]);
 } else {
 if ($_POST['cart_quantity'][$i]>MAX_PRODUCTS_QTY) $_POST['cart_quantity'][$i]=MAX_PRODUCTS_QTY;
 $attributes = ($_POST['id'][$_POST['products_id'][$i]]) ? $_POST['id'][$_POST['products_id'][$i]] : '';
 $_SESSION['cart']->add_cart($_POST['products_id'][$i], xtc_remove_non_numeric($_POST['cart_quantity'][$i]), $attributes, false);
 }
 }
 xtc_redirect(xtc_href_link($goto, xtc_get_all_get_params($parameters)));
 break;
 // customer adds a product from the products page
 case 'add_product':
 if (isset($_POST['products_id']) &amp;&amp; is_numeric($_POST['products_id'])) {
 if ($_POST['products_qty']>MAX_PRODUCTS_QTY) $_POST['products_qty']=MAX_PRODUCTS_QTY;
 $_SESSION['cart']->add_cart((int)$_POST['products_id'], $_SESSION['cart']->get_quantity(xtc_get_uprid($_POST['products_id'], $_POST['id']))+$_POST['products_qty'], $_POST['id']);
 }
 xtc_redirect(xtc_href_link($goto, xtc_get_all_get_params($parameters)));
 break;

 case 'check_gift':
 require_once(DIR_FS_INC .'xtc_collect_posts.inc.php');
 xtc_collect_posts();
 // echo $_POST['gift_code'];
 break;

 // customer wants to add a quickie to the cart (called from a box)
 case 'add_a_quickie' :

 if (GROUP_CHECK=='true') {
 $group_check="and group_ids LIKE '%c_".$_SESSION['customers_status']['customers_status_id']."_group%'";
 }

 $quickie_query = xtc_db_query("select
 products_fsk18,
 products_id from "
. TABLE_PRODUCTS . "
 where products_model = '"
. $_POST['quickie'] . "'
 "
.$group_check."
 "
);
 if (!xtc_db_num_rows($quickie_query)) {
 if (GROUP_CHECK=='true') {
 $group_check="and group_ids LIKE '%c_".$_SESSION['customers_status']['customers_status_id']."_group%'";
 }
 $quickie_query = xtc_db_query("select
 products_fsk18,
 products_id from "
. TABLE_PRODUCTS . "
 where products_model LIKE '%"
. $_POST['quickie'] . "%'
 "
.$group_check."
 "
);
 }
 if (xtc_db_num_rows($quickie_query) != 1) {
 xtc_redirect(xtc_href_link(FILENAME_ADVANCED_SEARCH_RESULT, 'keywords=' . $_POST['quickie'], 'NONSSL'));
 }
 $quickie = xtc_db_fetch_array($quickie_query);
 if (xtc_has_product_attributes($quickie['products_id'])) {
 xtc_redirect(xtc_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $quickie['products_id'], 'NONSSL'));
 } else {
 if ($quickie['products_fsk18']=='1' &amp;&amp; $_SESSION['customers_status']['customers_fsk18']=='1') {
 xtc_redirect(xtc_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $quickie['products_id'], 'NONSSL'));
 }
 if ($_SESSION['customers_status']['customers_fsk18_display']=='0' &amp;&amp; $quickie['products_fsk18']=='1') {
 xtc_redirect(xtc_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $quickie['products_id'], 'NONSSL'));
 }
 $_SESSION['cart']->add_cart($quickie['products_id'], 1);
 xtc_redirect(xtc_href_link($goto, xtc_get_all_get_params(array('action')), 'NONSSL'));
 }
 break;

 // performed by the 'buy now' button in product listings and review page
 case 'buy_now':
 if (isset($_GET['BUYproducts_id'])) {
 // check permission to view product
 $permission_query=xtc_db_query("SELECT group_ids from ".TABLE_PRODUCTS." where products_id='".(int)$_GET['BUYproducts_id']."'");
 $permission=xtc_db_fetch_array($permission_query);
 if (GROUP_CHECK=='true') {

 if (!strstr($permission['group_ids'],'c_'.$_SESSION['customers_status']['customers_status_id'].'_group')) {
 xtc_redirect(xtc_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . (int)$_GET['BUYproducts_id']));
 }
 }
 if (xtc_has_product_attributes($_GET['BUYproducts_id'])) {
 xtc_redirect(xtc_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . (int)$_GET['BUYproducts_id']));
 } else {
 $_SESSION['cart']->add_cart((int)$_GET['BUYproducts_id'], $_SESSION['cart']->get_quantity((int)$_GET['BUYproducts_id'])+1);
 }
 }
 xtc_redirect(xtc_href_link($goto, xtc_get_all_get_params(array('action'))));
 break;
 case 'notify':
 if (isset($_SESSION['customer_id'])) {
 if (isset($_GET['products_id'])) {
 $notify = (int)$_GET['products_id'];
 } elseif (isset($_GET['notify'])) {
 $notify = $_GET['notify'];
 } elseif (isset($_POST['notify'])) {
 $notify = $_POST['notify'];
 } else {
 xtc_redirect(xtc_href_link(basename($PHP_SELF), xtc_get_all_get_params(array('action', 'notify'))));
 }
 if (!is_array($notify)) $notify = array($notify);
 for ($i = 0, $n = sizeof($notify); $i < $n; $i++) {
 $check_query = xtc_db_query("select count(*) as count from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . $notify[$i] . "' and customers_id = '" . (int)$_SESSION['customer_id'] . "'");
 $check = xtc_db_fetch_array($check_query);
 if ($check['count'] < 1) {
 xtc_db_query("insert into " . TABLE_PRODUCTS_NOTIFICATIONS . " (products_id, customers_id, date_added) values ('" . $notify[$i] . "', '" . (int)$_SESSION['customer_id'] . "', now())");
 }
 }
 xtc_redirect(xtc_href_link(basename($PHP_SELF), xtc_get_all_get_params(array('action', 'notify'))));
 } else {
 //
 xtc_redirect(xtc_href_link(FILENAME_LOGIN, '', 'SSL'));
 }
 break;
 case 'notify_remove':
 if (isset($_SESSION['customer_id']) &amp;&amp; isset($_GET['products_id'])) {
 $check_query = xtc_db_query("select count(*) as count from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . (int)$_GET['products_id'] . "' and customers_id = '" . (int)$_SESSION['customer_id'] . "'");
 $check = xtc_db_fetch_array($check_query);
 if ($check['count'] > 0) {
 xtc_db_query("delete from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . (int)$_GET['products_id'] . "' and customers_id = '" . (int)$_SESSION['customer_id'] . "'");
 }
 xtc_redirect(xtc_href_link(basename($PHP_SELF), xtc_get_all_get_params(array('action'))));
 } else {

 xtc_redirect(xtc_href_link(FILENAME_LOGIN, '', 'SSL'));
 }
 break;
 case 'cust_order':
 if (isset($_SESSION['customer_id']) &amp;&amp; isset($_GET['pid'])) {
 if (xtc_has_product_attributes((int)$_GET['pid'])) {
 xtc_redirect(xtc_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . (int)$_GET['pid']));
 } else {
 $_SESSION['cart']->add_cart((int)$_GET['pid'], $_SESSION['cart']->get_quantity((int)$_GET['pid'])+1);
 }
 }
 xtc_redirect(xtc_href_link($goto, xtc_get_all_get_params($parameters)));
 break;
 }
 }

 // write customers status in session
 require(DIR_WS_INCLUDES . 'write_customers_status.php');

 // include the who's online functions
 xtc_update_whos_online();

 // split-page-results
 require(DIR_WS_CLASSES . 'split_page_results.php');

 // infobox
 require(DIR_WS_CLASSES . 'boxes.php');

 // auto activate and expire banners
 xtc_activate_banners();
 xtc_expire_banners();

 // auto expire special products
 xtc_expire_specials();

 // calculate category path
 if (isset($_GET['cPath'])) {
 $cPath = $_GET['cPath'];
 } elseif (isset($_GET['products_id']) &amp;&amp; !isset($_GET['manufacturers_id'])) {
 $cPath = xtc_get_product_path((int)$_GET['products_id']);
 } else {
 $cPath = '';
 }

 if (xtc_not_null($cPath)) {
 $cPath_array = xtc_parse_category_path($cPath);
 $cPath = implode('_', $cPath_array);
 $current_category_id = $cPath_array[(sizeof($cPath_array)-1)];
 } else {
 $current_category_id = 0;
 }

 // include the breadcrumb class and start the breadcrumb trail
 require(DIR_WS_CLASSES . 'breadcrumb.php');
 $breadcrumb = new breadcrumb;

 $breadcrumb->add(HEADER_TITLE_TOP, HTTP_SERVER);
 $breadcrumb->add(HEADER_TITLE_CATALOG, xtc_href_link(FILENAME_DEFAULT));

 // add category names or the manufacturer name to the breadcrumb trail
 if (isset($cPath_array)) {
 for ($i=0, $n=sizeof($cPath_array); $i<$n; $i++) {
 if (GROUP_CHECK=='true') {
 $group_check="and c.group_ids LIKE '%c_".$_SESSION['customers_status']['customers_status_id']."_group%'";
 }
 $categories_query = xtc_db_query("select
 cd.categories_name
 from "
. TABLE_CATEGORIES_DESCRIPTION . " cd,
 "
.TABLE_CATEGORIES." c
 where cd.categories_id = '"
. $cPath_array[$i] . "'
 and c.categories_id=cd.categories_id
 "
.$group_check."
 and cd.language_id='"
. (int)$_SESSION['languages_id'] . "'");
 if (xtc_db_num_rows($categories_query) > 0) {
 $categories = xtc_db_fetch_array($categories_query);
 $breadcrumb->add($categories['categories_name'], xtc_href_link(FILENAME_DEFAULT, 'cPath=' . implode('_', array_slice($cPath_array, 0, ($i+1)))));
 } else {
 break;
 }
 }
 } elseif (isset($_GET['manufacturers_id'])) {
 $manufacturers_query = xtc_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$_GET['manufacturers_id'] . "'");
 $manufacturers = xtc_db_fetch_array($manufacturers_query);
 $breadcrumb->add($manufacturers['manufacturers_name'], xtc_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . (int)$_GET['manufacturers_id']));
 }

 // add the products model to the breadcrumb trail
 if (isset($_GET['products_id'])) {
 $model_query = xtc_db_query("select products_model from " . TABLE_PRODUCTS . " where products_id = '" . (int)$_GET['products_id'] . "'");
 $model = xtc_db_fetch_array($model_query);
 $breadcrumb->add($model['products_model'], xtc_href_link(FILENAME_PRODUCT_INFO, 'cPath=' . $cPath . '&amp;products_id=' . (int)$_GET['products_id']));
 }

 // initialize the message stack for output messages
 require(DIR_WS_CLASSES . 'message_stack.php');
 $messageStack = new messageStack;

 // set which precautions should be checked
 define('WARN_INSTALL_EXISTENCE', 'true');
 define('WARN_CONFIG_WRITEABLE', 'true');
 define('WARN_SESSION_DIRECTORY_NOT_WRITEABLE', 'false');
 define('WARN_SESSION_AUTO_START', 'true');
 define('WARN_DOWNLOAD_DIRECTORY_NOT_READABLE', 'true');

 // for tracking of customers
 $_SESSION['user_info'] = array();
 if (!$_SESSION['user_info']['user_ip']) {
 $_SESSION['user_info']['user_ip'] = $_SERVER['REMOTE_ADDR'];
//    $user_info['user_ip_date'] =  value will be in fact added when login ;
 $_SESSION['user_info']['user_host'] = gethostbyaddr( $_SERVER['REMOTE_ADDR'] );;
 $_SESSION['user_info']['advertiser'] = $_GET['ad'];
 $_SESSION['user_info']['referer_url'] = $_SERVER['HTTP_REFERER'];
 }

 // Include Template Engine
 require(DIR_WS_CLASSES . 'smarty_2.6.2/Smarty.class.php');

 if (isset($_SESSION['customer_id'])) {
 $account_type_query=xtc_db_query("SELECT
 account_type,
 customers_default_address_id
 FROM
 "
.TABLE_CUSTOMERS."
 WHERE customers_id = '"
.(int)$_SESSION['customer_id']."'");
 $account_type=xtc_db_fetch_array($account_type_query);

 // check if zone id is unset bug #0000169
 if (!isset($_SESSION['customer_country_id'])) {
 $zone_query=xtc_db_query("SELECT  entry_country_id
 FROM "
.TABLE_ADDRESS_BOOK."
 WHERE customers_id='"
.(int)$_SESSION['customer_id']."'
 and address_book_id='"
.$account_type['customers_default_address_id']."'");

 $zone=xtc_db_fetch_array($zone_query);
 $_SESSION['customer_country_id']=$zone['entry_country_id'];
 }
 $_SESSION['account_type']=$account_type['account_type'];
 } else {
 $_SESSION['account_type']='0';
 }

 // modification for nre graduated system
 unset($_SESSION['actual_content']);
 xtc_count_cart();



?>

&amp;nbsp;

PHP Scripts for Stock Port E-Commerce

This script allows you to display Yahoo! Finance Stock Quotes on your web site. You can view individual stocks by entering the proper Ticker Symbol into the corresponding form.This script is very easy to install, use and customize.

 

<H1>Stocks</H1>

<?

include ("header.php");

IF (!isset($tickersymbol))
{
echo ("&amp;nbsp;&amp;nbsp;&amp;nbsp;Welcome to Stock Port. Here you can view individual stocks by entering the proper Ticker Symbol into the proceeding form.<p>");

?>

<div align="center">
<table border=0 cellpadding=0 cellspacing=0 cols=2 width=525>
<tr>
<td width=245 align="center">
<IMG SRC="http://a204.g.akamai.net/f/204/507/5m/charts-l.quote.com:443/GIF?User=demo&amp;Pswd=demo&amp;DataType=GIF&amp;Symbol=INDEX:COMPX&amp;Interval=D&amp;Display=17&amp;Study=None&amp;Wd=240&amp;Ht=200">
</td>
<td width=280 align="center">
<IMG SRC="http://a204.g.akamai.net/f/204/507/5m/charts-l.quote.com:443/GIF?User=demo&amp;Pswd=demo&amp;DataType=GIF&amp;Symbol=INDEX:INDU&amp;Interval=D&amp;Display=17&amp;Study=None&amp;Wd=275&amp;Ht=200">
</td>
</tr>
</table>
</div>



<?

}


ELSE IF (isset($tickersymbol))
{

$open = fopen("http://quote.yahoo.com/d/quotes.csv?s=$tickersymbol&amp;f=sl1d1t1c1ohgv&amp;e=.csv", "r");
$read = fread($open, 2000);
fclose($open);

$read = str_replace("\"", "", $read);
$read = explode(",", $read);

IF ($read[1] == 0)
{
echo ("The symbol you provided (<b>\"$tickersymbol\"</b>) doesn't appear to be registered<BR></FONT><BR>");
}

ELSE
{

?>

<div align="center">

<!-- YOU CAN CHANGE THE TABLE BELOW TO MATCH YOUR WEB SITE -->

<TABLE BORDER=1 BORDERCOLOR="#006699" CELLSPACING=0 CELLPADDING=0 WIDTH=500>
<TR>
<TD width=150><b>Ticker Symbol</b>:</TD>
<TD><? echo ("$read[0]"); ?></TD>
</TR>
<TR>
<TD width=150><b>Last Trade</b>:</TD>
<TD><? echo ("$read[1]"); ?></TD>
</TR>
<TR>
<TD width=150><b>Last Trade At</b>:</TD>
<TD><? echo ("$read[2] $read[3]"); ?></TD>
</TR>
<TR>
<TD width=150><b>Change</b>:</TD>
<TD><? echo ("$read[4]"); ?></TD>
</TR>
<TR>
<TD width=150><b>Opened At</b>:</TD>
<TD><? echo ("$read[5]"); ?></TD>
</TR>
<TR>
<TD width=150><b>Day Range</b>:</TD>
<TD><? echo ("$read[6] - $read[7]"); ?></TD>
</TR>
<TR>
<TD width=150><b>Volume</b>:</TD>
<TD><? echo ("$read[8]"); ?></TD>
</TABLE>
<p>
<img src="http://ichart.yahoo.com/t?s=<? echo ("$read[0]"); ?>">
</div>

<?

}

}

?>

<p>

<div align="center">
<FORM ACTION="<? echo ("$PHP_SELF"); ?>" METHOD="POST">
<table border=0 cols=2 width=200>
<tr>
<td width=100>
Ticker Symbol:
</td>
<td width=100>
<input type=text name="tickersymbol">
</td>
</tr>
<tr align="center">
<td colspan=2>
<input type=submit value="Check Stock">
</td>
</tr>
</table>
</FORM>
</div>

<?
echo ("<center>This Script Provided Free By Whole Hog Software. This, and other free scripts are available at <A HREF=\"http://www.wholehogsoftware.com\">http://www.wholehogsoftware.com</a>.</center>");
include ("footer.php");
?>

&amp;nbsp;

&amp;nbsp;

Scripts for Zen Database Manager E-Commerce

The first part is a PHP addon for the admin section of Zen Cart that allows export/import of records into the Zen Cart database. It will allow record insert, update and delete. The second part is a windows application written in C# that will let you manage your Zen Cart product database. You will be able to manage Manufacturers, Categories and Products. There will be full support for multiple languages in Zen Cart.

 

<?php
//     Zen Database Manager (Database Import/Export For ZenCart)
//     Copyright (C) 2005 Jarrod Connolly
//
//     This program is free software; you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation; either version 2 of the License, or
//     (at your option) any later version.
//
//     This program is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
//
//     You should have received a copy of the GNU General Public License
//     along with this program; if not, write to the Free Software
//     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


 // include library for working with zip files
 require_once('pclzip.lib.php');


 function cleartempfolder()
 {
 global $tempdir, $tablenamelist;

 foreach ($tablenamelist as $i => $tablename)
 {
 $filename = $tempdir.$tablename.'.xml';
 if( file_exists($filename) )
 {
 unlink( $filename );
 }
 }

 if( file_exists($tempdir.'export.zip') )
 {
 unlink( $tempdir.'export.zip' );
 }
 }
 function createexportfile()
 {
 global $tempdir, $tablenamelist;

 // list of xml files for zip
 $filelist = array();

 foreach ($tablenamelist as $i => $tablename)
 {
 $filename = $tempdir.$tablename.'.xml';

 // query database and save xml file
 $xml = BuildZenXML('select * from '.$tablename, $tablename);

 //save xml data to file
 WriteXMLDataToFile( $xml, $filename );

 // add filename to array
 $filelist[]=$filename;
 }

 // create zip archive for download
 $archive = new PclZip($tempdir.'export.zip');
 $v_list = $archive->add( $filelist, PCLZIP_OPT_REMOVE_PATH, $tempdir );
 if ($v_list == 0)
 {
 die("Error : ".$archive->errorInfo(true));
 }
 }

 function downloadfile()
 {
 global $tempdir;

 $fileName = "export.zip"; // supply a file name.
 $fileString=$tempdir.$fileName; // combine the path and file

 // translate file name properly for Internet Explorer.
 if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
 {
 $fileName = preg_replace('/\./', '%2e', $fileName, substr_count($fileName, '.') - 1);
 }

 // make sure the file exists before sending headers
 if(!$fdl=fopen($fileString,'r'))
 {
 die("Cannot Open File!");
 }
 else
 {
 header("Cache-Control: ");// leave blank to avoid IE errors
 header("Pragma: ");// leave blank to avoid IE errors
 header("Content-type: application/octet-stream");
 header("Content-Disposition: attachment; filename=\"".$fileName."\"");
 header("Content-length:".(string)(filesize($fileString)));
 sleep(1);
 fpassthru($fdl);
 fclose($fd1);
 }
 }

 function testtempdir()
 {
 global $tempdir;

 if (!is_dir("$tempdir"))
 {
 echo "<br>The directory <b>(" . $tempdir . ")</b> doesn't exist";
 }
 if (!is_writeable("$tempdir"))
 {
 echo "<br>The directory <b>(" . $tempdir . ")</b> is NOT writable, Please Chmod (777)";
 }
 }


 function moveuploadfile()
 {
 global $tempdir;

 if (is_uploaded_file($_FILES['uploadedfile']['tmp_name']))
 {
 //get file size
 $size = $_FILES['uploadedfile']['size'];

 //get filename
 //$filename =  $_FILES['uploadedfile']['name'];
 $filename = 'export.zip';

 // put uploaded file in temp folder
 move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$tempdir.$filename);
 }
 }


 function unpackuploadfile()
 {
 global $tempdir;

 $archive = new PclZip($tempdir.'export.zip');
 $archive->extract(PCLZIP_OPT_PATH, $tempdir);
 }

 function makedatabasechanges()
 {
 global $tempdir, $tablenamelist;

 foreach ($tablenamelist as $i => $tablename)
 {
 $filename = $tempdir.$tablename.'.xml';

 $data = GetXMLDataFromFile( $filename );

 UpdateDataBase( $data, $tablename );
 }
 }
 function UpdateDataBase( $data, $tablename )
 {
 global $db;

 $parser = xml_parser_create();
 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
 xml_parse_into_struct($parser, $data, $values, $tags);
 xml_parser_free($parser);


 foreach ($tags as $key=>$val)
 {
 if( $key == $tablename )
 {
 $rsTableMeta = $db->MetaColumns($tablename);

 for ($i=0; $i < count($val); $i+=2)
 {
 $query = 'update '.$tablename.' set ';
 $whereclause = '';

 $offset = $val[$i] + 1;
 $len = $val[$i + 1] - $offset;

 $tvalues = array_slice($values, $offset, $len);

 for ($j=0; $j < count($tvalues); $j++)
 {
 $fieldname = $tvalues[$j]["tag"];
 $fieldvalue = mysql_escape_string( $tvalues[$j]["value"] );

 $fieldflags = $rsTableMeta[strtoupper($fieldname)]->flags;
 $flagarray = explode( " ", $fieldflags );

 if( in_array( "primary_key", $flagarray ) )
 {
 if( $whereclause == "" )
 {
 $whereclause = ' where ';
 }
 else
 {
 $whereclause .= ' and ';
 }

 $whereclause .= $fieldname."='".$fieldvalue."'";

 }
 else
 {
 $query .= $fieldname."='".$fieldvalue."',";
 }
 }
 $query = substr($query,0,strlen($query)-1);
 $query .= $whereclause;

 $db->Execute($query);
 }

 }
 }

 }
 function GetXMLDataFromFile( $filename )
 {
 $data = '';

 if (file_exists($filename))
 {
 $f = fopen($filename,'r');
 $data = fread($f,filesize($filename));
 fclose($f);
 }

 return $data;
 }
 function WriteXMLDataToFile( $xmldata, $filename )
 {
 $f = @fopen($filename,'w');
 @fwrite($f,$xmldata);
 @fclose($f);
 }

 function &amp; BuildZenXML($query, $tablename)
 {
 global $db;

 $rs = $db->Execute($query);

 $xml .= '<ZEN>'."\n";

 while (!$rs->EOF)
 {
 $xml .= "\t".'<'.$tablename.'>'."\n";

 $keys = $rs->fields;

 foreach($keys as $FieldName => $FieldValue)
 {
 $content = $FieldValue;

 if( $content != NULL )
 {
 $xml .= "\t\t".'<'.strtolower($FieldName).'>';

 $content =&amp; str_replace( "&amp;", "&amp;amp;", $content );
 $content =&amp; str_replace( ">", "&amp;gt;", $content );
 $content =&amp; str_replace( "<", "&amp;lt;", $content );
 $content =&amp; str_replace( "'", "&amp;apos;", $content );
 $content =&amp; str_replace( '"', "&amp;quot;", $content );

 $xml .= $content;

 $xml .= '</'.$FieldName.'>'."\n";
 }
 }

 $xml .= "\t".'</'.$tablename.'>'."\n";

 $rs->MoveNext();
 $j++;
 }

 $xml .= '</ZEN>'."\n";

 //@$rs->Move(0);


 return $xml;
 }

?>

&amp;nbsp;