<?
session_start();

if (file_exists("../includes/merchant/common.php"))
{
	include("../includes/merchant/common.php");
}
else
{
	include("../includes/common.php");
}


if ((isset($_GET['IS_MERCHANT']) && 1 == $_GET['IS_MERCHANT'])
	||
	(isset($_POST['IS_MERCHANT']) && 1 == $_POST['IS_MERCHANT']))
{
	if (file_exists("../includes/merchant/merchant_user_class.php")) //merchant module installed
	{
		require("../includes/merchant/merchant_user_class.php");
		$order_id = isset($_GET['LMI_PAYMENT_NO'])?$_GET['LMI_PAYMENT_NO']:$_POST['LMI_PAYMENT_NO'];
		
		$db->query("SELECT * FROM merchant_orders WHERE id=".intval($order_id));
		$res = $db->getRow();
		$merchant_user = new MerchantUser($db);
		if ($merchant_user->loadFromDb($res->merchant_id))
		{
			$merchant_user->success($order_id);
		}
	}
}

$info = "Спасибо за интерес к нашей системе!";

if(is_numeric($_SESSION["EX_ORDER_ID"]))
{
	$query = "select * from orders where orders.id=".$_SESSION["EX_ORDER_ID"];
	$order_row = @mysql_fetch_object(@mysql_query($query));
	
	if($order_row->id=="")
	{
		$error = base64_encode("Ошибка при передаче данных.");
		header("Location: $SITE_URL/error.php?error=$error");
		exit;
	}
	
	$tmp_row = @mysql_fetch_object(@mysql_query("select * from hashes where owner_id=$order_row->id and type=1"));
	$hash = $tmp_row->hash;
	
	
	$query = "select * from ex_currencies where id=$order_row->ex_currency_from_id";
	$from_row = @mysql_fetch_object(@mysql_query($query));
	
	$query = "select * from ex_currencies where id=$order_row->ex_currency_to_id";
	$to_row = @mysql_fetch_object(@mysql_query($query));
	
}	

$smarty->assign("order_row", $order_row);
$smarty->assign("metal_amount_from", round($order_row->metal_amount_from, 6));
$smarty->assign("metal_amount_to", round($order_row->metal_amount_to, 6));
$smarty->assign("ex_order_id", intval($_SESSION["EX_ORDER_ID"]));
$smarty->assign("from_row", $from_row);
$smarty->assign("to_row", $to_row);
$smarty->assign("msg", $msg);
$smarty->assign("SITE_URL", $SITE_URL);
$smarty->assign("hash", $hash);
$smarty->assign("email", $email);

$smarty->assign("title", $SETTINGS['site_name']);
$smarty->assign("info", "Добро пожаловать в универсальную обменную систему!");
$smarty->assign("ex_currencies", $ex_currencies);
$smarty->assign("main_class", "main");
$smarty->assign("money_cources", get_currency_cources());
$smarty->assign("metal_cources", get_metal_cources());
$smarty->assign("status", $status);
$smarty->display("smartex_success.tpl");

?>