<?
define("ADMIN_AUTHORIZATION",1);
include("../../../includes/common.php");

$orderRow = mysql_fetch_object(mysql_query("SELECT * FROM orders WHERE id='".intval($_GET["ord_id"])."'"));

$id = trim($_GET['id']);
$code = trim($_GET['code']);
if(!is_numeric($id)){
	$id=0;
}

$smarty->assign('trans_id',$id);

if($code == "WMR"||$code == "WMZ"||$code == "WME"||$code == "WMU")
{
	$smarty->assign('ex_currency',"wm");
	
	$row = mysql_fetch_object(mysql_query("select * from wm_orders where id=$id"));

	switch($row->status){
		case 0:
			$status = "<font color=green>OK</font>";
			break;
		case 1:
			$status = "<font color=blue><b>В процессе</b></font>";
			break;
		case 2:
			$status = "<font color=red>Ошибка</font>";
			break;
		default:
			$status = "неизвестно";
			break;
	}
	switch($row->type){
		case 0:
			$type = "<font color=green>На системный счет</font>";
			$p_status = $orderRow->to_status == 0 ?"<font color=green>Оплачен</font>":"<font color=red>Не оплачен</font>";
			break;
		case 1:
			$type = "<font color=red>Из системы</font>";
			$p_status = $orderRow->from_status == 0 ?"<font color=green>Оплачен</font>":"<font color=red>Не оплачен</font>";
			break;
		default:
			$type = "неизвестно";
			break;
	}
	
	$smarty->assign('payer_wm',$row->payer_wm);
	$smarty->assign('payer_purse',$row->payer_purse);
	$smarty->assign('payee_wm',$row->payee_wm);
	$smarty->assign('payee_purse',$row->payee_purse);
	$smarty->assign('sys_invs_no',$row->sys_invs_no);
	$smarty->assign('sys_trans_no',$row->sys_trans_no);
}	
elseif($code == "EGOLD"||$code == "ESILVER"||$code == "EPLATINUM"||$code == "EPALLADIUM")
{
	$smarty->assign('ex_currency',"egold");
	
	$row = mysql_fetch_object(mysql_query("select * from egold_orders where id=$id"));
	if($row->type==0){
		$order_row = mysql_fetch_object(mysql_query("select orders.* from orders left outer join ex_currencies on orders.ex_currency_from_id = ex_currencies.id where orders.from_order_id=$id and ex_currencies.code='$code'"));
	}
	elseif($row->type==1){
		$order_row = mysql_fetch_object(mysql_query("select orders.* from orders left outer join ex_currencies on orders.ex_currency_to_id = ex_currencies.id where orders.to_order_id=$id and ex_currencies.code='$code'"));
	}
	
	switch($row->payment_metal_id){
		case 1:
			$metal = "Gold";
			break;
		case 2:
			$metal = "Silver";
			break;
		case 3:
			$metal = "Platinum";
			break;
		case 4:
			$metal = "Palladium";
			break;
		default:
			$metal = "неизвестно";
			break;
	}
	switch($row->status){
		case 0:
			$status = "<font color=green>OK</font>";
			break;
		case 1:
			$status = "<font color=blue><b>В процессе</b></font>";
			break;
		case 2:
			$status = "<font color=red>Ошибка</font>";
			break;
		default:
			$status = "неизвестно";
			break;
	}
	switch($row->type){
		case 0:
			$type = "<font color=green>На системный счет</font>";
			$p_status = $orderRow->to_status == 0 ?"<font color=green>Оплачен</font>":"<font color=red>Не оплачен</font>";
			break;
		case 1:
			$type = "<font color=red>Из системы</font>";
			$p_status = $orderRow->from_status == 0?"<font color=green>Оплачен</font>":"<font color=red>Не оплачен</font>";
			break;
		default:
			$type = "неизвестно";
			break;
	}


	$date = getdate($row->timestampgmt);
	$day = $date['mday'];
	$month = $date['mon'];
	$year = $date['year'];
	$h = $date['hours'];
	$m = $date['minutes'];
	$s = $date['seconds'];
	$year = $date['year'];

	$date = $h.":".$m.":".$s."<br>".$day." ".$MONTH_RUS[$month-1]." ".$year;
	
	$smarty->assign('payment_batch_num',$row->payment_batch_num);
	$smarty->assign('payer_account',$row->payer_account);
	$smarty->assign('payee_account',$row->payee_account);
	$smarty->assign('sum_brutto',"<b>" . round($row->actual_payment_ounces*31.1034768,6) . " гр.</b><br>" . $row->actual_payment_ounces . " тр. унций");
	$smarty->assign('sum_netto', "<b>" . round(($row->actual_payment_ounces-$row->feeweight)*31.1034768,6) . " гр.</b><br>" . round(($row->actual_payment_ounces-$row->feeweight),6) . " тр. унций");
	$smarty->assign('comission', "<b>" . round($row->feeweight*31.1034768,6) . " гр.</b><br>" . $row->feeweight . " тр. унций");
	$smarty->assign('usd_per_ounce',$row->usd_per_ounce);
	$smarty->assign('date',$date);
	$smarty->assign('metal',$metal);
}

$smarty->assign("email", htmlspecialchars(stripslashes($orderRow->email)));
$smarty->assign("type", $type);
$smarty->assign("status", $status);
$smarty->assign("p_status", $p_status);

$smarty->display("admin_order_info.tpl");

?>