<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}

include("config.inc.php");
include("function.inc.php");
//Set Time Execution For the Report
//ini_set('max_execution_time', $config['ReportTimeExecution']);
set_time_limit(0);


$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}
print <<< HERE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
<HEAD>



<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<TITLE> Reconcilation Report </TITLE>
 

<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<script type="text/javascript" language="javascript">


function PrintPreview(JourId)
{
	var str = '';
	
	str = 'Form_JournalPreview.php?journal_id='+JourId;
	window.open(str);

}

function UpdateRecord(JourId){
	win = window.open('Form_Journal_Actions.php?mainmode=EditJournalFromReport&SJourId='+JourId, 'Form_JournalSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=1100,height=750,left=20,top=20');
	win.creator = self;
	win.focus();
}

</script>
<style type="text/css">
/*
table.params td { font-size: 12px; 
                  font-family:Times-New-Roman;
                 }

			 
table.master th { font-size: 14px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
				 }
				 
table.master td { font-size: 12px; 
                  font-family:Times-New-Roman;
                 }
		*/	 		 
th.headborder {
                border-width: 1px;
				border-style: 1px solid black;
				border-color: #666666;
               } 
 td.headborder {
                border-width: 1px;
				padding: 1px;
				border-style: none solid;
				border-color: #666666;
               }	 	   
			   

td.headborderdt {
                border-width: 1px;
				padding: 1px;
				border-style: solid;
				border-color: #666666;
               }
			   
table.totals td { font-size: 12px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                 }					  
td.totalborder {
                font-weight: bold;
                border-width: 1px;
				padding: 1px;
				border-style: solid;
				border-color: #666666;
               }			 		  
</style>
</HEAD>
HERE;

$reconcile_id = $GET['recid'];

$querylog="SELECT FA_Journal as FA_Journal 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);
			}

$querylog=" select ifNull(FA_JournalDel,0) As FA_JournalDel, ifNull(FA_JournalMod,0) As FA_JournalMod, ".
		  " ifNull(print,0) As FA_JournalPreview, ifNull(login_belongstogrp,0) As FI_BelongsToGrp, ifNull(ShowTransaction,0) As ShowTransaction  ".
		  " 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);
			}
			
$querylog="SELECT print as printaccess 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);
			}

$querylog=" select ifNull(FI_RepRestrictProject,0) As FI_RepRestrictProject, ifNull(FI_RepRestrictCostcenter,0) As FI_RepRestrictCostcenter, ".
		  " ifNull(login_belongstogrp,0) As FI_BelongsToGrp ".
          " 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_BelongsToGroup,0) As Module_BelongsToGroup From Module ";
			$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
			while($rowmodule=mysql_fetch_array($resultmodule)){
				extract($rowmodule);
			}

$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, Base1, Base2, Company_Name As CompanyName from setup";
			$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
			$rowsetup=mysql_fetch_row($resultsetup);
$base1 = $rowsetup[3]; 
$base2 = $rowsetup[4];	
$DecimalBase = $rowsetup[2];
$DecimalBase2 = $rowsetup[2];

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


//my code get header

		$fromledger=$_GET['fromledger'];
		$fromledgername=$_GET['fromledgername'];
		$toledger=$_GET['toledger'];
		$toledgername=$_GET['toledgername'];
		$fromdate=$_GET['fromdate'];
		$todate=$_GET['todate'];
		$concail=$_GET['concail'];
		$currency=$_GET['currency'];
		$borderstyle="";
		
		$querycheck="select ledger.ledger_number,ledger.ledger_name,journal_date ,Journaldt_reconciled,Journaldt_reconciledref
				 from journaldt , ledger where Journaldt_reconciled !=1 
				 and (journal_date BETWEEN '$fromdate' AND '$todate')";
		$resultsetup=mysql_query($querycheck,$connection) or die(mysql_error());
//logo

$expdateX = explode("/",$fromdate);
// var_dump($expdateX);
$fromdatenewX = $expdateX[2]."-".$expdateX[1]."-".$expdateX[0];
// echo"<BR>".$fromdatenewX;
// querying prev Balance
$qrPrvBal ="SELECT
			ifnull(sum( IF ( journaldt_dbcd = 'D', if('$currency' = '$base1' , Journaldt_amount1 , Journaldt_amount2), - 1 * if('$currency' = '$base1' , Journaldt_amount1 , Journaldt_amount2) ) ) ,0) 
		FROM
			journaldt 
		WHERE
			ledger_number = '$fromledger'
			and Journal_date <= concat(DATE_ADD('$fromdatenewX' ,INTERVAL -1 DAY) , ' 23:59:59') 
			and currency_code = '$currency'";
$respvBal = mysql_query($qrPrvBal,$connection);
$rowPrvBal = mysql_fetch_array($respvBal);
$prvBalance = $rowPrvBal[0];





echo "		<table  border='0' align='left' class='report-master' width='1100'  style='table-layout:fixed; border-collapse:collapse;' cellpadding='0' cellspacing='0'>
				<col width=40>
				<col width=40>
				<col width=40>
				 <tr>
					<td align='center'><label><span class='style11'>
						<img src='LogoFile.php'  width='160' height='100' border='0' /></span></label></td>
					<td align='center'><span style='font-size:18px; font-weight:bold;'> </span></td>
					<td align='center'><span style='font-size:18px; font-weight:bold;'> </span></td>
				</tr>
			</table>";
//title		
echo "		<table  border='0' align='left' class='report-master' width='1100'  style='table-layout:fixed; border-collapse:collapse;' cellpadding='0' cellspacing='0'>
				 <tr height='100px'>
					<td align='center'><span style='font-size:18px; font-weight:bold;'>Reconcilation Report </span></td>
				</tr>
			</table>";
//search info			
echo "		<table  border='0' align='left' class='report-master' width='1100'  style='table-layout:fixed; border-collapse:collapse;' cellpadding='0' cellspacing='0'>
				 <col width=40>
				 <col width=100>
				 <col width=40>
				 <col width=100>
				 <tr>
					<td $borderstyle><span style='font-size:14px; font-weight:bold;'>Ledger Number: </span></td>
					<td $borderstyle>&nbsp;&nbsp; $fromledger</td>
					<td $borderstyle><span style='font-size:14px; font-weight:bold;'>Ledger Name: </span></td>
					<td $borderstyle>&nbsp;&nbsp; $fromledgername</td>
				</tr>
				<tr>
					<td $borderstyle><span style='font-size:14px; font-weight:bold;'>From Date: </span></td>
					<td $borderstyle>&nbsp;&nbsp; $fromdate</td>
					<td $borderstyle><span style='font-size:14px; font-weight:bold;'>To Date: </span></td>
					<td $borderstyle>&nbsp;&nbsp; $todate</td>
				</tr>
				<tr>
					<td $borderstyle><span style='font-size:14px; font-weight:bold;'>Option: </span></td>";
					if($concail==''){
echo "					<td $borderstyle>&nbsp;&nbsp; All</td>";
					}
					if($concail=='1'){
echo "					<td $borderstyle>&nbsp;&nbsp; Reoncilation</td>";					
					}
					if($concail=='0'){
echo "					<td $borderstyle>&nbsp;&nbsp; Un-Reconcile</td>";						
					}
echo "				<td $borderstyle></td>				";					
echo "				<td $borderstyle></td>				";					
echo "			</tr>

<tr>
					<td $borderstyle><span style='font-size:14px; font-weight:bold;'>Previous Balance: </span></td>
					<td $borderstyle>&nbsp;&nbsp;". number_format($prvBalance,$DecimalBase)."</td>
					
				</tr>

			</table>";
		
//search result	
echo "		<table  style='border:0px solid black; padding-top:20px;' align='left'  width='1100'  style='table-layout:fixed; border-collapse:collapse;' cellpadding='0' cellspacing='0'>
			<tr>
				<td>";
					//echo"You have saved your option";
				
					$fromledger=$_GET['fromledger'];
					$fromledgername=$_GET['fromledgername'];
					$toledger=$_GET['toledger'];
					$toledgername=$_GET['toledgername'];
					$fromdate=$_GET['fromdate'];
					$todate=$_GET['todate'];
				  
					$expdate = explode("/",$fromdate);
					$expdate1 = explode("/",$todate);

					$fromdatenew = $expdate[2]."-".$expdate[1]."-".$expdate[0]; 
					$todatenew = $expdate1[2]."-".$expdate1[1]."-".$expdate1[0]; 
					$treconcail='';
					$tunreconcail='';
					$i=0;
					$journaldtids = explode(',',$tobechecked); 

					//Table save result
echo "	<table  width='1100'>
				<col width=90>
				<col width=80>
				<col width=250>
				<col width=80>
				<col width=120>
				<col width=120>
				<col width=120>
				<col width=80>";
	if($txtmanualno == 1) echo "<col width=80>";			
					
					echo "<tr style='height:38px'>
							<td style='font-family:initial; border-bottom:2px solid black; border-right:1px solid darkgray; border-top:1px solid darkgray;'><b><span style='color:black; font-size:14px;'>Date</span></b></td>
							<td style='font-family:initial; border-bottom:2px solid black; border-right:1px solid darkgray; border-top:1px solid darkgray;'><b><span style='color:black; font-size:14px;'>Ref</span></b></td>
							<td style='font-family:initial; border-bottom:2px solid black; border-right:1px solid darkgray; border-top:1px solid darkgray;'><b><span style='color:black; font-size:14px;'>Description</span></b></td>
							<td style='font-family:initial; border-bottom:2px solid black; border-right:1px solid darkgray; border-top:1px solid darkgray;'><b><span style='color:black; font-size:14px;'>Curr</span></b></td>
							<td style='font-family:initial; border-bottom:2px solid black; border-right:1px solid darkgray; border-top:1px solid darkgray;'><b><span style='color:black; font-size:14px;'>Debit</span></b></td>
							<td style='font-family:initial; border-bottom:2px solid black; border-right:1px solid darkgray; border-top:1px solid darkgray;'><b><span style='color:black; font-size:14px;'>Credit</span></b></td>
							<td style='font-family:initial; border-bottom:2px solid black; border-right:1px solid darkgray; border-top:1px solid darkgray;'><b><span style='color:black; font-size:14px;'>Balance</span></b></td>";
					if($txtmanualno == 1)	
					echo "<td style='font-family:initial; border-bottom:2px solid black; border-right:1px solid black; border-top:1px solid darkgray;'><b><span style='color:black; font-size:14px;'>Manual No</span></b></td>";
								
					echo "<td style='font-family:initial; border-bottom:2px solid black; border-right:1px solid black; border-top:1px solid darkgray;'><b><span style='color:black; font-size:14px;'>Check</span></b></td>";
								
							foreach($journaldtids as $journaldtid){ 
							$query1="UPDATE journaldt SET Journaldt_reconciled='1' 
								WHERE Journal_id=$journaldtid"; 
							//echo $query1;
								$resupdate = mysql_query($query1,$connection);
							}
						
										   
							$queryall="	select temp_reconciledt.journaldt_id,temp_reconciledt.Ledger_number,date_format(temp_reconciledt.Journal_date,'%d-%m-%Y'),a.Journal_refgovernment ,temp_reconciledt.Journaldt_ValueDate,
										temp_reconciledt.Journaldt_desc,temp_reconciledt.Journaldt_dbcd, temp_reconciledt.Currency_code,temp_reconciledt.Journaldt_amount,temp_reconciledt.Journaldt_reconciled, temp_reconciledt.manual_no,
										reconciledt_id
										from temp_reconciledt
										inner join journaldt on journaldt.journaldt_id = temp_reconciledt.journaldt_id
										left join journal a on a.journal_id=journaldt.journal_id
										where if('$concail'='',1=1, temp_reconciledt.Journaldt_reconciled ='$concail') 
										AND temp_reconciledt.ledger_number BETWEEN if('$fromledger' = '',temp_reconciledt.ledger_number,'$fromledger') AND if('$toledger'='',temp_reconciledt.ledger_number,'$toledger') 
										AND temp_reconciledt.Currency_code ='$currency' AND date_format(temp_reconciledt.journal_date,'%Y-%m-%d') BETWEEN '$fromdatenew' AND '$todatenew' 
										order by temp_reconciledt.Journal_date, temp_reconciledt.journaldt_id ";


							$queryreconcail="select temp_reconciledt.journaldt_id,temp_reconciledt.Ledger_number,date_format(temp_reconciledt.Journal_date,'%d-%m-%Y'),a.Journal_refgovernment ,temp_reconciledt.Journaldt_ValueDate,
											temp_reconciledt.Journaldt_desc,temp_reconciledt.Journaldt_dbcd, temp_reconciledt.Currency_code, temp_reconciledt.Journaldt_amount,temp_reconciledt.Journaldt_reconciled, temp_reconciledt.manual_no,
											reconciledt_id
											from temp_reconciledt
											inner join journaldt on journaldt.journaldt_id = temp_reconciledt.journaldt_id
											left join journal a on a.journal_id=journaldt.journal_id
											where temp_reconciledt.Journaldt_reconciled='1'
											AND temp_reconciledt.ledger_number BETWEEN if('$fromledger' = '',temp_reconciledt.ledger_number,'$fromledger') AND if('$toledger'='',temp_reconciledt.ledger_number,'$toledger') 
											AND temp_reconciledt.Currency_code ='$currency' AND date_format(temp_reconciledt.journal_date,'%Y-%m-%d') BETWEEN '$fromdatenew' AND '$todatenew' 
											order by temp_reconciledt.Journal_date, temp_reconciledt.journaldt_id ";
						
							$queryunreconcail="select temp_reconciledt.journaldt_id,temp_reconciledt.Ledger_number,date_format(temp_reconciledt.Journal_date,'%d-%m-%Y'),a.Journal_refgovernment ,temp_reconciledt.Journaldt_ValueDate,
											temp_reconciledt.Journaldt_desc,temp_reconciledt.Journaldt_dbcd, temp_reconciledt.Currency_code,temp_reconciledt.Journaldt_amount,temp_reconciledt.Journaldt_reconciled, temp_reconciledt.manual_no,
											reconciledt_id
											from temp_reconciledt
											inner join journaldt on journaldt.journaldt_id = temp_reconciledt.journaldt_id
											left join journal a on a.journal_id=journaldt.journal_id
											where temp_reconciledt.Journaldt_reconciled='0'
											AND temp_reconciledt.ledger_number BETWEEN if('$fromledger' = '',temp_reconciledt.ledger_number,'$fromledger') AND if('$toledger'='',temp_reconciledt.ledger_number,'$toledger') 
											AND temp_reconciledt.Currency_code ='$currency' AND date_format(temp_reconciledt.journal_date,'%Y-%m-%d') BETWEEN '$fromdatenew' AND '$todatenew' 
											order by temp_reconciledt.Journal_date, temp_reconciledt.journaldt_id ";
						
												
								$result=mysql_query($queryunreconcail,$connection) or die(mysql_error());
								$num_rowss = mysql_num_rows($result);
								$tunreconcail=$num_rowss;
								
								$result2=mysql_query($queryreconcail,$connection) or die(mysql_error());
								$num_rows = mysql_num_rows($result2);
								$treconcail=$num_rows;	

								$result=mysql_query($queryall,$connection) or die(mysql_error());
								//echo $result;
								$i = 0;
								while($row = mysql_fetch_row($result)){
								$journaldt_id = $row[0];
								$ledger_number = $row[1];;
								$journal_date = $row[2];
								$journal_date=explode(" ", $journal_date);
								$Journaldt_reconciledref=$row[3];
								$Journaldt_ValueDate=$row[4];
								$Journaldt_ValueDate=explode(" ", $Journaldt_ValueDate);
								$Journaldt_desc=$row[5];
								$journaldt_dbcd=$row[6];
								$Currency_code=$row[7];
								$Journaldt_amount = $row[8];
								$Journaldt_reconciled = $row[9];
								$Journaldt_manualno = $row[10];
								
								if($Currency_code == $base2) {
						$DecimalBase = $DecimalBase2;
					}
								($i%2 == 0) ? $altColor='#e0e0e0'  : $altColor='#FFFFFF';
				echo"	<tr style='background-color:$altColor'>			";
				echo"		<td style='font-family:monospace; border-right:1px solid darkgray;' font-size:15px;'>".$journal_date[0]."</td>";
				echo"		<td style='font-family:monospace; border-right:1px solid darkgray;'font-size:15px;'>".$Journaldt_reconciledref."</td>";
				echo"		<td style='font-family:monospace; border-right:1px solid darkgray;' font-size:15px;'>".$Journaldt_desc."</td>";
				echo"		<td style='font-family:monospace; border-right:1px solid darkgray;' font-size:15px;'>".$Currency_code."</td>";
						if($journaldt_dbcd == 'D'){
				echo"		<td style='font-family:monospace; border-right:1px solid darkgray;' font-size:15px;'>".number_format($Journaldt_amount,$DecimalBase)."</td>";
								$debit=$Journaldt_amount;
				echo"		<td style='font-family:monospace; border-right:1px solid darkgray;' font-size:15px;'></td>";
						}
						if($journaldt_dbcd == 'C'){
				 echo"		<td style='font-family:monospace; border-right:1px solid darkgray;' font-size:15px;'></td>";
								$Credit=$Journaldt_amount;
				 echo"		<td style='font-family:monospace; border-right:1px solid darkgray;' font-size:15px;'>".number_format($Journaldt_amount,$DecimalBase)."</td>";
						}
						if($journaldt_dbcd ==''){
				 echo"		<td style='font-family:monospace; border-right:1px solid darkgray;' font-size:15px;'></td>";
				 echo"		<td style='font-family:monospace; border-right:1px solid darkgray;' font-size:15px;'></td>";
						}
							
						$balance=$balance2 + ($debit-$Credit);
						
				if($i==0)
					$balance += $prvBalance;
						$balance2 = $balance;
						$debit = 0;
						$Credit = 0;
							if($balance<0){
								$balance_format=abs($balance);
							echo "<td style='font-family:monospace; border-right:1px solid darkgray;' font-size:15px;''>(".number_format($balance_format,$DecimalBase).")</td>";
								}
								else{
							echo"		<td style='font-family:monospace; border-right:1px solid darkgray;' font-size:15px;'>".number_format($balance,$DecimalBase)."</td>";
								}
							if($Journaldt_reconciled == 1) $chktrue = ' checked ';
							else $chktrue = ' ';
							
							if($Journaldt_reconciled == 1){
				$counter++;
				if($journaldt_dbcd == 'D'  ){
			
				$debit=$Journaldt_amount;
	
				}
				if($journaldt_dbcd == 'C' ){
					
					 $Credit=$Journaldt_amount;	 
				}
					
				$bal=$bal2 + ($debit-$Credit);
				
				$bal2 = $bal;
				$debit = 0;
				$Credit = 0;
				}	
			else {
				if($journaldt_dbcd == 'D' ){
			
				$debit=$Journaldt_amount;
	
				}
				if($journaldt_dbcd == 'C' ){
					
					 $Credit=$Journaldt_amount;	 
				}
					
				$unrec=$unrec2 + ($debit-$Credit);
				
				$unrec2 = $unrec;
				$debit = 0;
				$Credit = 0;
				
			}
			if($txtmanualno == 1)					
			echo "		<td style='font-family:monospace; border-right:1px solid darkgray;' font-size:15px;'>$Journaldt_manualno</td>";
			echo "		<td style='font-family:monospace; border-right:1px solid darkgray;' font-size:15px;'>";
			if($chktrue == ' '){
				echo"&nbsp;";//image not reconciled
			}else{
				echo"<img src='img/confirm-1.png' height='20' width='20'>"; // image reconciled
			}
			echo"</td>
					</tr>";
									//	$treconcail=$treconcail+1;
										$tamount=$balance2;
										$trec=$bal2;
										$tunrec=$unrec2;
										$i++;
							}
							echo "<tr>";
							//dropdown show
							//	echo "<td colspan='3' style='border:0; border-top:1px solid darkgray; border-right:1px solid darkgray;'></td>";
								if($tamount<0){
									$tamount=abs($tamount);
								echo "<td colspan='3' style='border-top:1px solid darkgray; border-right:1px solid darkgray; border-bottom:1px solid darkgray;'>GL Balance:<b>&nbsp;&nbsp; ( ".number_format($tamount,$DecimalBase)." )</b></td>";
								}
								else{
								echo "<td colspan='3' style='border-top:1px solid darkgray; border-right:1px solid darkgray; border-bottom:1px solid darkgray;'>GL Balance:<b>&nbsp;&nbsp;".number_format($tamount,$DecimalBase)."</b></td>";	
								}
									echo "<td colspan='3' style='border-top:1px solid darkgray; border-right:1px solid darkgray; border-bottom:1px solid darkgray;'> Outstanding Balance:<b> ". number_format($tunrec,$DecimalBase) . "</b> <br> <hr>
														   Ending Bank Balance: <b>". number_format($trec,$DecimalBase) ."</b></td>";
								echo "<td colspan='2' style='border-top:1px solid darkgray; border-bottom:1px solid darkgray; border-right:1px solid darkgray;'>Nb of Outstanding Transaction:<b>$tunreconcail</b><hr>Total Nb Transaction:<b>$treconcail</b></td>";
							echo "</tr>";
			echo"		</tr>";
			echo" </table>
				</td>
			</tr>
		
		</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;
}

function explodeword($date)
{
$trim = explode('/',$date);
$trim = "$trim[2]"."-"."$trim[1]"."-"."$trim[0]";
return $trim;
}

function format_currency($amount, $DecimalBase) { 

    if($amount < 0) 
        return "(".number_format(abs($amount),$DecimalBase).")"; 
 
    else return number_format($amount, $DecimalBase); 
} 

if ($printaccess==1)
print <<< HERE

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

?>