<?php

include("config.inc.php");
session_start();
$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536) or die("Could not connect to DB");
mysql_select_db($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");

print <<<HERE
<html>
<head>
<title>Choose an option</title>
<script>
function updateRecord(){
	var TransId = document.getElementById('TransId').value;
	var vTransType = document.getElementById('vTransType').value;
	var warning = document.getElementById('warning').value;
	if(warning == 0){
			var str="Form_Trans_Actions.php?TransType="+vTransType+"&mainmode=editfromreport&STransId="+TransId;
	        window.open(str);
			self.close();
	}
	else{
			alert("Error: Current Transaction in Progress!");
	}
}
function PrintPreview(){
	var TransId = document.getElementById('TransId').value;
	var vTransType = document.getElementById('vTransType').value;
	str = 'Form_TransPreview.php?TransId='+TransId+'&TransType='+vTransType;
	window.open(str);
	self.close();
}
</script>
</head>
<body>
HERE;
$TransId    = $_GET['TransId'];
$vTransType = $_GET['vTransType'];
$warning    = $_GET['warning'];
$query_checkcreditnote  = "select count(*) as NumberInPending from temp_trans where trans_id = '".$TransId."'";
$result_checkcreditnote = mysql_query($query_checkcreditnote, $connection);
$row_checkcreditnote    = mysql_fetch_array($result_checkcreditnote);
extract($row_checkcreditnote);
if($NumberInPending > 0){
	$warning = 1;
}
else{
	$warning = 0;
}
$query_login  = "select FA_Journal as FA_Journal, FA_Receipt, FA_ReceiptMod, FA_CreditNote, FA_CreditNoteMod, FA_DebitNote, FA_DebitNoteMod, FA_Payment, FA_PaymentMod
                 from ".$_SESSION['dbLabel'].".login 
				 where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')";
$result_login = mysql_query($query_login, $connection);
$row_login    = mysql_fetch_array($result_login);
extract($row_login);
echo "<input type='hidden' id='TransId' value='$TransId'>";
echo "<input type='hidden' id='vTransType' value='$vTransType'>";
echo "<input type='hidden' id='warning' value='$warning'>";
if($vTransType == 'CV' && $FA_CreditNote == 1 && $FA_CreditNoteMod == 1){
echo "<button style='width: 100%; cursor: pointer' onclick=\"updateRecord()\">Edit Current Transaction</button>";
echo "<div style='height: 5px'></div>";
}
else
	if($vTransType == 'DV' && $FA_DebitNote == 1 && $FA_DebitNoteMod == 1){
echo "<button style='width: 100%; cursor: pointer' onclick=\"updateRecord()\">Edit Current Transaction</button>";
echo "<div style='height: 5px'></div>";
}
else
	if($vTransType == 'PV' && $FA_Payment == 1 && $FA_PaymentMod == 1){
echo "<button style='width: 100%; cursor: pointer' onclick=\"updateRecord()\">Edit Current Transaction</button>";
echo "<div style='height: 5px'></div>";
}
else
	if($vTransType == 'RV' && $FA_Receipt == 1 && $FA_ReceiptMod == 1){
echo "<button style='width: 100%; cursor: pointer' onclick=\"updateRecord()\">Edit Current Transaction</button>";
echo "<div style='height: 5px'></div>";
}
echo "<button style='width: 100%; cursor: pointer' onclick=\"PrintPreview()\">Preview Current Transaction</button>";
print <<<HERE
</body>
</html>
HERE;
?>