<?php
/**
 * List of Booked Items
 * By Nadine 
 */

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



if ($fromdate == '') $fromdate = date('d/m/Y');
if ($todate == '')   $todate   = date('d/m/Y');

$pageTitle = "List of Booked Items";

print <<< HERE

<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<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="js/grid/UI_DataGrid_V1.css">
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>


<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20101112" media="screen"></link>
<script type="text/javascript" src="dhtmlgoodies_calendar.js?random=20100118"></script>

<title>$pageTitle</title>
<style>
.style8 {
	font-size: 11px;
    color: #999999;
	font-weight: bold;
}
td > input {
	font-size: 12px;
	height: 15px;
}
</style>
</head>
<body>
<form id='form1' name='form1' method='post' action=''>

HERE;


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'>$pageTitle</span></td>
				<td valign='middle' style='height:26px;'>&nbsp;</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='50'  height='34'></td>
				<td valign='middle' height='34' width='720px' align='left'>
				<button type='button' id='btnClear' name='btnClear'  onclick='ClearPage();return false;' title='Clear'><span><span>Clear</span></span></button>
				<button type='button' id='btnPost' name='btnPost' onclick=\"PrintPreview('0'); return false;\" title='Print'><span><span>Print</span></span></button>
				<button type='button' id='btnExcel' name='btnExcel' onclick=\"PrintPreview('1'); return false;\" title='Export Excel'><span><span>Excel</span></span></button>
				</td>";
echo"		</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' >
		<table border='0' style='width: 100%'>
		  <col width=45%><col width=10%><col width=45%>";	

//sub Table 1
echo "<tr><td><table border=0 cellpadding=0 cellspacing=0 width=100%><col width=15%><col width=30%><col width=55%>";
	// Date
echo "<tr height='30px'>
			<td colspan='2'><span class='style8'>Date</span></td>
			<td><span class='style8'>Group By</span></td>
	 </tr>";
echo "<tr height='25px'>
		<td><span class='style8'>From</span></td>
		<td><input type='text' name='fromdate' id='fromdate' value='$fromdate' style='width:60%;'>
			<a href='#' onclick=\"displayCalendar(document.form1.fromdate,'dd/mm/yyyy',this); return false; \" name='anchor1' id='anchor1'><img src='./img/cal.gif'></a>
		</td>
		<td rowspan='2'>
			<div style='height: inherit;width: inherit;'><span class='style8'>
						<input type='radio' name='grpby' id='grpby' value='1' checked>Items<br>
						<input type='radio' name='grpby' id='grpby' value='2' >Client and Item <br>
			</span></div>
		</td>
	</tr>";
echo "<tr height='25px'>
		<td><span class='style8'>To</span></td>
		<td><input type='text' name='todate' id='todate' value='$todate' style='width:60%;'>
		<a href='#' onclick=\"displayCalendar(document.form1.todate,'dd/mm/yyyy',this); return false; \" name='anchor1' id='anchor1'><img src='./img/cal.gif'></a>
		</td>
	</tr>";

// Client	
echo "<tr height='30px'><td colspan='2'><span class='style8'>Client</span></td><td></td></tr>";
echo "<tr height='25px'>
		<td><span class='style8'>From</span></td>
		<td colspan='2'>
			<input type='text' name='fromclient' id='fromclient' value='$fromclient' style='width:40%;'>
			<input type='text' name='fromdesc' id='fromdesc' value='$fromdesc' style='width:50%;'>
			<img src='img/btnopen.jpg' height='15' width='15' onclick=\"showClientSearch('1');\" title='Show Clients Search'>
		</td>
	</tr>";
echo "<tr height='25px'>
		<td><span class='style8'>To</span></td>
		<td colspan='2'>
			<input type='text' name='toclient' id='toclient' value='$toclient' style='width:40%;'>
			<input type='text' name='todesc' id='todesc' value='$todesc' style='width:50%;'>
			<img src='img/btnopen.jpg' height='15' width='15' onclick=\"showClientSearch('2');\" title='Show Clients Search'>
		</td>
	</tr>";	

echo"</table></td>";
//End sub Table 1
echo "<td></td>";
//sub Table 2
echo "<td><table border=0 cellpadding=0 cellspacing=0 width=100%><col width=15%><col width=30%><col width=55%>";
	// Empty rows
	echo "<tr height='30px'><td><span class='style8'>Show Qty</span></td><td></td><td></td></tr>";
	echo "<tr height='25px'>
			<td rowspan='2' colspan='2'>
				<div ><span class='style8'>
					<input type='radio' name='qtytype' id='qtytype' value = '1' checked> Booked <br>
					<input type='radio' name='qtytype' id='qtytype' value = '2' > Available
				</span></div>
			</td>
			<td></td>
		</tr>";
	echo "<tr height='25px'>
			<td></td>
		</tr>";
	
	// Items	
	echo "<tr height='30px'><td colspan='2'><span class='style8'>Items</span></td><td></td></tr>";
	echo "<tr height='25px'>
			<td><span class='style8'>From</span></td>
			<td colspan='2'>
				<input type='text' name='fromitem' id='fromitem' value='$fromitem' style='width:40%;'>
				<input type='text' name='fromitemdesc' id='fromitemdesc' value='$fromitemdesc' style='width:50%;'>
				<img src='img/btnopen.jpg' height='15' width='15' onclick=\"showItemSearch('1');\" title='Show Items Search'>
			</td>
		</tr>";
	echo "<tr height='25px'>
			<td><span class='style8'>To</span></td>
			<td colspan='2'>
				<input type='text' name='toitem' id='toitem' value='$toitem' style='width:40%;'>
				<input type='text' name='toitemdesc' id='toitemdesc' value='$toitemdesc' style='width:50%;'>
				<img src='img/btnopen.jpg' height='15' width='15' onclick=\"showItemSearch('2');\" title='Show Items Search'>
			</td>
		</tr>";	
echo "</table></td></tr>";
//End sub Table 2
echo"   </table></td>";

echo"</table></td></tr>"; 



echo" <tr height='30'><td align='center' id='content-bottom' ></td></tr>";  
echo" </table>  ";//end of last table menu


print <<< HERE
<script>
function showClientSearch(str){
	window.open("select_client.php?item="+str,"Clients","width=800px,height=600px");
}

function showItemSearch(str){
	window.open("select_item.php?item="+str,"Items","width=800px,height=600px");
}


function PrintPreview(exp){
	let str = '', 
		x = document.form1;

	let  fromdate 	= x.fromdate.value;	
	let  todate 	= x.todate.value;	
	let  fromclient = encodeURIComponent(x.fromclient.value);	
	let  toclient 	= encodeURIComponent(x.toclient.value);	
	let  fromitem 	= encodeURIComponent(x.fromitem.value);	
	let  toitem 	= encodeURIComponent(x.toitem.value);	
	let  grpbyval	= 0;
	let  qtytypeval	= 0;
	
	for(let i=0;i<x.grpby.length;i++)
		if(x.grpby[i].checked)
			grpbyval = x.grpby[i].value;

	for(let i=0;i<x.qtytype.length;i++)
		if (x.qtytype[i].checked)
			qtytypeval = x.qtytype[i].value;

	if (exp == 0) str = 'Rep_ListofBookedItems.php';	
	if (exp == 1) str = 'Exp_ListofBookedItems.php';	
	if (str != ''){
		str += '?fromdate='+fromdate+'&todate='+todate+'&fromclient='+fromclient+'&toclient='+toclient+'&fromitem='+fromitem+'&toitem='+toitem+'&grpbyval='+grpbyval+'&qtytypeval='+qtytypeval;
		window.open(str);
	}
}

function ClearPage(){
	let x = document.form1
	x.fromdate.value = '';	
	x.todate.value = '';	
	x.fromclient.value = '';	
	x.toclient.value = '';	
	x.fromitem.value = '';	
	x.toitem.value = '';	
	x.action = 'Form_ListofTanks.php';
	x.submit();
}
</script>

HERE;


echo"  
</form>";
echo "</body>
</html>";

?>