<?php
/*
+--------------------------------------------------------------------------
|   CubeCart 4
|   ========================================
|	CubeCart is a registered trade mark of Devellion Limited
|   Copyright Devellion Limited 2006. All rights reserved.
|   Devellion Limited,
|   5 Bridge Street,
|   Bishops Stortford,
|   HERTFORDSHIRE.
|   CM23 2JU
|   UNITED KINGDOM
|   http://www.devellion.com
|	UK Private Limited Company No. 5323904
|   ========================================
|   Web: http://www.cubecart.com
|   Email: info (at) cubecart (dot) com
|	License Type: CubeCart is NOT Open Source Software and Limitations Apply 
|   Licence Info: http://www.cubecart.com/v4-software-license
+--------------------------------------------------------------------------
|	remote.inc.php
|   ========================================
|	Manages remote calls from 3rd party servers	
+--------------------------------------------------------------------------
*/
if (!defined('CC_INI_SET')) die("Access Denied");

## START  MAIN CONTENT
if (in_array($_REQUEST['type'], array('gateway', 'altCheckout'))) {
	## make sure module is enabled
	if (isset($_REQUEST['module'])) {
		$query = "SELECT folder FROM ".$glob['dbprefix']."CubeCart_Modules WHERE module=".$db->mySQLSafe($_REQUEST['type'])." AND folder=".$db->mySQLSafe($_REQUEST['module'])." AND status = 1";
		$gatewayStatus = $db->select($query);
	}
	if (!$gatewayStatus) exit;
	
	$modulePath = "modules".CC_DS.$_REQUEST['type'].CC_DS.sanitizeVar($_REQUEST['module']).CC_DS;
	
	$module = fetchDbConfig($gatewayStatus[0]['folder']);
	
	switch(sanitizeVar($_REQUEST['cmd'])) {
		## Payment Gateway Callbacks
		case "call":
			$moduleFullPath = $modulePath."call.inc.php";
			break;
		## Process Payment
		case "process":
			$moduleFullPath = $modulePath."process.inc.php";
			break;
	}

	if (file_exists($moduleFullPath)) {
		require_once "classes".CC_DS."cart".CC_DS."order.php";
		$order = new order();
		include_once $moduleFullPath;
	} else {
		die("Module path doesn't exist!");
	}
}

if ($_REQUEST['cmd'] == "process") {
	/*
	1 = Payment Failed link to try again
	2 = Payment successful and complete 
	3 = Payment may or may not have been approved yet
	*/
	if (!isset($paymentResult)) { 
		$paymentResult = "3";
	}
	
	$redirect = $glob['storeURL']."/index.php?_g=co&_a=confirmed&amp;s=".$paymentResult;
	
	if(isset($cart_order_id) && !empty($cart_order_id)) {
		$redirect .= "&amp;cart_order_id=".$cart_order_id;
	}
	httpredir($redirect);
}
?>