<?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
*/	
	defined('_FEXEC') or die();
	error_reporting(E_ALL & ~E_NOTICE);
    ini_set('session.bug_compat_42',0);
    ini_set('session.bug_compat_warn',0);
  	$REGISTER_LONG_ARRAYS=false;
	define('CHECK_CON','');   

	if(!isset($HTTP_GET_VARS)) {
 		if($openfile=='shopping_cart.php') $GLOBALS['PHP_SELF']=$openfile;
 	}
 	$seo_config =& JFactory::getConfig();
	$joomla_seo = $seo_config->getValue('config.sef');		
	if($joomla_seo==1) $PHP_SELF=str_replace("?openfile=","",$PHP_SELF);
	
  if($before_session){	 
	 $_SERVER['SCRIPT_FILENAME']=$_SERVER['DOCUMENT_ROOT'].((strpos($_SERVER['DOCUMENT_ROOT'],"\\")>0)?str_replace("/","\\",$_SERVER['PHP_SELF']):$_SERVER['PHP_SELF']);
	 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;
	 }
	 if (strtolower(ini_get("register_globals"))=="on" || strtolower(ini_get("register_globals"))=="1" ) {
		 $REGISTER_GLOBALS=true;
	 } else {
		 $REGISTER_GLOBALS=false;
	 }
	  
	 if (!$REGISTER_GLOBALS) { 
	    extract($_GET, EXTR_SKIP); 
	    extract($_POST, EXTR_SKIP); 
	    extract($_COOKIE, EXTR_SKIP);
		extract($_SERVER,EXTR_SKIP);
  	 }
	  ini_set('default_charset','iso-8859-1'); //set charset
	  // start the timer for the page pars	e time log
	  define('PAGE_PARSE_START_TIME', microtime());
	// set the level of error reporting
	  error_reporting(E_ALL & ~E_NOTICE);
	// check if register_globals is enabled.
	// since this is a temporary measure this message is hardcoded. The requirement will be removed before 2.2 is finalized.
	// Set the local configuration parameters - mainly for developers
	if (file_exists(DIR_WS_INCLUDES.'/local/configure.php')) include(DIR_WS_INCLUDES.'/local/configure.php');
	// include server parameters
	if ($joomla_include) {
		$home_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];		
		$home_url=substr($home_url,0,strpos($home_url,'link_index.php'));
		$ws_catalog="";
		$CONFIG = new JConfig();
		if(is_object($CONFIG)) {
		  $log_path=$CONFIG->log_path;
		  if($log_path!="" && defined('DS')){
		  	 $log_path_split=strrpos($log_path,DS);
		  	 $fs_catalog=substr($log_path,0,$log_path_split+1);
		  }
		  define('DIR_FS_CATALOG', $fs_catalog);
		  $script_name=substr($_SERVER['PHP_SELF'],0,strpos($_SERVER['PHP_SELF'],".php"));	  
  		  $ws_catalog = str_replace("//","/",dirname($script_name).'/');
		}
		define('HTTP_HOME_URL', $home_url);
		if($ws_catalog!=""){		  
		   define('DIR_WS_HTTP_CATALOG', $ws_catalog);		
		   define('DIR_WS_HTTPS_CATALOG', DIR_WS_HTTP_CATALOG);
		} 
		define('DIR_WS_IMAGES','freeway/images/');
		define('DIR_WS_INCLUDES','freeway/includes/');
		define('DIR_WS_TEMPLATES', 'freeway/templates/');
		require(CHECK_CON . $freeway_path_after_joomla.'includes/configure.php');
		include_once(DIR_WS_CLASSES . 'request.php');
		$REQUEST= new phprequest();
	}	
	 require(DIR_WS_CLASSES . 'filter_input.php');
$INPUT_FILTER = new filter_input();
	if (strlen(DB_SERVER) < 1 && is_dir('install')) header('Location: install/index.php');
	// set the type of request (secure or not)
	  $request_type = (getenv('HTTPS') == 'on') ? 'SSL' : 'NONSSL';
	
	// set php_self in the local scope
	  if (!isset($PHP_SELF)) $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
	  if ($request_type == 'NONSSL')
	    define('DIR_WS_CATALOG', DIR_WS_HTTP_CATALOG);
	  else
	    define('DIR_WS_CATALOG', DIR_WS_HTTPS_CATALOG);
		$TEMPLATE_MAIN_PAGE='';
	// 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');
	
	// customization for the design layout
	
	// include the database functions
	  require(DIR_WS_FUNCTIONS . 'database.php');				 	
 
// make a connection to the database... now
  tep_db_connect() or die('Unable to connect to database server!');

// set the application 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']);
  }

// if gzip_compression is enabled, start to buffer the output
  if ( (GZIP_COMPRESSION == 'true') && ($ext_zlib_loaded = extension_loaded('zlib')) && (PHP_VERSION >= '4') ) {
    if (($ini_zlib_output_compression = (int)ini_get('zlib.output_compression')) < 1) {
      if (PHP_VERSION >= '4.0.4') {
        ob_start('ob_gzhandler');
      } else {
        include(DIR_WS_FUNCTIONS . 'gzip_compression.php');
        ob_start();
        ob_implicit_flush();
      }
    } 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' && strpos($req_url,"link_index.php")<=0) {
		  $path_info=$req_url;
		  if(strpos($path_info,"/ex/")>0) $path_info=substr($path_info,strpos($path_info,"/ex/")+4);
		  $path_info=substr($path_info,strpos($path_info,"option"));
		  if (strlen($path_info) > 1) {
			  $GET_array = array();
			  $vars = explode('/', $path_info);
			  for ($i=0, $n=count($vars); $i<$n; $i++) {
				if (strpos($vars[$i], '[]')) {
				  $GET_array[substr($vars[$i], 0, -2)][] = $vars[$i+1];
				} else {
				  $HTTP_GET_VARS[$vars[$i]] = $vars[$i+1];
				}
				$i++;
			  }
			  if (sizeof($GET_array) > 0) 
				while (list($key, $value) = each($GET_array))  $HTTP_GET_VARS[$key] = $value;
		}
  }
// define general functions used application-wide
  require(DIR_WS_FUNCTIONS . 'general.php');  
  require(DIR_WS_FUNCTIONS . 'html_output.php');

// set the cookie domain
  $cookie_domain = (($request_type == 'NONSSL') ? HTTP_COOKIE_DOMAIN : HTTPS_COOKIE_DOMAIN);
  $cookie_path = (($request_type == 'NONSSL') ? HTTP_COOKIE_PATH : HTTPS_COOKIE_PATH);
  
// include cache functions if enabled
if (USE_CACHE == 'true') include(DIR_WS_FUNCTIONS . 'cache.php');
// SEF BEGIN  
  require(DIR_WS_CLASSES . 'seo_url.php');  
  $SEO_URL = new seo_url;  
  if ($GLOBALS["SEO_URL"]->enabled){
	  $SEO_URL->restore_seo_url();
  }  
 // include shopping cart class

  require(DIR_WS_CLASSES . 'shopping_cart.php');
  require(DIR_WS_CLASSES . "services.php");

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


// some code to solve compatibility issues
  require(DIR_WS_FUNCTIONS . 'compatibility.php');
  }else if($after_session){  	 
   $NOGLOBALS_SESSION_DATA=array();

// define how the session functions will be used  
	require(DIR_WS_FUNCTIONS . 'joomla_sessions.php');
    
  $session_started = true;  
// set SID once, even if empty
// 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 (count($NOGLOBALS_SESSION_DATA)>0){
		reset($NOGLOBALS_SESSION_DATA);
		while(list($key,$value)=each($NOGLOBALS_SESSION_DATA)){
			$$key=$value;
		}
	}
  }   
  $SID = (defined('SID') ? SID : '');
  
  if (!tep_session_is_registered('GLOBAL_LIST_SESSION')){
  	$NOGLOBALS_SESSION_DATA["GLOBAL_LIST_SESSION"]=array();
  }
  //if(base64_decode($openfile)=='shopping_cart.php' || tep_session_is_registered('cart')) print_r($cart);
  if (tep_session_is_registered('cart') && is_object($cart)) {
    if (version_compare(phpversion(), "4.0.0", "<")) {
      $broken_cart = $cart;
      $cart = new shoppingCart;
      $cart->unserialize($broken_cart);
    }
  } else {
    tep_session_register('cart');
    $cart = new shoppingCart;    
  }  
  if(base64_decode($openfile)=='shopping_cart.php') {
    	//print_r($_SESSION);
    }
  //check the cookie for the user values
    
  $current_file=basename($PHP_SELF);

  if (tep_session_is_registered('customer_id') && $HTTP_COOKIE_VARS['survey_login_id']!=$customer_id){
     tep_setcookie('survey_login_id',$customer_id,time()+(30*24*60*60),$cookie_path,$cookie_domain);
  }

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

// include the mail 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');
    }

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

// 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;
    }
  }
  
// navigation history
  if (tep_session_is_registered('navigation')) {
    if (PHP_VERSION < 4) {
      $broken_navigation = $navigation;
      $navigation = new navigationHistory;
      $navigation->unserialize($broken_navigation);
    }
  } else {
    tep_session_register('navigation');
    $navigation = new navigationHistory;
  }
  $navigation->add_current_page();

// BOF: Down for Maintenance except for admin ip
if (EXCLUDE_ADMIN_IP_FOR_MAINTENANCE != getenv('REMOTE_ADDR')){
	if (DOWN_FOR_MAINTENANCE=='true' and !strstr($PHP_SELF,DOWN_FOR_MAINTENANCE_FILENAME)) { tep_redirect(tep_href_link(DOWN_FOR_MAINTENANCE_FILENAME)); }
	}
// do not let people get to down for maintenance page if not turned on
if (DOWN_FOR_MAINTENANCE=='false' and strstr($PHP_SELF,DOWN_FOR_MAINTENANCE_FILENAME)) {
    tep_redirect(tep_href_link(FILENAME_DEFAULT));
}
 // EOF: WebMakers.com Added: Down for Maintenance
 // BOF: WebMakers.com Added: Functions Library
    include(DIR_WS_FUNCTIONS . 'webmakers_added_functions.php');
  // EOF: WebMakers.com Added: Functions Library
  $HTTP_POST_VARS['password2']=tep_db_prepare_input($HTTP_POST_VARS['confirmation']);  
   $user=& JFactory::getUser();
   if($user->id>0){
  		$check_user=tep_db_query("select customers_username,customers_id,customers_default_address_id,customers_firstname from ".TABLE_CUSTOMERS." where customers_username='".$user->username."'");
  		$customer_found=false;
  		if(tep_db_num_rows($check_user)>0)
  			$customer_found=true;
  		else {
  			$new_password = tep_create_random_value(ENTRY_PASSWORD_MIN_LENGTH);
      		//create new password
      		  	$password = '';
      		  	$type=ENCRYPTION_STYLE;
			    for ($i=0; $i<10; $i++)  $password .= tep_rand();
			    $salt = substr(md5($password), 0, 2);
				if ($type=="V")
				    $password = md5(md5($new_password) . $salt) . ':' . $salt;
				else
					$password = md5($salt . $new_password) . ':' . $salt;
				$crypted_password=tep_db_input($password);
      		//create new password
  			$insert_new_customer=array('customers_firstname'=>$user->name,'customers_lastname'=>$user->name,'customers_username'=>$user->username,'customers_email_address'=>$user->email,'customers_password'=>$crypted_password);
  			tep_db_perform(TABLE_CUSTOMERS,$insert_new_customer);
  			$c_id=tep_db_insert_id();
  			if($c_id>0){
  				$insert_customer_address_book=array('customers_id'=>$c_id,'entry_gender'=>'m','entry_firstname'=>$user->name,'entry_lastname'=>$user->name,'entry_postcode'=>'4895','entry_city'=>'','entry_state'=>tep_get_zone_name(STORE_COUNTRY,STORE_ZONE,STORE_ZONE),'entry_country_id'=>STORE_COUNTRY);
  				tep_db_perform(TABLE_ADDRESS_BOOK,$insert_customer_address_book);
  				$a_id=tep_db_insert_id();
  				tep_db_query("update ".TABLE_CUSTOMERS." set customers_default_address_id='".$a_id."' where customers_id='".$c_id."'");	
  			}
  			$customer_found=true;
  		}  		
  		if($customer_found && $customer_id==0){
  			$check_customer=tep_db_fetch_array($check_user);
  			$check_country_query = tep_db_query("select entry_country_id, entry_zone_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$check_customer['customers_id'] . "' and address_book_id = '" . (int)$check_customer['customers_default_address_id'] . "'");
	        $check_country = tep_db_fetch_array($check_country_query);		    
	        $customer_id = $check_customer['customers_id'];
	        $customer_default_address_id = $check_customer['customers_default_address_id'];
	        $customer_first_name = $check_customer['customers_firstname'];
	        $customer_country_id = $check_country['entry_country_id'];
	        $customer_zone_id = $check_country['entry_zone_id'];	        
        	tep_session_register('customer_id');
        	tep_session_register('customer_default_address_id');
        	tep_session_register('customer_first_name');
        	tep_session_register('customer_country_id');
        	tep_session_register('customer_zone_id');
        	$merge_details[TEXT_SM]=STORE_NAME;
			$merge_details[TEXT_SN]=STORE_OWNER;
		    $merge_details[TEXT_SE]=STORE_OWNER_EMAIL_ADDRESS;
		    $merge_details[TEXT_LE]=$user->email;
		    $merge_details[TEXT_LP]=$new_password;
		    
		    $send_details[0]['to_name'] = $user->name;
	        $send_details[0]['to_email'] = $user->email;
	        $send_details[0]['from_name']=STORE_OWNER;
	        $send_details[0]['from_email']=STORE_OWNER_EMAIL_ADDRESS;
            if($new_password) tep_send_default_email("CUS",$merge_details,$send_details);
            $cart->restore_contents();
  		}
  	}
  if (isset($HTTP_GET_VARS['action'])) {
// redirect the customer to a friendly cookie-must-be-enabled page if cookies are disabled
    if ($session_started == false) {
      tep_redirect(tep_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 ($HTTP_GET_VARS['action'] == 'buy_now') {
        $parameters = array('action', 'pid', 'products_id');
      } else {
        $parameters = array('action', 'pid');
      }
    }
    switch ($HTTP_GET_VARS['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']) ? tep_db_prepare_input($HTTP_POST_VARS['cart_delete']) : array()))) {
                                  $cart->remove(tep_db_prepare_input($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[tep_db_prepare_input($HTTP_POST_VARS['products_id'][$i])] : '';
                                  } else {
                                    $attributes = ($HTTP_POST_VARS['id'][$HTTP_POST_VARS['products_id'][$i]]) ? tep_db_prepare_input($HTTP_POST_VARS['id'][$HTTP_POST_VARS['products_id'][$i]]) : '';
                                  }
                                  $cart->add_cart(tep_db_prepare_input($HTTP_POST_VARS['products_id'][$i]), tep_db_prepare_input($HTTP_POST_VARS['cart_quantity'][$i]), $attributes, false);
                                }
                              }
                              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['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) {
					$products_id=(int)$HTTP_POST_VARS['products_id'];
					$subscription_start_date = isset($HTTP_POST_VARS['your_start_date'])?tep_convert_date_raw($HTTP_POST_VARS['your_start_date']):'0000-00-00';
					$serverDate = date('Y-m-d',getServerDate(false));
					
					$qty=isset($HTTP_POST_VARS['qty'])?(int)$HTTP_POST_VARS['qty']:1;
					if ($qty<=0) $qty=1;

					$attributes="";
					if (isset($HTTP_POST_VARS['id'])){
						$attributes=tep_db_prepare_input($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]]=tep_db_prepare_input($HTTP_POST_VARS['attrValues'][$icnt]);
					}
					$salemaker_id=isset($HTTP_POST_VARS['salemaker_id'])?(int)$HTTP_POST_VARS['salemaker_id']:0;
					//if (!$cart->is_price_break((int)$HTTP_POST_VARS['products_id'])) $qty+=$cart->get_quantity(tep_get_uprid($products_id, $HTTP_POST_VARS['id']));
					$cart->add_cart($products_id, $qty, $attributes,true,array(),0,$salemaker_id);
					// check for forced products;
					$xsell_ids=(isset($HTTP_POST_VARS["xsell_forced_id"])?tep_db_prepare_input($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());
							
						$sale_query=tep_db_query("select apply_to_cross_sale from " . TABLE_SALEMAKER_SALES . " where sale_id='" . tep_db_input($salemaker_id) . "'")	;
						$sale_result=tep_db_fetch_array($sale_query);
						$sale_id=0;
						if($sale_result['apply_to_cross_sale']=='Y')
							$sale_id=$salemaker_id;
						
						 $cart->add_cart($xsell_ids[$lcnt], 1, $attr,true,array(),0,$sale_id);
						}
					}
				}
				tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                break;
				
				
		// Modificacion Wishlist Checkboxes
case 'add_products_wishlist' : if (isset($HTTP_POST_VARS['add_wishprod'])) {
			if ($HTTP_POST_VARS['borrar'] == 0) {
  				  foreach ($HTTP_POST_VARS['add_wishprod'] as $value) {
   					 if (ereg('^[0-9]+$', $value)) {					tep_db_query("delete from " . TABLE_WISHLIST . " where products_id = $value and customers_id = '" . $customer_id . "'");
    			$cart->add_cart($value, $cart->get_quantity(tep_get_uprid($value, tep_db_prepare_input($HTTP_POST_VARS['id'])))+1, tep_db_prepare_input($HTTP_POST_VARS['id']));
   				 }
  			}
			tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
		}
	if ($HTTP_POST_VARS['borrar'] == 1) {
  		foreach ($HTTP_POST_VARS['add_wishprod'] as $value) {
   			 if (ereg('^[0-9]+$', $value)) {
 				tep_db_query("delete from " . TABLE_WISHLIST . " where products_id = $value and customers_id = '" . $customer_id . "'");
  			 }
 		 }
		tep_redirect(tep_href_link(FILENAME_WISHLIST));
	   }
	}
  break;
		// Fin Wishlist Checkboxes

// Add product to the wishlist
      case 'add_wishlist' :   if (ereg('^[0-9]+$', $HTTP_GET_VARS['products_id'])) {
                                if ($HTTP_GET_VARS['products_id']) {
                                  tep_db_query("delete from " . TABLE_WISHLIST . " where products_id = '" . tep_db_input(tep_db_prepare_input($HTTP_GET_VARS['products_id'])) . "' and customers_id = '" . $customer_id . "'");
                                  tep_db_query("insert into " . TABLE_WISHLIST . " (customers_id, products_id, products_model, products_name, products_price) values ('" . $customer_id . "', '" . tep_db_input($products_id) . "', '" . $products_model . "', '" . $products_name . "', '" . $products_price . "' )");
                                }
                              }
                              tep_redirect(tep_href_link(FILENAME_WISHLIST));
                              break;


      case 'wishlist_add_cart': reset ($lvnr);
                                reset ($lvanz);
                                  while (list($key,$elem) =each ($lvnr))
                                        {
                                        (list($key1,$elem1) =each ($lvanz));
                                        tep_db_query("update " . TABLE_WISHLIST . " set products_quantity = '" . $elem1 . "' where customers_id = '" . $customer_id . "' and products_id = '" . $elem . "'");
                                        tep_db_query("delete from " . TABLE_WISHLIST . " where customers_id= '" . $customer_id . "' and products_quantity = '999'");
                                        $produkte_mit_anzahl=tep_db_query("select * from " . TABLE_WISHLIST . " where customers_id = '" . $customer_id . "' and products_id = '" . $elem . "' and products_quantity<>'0'");

                                  while ($HTTP_GET_VARS=mysql_fetch_array($produkte_mit_anzahl))
                                  {
                                  $cart->add_cart(tep_db_prepare_input($HTTP_POST_VARS['products_id']), tep_db_prepare_input($HTTP_POST_VARS['products_quantity']));
                                  }
                                          }
                                reset ($lvanz);
                              tep_redirect(tep_href_link(FILENAME_WISHLIST));
                              break;


// remove item from the wishlist
      case 'remove_wishlist':
                              tep_db_query("delete from " . TABLE_WISHLIST . " where products_id = '" . tep_db_input($HTTP_GET_VARS['pid']) . "' and customers_id = '" . tep_db_input($customer_id) . "'");
                              tep_redirect(tep_href_link(FILENAME_WISHLIST));
                              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=' . tep_db_prepare_input($HTTP_GET_VARS['products_id'])));
                        } else {
                            $cart->add_cart($HTTP_GET_VARS['products_id'], $cart->get_quantity(tep_db_prepare_input($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 = tep_db_prepare_input($HTTP_GET_VARS['products_id']);
                                } elseif (isset($HTTP_GET_VARS['notify'])) {
                                  $notify = tep_db_prepare_input($HTTP_GET_VARS['notify']);
                                } elseif (isset($HTTP_POST_VARS['notify'])) {
                                  $notify = tep_db_prepare_input($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 = '" . tep_db_input($notify[$i]) . "' and customers_id = '" . tep_db_input($customer_id) . "'");
                                  $check = tep_db_fetch_array($check_query);
                                  if ($check['count'] < 1 && isset($HTTP_GET_VARS['products_id'])) {
                                    tep_db_query("insert into " . TABLE_PRODUCTS_NOTIFICATIONS . " (products_id, customers_id, date_added) values ('" . tep_db_input($notify[$i]) . "', '" . tep_db_input($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 = '" . tep_db_input(tep_db_prepare_input($HTTP_GET_VARS['products_id'])) . "' and customers_id = '" . tep_db_input($customer_id) . "'");
                                $check = tep_db_fetch_array($check_query);
                                if ($check['count'] > 0) {
                                  tep_db_query("delete from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . tep_db_input(tep_db_prepare_input($HTTP_GET_VARS['products_id'])) . "' and customers_id = '" . tep_db_input($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=' . tep_db_prepare_input($HTTP_GET_VARS['pid'])));
                                } else {
                                  $cart->add_cart(tep_db_prepare_input($HTTP_GET_VARS['pid']), $cart->get_quantity(tep_db_prepare_input($HTTP_GET_VARS['pid']))+1);
                                }
                              }
                              tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                              break;
    }
  }

// include the who's online functions
  require(DIR_WS_FUNCTIONS . 'whos_online.php');
  tep_update_whos_online();

// include the password crypto functions
  require(DIR_WS_FUNCTIONS . 'password_funcs.php');

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

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

// Lango added for template BOF:
  require(DIR_WS_INCLUDES . 'template_application_top.php');
// Lango added for template EOF:

if (!defined('TEMPLATENAME_MAIN_PAGE')) define('TEMPLATENAME_MAIN_PAGE',TEMPLATENAME_MAIN_PAGE_DEFAULT);


// auto activate and expire banners
  require(DIR_WS_FUNCTIONS . 'banner.php');
  tep_activate_banners();
  tep_expire_banners();

// auto expire special products
  require(DIR_WS_FUNCTIONS . 'specials.php');
  tep_expire_specials();

// auto expire featured products
  require(DIR_WS_FUNCTIONS . 'featured.php');
  tep_expire_featured();

// calculate category path
  if (isset($HTTP_GET_VARS['cPath'])) { 
    $cPath = $HTTP_GET_VARS['cPath'];
  } elseif ((int)isset($HTTP_GET_VARS['products_id']) && !isset($HTTP_GET_VARS['manufacturers_id'])) {
    $cPath = (int)tep_get_product_path($HTTP_GET_VARS['products_id']);
  } 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;
  }
   if (tep_not_null($cPath)){
     tep_set_session_value('prev_category_viewed','cPath='.$cPath);
  }

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

  if (tep_session_is_registered('customer_id') && defined("HTTP_HOME_URL") && ENABLE_WEB_SERVICE){
	$breadcrumb->add(HEADER_TITLE_TOP, (defined("HTTP_HOME_URL")?HTTP_HOME_URL:HTTP_SERVER) . "?user_id=" . $customer_id . "&session_key=" . tep_session_id() . "&type=1981");
} else {
	$breadcrumb->add(HEADER_TITLE_TOP, (defined("HTTP_HOME_URL")?HTTP_HOME_URL:HTTP_SERVER));
}

  $breadcrumb->add(HEADER_TITLE_CATALOG, tep_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++) {
      $categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$cPath_array[$i] . "' and language_id = '" . (int)$languages_id . "'");
      if (tep_db_num_rows($categories_query) > 0) {
        $categories = tep_db_fetch_array($categories_query);
        $breadcrumb->add($categories['categories_name'], tep_href_link(FILENAME_DEFAULT, 'cPath=' . implode('_', array_slice($cPath_array, 0, ($i+1)))));
      } else {
        break;
      }
    }
  } elseif (isset($HTTP_GET_VARS['manufacturers_id'])) {
    $manufacturers_query = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'");
    if (tep_db_num_rows($manufacturers_query)) {
      $manufacturers = tep_db_fetch_array($manufacturers_query);
      $breadcrumb->add($manufacturers['manufacturers_name'], tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id']));
    }
  }
// add the products model to the breadcrumb trail
  if (isset($HTTP_GET_VARS['products_id'])) {
    $model_query = tep_db_query("select p.products_model, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and p.products_id=pd.products_id and pd.language_id='" . (int)$languages_id . "' ");
    if (tep_db_num_rows($model_query)) {
      $model = tep_db_fetch_array($model_query);
		if($model['products_model']!="")
			$product_name=$model['products_model'];
		else
			$product_name=$model['products_name'];	
      $breadcrumb->add($product_name, tep_href_link(FILENAME_PRODUCT_INFO, 'cPath=' . $cPath . '&products_id=' . (int)$HTTP_GET_VARS['products_id']));
    }
  }

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

  if ($GLOBALS["SEO_URL"]->lastError!='')
	  $messageStack->add('header', $GLOBALS["SEO_URL"]->lastError, 'error');


// error handler function

// set which precautions should be checked
  define('WARN_INSTALL_EXISTENCE', 'true');
  define('WARN_CONFIG_WRITEABLE', 'true');
  define('WARN_SESSION_DIRECTORY_NOT_WRITEABLE', 'true');
  define('WARN_SESSION_AUTO_START', 'true');
  define('WARN_DOWNLOAD_DIRECTORY_NOT_READABLE', 'true');
  define('WARN_IMAGES_DIRECTORY_NOT_WRITEABLE','true');
  define('WARN_IMAGES_BIG_DIRECTORY_NOT_WRITEABLE','true');
  define('WARN_IMAGES_SMALL_DIRECTORY_NOT_WRITEABLE','true');
  define('WARN_LOG_DIRECTORY_NOT_WRITABLE','true');
// Include OSC-AFFILIATE
  require(DIR_WS_INCLUDES . 'affiliate_application_top.php');
  require(DIR_WS_INCLUDES . 'add_ccgvdc_application_top.php');

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

 require(DIR_WS_INCLUDES . "events_application_top.php");
 require(DIR_WS_INCLUDES . "services_application_top.php");
 } 
  $filename_encode=base64_encode('link_index.php');
  if($joomla_seo==1) $filename_encode=base64_encode('component/freeway/');
 //bG9naW4ucGhw
    
 /*if(basename($PHP_SELF)=='link_index.php' && base64_decode($openfile)=='login.php') { 
  //tep_redirect(JRoute::_('index.php?option=com_user&view=login&return='.$filename_encode,true));
  //tep_redirect(tep_href_link('index.php?option=com_user&view=login&return='.$filename_encode));
 }*/
 //$PHP_SELF=str_replace('link_index.php','shopping_cart.php',$PHP_SELF);
 
?>
