<?php


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

include("config.inc.php");

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");


$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");

$query="select ifnull(ShowReportHeader,0) as ShowReportHeader from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."' ";
$result=mysql_query($query,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result)){
	extract($rows);
}
if($ShowReportHeader=='')
	$ShowReportHeader=1;

$querylog="SELECT print as printaccess, ifNull(FI_Grn,0) As FI_Grn, ifNull(FI_Purchases,0) As FI_Purchases, ExporttoExcel from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."')	";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

$querymodule=" Select  ifNull(module_ReferenceByCostcenter,0) As module_ReferenceByCostcenter From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

$querylog="SELECT RI_ListTransaction as loginaccess from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."')	";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}
if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");
	
	

$querylog="select * from ".$HTTP_SESSION_VARS['dbLabel'].".login where user_account='".$HTTP_SESSION_VARS['useraccount']."'";
$resultlog=mysql_query($querylog) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
extract($rows);

}


$querysalessetup="select Salesttc from salessetup";
$resultsalessetup=mysql_query($querysalessetup,$connection) or die(mysql_error());
while($rowssalessetup=mysql_fetch_array($resultsalessetup)){
  extract($rowssalessetup);
}

$querysetup ="select base1, base2, if(DefaultBase=1, base1, base2) as defaultcurr from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
$rowsetup=mysql_fetch_row($resultsetup);
$defaultcurr = $rowsetup[2];

$querydflproject="select project_code as defaultproject from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."' and default_project=1 ";
$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflproject)){
extract($rows);

}

$queryproject=" select distinct project.project_code, project_name ".
              " from project left join ".$HTTP_SESSION_VARS['dbLabel'].".loginstk on project.project_code like concat(loginstk.project_code,'%') ".
			  " where user_account='".$HTTP_SESSION_VARS['useraccount']."' ".
			  " and (loginstk.project_code is not null and loginstk.project_code != '') ".
			  " order by project.project_code";
			  
$projectresult = mysql_query($queryproject,$connection) or die(mysql_error());
$projectrows   = mysql_num_rows($projectresult);
if ($projectrows == 0)
    $queryproject=" select distinct project_code, project_name from project order by project_code ";			  
$resultproject=mysql_query($queryproject,$connection) or die(mysql_error());


$querysordertype="select Sorder_Type, Sorder_TypeName from sordertype where FormType = 'Sorder' order by Sorder_Type";
$resultsordertype=mysql_query($querysordertype,$connection) or die(mysql_error());

if (empty($fromdate)) $fromdate = displayToday();
if (empty($todate))   $todate   = displayToday();

print <<< HERE


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">

<script language="JavaScript" src="CalendarPopup.js" ></script>
<script type="text/javascript" language="javascript">

function cgr7(){
x=document.form1;
//code1a=x.code1a.value;
document.form1.action="select_client.php?item=1";
document.form1.btncode1.submit();

}

function cgr8(){
x=document.form1;
//code2a=x.code2a.value;
document.form1.action="select_client.php?item=2";
document.form1.btncode2.submit();

}

all = 0;  // 0 means 'no', 1 means 'yes'

function showlistledger(str){

	if(str==1){
		varledger = document.form1.fromledger.value;
		varledgername = document.form1.fromledgername.value;
	} else {
		varledger   = document.form1.toledger.value;
		varledgername = document.form1.toledgername.value;
	}
	var selectpage = 'select_ledger.php?item='+str+'&PLedger_Number='+varledger+'&PLedger_Name='+varledgername;
	window.open(selectpage,'mywindow','width=800,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function PrintPrev(exp)
{

	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
  	
	for (var i=0; i < document.form1.Grp.length; i++)
	{
		if (document.form1.Grp[i].checked)
		{
			var vargrp = document.form1.Grp[i].value;
		}
	}
	
	varprtheader = 0;
	if (document.form1.prtheader.checked)
		varprtheader = 1;
	
	varnewPage = 0;
	if (document.form1.newPage.checked)    varnewPage = 1;	
  
	varfromLedger = document.form1.fromledger.value;
	vartoLedger   = document.form1.toledger.value;

	str = 'Rep_LedgerList.php?fromLedger='+varfromLedger+'&toLedger='+vartoLedger+'&Grp='+vargrp+'&newPage='+varnewPage+'&prtheader='+varprtheader+'&export='+exp;
  
	window.open(str);
	
 
}

</script>


<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
.style1 {
	color: #FF0000;
	font-family: "Times New Roman", Times, serif;
	font-size: 20px;
}
.style8 {font-size: 11px; color: #999999; font-weight: bold; }
.style11 {font-size: 11px}
body {
	margin-top: 0px;
}

</style>

<title>List of Ledgers</title>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20101112" media="screen"></link>
<script type="text/javascript" src="dhtmlgoodies_calendar.js?random=20100118"></script>

</head>
<body>
HERE;

echo "<form id='form1' name='form1' method='post' action='$_SERVER[PHP_SELF]'>";

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";


echo" <tr style='height:26px;'>
		<td  valign='top' id='content-top'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'>  List Transaction</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";

echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='30'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px' align='left'>";
				
echo" <button type='reset' id='btnClear' name='btnClear'  title='Clear Page'><span><span>Clear</span></span></button>";
     

	 echo" <button type='button' id='preview' name='preview' onClick=\"PrintPrev(0)\"; title='Preview'><span><span>Preview</span></span></button>";
	

if ($ExporttoExcel==1){
	 echo" <button type='button' id='btnExcel' name='btnExcel' onClick=\"PrintPrev(1)\"; title='Export Excel'><span><span>Export Excel</span></span></button>";

}	
else{}
	
	

echo"	</td></tr></table>";
echo"</td></tr>";				

		
echo"<tr><td id='content-body'>
<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
   <tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='10'>";		
   
echo "  <table height='534' border='0' align='center' width='100%'>";


echo"    <tr height='15px'>";
echo"      <td colspan='2' rowspan='3' bgcolor='#F5F5F5' valign='top'><span class='style8'>";

echo "<input name='Grp' type='radio' value='Group'  />";
echo"      Group Account";
echo"      <br />";
echo "<input name='Grp' type='radio' value='Auxiliary' />";
echo"      Auxiliary Account<br />";
echo "<input name='Grp' type='radio' value='Both' checked/>";
echo"       Both <br />";

echo"      <input name='newPage' type='checkbox' id='newPage' value='both1'/>";
echo"      Force new page for each class <br>";


if($ShowReportHeader== 1 && $module_ReferenceByCostcenter== 1)
	echo"      <input name='prtheader' type='checkbox' id='prtheader' value='1' checked />";
else
if($ShowReportHeader== 0 && $module_ReferenceByCostcenter== 1)
	echo"      <input name='prtheader' type='checkbox' id='prtheader' value='1'  />";
else
if($module_ReferenceByCostcenter== 0)
	echo"      <input name='prtheader' type='checkbox' id='prtheader' value='1' checked />";
else
	echo"      <input name='prtheader' type='checkbox' id='prtheader' value='1'  />";
echo"      Show Report Header";
echo"      </span>";
echo"
        <p class='style8'>
      </p></td>";
	
echo" <td align='right' bgcolor='#F5F5F5'><span class='style8'>From Ledger</span></td>
      <td colspan='4' bgcolor='#F5F5F5'><span class='style8'>
	  <label>
        <input name='fromledger' type='text' id='fromledger' size='15'/>";
echo"   <input name='fromledgername' type='text' id='fromledgername' size='30'/>";
echo"   <input name='btncode1' type='hidden' id='btncode1' value='...' onclick='cgr7()' style='width:20px; height:20px; border:thin;' title='Select Supplier From' />
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Supplier From ' 
             onClick='showlistledger(1);' ><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label>

      </td> 
    </tr>
    <tr height='15px'>
      <td align='right' bgcolor='#F5F5F5'><span class='style8'>To Ledger</span></td>
      <td colspan='4' bgcolor='#F5F5F5'><span class='style8'>
	  <label>
        <input name='toledger' type='text' id='toledger' size='15'/>";
echo"   <input name='toledgername' type='text' id='toledgername' size='30'/>";
echo"  <input name='btncode2' type='hidden' id='btncode2' value='...' onclick='cgr8()' style='width:20px; height:20px; border:thin;' title='Select Supplier To' />
        </label></span>
        <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Supplier To ' 
        onClick='showlistledger(2);' ><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label>
      </td>
	  <td valign='top' colspan='2' rowspan='4' bgcolor='#F5F5F5'>";
	  
	  echo"<div style='overflow:auto; height:80px; width:65px;' ><table border='0'><tr><td>";
		echo "<input type='hidden' name='i' value='$i'>";
		echo "</td></tr></table></div>";  

echo" </td>
    </tr>
    <tr>
      <td colspan='5' bgcolor='#F5F5F5'>&nbsp;</td>
	  <td colspan='2' bgcolor='#F5F5F5'>&nbsp;</td>
    </tr>
  ";
	
	echo"   </table></td></tr>"; 
 echo"   </table></td></tr><tr height='30'><td align='center' id='content-bottom' ></td></tr>";  
 echo" </table>
 
</form>
</body>
</html>";

// <input name='submit' type='submit' id='submit' value='Search' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'  /> 

//Return Date in DD/MM/YYYY format
function displayFromDate($data){
	return "01/01/".substr($data, 6, 4);		
}
//Return Today's Date in DD/MM/YYYY format
function displayToday(){
	return strftime("%d")."/".strftime("%m")."/".strftime("%Y");
}

?>
