<?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_TargetRebateReport as loginaccess, print as printaccess , 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';	

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

HERE;

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


if (empty($fromdate))	
	$fromdate = displayFromDate(displayToday());
if (empty($todate))	
	$todate = displayToday();
	
	
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">
<!--


function PrintPrev(printaccess)
{
	var x = document.form1;
	
	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
  	
  
	for (var i=0; i < x.currency.length; i++)
	{
		if (x.currency[i].checked)
		{
		  var varcurrency = x.currency[i].value;
		}
	}
	 
	for (var i=0; i < x.reports.length; i++)
	{
		if (x.reports[i].checked)
		{
		  var varreports = x.reports[i].value;
		}
	}
	
	varfromdate   = x.fromdate.value;
	vartodate     = x.todate.value;
	varfromclt    = x.fromclient.value;
	vartoclt      = x.toclient.value;
	  
	str =   'Rep_TargetRebateReport.php?fromdate='+varfromdate+'&todate='+vartodate+'&curr='+varcurrency
		   +'&reports='+varreports+'&fromclient='+varfromclt+'&toclient='+vartoclt;
		   
		   
	if (printaccess==1)
		window.open(str);
	else
		window.open(str,"Report", "width=900,height=600,screenX=0,left=50,screenY=0,top=0,status=no,menubar=no,scrollbars=yes,resizable=yes");
}

function ExportExcel() {
	var x = document.form1;
	
	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
  	
  
	for (var i=0; i < x.currency.length; i++)
	{
		if (x.currency[i].checked)
		{
		  var varcurrency = x.currency[i].value;
		}
	}
	 
	for (var i=0; i < x.reports.length; i++)
	{
		if (x.reports[i].checked)
		{
		  var varreports = x.reports[i].value;
		}
	} 
	
	varfromdate   = x.fromdate.value;
	vartodate     = x.todate.value;
	varfromclt    = x.fromclient.value;
	vartoclt      = x.toclient.value;
	
	str =   'Exp_TargetRebateReport.php?fromdate='+varfromdate+'&todate='+vartodate+'&curr='+varcurrency
		   +'&reports='+varreports+'&fromclient='+varfromclt+'&toclient='+vartoclt;
		   
		   
	window.open(str);


}


function showlistclient(str){

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


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


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'>Target Rebate Report</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('".$printaccess."')\"; title='Preview'><span><span>Preview</span></span></button>";
	

if ($ExporttoExcel==1){
	 echo" <button type='button' id='btnExcel' name='btnExcel' onClick=\"ExportExcel()\"; 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 border="0" align="center" width="100%">';


echo" <tr>";	  
echo"   <td width='20%' height='19' colspan='2' align='left' bgcolor='#F5F5F5'><span class='style8'>Date</span></td> ";
echo"   <td width='15%' height='19' align='center' bgcolor='#F5F5F5'><span class='style8'>Currency</span></td>";
echo"   <td width='15%' height='19' align='center' bgcolor='#F5F5F5'><span class='style8'>Reports</span></td>";
echo"   <td width='50%' height='19' colspan='2' align='left' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";

echo" <tr>";	  
echo"   <td width='5%'  valign='middle' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='15%'  valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"      <input type='text' name='fromdate' value='$fromdate' maxlength='10' style='width:80px;'>";
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='15%' valign='top' rowspan='2' bgcolor='#F5F5F5'><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>";
echo"   </td>";

echo"   <td width='15%' valign='top' rowspan='2' bgcolor='#F5F5F5'><span class='style8'><label>";
echo"      <input name='reports' type='radio' value='1' checked='checked'>Target Report</label></span>";
echo"   <br><span class='style8'><label>";
echo"      <input name='reports' type='radio' value='2'>Rebate Report</label></span>";
echo"   </td>";

echo"   <td width='50%' colspan='2' rowspan='2' bgcolor='#F5F5F5' valign='top'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";

echo" <tr>";
echo"   <td width='5%' valign='top' bgcolor='#F5F5F5'><span class='style8'>To</span></td>";
echo"   <td width='12%' valign='top' bgcolor='#F5F5F5'><span class='style8'>";
echo"      <input type='text' name='todate' value='$todate'  maxlength='10' style='width:80px;'>";
echo"      <A HREF=\"#\" onClick=\"displayCalendar(document.form1.todate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span></td>";
echo" </tr>";

echo" <tr>";
echo"   <td colspan='6' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";


echo" <tr height='20'>";
echo"   <td colspan='4' bgcolor='#F5F5F5'><span class='style8'>Client Code / Description</span></td>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";

echo" <tr>";	  
echo"   <td width='5%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='45%'  colspan='3' valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
        <input name='fromclient' type='text' id='fromclient' size='15' value='".$fromclient."' />
        <input name='fromdesc' type='text' id='fromdesc' size='39' value='".$fromdesc."' />
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Client From ' 
             onClick='showlistclient(1); '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";	 

echo"   <td colspan='2'  align='right' bgcolor='#F5F5F5' ><span class='style8'>&nbsp;</span></td>";		
echo" </tr>";
   
echo" <tr>";	  
echo"   <td width='5%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";
echo"   <td width='45%'  colspan='3' valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
        <input name='toclient' type='text' id='toclient' size='15' value='".$toclient."' />
        <input name='todesc' type='text' id='todesc' size='39' value='".$todesc."' />
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Client To ' 
             onClick='showlistclient(2); '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>"; 

echo"   <td colspan='2'  align='right' bgcolor='#F5F5F5' ><span class='style8'>&nbsp;</span></td>";
echo" </tr>";

echo" <tr>";
echo"   <td colspan='6' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";
   /* <tr>
      <td colspan='6' align='center' bgcolor='#F5F5F5'>
	  <input type='reset'  name='clearbtn' value='Clear' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' />
	  <input type='button' name='preview' id='Preview' 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()\";/>
      </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");
}
	  
?>