<?php

session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");


$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");
	
if (empty($mode)) $mode = 'insertdt';
$type='';
if ($mode == 'insertdt') $type='Add';
else if ($mode == 'editdt') $type='Edit';

/// Reading top label
$query_mainLabel="select FinancialTot_Label,FinancialTot_Level,FinancialTot_TreeCode from financialtotlabel
				where FinancialTot_code='".$financial_code."'";
$result_mainLabel = mysql_query($query_mainLabel, $connection);
$row_mainLabel=mysql_fetch_row($result_mainLabel);
$toplabel=$row_mainLabel[0];
$financialtot_treecode=$row_mainLabel[2];

/// Reading Selected Label

if($mode=='insertdt'){
	$query_Label="select FinancialTot_Label,FinancialTot_code,FinancialTot_TreeCode from financialtotlabel
					where FinancialTot_code='".$financialdt_code."'";
	$result_Label = mysql_query($query_Label, $connection);
	$row_Label=mysql_fetch_row($result_Label);
	$parentlabel=$row_Label[0];
	$financial_relatedcode=$row_Label[1];
}


/// Reading detail in edit mode	
if($financialdt_code!='' && $mode=='editdt'){
	$query_detailLabel= " select FinancialTot_Label, FinancialTot_RelatedCode ,FinancialTot_Sign,FinancialTot_ShowResult,
						FinancialTot_skiprows,FinancialTot_bold,FinancialTot_background,FinancialTot_Level,
						FinancialTot_LevelCode
						from financialtotlabel
						where FinancialTot_code='".$financialdt_code."'";
	//echo$query_detailLabel;
	$result_detailLabel = mysql_query($query_detailLabel, $connection);
	$row_dtLabel=mysql_fetch_row($result_detailLabel);
		
		$financial_label=$row_dtLabel[0];
		$financial_relatedcode=$row_dtLabel[1];
	
		$financialtot_sign=$row_dtLabel[2];
		$financialtot_showresult=$row_dtLabel[3];
		$financialtot_skiprows=$row_dtLabel[4];
		$financialtot_bold=$row_dtLabel[5];
		$financialtot_background=$row_dtLabel[6];
		$financialtot_level=$row_dtLabel[7];
		
			
}

	
//Read From Setup Table							
$querysetup= " select grid_color1, grid_color2 from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

///Read Level of detail with ledger
$query_level="select distinct FinancialTot_Level from FinancialTotLabel where FinancialTot_TreeCode='".$financialtot_treecode."'
				and FinancialTot_code in(select FinancialTot_code from Financialtemplate)";
//echo$query_level;
$result_detailLabel = mysql_query($query_level, $connection);
$row_detailLabel=mysql_fetch_row($result_detailLabel);
$min_level=$row_detailLabel[0];



/// Drop down of related labels
$financialtot_leveltop=$financialtot_level-1;
$queryfinancialrelated = "select FinancialTot_Code, FinancialTot_Label from FinancialTotLabel 
						where FinancialTot_Code not in (
						select distinct FinancialTotLabel.FinancialTot_Code
						from Financialtemplate ,FinancialTotLabel
						where Financialtemplate.FinancialTot_code=FinancialTotLabel.FinancialTot_code)
						and FinancialTot_TreeCode='".$financial_code."'";
					
	if($mode=='editdt')						
		$queryfinancialrelated = $queryfinancialrelated." and financialtot_level='".$financialtot_leveltop."'";
	if($mode=='insertdt' && $min_level!='')			
		$queryfinancialrelated = $queryfinancialrelated." and financialtot_level<'".$min_level."'";
		
	$queryfinancialrelated = $queryfinancialrelated." order by FinancialTot_Label	";

$resultfinancialrelated = mysql_query($queryfinancialrelated, $connection) or die(mysql_error());
	
print <<<HERE

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="default.css" type="text/css" />
<script type="text/javascript" language="javascript">

function SubmitRecord(){
	x=document.financialreportdt;

	 if (x.financial_label.value =="")
	{
		alert("Label is mandatory!");
		x.financial_label.focus();
		return 0;
	}
	
	else  if (x.financial_relatedcode.value =="")
	{
		alert("Related is mandatory!");
		x.financial_relatedcode.focus();
		return 0;
	}
	

	else{
	x.action="Form_FinancialAccounts_Actions.php";
	x.submit();
	}
}

function setfinancialtot_sign(){
	var x = document.financialreportdt;
	if (x.chckfinancialtot_sign.checked==true)
		x.financialtot_sign.value=1;
	else	
	x.financialtot_sign.value=-1;
}

function setfinancialtot_showresult(){
	var x = document.financialreportdt;

	if (x.chckfinancialtot_showresultstatus.checked==true)
		x.financialtot_showresult.value=1;
	else	
	x.financialtot_showresult.value=0;
}

function setfinancialtot_skiprows(){

	var x = document.financialreportdt;
	if (x.chckfinancialtot_skiprowsstatus.checked==true)
		x.financialtot_skiprows.value=1;
	else	
		x.financialtot_skiprows.value=0;
}

function setfinancialtot_bold(){
	var x = document.financialreportdt;
	if (x.chckfinancialtot_boldstatus.checked==true)
		x.financialtot_bold.value=1;
	else	
		x.financialtot_bold.value=0;
}

function setfinancialtot_background(){
	var x = document.financialreportdt;
	if (x.chckfinancialtot_backgroundstatus.checked==true)
		x.financialtot_background.value=1;
	else	
		x.financialtot_background.value=0;
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Financial Accounts Detail</title>


<script type="text/javascript" src="dropdown.js"></script>
<link rel="stylesheet" href="default.css" type="text/css" />
<link rel="stylesheet" href="short.css" type="text/css" />
<link rel="stylesheet" href="dropdown.css" type="text/css" />
<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}
.style11 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; font-size: 10px;}
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #FFFFFF ;font-size: 10px;}

</style>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="tabs.css">
</head>
<body>
<form name='financialreportdt' method='post'>
<input type=hidden name='mode' value='$mode'>
<input type=hidden name='financial_code' value='$financial_code'>
<input type=hidden name='financialdt_code' value='$financialdt_code'>
<input type=hidden name='message' value='$message'>

HERE;



$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";

echo"<table border=0 style='table-layout:fixed' align='left' valign='top'>";
print <<< HERE
		<tr bgcolor='#D0D0D0'><th height="15"  align="center" valign="top"><span class="style3">$type Detail</span></th></tr>
		<tr bgcolor='#F7F7F7' >	
			 <td align='center'><font size='1' color='#FF0000' face='Verdana'><b>$message</b></font></td></tr>			 
      
HERE;

echo"<tr><td><table border=0 style='table-layout:fixed' align='left' valign='top'>
		<col width=140>
		<col width=120>
		<col width=120>
		<col width=140>";

//echo"<tr bgcolor='#F7F7F7'><td valign='center' align='left' ><span class='style12'>&nbsp;</span></td><td colspan='5'><font face='Verdana' size='2'><b>$toplabel</b></font> &nbsp;</td></tr>";


echo"<tr bgcolor='#F7F7F7' height='25'><td valign='center' align='left' ><span class='style12'>Label&nbsp;<span class='style26'></span></span></td>";
echo"<td colspan='5'><input type='text' name='financial_label' value='".htmlspecialchars($financial_label, ENT_QUOTES)."' style='width:350px; ' maxlength='50' /></td></tr>";

echo"<tr bgcolor='#F7F7F7'><td valign='center' align='left' ><span class='style12'>Choose Parent Label</span></td>";

echo"<td colspan='5'>";

if($mode!='insertdt'){
	echo"<select name='financial_relatedcode' style='width: 250px;'";
	echo"> ";
	echo"<option></option>";
	while($relatedfin=mysql_fetch_row($resultfinancialrelated)){
		echo"<option ";
		if ($financial_relatedcode==$relatedfin[0])
			echo " selected ";
		echo" value='$relatedfin[0]'>$relatedfin[1] </option>";
	}
	echo"</select>";
}	
else if($mode=='insertdt'){

	echo"<font face='Verdana' size='2'><b>$parentlabel</b></font>";
	echo"<input type='hidden' name='financial_relatedcode' value='$financial_relatedcode'>";



}	
	
echo"	</td>";

echo"</tr>";

echo"<tr bgcolor='#F7F7F7' height='25'><td><span class='style12'>Level : &nbsp;</span>";
echo"<font face='Verdana' size='2'><b>$financialtot_level</b></font></span></td>
<td valign='center' align='left' >";

	if ($financialtot_sign == '') 
		$financialtot_sign = 1;
	
	if ($financialtot_showresult == '') 
		$financialtot_showresult = 0;
	
	if ($financialtot_skiprows == '') 
		$financialtot_skiprows = 0;
	
	if ($financialtot_bold == '') 
		$financialtot_bold = 0;
		
	if ($financialtot_background == '') 
		$financialtot_background = 0;
		
	if ($financialtot_sign == 1) $financialtot_signstatus = 'checked'; 
	if ($financialtot_showresult == 1) $financialtot_showresultstatus = 'checked'; 
	//if ($financialtot_skiprows == 1) $financialtot_skiprowsstatus = 'checked'; 
	//if ($financialtot_bold == 1) $financialtot_boldstatus = 'checked'; 
	//if ($financialtot_background == 1) $financialtot_backgroundstatus = 'checked'; 
	
	echo"<input type='checkbox' name='chckfinancialtot_sign' $financialtot_signstatus onclick='setfinancialtot_sign()';/>
	<span class='style12'>Sign&nbsp;<span class='style26'></span></span>
	<input type='hidden' name='financialtot_sign' id='financialtot_sign' value='$financialtot_sign'/>		
	</td>";
	echo"<td colspan='4'>";
	echo"<input type='checkbox' name='chckfinancialtot_showresultstatus' $financialtot_showresultstatus onclick='setfinancialtot_showresult()'/>
	<span class='style12'>ShowResult&nbsp;<span class='style26'></span></span>
	<input type='hidden' name='financialtot_showresult' id='financialtot_showresult' value='$financialtot_showresult'/>		
	</td>";
echo"</tr>";

//echo"<tr bgcolor='#F7F7F7' height='25'>";
	
	
	//echo"<td>";
	//echo"<input type='checkbox' name='chckfinancialtot_skiprowsstatus' $financialtot_skiprowsstatus onclick='setfinancialtot_skiprows()'/>
	//<span class='style12'>SkipRows&nbsp;<span class='style26'></span></span>
	echo"<input type='hidden' name='financialtot_skiprows' id='financialtot_skiprows' value='$financialtot_skiprows'/>";		
	//</td>";
	
	//echo"<td>";
//	echo"<input type='checkbox' name='chckfinancialtot_boldstatus' $financialtot_boldstatus onclick='setfinancialtot_bold()'/>
//	<span class='style12'>Bold&nbsp;<span class='style26'></span></span>
	echo"<input type='hidden' name='financialtot_bold' id='financialtot_bold' value='$financialtot_bold'/>";
	
	//</td>";
	
	//echo"<td>";
	//echo"<input type='checkbox' name='chckfinancialtot_backgroundstatus' $financialtot_backgroundstatus onclick='setfinancialtot_background()'/>
	//<span class='style12'>Background&nbsp;<span class='style26'></span></span>
	echo"<input type='hidden' name='financialtot_background' id='financialtot_background' value='$financialtot_background'/>";		
	//</td>
	//</tr>";
	
echo"</table></td></tr>";	

echo"<tr><td><table border=0 align=center width=100%> <tr bgcolor=#D8D8D8 height='35'>";
echo"<td align='center'><input type='button' name='btnPost' id='btnPost' value='Submit Record' ";//post
echo" onclick='SubmitRecord();' $style	title='Save Changes' /></td>";
echo"  </tr></table>";

print <<< HERE
       </td>
      </tr>
	  </table>
HERE;

if($refreshpage=='1'){
	echo'<script type="text/javascript" language="javascript">';
	echo"	opener.document.financialreport.submit();";
	echo"</script>";
}

print <<<HERE
</form>
</body>

HERE;

?>

