<?php

if(isset($_GET['report']))
{
$report=$_GET['report'];
if($report=="ChartOfAccounts")
{

		//$data=array();
		if(isset($_GET['GLStartsWith']) && $_GET['GLStartsWith']!="" && $_GET['GLStartsWith']!="undefined")
		{
		$GLCode=$_GET['GLStartsWith'];
		$GLCode="GLCode like '".$GLCode."%' and";
		}
		else
		{
			$GLCode="";
		}
				if(isset($_GET['Group']) && $_GET['Group']!="")
		{
			$Group="acc.[Group]=".$_GET['Group']." and ";
		}
		else
		{
			$Group=	"";
		}

		$searchbox=$Group.$GLCode;

		 $sql="select ROW_NUMBER() OVER (ORDER BY [Attr18])  as row_num,COAName,Hierarchy,Under,CostCenterID,COAID,GLCode,Degree as Level,
(select COAName  from accounts as c where c.COAID=acc.Under) as L3,
(select COAName  from accounts as c where c.COAID=(select Under from accounts as cc where cc.COAID=acc.Under)) as L2,
(select COAName  from accounts as c where c.COAID=(select Under from accounts as cc where cc.COAID=(select Under from accounts as ccc where ccc.COAID=acc.Under))) as COAHead,(select COAName  from accounts as c where c.COAID=(select Under from accounts as cc where cc.COAID=(select Under from accounts as ccc where ccc.COAID=acc.Under))) as L1
,'' as col_Action,Attr1,Attr2,Attr3,Attr4,Attr5,Attr6,Attr7,Attr8,Attr9,Attr10,Attr11,Attr12,Attr13,Attr14,Attr15,Attr16,Attr17,Attr18,Attr19,Attr20 from accounts as acc where $searchbox acc.Active=1 order by GLCode";
			/*$fields="";
	$result=odbc_exec($connection,$sql);
	for($r=1;$r<=odbc_num_fields($result);$r++)
	{	
	$fields=odbc_field_name($result, $r);
	$contents .= $fields."\t";
	}
	$contents .="\n";
	if(odbc_num_rows($result)>0)
	{
		while($row=odbc_fetch_array($result))
		{
			foreach ($row as $key => $value) {
				# code...
	$contents .= utf8_encode($row[$key])."\t";
			}
	$contents .= "\n";
		
		}
	header('Content-type: application/ms-excel');
	header('Content-Disposition: attachment; filename='.$report);
	echo $contents;
	}*/
	
$file=$report;
$sql=urlencode($sql);
echo "<script>window.location.href='excelexport.php?file=$file&query=$sql';
</script>";
}

	
}

?>