<?php


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

print <<< HERE

<HTML>
<HEAD>
<TITLE> Currencies Details </TITLE>

<style type="text/css">

table.master th { font-size: 14px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
				  border-top: 2 solid #000000;
				  border-bottom: 1 solid #000000;
				 }
table.master td { font-size: 14px; 
                  font-family:Times-New-Roman;
                 }
table.master td.reportfooter {font-size: 14px; 
                              font-weight: bold;
                              font-family:Times-New-Roman;
				              border-top: 1 solid #000000;
							  }
							  

</style>


</HEAD>

<BODY>
HERE;

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

						
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, ".
             " Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}



$now=current_server_time($connection);
$dt=split(" ",$now[0]);
$printdate=split("-",$dt[0]);




	echo "<table border=0 width=100% cellspacing=0 cellpadding=0><tr><td align='left'>";
	echo "<table border=0 width='650' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
		  <col width=175>
		  <col width=175>
		  <col width=112>
		  <col width=112>
		  <col width=1>";    
	

	echo "<tr><td height='60'><img src='img/imgheader1.jpg' width='115' height='50' /></td><td align='center'><b><font size=5>Currencies Details</font></td><td align='right' colspan= '3' ><font size='2'><b>Printed&nbsp;Date&nbsp;&amp;&nbsp;Time:</b>&nbsp;&nbsp;";
	echo $printdate[2]."/".$printdate[1]."/".$printdate[0];
	echo "<br>".$dt[1]." ".$dt[2]. " ".$dt[3];
	echo "</font></td></tr>";
	
	
	echo "<tr height='25'>";
	echo "  <th align='left' >Code</th>";
	echo "  <th align='left' >Date</th>";
	echo "  <th align='left' >Rate</th>";
	echo "  <th align='left' >Parity</th>";
	echo "  <th align='left' >&nbsp;</th>";
	echo "</tr>";
	
	//echo "<tr height= '35'><td colspan = '4' class = 'reportfooter'></td></tr>";
	

	$query = "select Currency_code, date_format(Curdt_date, '%d/%m/%Y'), Curdt_rate, Curdt_parity from Curdt order by Currency_code";
	
        //echo $query;

	$result= mysql_query($query, $connection);
	$totalrows= mysql_num_rows($result);
	
    while($row=mysql_fetch_row($result)){

		
		$Currency_code=$row[0];
	    $Curdt_date=$row[1];
	    $Curdt_rate=$row[2];
	    $Curdt_parity=$row[3];

		
		echo "<tr>";
		echo "  <td align='left' >$Currency_code</td>";
		echo "  <td align='left' >$Curdt_date</td>";
		echo "  <td align='left' >$Curdt_rate</td>";
		echo "  <td align='left' >$Curdt_parity</td>";
		echo "  <td align='left' >&nbsp;</td>";
		echo "</tr>";
		}
		
		
		

	
	echo "<tr height= '35'><td colspan = '4' class = 'reportfooter'> Total Records: $totalrows </td></tr>";
	echo "</table></table>";

function current_server_time($connection){

  $string="Select date_format(NOW(),'%Y-%m-%d %h:%i %p') ";
  $result=mysql_query($string,$connection) or die(mysql_error());
  $now=mysql_fetch_row($result);

  return $now;
}


print <<< HERE

<script language=javascript>
if (typeof(window.print) != 'undefined')
{
    window.print();
}
</script>
</BODY>
</HTML>
HERE;
?>