<?php
session_start();
if (!isset($_SESSION['reusername'])) { echo 'Sorry You Dont Have permissions to View this Page!'; exit();}
require_once 'includes/database.php';
require_once 'includes/funcs.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>QIA | Endorsement </title>
<script type="text/javascript" src="js/jquery-1.10.2.js"></script>
<link rel="stylesheet" type="text/css" href="css/allcss.css">

</head>
<body>

<p><a href="#" id="printnow" class="printnow" onclick="myprint();" style="float:left;">Print</a>
<a href="#" id="closenow" class="closenow" onclick="window.close();">Close</a></p>
<div id="printblk">
<?php 
echo '<table id="insf" cellpadding="5px" style="width:95%; margin-left:10px; border-collapse:collapse;font-size:14px;font-family:Arial;">';
echo '<tr><td><img style="vertical-align:top;" src="images/inslogo.png">&nbsp;</img></td> <td colspan="3"> <span style="font-size:28px;font-weight:bold;font-family:Trebuchet MS">QOOLPOINT INSURANCE AGENCY </span> <br> <span style="font-size:14px;font-weight:bold;font-family:Trebuchet MS"> P.O.Box 82496 - 80100, Mombasa  Tel: 0412228887 / 0722718887 <br> Email: insurance@qool-point.co.ke </span><br>REGULATED BY THE INSURANCE REGULATORY AUTHORITY<br></td><tr>';
echo '<tr><td colspan="4">&nbsp;</td></tr>';
echo '<tr align="center"><td colspan="4" style="font-size:24px;font-weight:bold;border: 1px solid #666;"> ENDORSEMENT  </br></td></tr>';
echo '<tr><td colspan="4">&nbsp;</td></tr>';
echo '<tr><td colspan="4">&nbsp;</td></tr>';
if(isset($_GET['insno'])) {
	$user = $_SESSION['reusername'];
	$db=new MySQLDatabase();
	$db->open_connection();
	$insno = $_GET['insno'];	$agp = '';		$endomemo=''; 	$endoline='';		$endono='';		
	$lineterms='';		$ts='';
	$sql = mysqli_query($db->connection, "SELECT * FROM endorses WHERE insno = '$insno';") or die (mysqli_error($db->connection) ); 
	if ($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)){ $endono = $row['endono']; 
										 $endomemo = $row['endomemo']; 
										 $endoline = $row['endoline']; 
										 $lineterms = $row['lineterms'];
		$ts = substr($row['ts'],8,2)."-".substr($row['ts'],5,2)."-".substr($row['ts'] ,0,4).' '.substr($row['ts'],11,2).":".substr($row['ts'],14,2).":".substr($row['ts'] ,17,2);
			$idate = substr($row['idate'],8,2)."-".substr($row['idate'],5,2)."-".substr($row['idate'] ,0,4); }
	$sql = mysqli_query($db->connection, "SELECT * FROM insrecs WHERE insno = '$insno';") or die (mysqli_error($db->connection) ); 
	if ($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)){
		$ph = $row['insurer'].' / '.$row['cname']; 	$sup= getsupplier($row['supp']);
		if($row['agpno'] !==''){ $agp = $row['agpno']; }
		else if($row['agpno3'] !==''){ $agp = $row['agpno3']; }
		else if($row['agpno2'] !==''){ $agp = $row['agpno2']; }
		else if($row['agpno1'] !==''){ $agp = $row['agpno1']; }
		echo '<tr><td style="border: 1px solid #666;">Endorsement No.</td> <td style="border: 1px solid #666;">'.$endono.'</td> <td style="border: 1px solid #666;">Insurer </td>  <td style="border: 1px solid #666;"> '.$ph.'</td></tr>';	
		echo '<tr><td colspan="2" style="border: 1px solid #666;">Provider</td> <td colspan="2" style="border: 1px solid #666;">'.$sup.'</td> </tr>';	
		echo '<tr><td colspan="4">&nbsp;</td></tr>';
		echo '<tr><td colspan="4">'.$endoline.'</td></tr>';
		echo '<tr><td colspan="4">&nbsp;</td></tr>';
		echo '<tr style="border: 1px solid #666;"><td colspan="4"></br><b>MEMORANDUM</b></br></br>'.$endomemo.'</td></tr>';
		echo '<tr><td colspan="4">&nbsp;</td></tr>';
		echo '<tr><td colspan="4">'.$lineterms.' </td></tr>';
		echo '<tr><td colspan="4">&nbsp;</td></tr>';
		echo '</table>';
		echo '<input type="hidden" id="insno" name="insno" value="'.$insno.'"/></td> </tr>';
		
		
    }
}
?> 
<table style="width:95%; margin-left:10px;border-collapse:collapse;font-size:12px;font-family:Arial;">
	<tr> <td colspan="2" align="left"><br><br><br>Printed By:&nbsp; <?php echo $user.'  '.$ts; ?></td> <td colspan="2" align="right"><br><br><br> &nbsp;&nbsp;&nbsp;&nbsp;Approved By:_____________</td></tr>
</table>
</div>
</body></html>

<script type="text/javascript">       
function myprint(){
	var w = window.open('', '', 'width=900,height=600,resizeable,scrollbars');
	 w.document.write($("#printblk").html());
	 w.document.write('<link rel="stylesheet" type="text/css" href="css/allcss.css">');
	 w.document.close(); 										// needed for chrome and safari
	 javascript:w.print();
	 w.close();
};	
</script>
