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

$SerialNumber = $_GET['SerialNumber'];

print <<<HERE
<html>
<head>
</head>
<body>
HERE;
echo "<table style='width: 800px; margin: auto'>
<tr>
<th colspan=3 style='font-size: 24px; font-family: Arial'>Serial Number History [$SerialNumber]</th>
</tr>
<tr>
<th colspan=3 style='height: 15px'></th>
</tr>
<tr>
<th style='width: 25%; font-size: 20px; font-family: Arial; background: #dddddd; padding: 5px; color: #999999'>RMA Ref #</th>
<th style='width: 50%; font-size: 20px; font-family: Arial; background: #dddddd; padding: 5px; color: #999999'>Item Code</th>
<th style='width: 25%; font-size: 20px; font-family: Arial; background: #dddddd; padding: 5px; color: #999999'>Date</th>
</tr>";
$query_history  = "select rmadt.item_code as ItemCode, rma.rma_reference as RMARef, date_format(rma.rma_date, '%d/%m/%Y %H:%i:%s') as RMADate, rmadt.Serial_Number
                   from rmadt inner join rma on rma.rma_id = rmadt.rma_id
                   where rma.rma_type = 'MI' and rmadt.Serial_Number = '$SerialNumber'";
$result_history = mysql_query($query_history, $connection);
$count = 0;
while($row_history = mysql_fetch_array($result_history)){
	extract($row_history);
	$count++;
	if($count %2 != 0){
		$color = "#e6e6e6";
	}
	else{
		$color = "#f7f7f7";
	}
	echo "<tr>
          <th style='width: 25%; font-size: 16px; font-family: Arial; background: $color; padding: 5px; color: #000000'>$RMARef</th>
          <th style='width: 50%; font-size: 16px; font-family: Arial; background: $color; padding: 5px; color: #000000'>$ItemCode</th>
		  <th style='width: 25%; font-size: 16px; font-family: Arial; background: $color; padding: 5px; color: #000000'>$RMADate</th>
          </tr>";
}
echo"</table>";
?>