<?php


session_start();
if($HTTP_SESSION_VARS['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($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");


$querylog="SELECT RI_SalesReports as loginaccess ,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);
}
if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");

	
if ($ExporttoExcel==1)
	$ExporttoExcelStatus= 'button';
else
	$ExporttoExcelStatus= 'hidden';	
	

	
$querylog="select * from ".$HTTP_SESSION_VARS['dbLabel'].".login where user_account='".$HTTP_SESSION_VARS['useraccount']."' and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."')";
$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;
//Read From Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter ".
             " From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}


$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];

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

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

$fromyear  = strftime("%Y");
$toyear    = strftime("%Y");
$frommonth = strftime("%B");
$tomonth   = strftime("%B");

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 language="JavaScript" src="CalendarPopup.js" ></script><!-- Date only with year scrolling -->
<script type="text/javascript" language="javascript">
<!--






// by serine

function PrintPrev(exp)
{
	var frommonth=document.form1.frommonth.value;
	var tomonth=document.form1.tomonth.value;
	var fromyear=document.form1.fromyear.value;
	var toyear=document.form1.toyear.value;
	var curr=document.form1.currency.value;
window.open('rep_banks.php?frommonth='+frommonth+'&tomonth='+tomonth+'&fromyear='+fromyear+'&toyear='+toyear+'&curr='+curr+'&exp='+exp);
}

-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Bank Reports</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=''>";
		
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'>Bank Reports</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='button' id='btnClear' name='btnClear' onclick='ClearPage();return false;' title='Clear'><span><span>Clear</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>";

	}	
	  
	//echo" <button type='button' id='btnLoadOptions' name='btnLoadOptions' onClick=\"LoadOptions()\"; title='Load Template'><span><span>Load Options</span></span></button>";  
	//echo" <button type='button' id='btnSelectOptions' name='btnSelectOptions' onClick=\"SelectOptions()\"; title='Select Options'><span><span>Select Options</span></span></button>";  
	echo"<button type='button' id='btnPreview' name='btnPreview'  onClick='PrintPrev(0); return false;' title='Preview'><span><span>Preview</span></span></button>";
echo"	</td></tr></table>"; //onclick='SearchForProject(); return false;'
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>";	  
echo"   <td width='33%'  valign='top' bgcolor='#F5F5F5' >";
echo" 	<table border='0' align='left' width='100%' cellpadding=0 cellspacing=1>";
echo"   <tr width='17%'  colspan='2' align='left' bgcolor='#F5F5F5'><span class='style8'>Date</span></tr> ";
echo"   <td width='15%' valign='center'><span class='style8'><label>From</label></span></td>";
echo"   <td width='50%' valign='center'><select name='frommonth'>    
			<option value='1' >January</option>
			<option value='2' >February</option>
			<option value='3' >March</option>
			<option value='4' >April</option> 
			<option value='5' >May</option>
			<option value='6' >June</option>
			<option value='7' >July</option>
			<option value='8' >August</option>
			<option value='9' >September</option>
			<option value='10' >October</option>
			<option value='11' >November</option>
			<option value='12' >December</option>";
echo"   </select>";
echo"   <input type='text' name='fromyear' value='$fromyear'  maxlength='4' style='width:35px;'>";			
echo"   </td></tr>";

echo"   <tr><td valign='center'><span class='style8'><label>To</label></span></td>";
echo"   <td valign='center'><select name='tomonth'>    
			<option value='1' >January</option>
			<option value='2' >February</option>
			<option value='3' >March</option>
			<option value='4' >April</option>
			<option value='5' >May</option>
			<option value='6' >June</option>
			<option value='7' >July</option>
			<option value='8' >August</option>
			<option value='9' >September</option>
			<option value='10' >October</option>
			<option value='11' >November</option>
			<option value='12' >December</option>";
echo"   </select>";
echo"   <input type='text' name='toyear' value='$toyear'  maxlength='4' style='width:35px;'>";			
echo"   </td></tr>";

echo"   <tr></tr>";
echo"   <tr></tr>";
echo"   <td width='17%' height='19' align='left' bgcolor='#F5F5F5'><span class='style8'>Currency</span></td>";
//echo"   <td width='25%' height='19' align='center' bgcolor='#F5F5F5' colspan='2'><span class='style8'>Reports </span></td>";
//echo"   <td width='48%' height='19' align='center' bgcolor='#F5F5F5'><span class='style8'>Options </span></td>";
echo" </tr>";

echo" <tr height='30px'>";	  
echo"   <br></br>";
//echo"   <td width='5%'  valign='middle' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
//echo"   <td width='12%'  valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
//echo"      <input type='text' name='fromdate' value='$fromdate' maxlength='10' size='8'>";
//echo"      <A HREF=\"#\" onClick=\"displayCalendar(document.form1.fromdate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span></td>";
echo"   <td width='10%' rowspan='2' valign='top' bgcolor='#F5F5F5'><span class='style8'><label>";
//echo"      <input name='currency' type='radio' value='currency1'>Currency</label></span>";
echo"   <br><span class='style8'><label>";
echo"      <input name='currency' type='radio' value='$rowsetup[0]' "; if($defaultcurr == $rowsetup[0]) echo "checked"; echo">$rowsetup[0]</label></span>";
echo"   <br><span class='style8'><label>";
echo"      <input name='currency' type='radio' value='$rowsetup[1]' "; if($defaultcurr == $rowsetup[1]) echo "checked"; echo">$rowsetup[1]</label></span></td>";



echo" <tr>";
echo"   <td colspan='5' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";
 /*echo"   <tr>
      <td colspan='5' align='center' bgcolor='#F5F5F5'>
	  <input type='button' name='btnClear' value='Clear' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' onClick=\"ClearPage()\"; />
	  <input type='button' name='btnPreview' id='btnPreview' value='Preview' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' onClick=\"printPrev('".$printaccess."')\"; />
	  <input type='".$ExporttoExcelStatus."' name='btnExcel' id='btnExcel' value='Export Excel' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' onClick=\"exportExcel()\";/>	  
	  <input type='button' name='btnLoadOptions' id='btnLoadOptions' value='Load Options' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' onClick=\"LoadOptions()\"; title='Load Template' />
	  <input type='button' name='btnSelectOptions' id='btnSelectOptions' value='Select Options' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' onClick=\"SelectOptions()\"; title='Select Options' />
      </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>";

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

	  
?>