<?php

function getChangeTyreDetails($changeTyreId, $Dt_Type, $connection){
	$queryTyre = "select tyretype_code from tyreTypes where changeTyreDt_type = '$Dt_Type'";
	


	echo "<table width=1020px border=0 cellspacing=2 cellpadding=0>
			<col width='25px'><col width='100px'><col width='100px'><col width='120px'><col width='120px'>
			<col width='130px'><col width='130px'><col width='190px'><col width='30px'>";
	
	echo "<tr height='30px' bgcolor='#a9a9a9'>
			<td></td>
			<td align='center'><span class='style1'>Tyre Type</span></td>
			<td align='center'><span class='style1'>SN</span></td>
			<td align='center'><span class='style1'>Brand</span></td>
			<td align='center'><span class='style1'>Estimated Distance</span></td>
			<td align='center'><span class='style1'>Vehicle</span></td>
			<td align='center'><span class='style1'>Driver</span></td>
			<td align='center'><span class='style1'>Remark</span></td>
			<td></td>
		</tr>";

	$bgcolor = "#e6e6e6";	
	$i = 0;
	echo "<tr height='25px' bgcolor='$bgcolor'>
			<td align='center'><img src='img/undo-1.png' onmouseover=\"style.cursor='pointer'\" onclick=\"clearRecord('$Dt_Type','$i');\" title='Clear Record'></td>
			<td><select name='tyreType$i$Dt_Type' id='tyreType$i$Dt_Type' style='width: 95px;'><option values=''></option>";
	$resTyre = mysql_query($queryTyre, $connection);
	while ($rowTyre = mysql_fetch_array($resTyre)){
		echo "<option values='$rowTyre[0]'>$rowTyre[0]</option>";	
	}		
	echo "	</select></td>
			<td><input type='text' name='tyreSerialNo$i$Dt_Type' id='tyreSerialNo$i$Dt_Type' value='' style='width:95px;'></td>
			<td><input type='text' name='tyreBrand$i$Dt_Type' id='tyreBrand$i$Dt_Type' value='' style='width:115px;'></td>
			<td><input type='number' name='tyreEstDist$i$Dt_Type' id='tyreEstDist$i$Dt_Type' value='' style='width:115px;'></td>
			<td><input type='text' name='vehicleName$i$Dt_Type' id='vehicleName$i$Dt_Type' value='' style='width:110px;'>
			<input type='hidden' name='vehicleId$i$Dt_Type' id='vehicleId$i$Dt_Type' value='' >
			<img src='img/scroll-down-1.png' title=' Select Vehicle ' onclick=\"searchVehicle('$i','$Dt_Type');\" onmouseover=\"style.cursor='pointer'\">
			</td>
			<td><input type='text' name='driverName$i$Dt_Type' id='driverName$i$Dt_Type' value='' style='width:125px;' readonly>
			<input type='hidden' name='driverId$i$Dt_Type' id='driverId$i$Dt_Type' value='' ></td>
			<td><input type='text' name='tyreRemarkdt$i$Dt_Type' id='tyreRemarkdt$i$Dt_Type' value='' style='width:185px;'></td>
			<td align='center'><img src='img/confirm-1.png' onmouseover=\"style.cursor='pointer'\" onclick=\"submitRecord('','$Dt_Type','$i');\" title='Submit Record'></td>
		</tr>";

	$querydt = "select changeTyreDt_id, tyre_type, tyre_serialNo, tyre_brand, tyre_estimatedDist, changeTyreDt.vehicle_id, vehicle_driver, changeTyreDt_remark,
				vehicle_platenumber, concat(employee_firstname,' ',ifnull(employee_lastname,''))
				from changeTyreDt
				left join vehicle on vehicle.vehicle_id = changeTyreDt.vehicle_id
        		left join employee on employee.employee_id = vehicle_driver
				where changeTyre_id = $changeTyreId and changeTyreDt_type = '$Dt_Type' "; 
	$resultdt = mysql_query($querydt, $connection);
	while ($rowdt = mysql_fetch_array($resultdt)){
		$bgcolor = "#e6e6e6";	
		$i++;

		echo "<tr height='25px' bgcolor='$bgcolor'>
				<td align='center'><img src='img/delete.png' onmouseover=\"style.cursor='pointer'\" onclick=\"deletedtRecord('$rowdt[0]','$Dt_Type','$i');\" title='Clear Record'></td>
				<td><select name='tyreType$i$Dt_Type' id='tyreType$i$Dt_Type' style='width: 95px;'><option values=''></option>";
		$resTyre = mysql_query($queryTyre, $connection);
		while ($rowTyre = mysql_fetch_array($resTyre)){
			echo "<option values='$rowTyre[0]' ".($rowTyre[0] == $rowdt[1]?'selected':'').">$rowTyre[0]</option>";	
		}		
		echo "	</select></td>
				<td><input type='text' name='tyreSerialNo$i$Dt_Type' id='tyreSerialNo$i$Dt_Type' value='$rowdt[2]' style='width:95px;'></td>
				<td><input type='text' name='tyreBrand$i$Dt_Type' id='tyreBrand$i$Dt_Type' value='$rowdt[3]' style='width:115px;'></td>
				<td><input type='text' name='tyreEstDist$i$Dt_Type' id='tyreEstDist$i$Dt_Type' value='$rowdt[4]' style='width:115px;'></td>
				<td><input type='text' name='vehicleName$i$Dt_Type' id='vehicleName$i$Dt_Type' value='$rowdt[8]' readonly style='width:110px;'>
				<input type='hidden' name='vehicleId$i$Dt_Type' id='vehicleId$i$Dt_Type' value='$rowdt[5]'>
				<img src='img/scroll-down-1.png' title=' Select Vehicle ' onclick=\"searchVehicle('$i','$Dt_Type');\" onmouseover=\"style.cursor='pointer'\">
				</td>
				<td><input type='text' name='driverName$i$Dt_Type' id='driverName$i$Dt_Type' value='$rowdt[9]' style='width:125px;' readonly>
					<input type='hidden' name='driverId$i$Dt_Type' id='driverId$i$Dt_Type' value='$rowdt[6]' >
				</td>
				<td><input type='text' name='tyreRemarkdt$i$Dt_Type' id='tyreRemarkdt$i$Dt_Type' value='$rowdt[7]' style='width:185px;'></td>
				<td align='center'><img src='img/confirm-1.png' onmouseover=\"style.cursor='pointer'\" onclick=\"submitRecord('$rowdt[0]','$Dt_Type','$i');\" title='Submit Record'></td>
			</tr>";	

	}

	echo "</table>";

}


function showChangedTyre($vehicle_id, $perpage, $startrange, $connection){
	echo "<div style='overflow-y: scroll;overflow-x: hidden;height:280px;'>";
	echo "<table border=0 width=900px><col width=100px><col width=150px><col width=150px><col width=150px><col width=150px><col width=200px>";
	$query = "select date_format(changeTyre_Date,'%d-%m-%Y'),tyre_type, tyre_serialNo, tyre_brand, tyre_estimatedDist, vehicle_id, vehicle_driver, changeTyreDt_remark, changeTyreDt_type
		from changeTyreDt
		inner join changeTyre on changeTyre.changeTyre_id = changeTyreDt.changeTyre_id
		where vehicle_id = $vehicle_id
		order by date_format(changeTyre_Date,'%Y-%m-%d'), tyre_type, changeTyreDt_type ";
	$result = mysql_query($query, $connection);
	$totalrows = mysql_num_rows($result);
	$query .= " limit $startrange, $perpage ";
	$result = mysql_query($query, $connection);
	$ct = 0;
	while ($row = mysql_fetch_array($result)){
		if($ct%2) $bgcolor="#F7F7F7";
		else $bgcolor="#D8D8D8";
		
		echo"<tr height='20px' bgcolor='$bgcolor'>
				<td valign='center' align='left' ><span class='style25'>$row[0]</span></td>
				<td valign='center' align='left' ><span class='style25'>$row[1]</span></td>
				<td valign='center' align='left' ><span class='style25'>$row[2]</span></td>
				<td valign='center' align='left' ><span class='style25'>$row[3]</span></td>
				<td valign='center' align='left' ><span class='style25'>$row[4]</span></td>
				<td valign='center' align='left' ><span class='style25'>$row[5]</span></td>
			</tr>";	
		$ct++;	
	}

	echo "</table>";
	echo "</div>";
	echo "<div style='position: absolute;   bottom: 0;'>";
	echo "<table border=0 width=900px><col width=450px><col width=450px>";
	echo "<tr><td  align='right'>";
	if($startrange>0)
	echo "<img src='img/firstpage.png' title='First Page' onMouseOver=\"style.cursor='hand'\" onclick=\"navigateDiv('0','".$perpage."','*') \">";

	$diff= $startrange - $perpage;
	if (($diff) >= 0 ){
		$prvstartrange = $startrange - $perpage;
		echo "<img src='img/arrowleft.png' title='Previous Page' onMouseOver=\"style.cursor='hand'\" onclick=\"navigateDiv('".$startrange."','".$perpage."','*') \" >";
	}
	echo "</td><td style='border-left:1px solid black;'>";
	if ($startrange <= $totalrows){
		$startrange1 = $startrange + $perpage;
		if  ($startrange1 < $totalrows){
			echo "<img src='img/arrowright.png' title='Next Page' onMouseOver=\"style.cursor='hand'\" onclick=\"navigateDiv('".$startrange1."','".$perpage."','*') \">";
			echo "<img src='img/lastpage.png' title='LAst Page' onMouseOver=\"style.cursor='hand'\" onclick=\"navigateDiv('".$startrange."','".$perpage."','".$totalrows."') \">";
		}
	}
	echo "</td></tr>";
	echo "</table>";
	echo "</div>";	
}

?>