<?php
/*
  osCommerce, Open Source E-Commerce Solutions 
http://www.oscommerce.com 

Copyright (c) 2003 osCommerce 

osCommRes, Services Online 
http://www.oscommres.com 
Copyright (c) 2005 osCommRes 

Freeway eCommerce 
http://www.zac-ware.com/freeway 
Copyright (c) 2007 ZacWare

Released under the GNU General Public License
*/ 
// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
// Set the level of error reporting
  error_reporting(E_ALL & ~E_NOTICE);
   $NOGLOBALS_SESSION_DATA=array();
   if (version_compare(phpversion(), "4.5.0", "<")===true || ( strtolower(ini_get("register_long_arrays"))=="on" || strtolower(ini_get("register_long_arrays"))=="1")) {
	   $REGISTER_LONG_ARRAYS=true;
   } else {
		$REGISTER_LONG_ARRAYS=false;
   }
 $_SERVER['SCRIPT_FILENAME']=$_SERVER['DOCUMENT_ROOT'].((strpos($_SERVER['DOCUMENT_ROOT'],"\\")>0)?str_replace("/","\\",$_SERVER['PHP_SELF']):$_SERVER['PHP_SELF']);
 if (version_compare(phpversion(), "4.5.0", "<") === true) {
    $_GET = &$HTTP_GET_VARS;
    $_POST =& $HTTP_POST_VARS;
    $_SERVER =& $HTTP_SERVER_VARS;
    $_FILES =& $HTTP_POST_FILES;
    $_ENV =& $HTTP_ENV_VARS;
    if (isset($HTTP_COOKIE_VARS)) $_COOKIE =& $HTTP_COOKIE_VARS;
  } else if (!$REGISTER_LONG_ARRAYS){
    $HTTP_GET_VARS=&$_GET;
    $HTTP_POST_VARS=&$_POST;
    $HTTP_SERVER_VARS=&$_SERVER;
    $HTTP_POST_FILES=&$_FILES;
    $HTTP_ENV_VARS=&$_ENV;
    if (isset($_COOKIE)) $HTTP_COOKIE_VARS=&$_COOKIE;
 }
define('CHECK_CON','');
 if (strtolower(ini_get("register_globals"))=="on" || strtolower(ini_get("register_globals"))=="1" ) {
	 $REGISTER_GLOBALS=true;
 } else {
	 $REGISTER_GLOBALS=false;
 }
  ini_set('session.bug_compat_42','off');
  ini_set('session.bug_compat_warn','off');

// Start the clock for the page parse time log
  define('PAGE_PARSE_START_TIME', microtime());

  define('TITLE','Freeway');
  
  define('UPGRADE_VERSION_INFO',"Freeway version out of date. &nbsp; <a href='http://www.zac-ware.com/freeway' target='_blank'>Learn More</a>");
  define('WARNING_CONFIG_FILE_WRITEABLE', 'Warning: I am able to write to the configuration file: ' . dirname($HTTP_SERVER_VARS['SCRIPT_FILENAME']) . '/includes/configure.php. This is a potential security risk - please set the right user permissions on this file.');

// Set the local configuration parameters - mainly for developers
  if (file_exists('includes/local/configure.php')) include('includes/local/configure.php');
  
// Include application configuration parameters
  require('includes/configure.php');
  
/*  print_r($HTTP_POST_VARS);
  print_r($HTTP_GET_VARS);
*/


/*echo "array=";
print_r($HTTP_POST_VARS);
echo "<br>";
exit;*/
  include(DIR_WS_CLASSES . 'request.php');

  $REQUEST=new phprequest();

// Define the project version
  define('PROJECT_VERSION', 'osCommRes 1.0.1');

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

// set php_self in the local scope
  $PHP_SELF = (isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME']);

// Used in the "Backup Manager" to compress backups
  define('LOCAL_EXE_GZIP', '/usr/bin/gzip');
  define('LOCAL_EXE_GUNZIP', '/usr/bin/gunzip');
  define('LOCAL_EXE_ZIP', '/usr/local/bin/zip');
  define('LOCAL_EXE_UNZIP', '/usr/local/bin/unzip');

// 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');

//     define('BOX_WIDTH', 125); // how wide the boxes should be in pixels (default: 125)
 define('MENU_DHTML', false);

// Define how do we update currency exchange rates
// Possible values are 'oanda' 'xe' or ''
  define('CURRENCY_SERVER_PRIMARY', 'oanda');
  define('CURRENCY_SERVER_BACKUP', 'xe');

// include the database functions
   require(DIR_WS_FUNCTIONS . 'database.php');
  
   require(DIR_WS_CLASSES . 'filter_input.php');

	$INPUT_FILTER = new filter_input();
	if(count($HTTP_POST_VARS)>0){
		reset($HTTP_POST_VARS);
		while(list($key,) = each($HTTP_POST_VARS)){
			$HTTP_POST_VARS[$key]=tep_strip_input($key,$HTTP_POST_VARS[$key],"POST");
		}		
	}
	if (count($HTTP_GET_VARS)>0){
		reset($HTTP_GET_VARS);	
		while(list($key,) = each($HTTP_GET_VARS)){
			$HTTP_GET_VARS[$key]=tep_strip_input($key,$HTTP_GET_VARS[$key],"GET");
		}		
	}

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

// set application wide parameters
  $configuration_query = tep_db_query('select configuration_key as cfgKey, configuration_value as cfgValue from ' . TABLE_CONFIGURATION);
  while ($configuration = tep_db_fetch_array($configuration_query)) {
    define($configuration['cfgKey'], $configuration['cfgValue']);
  }
// define our general functions used application-wide
  require(DIR_WS_FUNCTIONS . 'general.php');
  require(DIR_WS_FUNCTIONS . 'html_output.php');
//Admin begin
 require(DIR_WS_FUNCTIONS . 'password_funcs.php');
//Admin end
//==========alert_action=============
if (isset($HTTP_GET_VARS['alert_action']))
{
	if($HTTP_GET_VARS['alert_action']=='hide_alert')
	{
		tep_db_query("update configuration set configuration_value='" . $HTTP_GET_VARS['version'] . "' where configuration_key='ALERT_MESSAGE_HIDE_VERSION'");
		tep_db_query("update configuration set configuration_value='" . $HTTP_GET_VARS['general'] . "' where configuration_key='GENERAL_MESSAGE_CREATE_DATE'");
	}
	echo "<script>";
	if($HTTP_GET_VARS['mode']=='2'){
		echo 'window.opener.location.href="' . tep_href_link(FILENAME_VERSION_UPGRADE) . '";';
	}
	echo "window.close();";
	echo "</script>";
	exit;
}

// initialize the logger class
  require(DIR_WS_CLASSES . 'logger.php');

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

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

// check to see if php implemented session management functions - if not, include php3/php4 compatible session class
  if (!function_exists('session_start')) {
    define('PHP_SESSION_NAME', 'osCAdminID');
    define('PHP_SESSION_PATH', '/');
    define('PHP_SESSION_SAVE_PATH', SESSION_WRITE_DIRECTORY);

    include(DIR_WS_CLASSES . 'sessions.php');
  }

// define how the session functions will be used
	if ($REGISTER_GLOBALS)
		require(DIR_WS_FUNCTIONS . 'sessions.php');
	else
		require(DIR_WS_FUNCTIONS . 'sessions_no_globals.php');
		
		//ticket
		if (!tep_session_is_registered('GLOBAL_LIST')){
  	$NOGLOBALS_SESSION_DATA["GLOBAL_LIST"]=array();
  }

// set the session name and save path
  tep_session_name('osCAdminID');
  tep_session_save_path(SESSION_WRITE_DIRECTORY);

// set the session cookie parameters
   if (function_exists('session_set_cookie_params')) {
    session_set_cookie_params(0, DIR_WS_ADMIN);
  } elseif (function_exists('ini_set')) {
    ini_set('session.cookie_lifetime', '0');
    ini_set('session.cookie_path', DIR_WS_ADMIN);
  }

// lets start our session
  tep_session_start();
  
  // Register Globals MOD - http://oscommerce.magic-seo-url.com
  if (!$REGISTER_GLOBALS) {
  	if ($REGISTER_LONG_ARRAYS){
		$NOGLOBALS_SESSION_DATA=&$HTTP_SESSION_VARS;
	} else {
		$NOGLOBALS_SESSION_DATA=&$_SESSION;
	}
    if ($REGISTER_LONG_ARRAYS) {
       $_SESSION =&$HTTP_SESSION_VARS;
    } else {
		$HTTP_SESSION_VARS=$_SESSION;
	}
	if (count($NOGLOBALS_SESSION_DATA)>0){
		reset($NOGLOBALS_SESSION_DATA);
		while(list($key,$value)=each($NOGLOBALS_SESSION_DATA)){
			$$key=$value;
		}
	}
  }

 // set the language
  if (tep_session_is_registered('language')) {
      tep_session_unregister('language');
  }
  
  if (!tep_session_is_registered('language') || isset($HTTP_GET_VARS['language'])) {
    if (!tep_session_is_registered('language')) {
      tep_session_register('language');
      tep_session_register('languages_id');
    }

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

    if (isset($HTTP_GET_VARS['language']) && tep_not_null($HTTP_GET_VARS['language'])) {
      $lng->set_language($HTTP_GET_VARS['language']);
    } else {
      $lng->get_browser_language();
    }

    $language = $lng->language['directory'];
    $languages_id = $lng->language['id'];
  }
   
// include the language translations
  require(DIR_WS_LANGUAGES . $language . '.php');
  $current_page = basename($PHP_SELF);
  if (file_exists(DIR_WS_LANGUAGES . $language . '/' . $current_page)) {
    include(DIR_WS_LANGUAGES . $language . '/' . $current_page);
  }
  

  
  
/* $languages =  tep_get_languages();
 for($i=0,$n=count($languages); $i<$n; $i++){
 	$language_id = $languages[$i]['id'];
	echo '[';
	print_r($HTTP_POST_VARS['products_description'][$language_id]);
	echo ']';
}
 exit;*/
  
  // currency
  if (!tep_session_is_registered('currency') || isset($HTTP_GET_VARS['currency'])){
    if (!tep_session_is_registered('currency')) tep_session_register('currency');

    if (isset($HTTP_GET_VARS['currency'])) {
      if (!$currency = tep_currency_exists($HTTP_GET_VARS['currency'])) $currency = DEFAULT_CURRENCY;
    } else {
      $currency = DEFAULT_CURRENCY;
    }
  }
  
  
  
  
// create the shopping cart & fix the cart if necesary
  if (tep_session_is_registered('cart') && is_object($cart)) {
    if (PHP_VERSION < 4) {
      $broken_cart = $cart;
      $cart = new shoppingCart;
      $cart->unserialize($broken_cart);
    }
  } else {
    tep_session_register('cart');
    $cart = new shoppingCart;
  }

// define our localization functions
  require(DIR_WS_FUNCTIONS . 'localization.php');

// Include validation functions (right now only email address)
  require(DIR_WS_FUNCTIONS . 'validations.php');

// setup our boxes
  require(DIR_WS_CLASSES . 'table_block.php');
  require(DIR_WS_CLASSES . 'box.php');

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

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

// entry/item info classes
  require(DIR_WS_CLASSES . 'object_info.php');

// email classes
  require(DIR_WS_CLASSES . 'mime.php');
  require(DIR_WS_CLASSES . 'email.php'); 
	if (defined('USE_SMTP') && USE_SMTP && file_exists(DIR_WS_CLASSES . 'class.phpgmailer.php')) {
	  require(DIR_WS_CLASSES . 'class.phpgmailer.php');
	}


// file uploading class
  require(DIR_WS_CLASSES . 'upload.php');

// calculate category path
  if (isset($HTTP_GET_VARS['cPath'])) {
    $cPath = $HTTP_GET_VARS['cPath'];
  } else {
    $cPath = '';
  }

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

// default open navigation box
  if (!tep_session_is_registered('selected_box')) {
    tep_session_register('selected_box');
    $selected_box = 'configuration';
  } 

  if (isset($HTTP_GET_VARS['selected_box'])) {
    $selected_box = $HTTP_GET_VARS['selected_box'];
  } 
  
  	
          
// the following cache blocks are used in the Tools->Cache section
// ('language' in the filename is automatically replaced by available languages)
  $cache_blocks = array(array('title' => TEXT_CACHE_CATEGORIES, 'code' => 'categories', 'file' => 'categories_box-language.cache', 'multiple' => true),
                        array('title' => TEXT_CACHE_MANUFACTURERS, 'code' => 'manufacturers', 'file' => 'manufacturers_box-language.cache', 'multiple' => true),
                        array('title' => TEXT_CACHE_ALSO_PURCHASED, 'code' => 'also_purchased', 'file' => 'also_purchased-language.cache', 'multiple' => true)
                       );

// check if a default currency is set
  if (!defined('DEFAULT_CURRENCY')) {
    $messageStack->add(ERROR_NO_DEFAULT_CURRENCY_DEFINED, 'error');
  }

// check if a default language is set
  if (!defined('DEFAULT_LANGUAGE')) {
    $messageStack->add(ERROR_NO_DEFAULT_LANGUAGE_DEFINED, 'error');
  }

 	if (function_exists('ini_get') && ((bool)ini_get('file_uploads') == false) ) {
  	  $messageStack->add(WARNING_FILE_UPLOADS_DISABLED,'warning');
 	}
 	if ( (file_exists(dirname($HTTP_SERVER_VARS['SCRIPT_FILENAME']) . '/includes/configure.php')) && (is_writeable(dirname($HTTP_SERVER_VARS['SCRIPT_FILENAME']) . '/includes/configure.php')) ) {
	  $messageStack->add(WARNING_CONFIG_FILE_WRITEABLE,'warning');
    }    
//JOOMLA1.5 extend  start  
  if(isset($HTTP_GET_VARS['user_hash_id']) && $HTTP_GET_VARS['user_hash_id']!=""){
	$hash_id=$HTTP_GET_VARS['user_hash_id'];
	require_once(str_replace('freeway/','',DIR_FS_CATALOG).'configuration.php');
	$config=new JConfig;	
	$conf_hash=md5(md5($config->user.$config->password));
	if($conf_hash==$hash_id){
		$check_customer_exists=tep_db_query("select a.admin_id as login_id,a.admin_groups_id as login_groups_id,a.admin_firstname as login_firstname,a.admin_lastname as login_firstname,a.admin_email_address as login_email_address,a.admin_logdate as login_logdate,a.admin_lognum as login_lognum,a.admin_modified as login_modified from ".TABLE_ADMIN." a,".TABLE_ADMIN_GROUPS." ag where ag.admin_groups_id=a.admin_groups_id and ag.admin_groups_name='Top Administrator' limit 1");
		$check_admin=tep_db_fetch_array($check_customer_exists);
		$login_id = $check_admin['login_id'];
        $login_groups_id = $check_admin['login_groups_id'];
        $login_first_name = $check_admin['login_firstname'];
        $login_email_address = $check_admin['login_email_address'];
        $login_logdate = $check_admin['login_logdate'];
        $login_lognum = $check_admin['login_lognum'];
        $login_modified = $check_admin['login_modified'];
        tep_set_session_value('login_id',$login_id);
        tep_set_session_value('login_groups_id',$login_groups_id);
        tep_set_session_value('login_first_name',$login_first_name);
    	// error count
    		tep_set_session_value('error_count',0);
		// error count 
		// find the admin groups name
		$group_query=tep_db_query("SELECT admin_groups_name from ". TABLE_ADMIN_GROUPS . " where admin_groups_id='". $login_groups_id . "'");
		$group_result=tep_db_fetch_array($group_query);
		$login_groups_name=$group_result['admin_groups_name'];		
		tep_set_session_value('login_groups_type',$login_groups_name);
		tep_set_session_value("login_email",$login_email_address);
		tep_set_session_value("top_admin_email",$login_email_address);
	    tep_set_session_value('login_email',$login_email_address);
	    // set top administrator email
		$admin_query=tep_db_query("SELECT admin_email_address from " . TABLE_ADMIN . " a, " . TABLE_ADMIN_GROUPS . " ag where ag.admin_groups_name='" . TEXT_ADMINISTRATOR_ENTRY . "' and a.admin_groups_id=ag.admin_groups_id");
		$admin_result=tep_db_fetch_array($admin_query);
		tep_set_session_value('top_admin_email',$admin_result["admin_email_address"]);
		$select_box="";
        tep_db_query("update " . TABLE_ADMIN . " set admin_logdate ='" . getServerDate(true) . "', admin_lognum = admin_lognum+1 where admin_id = '" . $login_id . "'");
        
	}
  }
 //JOOMLA1.5 extend end
 
 //Admin begin
  if (basename($PHP_SELF) != FILENAME_LOGIN && basename($PHP_SELF) != FILENAME_PASSWORD_FORGOTTEN && basename($PHP_SELF) != FILENAME_SEND_MESSAGES_SCRIPT)  
    tep_admin_check_login();  
//Admin end
// Include OSC-AFFILIATE
  require('includes/affiliate_application_top.php');
// include giftvoucher
  require(DIR_WS_INCLUDES . 'add_ccgvdc_application_top.php');

// WebMakers.com Added: Includes Functions for Attribute Sorter and Copier
require(DIR_WS_FUNCTIONS . 'webmakers_added_functions.php');

//include('includes/application_top_support.php');
//include('includes/application_top_newsdesk.php');
include('includes/application_top_faqdesk.php');

define('FILENAME_CREATE_ACCOUNT', 'create_account.php');
define('FILENAME_CREATE_ACCOUNT_PROCESS', 'create_account_process.php');
define('FILENAME_CREATE_ACCOUNT_SUCCESS', 'create_account_success.php');
define('FILENAME_CREATE_ORDER_PROCESS', 'create_order_process.php');
define('FILENAME_CREATE_ORDER', 'create_order.php');
define('FILENAME_EDIT_ORDERS', 'edit_orders.php');
//==================
  if (isset($HTTP_GET_VARS['product_action'])) {
// redirect the customer to a friendly cookie-must-be-enabled page if cookies are disabled
    switch ($HTTP_GET_VARS['product_action']) {
      // customer wants to update the product quantity in their shopping cart
      case 'update_product' : for ($i=0, $n=sizeof($HTTP_POST_VARS['products_id']); $i<$n; $i++) {
                                if (in_array($HTTP_POST_VARS['products_id'][$i], (is_array($HTTP_POST_VARS['cart_delete']) ? $HTTP_POST_VARS['cart_delete'] : array()))) {
                                  $cart->remove($HTTP_POST_VARS['products_id'][$i]);
                                } else {
                                  if (PHP_VERSION < 4) {
                                    // if PHP3, make correction for lack of multidimensional array.
                                    reset($HTTP_POST_VARS);
                                    while (list($key, $value) = each($HTTP_POST_VARS)) {
                                      if (is_array($value)) {
                                        while (list($key2, $value2) = each($value)) {
                                          if (ereg ("(.*)\]\[(.*)", $key2, $var)) {
                                            $id2[$var[1]][$var[2]] = $value2;
                                          }
                                        }
                                      }
                                    }
                                    $attributes = ($id2[$HTTP_POST_VARS['products_id'][$i]]) ? $id2[$HTTP_POST_VARS['products_id'][$i]] : '';
                                  } else {
                                    $attributes = ($HTTP_POST_VARS['id'][$HTTP_POST_VARS['products_id'][$i]]) ? $HTTP_POST_VARS['id'][$HTTP_POST_VARS['products_id'][$i]] : '';
                                  }
								  
                                  $cart->add_cart($HTTP_POST_VARS['products_id'][$i], $HTTP_POST_VARS['cart_quantity'][$i], $attributes, false,'',0,$HTTP_POST_VARS['txt_tax'][$i],$HTTP_POST_VARS['txt_price'][$i],$HTTP_POST_VARS['price_breaks'][$i],$HTTP_POST_VARS['discount_ids'][$i]);
                                }
                              }
                            //  tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                              break;
      // customer adds a product from the products page
      case 'add_product' :   
				if (isset($HTTP_POST_VARS['add_product_products_id']) && is_numeric($HTTP_POST_VARS['add_product_products_id'])) {
					$products_id=(int)$HTTP_POST_VARS['add_product_products_id'];
					if($HTTP_POST_VARS['add_product_options']) $HTTP_POST_VARS['id']=$HTTP_POST_VARS['add_product_options']; //for listing attributes options in cart
					//$cart->add_cart($products_id, $cart->get_quantity(tep_get_uprid($products_id, $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id'],true,array(),0);
					if($HTTP_POST_VARS['qty']==0) $HTTP_POST_VARS['qty']=1;
					
					//PPB
					$attributes="";
					if (isset($HTTP_POST_VARS['id'])){
						$attributes=$HTTP_POST_VARS['id'];
					} else if (isset($HTTP_POST_VARS['attrValues']) && isset($HTTP_POST_VARS['attrIds'])){
						for ($icnt=0,$n=count($HTTP_POST_VARS['attrValues']);$icnt<$n;$icnt++){
							$attributes[$HTTP_POST_VARS['attrIds'][$icnt]]=$HTTP_POST_VARS['attrValues'][$icnt];
						}
					}
					
					$salemaker_id=isset($HTTP_POST_VARS['salemaker_id'])?(int)$HTTP_POST_VARS['salemaker_id']:0;
					
										//$cart->add_cart($products_id, $cart->get_quantity(tep_get_uprid($products_id, $attributes))+$HTTP_POST_VARS['qty'], $attributes,true,array(),0);
					$cart->add_cart($products_id, $HTTP_POST_VARS['qty'], $attributes,true,array(),0,$HTTP_POST_VARS['txt_tax'][$i],$HTTP_POST_VARS['txt_price'][$i],$HTTP_POST_VARS['price_breaks'][$i],$salemaker_id);
					//PPB
				//	$cart->add_cart($products_id, $cart->get_quantity(tep_get_uprid($products_id, $HTTP_POST_VARS['id']))+$HTTP_POST_VARS['qty'], $HTTP_POST_VARS['id'],true,array(),0);
					// check for forced products;
					$xsell_ids=(isset($HTTP_POST_VARS["xsell_forced_id"])?$HTTP_POST_VARS["xsell_forced_id"]:array());
					if (count($xsell_ids)>0){
						for ($lcnt=0;$lcnt<count($xsell_ids);$lcnt++){
							$attr=(isset($xsell_forced_attributes[$xsell_ids[$lcnt]])?$xsell_forced_attributes[$xsell_ids[$lcnt]]:array());
							$cart->add_cart($xsell_ids[$lcnt], 1, $attr,true,array(),0);
						}
					}
				}
				//tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                break;
      // performed by the 'buy now' button in product listings and review page
      case 'buy_now' :        
	  				if (isset($HTTP_GET_VARS['products_id']) && is_numeric($HTTP_GET_VARS['products_id'])) {
                        if (tep_has_product_attributes($HTTP_GET_VARS['products_id'])) {
                           tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['products_id']));
                        } else {
                            $cart->add_cart($HTTP_GET_VARS['products_id'], $cart->get_quantity($HTTP_GET_VARS['products_id'])+1);
                        }
					}
                    tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                    break;
      case 'notify' :         if (tep_session_is_registered('customer_id')) {
                                if (isset($HTTP_GET_VARS['products_id'])) {
                                  $notify = $HTTP_GET_VARS['products_id'];
                                } elseif (isset($HTTP_GET_VARS['notify'])) {
                                  $notify = $HTTP_GET_VARS['notify'];
                                } elseif (isset($HTTP_POST_VARS['notify'])) {
                                  $notify = $HTTP_POST_VARS['notify'];
                                } else {
                                  tep_redirect(tep_href_link(basename($PHP_SELF), tep_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 = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . $notify[$i] . "' and customers_id = '" . $customer_id . "'");
                                  $check = tep_db_fetch_array($check_query);
                                  if ($check['count'] < 1) {
                                    tep_db_query("insert into " . TABLE_PRODUCTS_NOTIFICATIONS . " (products_id, customers_id, date_added) values ('" . $notify[$i] . "', '" . $customer_id . "', now())");
                                  }
                                }
                                tep_redirect(tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action', 'notify'))));
                              } else {
                                $navigation->set_snapshot();
                                tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
                              }
                              break;
      case 'notify_remove' :  if (tep_session_is_registered('customer_id') && isset($HTTP_GET_VARS['products_id'])) {
                                $check_query = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . $HTTP_GET_VARS['products_id'] . "' and customers_id = '" . $customer_id . "'");
                                $check = tep_db_fetch_array($check_query);
                                if ($check['count'] > 0) {
                                  tep_db_query("delete from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . $HTTP_GET_VARS['products_id'] . "' and customers_id = '" . $customer_id . "'");
                                }
                                tep_redirect(tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action'))));
                              } else {
                                $navigation->set_snapshot();
                                tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
                              }
                              break;
      case 'cust_order' :     if (tep_session_is_registered('customer_id') && isset($HTTP_GET_VARS['pid'])) {
                                if (tep_has_product_attributes($HTTP_GET_VARS['pid'])) {
                                  tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['pid']));
                                } else {
                                  $cart->add_cart($HTTP_GET_VARS['pid'], $cart->get_quantity($HTTP_GET_VARS['pid'])+1);
                                }
                              }
                              tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                              break;
    }
  }

//==============================

require('includes/classes/breadcrumb.php');
require(DIR_WS_INCLUDES . "events_application_top.php");
require(DIR_WS_INCLUDES . "services_application_top.php");
if(file_exists(DIR_WS_INCLUDES . "contract_database_tables.php"))
	require(DIR_WS_INCLUDES . "contract_database_tables.php");

	function json_string(&$array,$arr_mode="key"){
		global $js_string;
		$first=true;
		reset($array);
		$js_string.=($arr_mode=="num"?"[":"{");		
		while(list($key,)=each($array)){
			if (!$first) {
				$js_string.=",\n";
			}
			if($arr_mode!="num"){
				if(substr($key,0,2)=="NU")
					$js_string.="'".substr($key,2)."':";
				else
					$js_string.="'" . $key . "':";
			}
			$first=false;
			
			if (is_array($array[$key])){
				if (count($array[$key])>0)
					json_string($array[$key],substr($key,0,2)=="NU"?"num":"key");
				else
					$js_string.=(substr($key,0,2)=="NU"?"[]":"{}");
			} else{
				$js_string.=dispvalue($array[$key]);
			}
		}
		$js_string.=($arr_mode=="num"?"]":"}");
	}
	
	function dispvalue($value){
	  if(is_numeric($value)) return $value;
	  else if(is_bool($value)){
	  	return ($value)?'true':'false';
	  }else{
	    return "'".$value."'";
	  }		
	}

   function tep_strip_input($key,$data,$mode="GET"){
		global $INPUT_FILTER;
		if ($mode=="POST" && (strpos($key,'_description')!==false || strpos($key,'newsdesk_article_')!==false || strpos($key,'faqdesk_answer_')!==false || $key=='message_text' || $key=='file_contents')) return $data;
		if (is_array($data)) {
			if (count($data)>0){
				reset($data);
				while(list($key,)=each($data)){
					$data[$key]=tep_strip_input($key,$data[$key],$mode);
				}
			}
			return $data;
		} else {
			return $INPUT_FILTER->_cleanTags($data);
		}
	}	
	
  header('Content-Type: text/html; charset=UTF-8');
?>
