<?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");




$querylog="SELECT RA_StatementofAccount as loginaccess , ExporttoExcel from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$_SESSION['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");
*/
	
if ($ExporttoExcel==1)
	$ExporttoExcelStatus = 'button';
else
	$ExporttoExcelStatus = 'hidden';


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

}
$printaccess=$Print;

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

HERE;

$querylog=" select ifNull(FI_RepRestrictProject,0) As FI_RepRestrictProject, ifNull(FI_RepRestrictCostcenter,0) As FI_RepRestrictCostcenter ".
          " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."') ";
$resultlog=mysql_query($querylog) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

//Read From Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ifNull(module_ReferenceByCostcenter,0) As module_ReferenceByCostcenter ".
             " ,IfNull(Module_RestrictProjectReport,0) As Module_RestrictProjectReport, module_delivery as ModuleDelivery ".
			 " From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

$querysetup ="select base1, base2 from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
$rowsetup=mysql_fetch_row($resultsetup);

// Setting Initial Values For Parameters
$querydate=" Select Date_Format(Min(Journal_date),'%d/%m/%Y') As DefaultFromDate, ".
           " Date_Format(Max(Journal_date),'%d/%m/%Y') As DefaultToDate ".
		   " From JournalDt ";
$resultdate=mysql_query($querydate,$connection) or die(mysql_error());
$rowdate=mysql_fetch_row($resultdate);

if (!isset($fromdate)) $fromdate = $rowdate[0];
if (!isset($todate))   $todate = $rowdate[1];


$querycurrency="select Currency_code from currency order by currency_code";
$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error());

$queryjvtype="select type_name from jourtype order by type_name";
$resultjvtype=mysql_query($queryjvtype,$connection) or die(mysql_error());


$querydflproject="select project_code as defaultproject from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_project=1 ";
//echo$querydflproject;
$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflproject)){
	extract($rows);
}
$querydflcostcent="select costcent_code as defaultcostcent from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_costcenter=1 ";
$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflcostcent)){
	extract($rows);
}

if ((empty($fromproject)) && $Module_Project == 1  && $Module_RestrictProjectReport == 1 )
	$fromproject = $defaultproject;
if ((empty($fromcostcent)) && $Module_CostCenter == 1)
	$fromcostcent = $defaultcostcent;	

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

<html xmlns="http://www.w3.org/1999/xhtml">
<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 type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<script language="JavaScript" src="CalendarPopup.js" ></script><!-- Date only with year scrolling -->

<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>


<link type="text/css" href="js/calendar/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="js/calendar/jquery.datepick.js"></script>

<link type="text/css" href="js/grid/scripts/jquery-ui.css" rel="stylesheet">
<script type="text/javascript" src="js/grid/scripts/jquery-ui.min.js"></script>



<script type="text/javascript" language="javascript">
<!--
function cgr7(){
x=document.form1;
//code1a=x.code1a.value;
document.form1.action="select_item.php?item=1";
document.form1.btncode1.submit();

}

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

}

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




function showlistsalesman(str){
  var vdate, vcode; 
  vcode=encodeURIComponent(document.form1.clientsalesman.value);
  vname=encodeURIComponent(document.form1.clientsalesmanname.value);
  if(vcode=='')
	vcode=vname;
  window.open('List_Salesmen.php?frm=20&str=20&item='+str+'&PLedger_number='+vcode,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}



function Exportexcel(){

	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
  	
	for (var i=0; i < document.form1.date.length; i++)
	{
		if (document.form1.date[i].checked)	{
			var vardate = document.form1.date[i].value;
		}
	}	 
  
	for (var i=0; i < document.form1.transaction.length; i++)
	{
		if (document.form1.transaction[i].checked){
			var vartransaction = document.form1.transaction[i].value;
		}
	}
	 
	for (var i=0; i < document.form1.ledgeroption.length; i++)
	{
		if (document.form1.ledgeroption[i].checked) {
			var varledgeroption = document.form1.ledgeroption[i].value;
		}
	}
  
  
	varexclude = 0;
	if (document.form1.exclude.checked)   varexclude = 1;	
	
	varalltypes = 0;
	if (document.form1.alltypes.checked)  varalltypes = 1;	
	
	var checkname;
	var x, varjvtype;
	varjvtype = '';
	for (var i=1; i <= document.form1.i.value; i++)
	{
		checkname='type'+i;
	
		x = document.getElementById(checkname);
		if (varalltypes == 0 && x.checked) 
			varjvtype = varjvtype+",'"+x.value+"'";
    
	}
	varjvtype = varjvtype.substr(1);
  
	varcurr = 0;
	if (document.form1.curr.checked)    varcurr = 1;	 
	
	varcurrbase1 = 0;
	if (document.form1.currbase1.checked)  varcurrbase1 = 1;	
	
	varcurrbase2 = 0;
	if (document.form1.currbase2.checked)   varcurrbase2 = 1;		
	
	varcum = 0;
	if (document.form1.cumulative.checked)   varcum = 1;	
 	
  	

	varprtfolio = 0;
	if (document.form1.prtfolio.checked)   varprtfolio = 1;			
	
	varprtref = 0;
	if (document.form1.prtref.checked)	   varprtref = 1;
	
	varprtdesc = 0;
	if (document.form1.prtdesc.checked)    varprtdesc = 1;	
	
	varprtvaluedate = 0;
	if (document.form1.prtvaluedate.checked)    varprtvaluedate = 1;	
	
	varprtjvtype = 0;
	if (document.form1.prtjvtype.checked)    varprtjvtype = 1;		
	
	varshowunposted = 0;
	if (document.form1.showunposted.checked)    varshowunposted = 1;	
	
	varprtcostcent = 0;
	if (document.form1.prtcostcent.checked)    varprtcostcent = 1;		
  
	varprtproject = 0;
	if (document.form1.prtproject.checked)	   varprtproject = 1;			
	
	varprevbal = 0;
	if (document.form1.prevbal.checked)    varprevbal = 1;			
	
	vardtjv = 0;
	if (document.form1.dtjv.checked)    vardtjv = 1;	

	vardtdate = 0;
	if (document.form1.dtdate.checked)    vardtdate = 1;		
	
	varchecks = 0;
	if (document.form1.checks.checked)    varchecks = 1;	

	varparentprj = 0;
	if (document.form1.parentprj.checked)    varparentprj = 1;	
	
	varprintaging = 0;
	if (document.form1.prtaging.checked)    varprintaging = 1;		
	
	varprtheader = 0;
	if (document.form1.prtheader.checked)    varprtheader = 1;	
	
	varprtcstjour = 0;
	if (document.form1.prtcstjour.checked)    varprtcstjour = 1;	
	
	varprtwording = 0;
	if (document.form1.prtwording.checked)    varprtwording = 1;
	
    varprtwnac =0;
	if (document.form1.prtwnac.checked)    varprtwnac = 1;
	
	
  
	varfromdate   = document.form1.fromdate.value;
	vartodate     = document.form1.todate.value;
	varfromledger = document.form1.fromledger.value;
	vartoledger   = document.form1.toledger.value;
	varfromprj    = document.form1.fromproject.value;
	varfromcst    = document.form1.fromcostcent.value;
	varfromcur    = document.form1.fromcur.value;
	varcltprj     = document.form1.clientproject.value;
	varcltcst     = document.form1.clientcostcent.value;
	varsalesman     = document.form1.clientsalesman.value;
  
	varcltprj = varcltprj.replace('&','%26');
	varcltcst = varcltcst.replace('&','%26');
  
  
    if(document.getElementById("prtspecial").checked)
		var specialcheck = 1;
	else var specialcheck = 0;
	if(specialcheck == 1)
		str =   'Exp_StatementofAccountaction.php?fromdate='+varfromdate+'&todate='+vartodate+'&fromledger='+varfromledger
           +'&toledger='+vartoledger+'&fromproject='+varfromprj+'&fromcst='+varfromcst+'&fromcur='+varfromcur
		   +'&dateoption='+vardate+'&transaction='+vartransaction+'&ledgeroption='+varledgeroption
		   +'&curr='+varcurr+'&currbase1='+varcurrbase1+'&currbase2='+varcurrbase2+'&cum='+varcum
		   +'&alltypes='+varalltypes+'&exclude='+varexclude+'&jvtype='+varjvtype+'&showunposted='+varshowunposted
		   +'&prtfolio='+varprtfolio+'&prtref='+varprtref+'&prtdesc='+varprtdesc+'&prtvaluedate='+varprtvaluedate
		   +'&prtjvtype='+varprtjvtype+'&prtcostcent='+varprtcostcent+'&prtproject='+varprtproject+'&prevbal='+varprevbal
		   +'&dtjv='+vardtjv+'&dtdate='+vardtdate+'&checks='+varchecks+'&cltcst='+varcltcst+'&cltprj='+varcltprj
		   +'&parentprj='+varparentprj+'&prtaging='+varprintaging+'&prtheader='+varprtheader+'&prtcstjour='+varprtcstjour
		   +'&prtwording='+varprtwording+'&salesman='+varsalesman+'&prtwnac='+varprtwnac;
	else
	str =   'Exp_statementofaccount.php?fromdate='+varfromdate+'&todate='+vartodate+'&fromledger='+varfromledger
           +'&toledger='+vartoledger+'&fromproject='+varfromprj+'&fromcst='+varfromcst+'&fromcur='+varfromcur
		   +'&dateoption='+vardate+'&transaction='+vartransaction+'&ledgeroption='+varledgeroption
		   +'&curr='+varcurr+'&currbase1='+varcurrbase1+'&currbase2='+varcurrbase2+'&cum='+varcum
		   +'&alltypes='+varalltypes+'&exclude='+varexclude+'&jvtype='+varjvtype+'&showunposted='+varshowunposted
		   +'&prtfolio='+varprtfolio+'&prtref='+varprtref+'&prtdesc='+varprtdesc+'&prtvaluedate='+varprtvaluedate
		   +'&prtjvtype='+varprtjvtype+'&prtcostcent='+varprtcostcent+'&prtproject='+varprtproject+'&prevbal='+varprevbal
		   +'&dtjv='+vardtjv+'&dtdate='+vardtdate+'&checks='+varchecks+'&cltcst='+varcltcst+'&cltprj='+varcltprj
		   +'&parentprj='+varparentprj+'&prtaging='+varprintaging+'&prtheader='+varprtheader+'&prtcstjour='+varprtcstjour
		   +'&prtwording='+varprtwording+'&salesman='+varsalesman+'&prtwnac='+varprtwnac;
  
	window.open(str);
  
}


function kdClient(choice,e,app)
{   
	 x = document.form1;
	if(app==0){
		var clientcode = x.fromledger.value;
		if(clientcode=='')
		var clientcode = x.fromledgername.value;
	} else {
		var clientcode = x.toledger.value;
		if(clientcode=='')
		var clientcode = x.toledgername.value;
	}	
    var intKey = (window.Event) ? e.which : e.keyCode;
	
		
    if (intKey == 13) { //enter key
	
	
		var xmlhttp = getXMLHttpRequest();	
		
		
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				var data = xmlhttp.responseText.split("[BRK]");
				
					if(app==0){
						if(data[0]!=''){
								x.fromledger.value = data[0];
								x.fromledgername.value = data[1];
									if(x.toledger.value==''){
									x.toledger.value = data[0];
									x.toledgername.value = data[1];
									
									}
						}
						else showlistledger(1);
					} else {
						if(data[0]!=''){
								x.toledger.value = data[0];
								x.toledgername.value = data[1];
							//if(x.toledgername.value!=''){
							//	x.submit();	
							//} 
						}
						else showlistledger(2);						
					}
			}
		}
	    
		xmlhttp.open("GET","Form_Statementofaccount_Action.php?mode=getclientname&clientcode="+clientcode+"&choice="+choice);
		xmlhttp.send();
	
      
			
			
    }
	

}


function kdSalesman(choice,e,app)
{   
	 x = document.form1;
	if(app==0){
		var clientcode = x.clientsalesman.value;
		var clientname = x.clientsalesmanname.value;
	} else {
		var clientcode = x.clientsalesman.value;
		var clientname = x.clientsalesmanname.value;
	}	
    var intKey = (window.Event) ? e.which : e.keyCode;
	
		
    if (intKey == 13) { //enter key
	
	
		var xmlhttp = getXMLHttpRequest();	
		
		
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				var data = xmlhttp.responseText.split("[BRK]");
				 
					
					 
						if(data[0]!=''){
								x.clientsalesmanname.value = data[1];
									if(x.clientsalesman.value==''){
									x.clientsalesman.value = data[0];
									x.clientsalesmanname.value = data[1];
									
									}
						}
						else showlistsalesman(1);
					 
			}
		}
	    
		xmlhttp.open("GET","Form_statementofaccount_action.php?mode=getsalesmanname&clientcode="+clientcode+"&choice="+choice+"&clientname="+clientname);
		xmlhttp.send();
	
      
			
			
    }
	
	
  


}



function printPrev(printaccess)
{
	var x = document.form1;
	var sections = x.sections.value;
	//alert(sections);
	var from_date = x.from_date.value;
    var to_date = x.to_date.value;
	var trans_type = x.trans_type.value;
	var trans_company = x.trans_company.value;
	var trans_year = x.trans_year.value;
	var trans_operator = x.trans_operator.value;
	var delivery_ref_search = x.delivery_ref_search.value;
	var orderby = x.orderby.value;
	//var returndelivery_ref_search = x.returndelivery_ref_search.value;
	if(sections == ""){
		alert("Please choose a section!");
	}
	else{
	if(sections == "delivery"){
		var str = "Rep_UserLogDeliveries.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&delivery_ref_search="+delivery_ref_search+"&orderby="+orderby;
	}
	else
		if(sections == "return_delivery"){
			var str = "Rep_UserLogReturnDeliveries.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&returndelivery_ref_search="+delivery_ref_search+"&orderby="+orderby;
		}
		else
		if(sections == "sales_order"){
			var str = "Rep_UserLogSalesOrder.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&sorder_ref_search="+delivery_ref_search+"&orderby="+orderby;
		}
		else
		if(sections == "purchases"){
			var str = "Rep_UserLogPurchases.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&purchases_ref_search="+delivery_ref_search+"&orderby="+orderby;
		}
		else
		if(sections == "return_purchases"){
			var str = "Rep_UserLogReturnPurchases.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&purchases_ref_search="+delivery_ref_search+"&orderby="+orderby;
		}
		else
		if(sections == "purchase_order"){
			var str = "Rep_UserLogPurchaseOrder.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&porder_ref_search="+delivery_ref_search+"&orderby="+orderby;
		}
		else
		if(sections == "purchase_request"){
			var str = "Rep_UserLogPurchaseRequest.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&prequest_ref_search="+delivery_ref_search+"&orderby="+orderby;
		}
		else
		if(sections == "transfer"){
			var str = "Rep_UserLogTransfer.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&transfer_ref_search="+delivery_ref_search+"&orderby="+orderby;
		}
		else
		if(sections == "transfer_request"){
			var str = "Rep_UserLogTransferRequest.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&transfer_ref_search="+delivery_ref_search+"&orderby="+orderby;
		}
		else
		if(sections == "production"){
			var str = "Rep_UserLogProduction.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&production_ref_search="+delivery_ref_search+"&orderby="+orderby;
		}
		else
		if(sections == "adjustment"){
			var str = "Rep_UserLogAdjustment.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&adjustment_ref_search="+delivery_ref_search+"&orderby="+orderby;
		}
		else
			if(sections == "grnpurchases"){
				var str = "Rep_UserLogGRN.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&grnpurchases_ref_search="+delivery_ref_search+"&orderby="+orderby;
			}
			else
				if(sections == "journal"){
					var str = "Rep_UserLogJournal.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&journal_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
					if(sections == "RV" || sections == "PV" || sections == "CV" || sections == "DV"){
						var str = "Rep_UserLogTrans.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&trans_ref_search="+delivery_ref_search+"&trans_type2="+sections+"&orderby="+orderby;
					}
					else
				if(sections == "salesjv"){
					var str = "Rep_UserLogSalesJv.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&salesjv_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
				if(sections == "purchasesjv"){
					var str = "Rep_UserLogPurchasesJv.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&purchasesjv_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
				if(sections == "clients"){
					var str = "Rep_UserLogClients.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&client_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
				if(sections == "items"){
					var str = "Rep_UserLogItems.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&item_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
				if(sections == "salesmen"){
					var str = "Rep_UserLogSalesmen.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&salesman_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
				if(sections == "ledger"){
					var str = "Rep_UserLogLedger.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&ledger_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
				if(sections == "project"){
					var str = "Rep_UserLogProject.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&project_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
				if(sections == "costcenter"){
					var str = "Rep_UserLogCostcenter.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&costcenter_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
				if(sections == "currency"){
					var str = "Rep_UserLogCurrency.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&currency_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
				if(sections == "grouping"){
					var str = "Rep_UserLogGrouping.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&grouping_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
				if(sections == "subgroup"){
					var str = "Rep_UserLogSubGroup.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&subgroup_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
				if(sections == "warehouse"){
					var str = "Rep_UserLogWarehouse.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&warehouse_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
				if(sections == "category"){
					var str = "Rep_UserLogCategory.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&category_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
				if(sections == "area"){
					var str = "Rep_UserLogArea.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&area_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
				if(sections == "banks"){
					var str = "Rep_UserLogBanks.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&bank_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
				if(sections == "pos"){
					var str = "Rep_UserLogPOS.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&sale_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
				else
				if(sections == "alltransactions"){
					var str = "Rep_UserLogAllTransactions.php?from_date="+from_date+"&to_date="+to_date+"&trans_type="+trans_type+"&trans_company="+trans_company+"&trans_year="+trans_year+"&trans_operator="+trans_operator+"&sale_ref_search="+delivery_ref_search+"&orderby="+orderby;
				}
	else{
		var str = "";
	}
	window.open(str);
	}
}


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 str1, selectpage;
  for (var i=0; i < document.form1.ledgeroption.length; i++)
  {
    if (document.form1.ledgeroption[i].checked)
    {
      str1 = document.form1.ledgeroption[i].value;
	  if (str1 == 1)
	    selectpage = 'select_ledger.php?item='+str+'&PLedger_Number='+varledger+'&PLedger_Name='+varledgername;
	  else  if (str1 == 2)
        selectpage = 'select_document.php?item='+str+'&form=2';	
	   else  if (str1 == 3)
        selectpage = 'select_document.php?item='+str+'&form=3';		
    }
  }

  
  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 showlistProject(frm) {
	window.open('List_SorProject.php?frm='+frm+'&item=','mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistCostcenter(frm){

  window.open('List_SorCostcenter.php?frm='+frm+'&item=','mywindow','width=850,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function select_alljvtypes() {
   
   var checkname;
   var x;
   for (var i=1; i <= document.form1.i.value; i++)
  {
    checkname='type'+i;
	
	x = document.getElementById(checkname);
	if (document.form1.alltypes.checked) 
		x.checked = true;
	else
       	x.checked = false;
    
  }
  
  if (document.form1.alltypes.checked) {
     document.form1.exclude.checked = false;
     document.form1.exclude.disabled = true;
  }	 
  else
     document.form1.exclude.disabled = false;

}

function CheckCummulative() {

	var x= document.form1;
	if (x.curr.checked == false && ((x.currbase1.checked == true && x.currbase2.checked == false) || 
									(x.currbase1.checked == false && x.currbase2.checked == true))) 
		x.cumulative.disabled = false;	 
	else {
	    x.cumulative.checked = false;
        x.cumulative.disabled = true;	 	
	}	

}

function CheckValueDate(option) {

	var x= document.form1;
	if (x.prtvaluedate.checked == true && x.prtjvtype.checked == true && option == 1 ) 
		x.prtjvtype.checked = false;	 
		
	if (x.prtvaluedate.checked == true && x.prtjvtype.checked == true && option == 2 ) 
		x.prtvaluedate.checked = false;	 	

}

function CheckDetailedPerDate() {

	var x= document.form1;
	if (x.dtdate.checked == false ) { 
	
	  x.prtref.checked = false;
	  x.checks.checked = false;
	  x.dtjv.checked = false;
	  x.prtref.disabled = true;
	  x.checks.disabled = true;
	  x.dtjv.disabled = true;
	  
    } else {
      
      x.prtref.checked = true;
	  x.checks.checked = true;
	  x.prtref.disabled = false;
	  x.checks.disabled = false;
	  x.dtjv.disabled = false;	  
	
	}
		
	

}
-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>User Log</title>
<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>

<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>
</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>";

if($ModuleDelivery == 1){
	$Delivery = "Delivery";
}
else{
	$Delivery = "Sales";
}

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'>User Log</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'><span><span>Clear</span></span></button>";
		echo"<button type='button' id='btnPreview' name='btnPreview'  onClick=\"printPrev('".$printaccess."')\"; title='Preview'><span><span>Preview</span></span></button>";

	
  
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'>";

echo" <td colspan='3' bgcolor='#F5F5F5' valign='top'><table border='0' cellpading=1 cellspacing=0 width=100%>";


echo "<tr style='height: 15px'>
<td colspan=2></td>
</tr>";
$curr_date = date("d/m/Y");
echo "<tr>
<td style='width: 50%; vertical-align: top; text-align: left'>
<table width=100%>
<tr>
<td style='width: 30%'><b>Date:</b></td>
<td>From <input type='text' name='from_date' id='from_date' value='$curr_date' style='width: 75px' /> <A HREF=\"#\" onClick=\"displayCalendar(document.form1.from_date,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A> &nbsp;&nbsp;&nbsp;To <input type='text' name='to_date' id='to_date' value='$curr_date' style='width: 75px' /> <A HREF=\"#\" onClick=\"displayCalendar(document.form1.to_date,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></td>
</tr>
<tr>
<td><b>Ref # / Code: </b></td>
<td><input type='text' name='delivery_ref_search' id='delivery_ref_search' style='width: 282px' /></td>
</tr>
<tr>
<td style='width: 20%'><b>Type:</b></td>
<td><input type='radio' name='trans_type' value='a' checked /> All <input type='radio' name='trans_type' value='U' /> Update <input type='radio' name='trans_type' value='D' /> Delete </td>
</tr>
<tr>
<td style='width: 20%'><b>Company / Year:</b></td>
<td><select name='trans_company' id='trans_company' style='width: 141.5px;'>
<option value=''></option>";
// <td><input type='radio' name='trans_type' value='a' checked /> All <input type='radio' name='trans_type' value='I' /> Insert <input type='radio' name='trans_type' value='U' /> Update <input type='radio' name='trans_type' value='D' /> Delete </td>
$query_companies  = "select distinct(CompanyName) as ListOfCompanies from ".$_SESSION['dbLabel'].".listuserdir where usercode = '".$_SESSION['useraccount']."'";
$result_companies = mysql_query($query_companies, $connection);
while($row_companies = mysql_fetch_array($result_companies)){
	extract($row_companies);
	echo "<option value='$ListOfCompanies'>$ListOfCompanies</option>";
}	
echo"</select><select name='trans_year' id='trans_year' style='width: 141.5px;'>
<option value=''></option>";
$query_years  = "select distinct(Diryear) as ListOfYears from ".$_SESSION['dbLabel'].".listuserdir where usercode = '".$_SESSION['useraccount']."'";
$result_years = mysql_query($query_years, $connection);
while($row_years = mysql_fetch_array($result_years)){
	extract($row_years);
	echo "<option value='$ListOfYears'>$ListOfYears</option>";
}	
echo "</select></td>
</tr>
<tr>
<td style='width: 20%'><b>User:</b></td>
<td><select name='trans_operator' id='trans_operator' style='width: 283px'>
<option value=''></option>";
$queyr_users  = "select concat(user_name, ' [', user_account, ']') as ListOfUsers, user_account from ".$_SESSION['dbLabel'].".users";
$result_users = mysql_query($queyr_users, $connection); 
while($row_users = mysql_fetch_array($result_users)){
	extract($row_users);
	echo "<option value='$user_account'>$ListOfUsers</option>";
}
echo"</select></td>
</tr>
<tr>
<td style='vertical-align: top'><b>Order By:</b></td>
<td style='vertical-align: top'><input type='radio' name='orderby' value='date' checked> Date <br>
<input type='radio' name='orderby' value='user_date'> User & Date<br>
<input type='radio' name='orderby' value='company_date'> Company/Year & Date<br>
<input type='radio' name='orderby' value='company_user_date'> Company/Year, User, & Date</td>
</tr>
</table>
</td>
<td style='text-align: left; width: 25%; vertical-align: top;'><b>Archive</b><br>
<input type='radio' name='sections' value='items' /> Items<br>
<input type='radio' name='sections' value='ledger' /> Ledger<br>
<input type='radio' name='sections' value='clients' /> Clients<br>
<input type='radio' name='sections' value='salesmen' /> Salesmen<br>
<input type='radio' name='sections' value='project' /> Project<br>
<input type='radio' name='sections' value='costcenter' /> Costcenter<br>
<input type='radio' name='sections' value='currency' /> Currency<br>
<input type='radio' name='sections' value='grouping' /> Grouping<br>
<input type='radio' name='sections' value='subgroup' /> Sub Group<br>
<input type='radio' name='sections' value='warehouse' /> Warehouse<br>
<input type='radio' name='sections' value='category' /> Category<br>
<input type='radio' name='sections' value='area' /> Area<br>
<input type='radio' name='sections' value='banks' /> Banks<br>
<br>
<b>Accounting</b><br>
<input type='radio' name='sections' value='RV' /> Receipt<br>
<input type='radio' name='sections' value='PV' /> Payment<br>
<input type='radio' name='sections' value='CV' /> Credit Note<br>
<input type='radio' name='sections' value='DV' /> Debit Note<br>
<input type='radio' name='sections' value='journal' /> Journal<br>
<input type='radio' name='sections' value='salesjv' /> Sales Jv<br>
<input type='radio' name='sections' value='purchasesjv' /> Purchases Jv<br>
<br>

</td>
<td style='width: 25%; vertical-align: top; text-align: left'>
<b>Inventory</b><br>
<input type='radio' name='sections' value='delivery' /> $Delivery<br>
<input type='radio' name='sections' value='return_delivery' /> Return $Delivery<br>
";

// if($ModuleDelivery == 1){
// echo"<input type='radio' name='sections' value='sales' /> Sales<br>
// <input type='radio' name='sections' value='return_sales' /> Return Sales<br>";
// }
echo"<input type='radio' name='sections' value='sales_order' /> Sales Order<br>
<input type='radio' name='sections' value='purchases' /> Purchases<br>
<input type='radio' name='sections' value='return_purchases' /> Return Purchases<br>
<input type='radio' name='sections' value='purchase_order' /> Purchase Order<br>
<input type='radio' name='sections' value='transfer' /> Transfer<br>
<input type='radio' name='sections' value='transfer_request' /> Transfer Request<br>
<input type='radio' name='sections' value='adjustment' /> Adjustment <b>[Stock In / Out]</b><br>
<input type='radio' name='sections' value='grnpurchases' /> Good Receive Note<br>
<b>All Transactions</b><br>
<input type='radio' name='sections' value='alltransactions' /> All Transactions<br>
</td>

</tr>";
// <input type='radio' name='sections' value='production' /> Production <b>[Assemble]</b><br>
// <input type='radio' name='sections' value='purchase_request' /> Purchase Request<br>
//<input type='radio' name='sections' value='pos' /> POS Cash Register<br><br>



		

/*
echo" 
    <tr>
      <td colspan='6' align='center' bgcolor='#F5F5F5'>
	  <input name='clearbtn' type='reset'  value='Clear' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' />
	  <input name='preview' type='button' id='Preview' value='Preview' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' onClick=\"printPrev('".$printaccess."')\"; />
	  <input name='exporttoexcel' type='".$ExporttoExcelStatus."' id='exporttoexcel' value='Export Excel'  style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' onClick=\"Exportexcel()\"; />
	  
      </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>";

?>