<?php
require "tableinitiateclass.php";
require "../queryinitiateclass.php";
$tbl = new AddTable;
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Table index</title>
</head>
<style>
table
{
	width:100%;
	
		
}
</style>
<body>
<?php
// just the headers
$arrayheaders = array("head1","head2","head3");
// just the rows
$arrayrows = array(array("row1-1","row1-2","row1-3"), 
					array("row2-1","row2-2","row2-3"), 
					array("row3-1","row3-2","row3-3"), 
					array("row4-1","row4-2","row4-3"), 
					array("row5-1","row5-2","row5-3"));
					
					
$query = new AddSql("root","","map_directory_uphrm","localhost");
$arraycolumns = $query->getallColumn("rooms_uphrm");
$arrayfields = $query->getallascolQuery("rooms_uphrm");				
					
// display table styling still unfinished
echo $tbl->settblQuery(sizeof($arrayfields),sizeof($arraycolumns),$arraycolumns,$arrayfields);
// display search for row and column numbers
echo $tbl->gettableData(2,1);
// set search query
$tbl->searchRows("-3");
// display search query
echo $tbl->getsearchResults();
// reset table
$tbl->resetAll();
// get query string
$getquery = 'current';
// next page
$nextpage = $tbl->checkSet($getquery) + 1;
// back page
$backpage = $tbl->checkSet($getquery) - 1;
// display table with restriction of 2
echo $tbl->settblrestrictQuery(sizeof($arrayfields),sizeof($arraycolumns),
								$arraycolumns,$arrayfields,5,
								$tbl->checkSet($getquery));
// display back button

$totaldist = sizeof($arrayfields) / 5;
echo $tbl->toBack($backpage,$getquery);
// display next button
echo $tbl->toNext($nextpage,$getquery);



?>
<button onclick = "ajaxNav()" > Next </button>
<button onclick = "ajaxNavb()" > Back </button>
<div id = "tableDiv" >


	
</div>
<?php
echo $tbl->popupDelete();
?>
<script>
			var count = 1;
			function ajaxNav()
			{
				
			var xmlhttp;
			if (window.XMLHttpRequest)
			  {// code for IE7+, Firefox, Chrome, Opera, Safari
			  xmlhttp=new XMLHttpRequest();
			  }
			else
			  {// code for IE6, IE5
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
			xmlhttp.onreadystatechange=function()
			  {
			  if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
				document.getElementById("tableDiv").innerHTML=xmlhttp.responseText;
				}
			  }
			  	if(count<<?php echo $totaldist; ?>);
			  	count++;		
				xmlhttp.open("GET","ajaxnav.php?<?php echo $getquery; ?>="+ count,true);
				
				xmlhttp.send();
	
			}
			function ajaxNavb()
			{
				
			var xmlhttp;
			if (window.XMLHttpRequest)
			  {// code for IE7+, Firefox, Chrome, Opera, Safari
			  xmlhttp=new XMLHttpRequest();
			  }
			else
			  {// code for IE6, IE5
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
			xmlhttp.onreadystatechange=function()
			  {
			  if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
				document.getElementById("tableDiv").innerHTML=xmlhttp.responseText;
				}
			  }
			 	if(count>0);
			  	count--;		
				xmlhttp.open("GET","ajaxnav.php?<?php echo $getquery; ?>="+ count,true);
				xmlhttp.send();
	
			}
	</script>
</body>
</html>