<?php

session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}

header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
include("config.inc.php");
include("Form_GridTransport.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(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}

$querylog="SELECT FI_ChangingTyre as loginaccess, ifNull(FI_ChangingTyreApp,0) As FI_ChangingTyreApp 
		 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);
	}


if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");


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

print <<<HERE

<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="css-v2/style.css">
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="tabs.css">
<script type="text/javascript" src="js/tabsClass/tabber.js"></script>
<link rel="stylesheet" href="js/tabsClass/tabber.css" type="text/css" />
<script type="text/javascript" language="javascript">
var tabberOptions = {
  'manualStartup':true,
  'onClick': function(argsObj) {

    var t = argsObj.tabber; /* Tabber object */
    var id = t.id; /* ID of the main tabber DIV */
    var i = argsObj.index; /* Which tab was clicked (0 is the first tab) */
    var e = argsObj.event; /* Event object */
	
	if (id == 'tab1') document.getElementById('PTabIndex').value = i;
  },

  /* Optional: set an ID for each tab navigation link */
  'addLinkId': true
};

</script>
<script type="text/javascript" language="javascript">

function submitRecord(changeTyreDtId, Dt_Type, index){
	let tyreChangeDate 	 = document.getElementById('tyreChangeDate').value;
	let tyreChangeRemark = encodeURIComponent(document.getElementById('tyreChangeRemark').value);
	let changeTyreId 	 = document.getElementById('changeTyreId').value;
	
	let tyreType 	 = encodeURIComponent(document.getElementById('tyreType'+index+Dt_Type).value);
	let tyreSerialNo = encodeURIComponent(document.getElementById('tyreSerialNo'+index+Dt_Type).value);
	let tyreBrand 	 = encodeURIComponent(document.getElementById('tyreBrand'+index+Dt_Type).value);
	let tyreEstDist  = document.getElementById('tyreEstDist'+index+Dt_Type).value;
	let vehicleId 	 = document.getElementById('vehicleId'+index+Dt_Type).value;
	let driverId 	 = document.getElementById('driverId'+index+Dt_Type).value;
	let tyreRemarkdt = document.getElementById('tyreRemarkdt'+index+Dt_Type).value;
	
	let modedt = '';
	if (changeTyreDtId == '')
		modedt = 'insertdt';
	else 	
		modedt = 'editdt';

	let mode = '';
	if (changeTyreId == '')
		mode = 'insert';
	else 	
		mode = 'edit';

	if (tyreType == ''){
		alert("Please Select a Tyre Type!");
		return 0;
	} else if (vehicleId == ''){
		alert("Please Select a Vehicle!");
		return 0;
	}
	else {
		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)
			{
				let data = xmlhttp.responseText.split("[BRK]");
				if (data[1] != ''){
					document.tyre.message.value = data[1];
					alert(data[1]);
				}		
				if (changeTyreId == '' && data[2] != ''){
					document.getElementById('changeTyreId').value = data[2];
					document.tyre.submit();	

				}
				else
					document.getElementById('grid'+Dt_Type).innerHTML = data[3];				
			}
		}
		xmlhttp.open("GET","Form_ChangingTyre_Actions.php?mode="+mode+"&modedt="+modedt+"&changeTyreId="+changeTyreId+"&tyreChangeDate="+tyreChangeDate+"&tyreChangeRemark="+tyreChangeRemark+
					"&tyreType="+tyreType+"&tyreSerialNo="+tyreSerialNo+"&tyreBrand="+tyreBrand+"&tyreEstDist="+tyreEstDist+"&vehicleId="+vehicleId+
					"&driverId="+driverId+"&tyreRemarkdt="+tyreRemarkdt+"&changeTyreDtId="+changeTyreDtId+"&Dt_Type="+Dt_Type,true);
		xmlhttp.send();  
	}

}

function clearRecord(Dt_Type , index){
	document.getElementById('tyreType'+index+Dt_Type).value = '';
	document.getElementById('tyreSerialNo'+index+Dt_Type).value = '';
	document.getElementById('tyreBrand'+index+Dt_Type).value = '';
	document.getElementById('tyreEstDist'+index+Dt_Type).value = '';
	document.getElementById('vehicleId'+index+Dt_Type).value = '';
	document.getElementById('driverId'+index+Dt_Type).value = '';
	document.getElementById('tyreRemarkdt'+index+Dt_Type).value = '';
}

function deletedtRecord(changeTyreDtId, Dt_Type , index){
	let changeTyreId 	 = document.getElementById('changeTyreId').value;

	if(confirm("Are you sure you want to delete this record?")){
	if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp1=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp1.onreadystatechange=function()
		{
		if (xmlhttp1.readyState==4 && xmlhttp1.status==200)
			{
				let data = xmlhttp1.responseText.split("[BRK]");
				if (data[1] != ''){
					document.tyre.message.value = data[1];
					alert(data[1]);
				}	alert(data[3]);	
				document.getElementById('grid'+Dt_Type).innerHTML = data[3];				
			}
		}
		
		xmlhttp1.open("GET","Form_ChangingTyre_Actions.php?mode=&modedt=deletedt&changeTyreId="+changeTyreId+"&changeTyreDtId="+changeTyreDtId+"&Dt_Type="+Dt_Type,true);
	}
}

function searchTyres(){
	window.open("Form_SearchChangedTyres.php","Search","width=800px,height=500px");
}

function ClearPage(){
	let x = document.tyre;
	x.changeTyreId.value = '';
	x.tyreChangeDate.value = '';
	x.tyreChangeRemark.value = '';

	x.action = "Form_ChangingTyre.php";
	x.submit();
}

function savePage(){
	let mode = '';
	if (document.getElementById('changeTyreId').value == '')
		mode = 'insert';
	else 	
		mode = 'edit';
	document.tyre.action = "Form_ChangingTyre_Actions.php?mode="+mode+"&modedt=";
	document.tyre.submit();
}

function searchVehicle(index, divtype){
	window.open("Form_vehicleList.php?str=tyre&index="+index+"&divtype="+divtype,"List Vehicle","width=800px,height=600px");
}

</script>
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="tabs.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Change Tyre</title>


<script type="text/javascript" src="dropdown.js"></script>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}

input:focus, select:focus {
	border: 2px solid #008b8b;
}
input:hover, select:hover {
	border: 1px solid #008b8b;
}
/* Hide HTML5 Up and Down arrows. */
input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type="number"] {
-moz-appearance: textfield;
}

</style>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="tabs.css">
</head>
<body >
<form name='tyre' enctype="multipart/form-data" method="post">
<input type=hidden name='message' value='$message'>
<input type=hidden name='changeTyreId' id='changeTyreId' value='$changeTyreId'>
<input type='hidden' name='PTabIndex' id='PTabIndex' value='$PTabIndex'>
HERE;


$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";



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'>Changing Tyre</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";

	 
	
echo"<tr><td  height='18'  valign='top' id='content-top2'>";	
echo"</td></tr>";

 
echo"<tr><td align=left  id='content-body'>";

echo"<table border=0 align=left width=800> <tr  height='35'>";

echo"	<td align=left>";  	
echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<button type='button' id='btnClear' name='BtnClear' value='Clear Page'  onclick='ClearPage();'  title='Clear Page'><span><span>Clear Page</span></span></button>";
echo"<button type='button' name='btnPost' id='btnPost' value='Save' onclick='savePage();'  title='Save Changes' /><span><span>Save</span></span></button>";

echo"<button name='btnSearch' type='button' id='btnSearch' value='Search' onclick='searchTyres();' title='Search for Changed Tyres' /><span><span>Search</span></span></button>";

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

if ($changeTyreId != ''){
	$query = "select date_format(changeTyre_Date,'%d/%m/%Y'), changeTyre_remark from changeTyre where changeTyre_id = $changeTyreId ";
	$result = mysql_query($query, $connection);
	$row = mysql_fetch_row($result);
	$tyreChangeDate = $row[0];
	$tyreChangeRemark = $row[1];
}
	 
echo"<tr><td align=center id='content-body'>";
echo "<table border=0 width=470px><col width=50px><col width=120px><col width=300px>";
echo "<tr height='30px'>
		<td></td><td><span class='style1'>Date</span></td>
		<td><input type='text' name='tyreChangeDate' id='tyreChangeDate' value='$tyreChangeDate' style='width: 90px;'>
		<a href='#' onclick=\"displayCalendar(document.tyre.tyreChangeDate,'dd/mm/yyyy',this);  return false;\" name='anchor1' id='anchor1'><img src='./img/cal.gif' width='17' height='17' ></a>
		</td>
	 </tr>";
echo "<tr height='30px'>
		<td></td><td><span class='style1'>Remark</span></td>
		<td><input type='text' name='tyreChangeRemark' id='tyreChangeRemark' value='$tyreChangeRemark' style='width: 300px;'></td>
	</tr>";

echo "</table>";
echo"<table border=0 width=95%><tr><td width=5%></td><td>";

echo"	<div class='tabber' id='tab1' style='width:1050px; margin-top:10px; float:left; text-align:left;'>";

  echo"	<div class='tabbertab'>
				<h2 title='Vehicle'>Tractor Unit</h2>";	
	echo"		<div id='datagrid-d' style='width:1050px; height:350px; margin-top:5px; border:0px solid gray;'>";


//1st column	  
echo" <table border='0' width='1045px' style='' align='left' valign='top'><col width='1045px'><tr>
	<td  valign=top><div id='gridT' style='overflow-y:scroll;overflow-x:hidden;height:345px;'>";
	getChangeTyreDetails($changeTyreId,'T',$connection);	
echo "</div></td>";
echo"</tr>";
echo"</table>";

echo"</div>";
echo"</div>";
	
echo"	<div class='tabbertab'>
				<h2 title='Vehicle'>Flat Bed Section</h2>";	
echo"		<div id='datagrid-d' style='width:1045px; height:350px; margin-top:5px; border:0px solid gray;'>";
 
	
echo"<table border=0 width='1045px'>";
echo "<tr><td ><div id='gridF' style='overflow-y:scroll;overflow-x:hidden;height:345px;'>";
	getChangeTyreDetails($changeTyreId,'F',$connection);	
echo"</div></td></tr>";	

					
echo"</table>";						

echo"</div>";echo"</div>";
	
echo"</div>";

		
print <<< HERE
       </td>
      </tr>
	  </table>
HERE;


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


print <<< HERE
      
    <tr height='30'><td align='center' id='content-bottom' ></td></tr>
	  </table>
HERE;




echo"<script type=\"text/javascript\" language=\"javascript\">";
echo"	tabberAutomatic(tabberOptions);";
echo"   vTabIndex = document.getElementById('PTabIndex').value; ";
echo"	if (document.getElementById('tab1')) document.getElementById('tab1').tabber.tabShow(vTabIndex); ";
echo"</script>";

print <<<HERE
</form>
</body>

HERE;

?>














