<?php

session_start();
if($HTTP_SESSION_VARS['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($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");
	
	
//Read From Setup Table							
$querysetup= " select grid_color1, grid_color2 from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}
if ($modedt=='')
	$modedt='insert';

 

print <<<HERE

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="default.css" type="text/css" />
<script type="text/javascript" language="javascript">


function SubmitRecord() {
    var x = document.vehiclemovementitems;
	
	var vmode=x.modedt.value;	
	if (vmode=='insert')
		vmode = 'add_vehicleitems';
	else if (vmode=='edit')
		vmode = 'edit_vehicleitems';
		
	if (x.item_code.value =="")
	{
	alert("Item is mandatory!");
	x.item_code.focus();
	return 0;
	}
	x.action="Form_Vehicle_Actions.php?actionmode="+vmode;
	x.submit();
	}
	
	



function showitems(str){
  window.open('Form_TrackingItemsList.php?str='+str,'mywindow','width=500,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}


function UpdateDetail(Code){


	x = document.vehiclemovementitems;
	x.modedt.value='edit';
	x.vehiclemovementitems_id.value=Code; 
	 
	x.action="Form_VehicleMovementItems.php";
	x.submit();
}

function DeleteDetail(Code){


if (confirm ( "Are you sure you want to Delete This Record ?"))
	{
		x = document.vehiclemovementitems;
		x.modedt.value='delete';
		x.vehiclemovementitems_id.value=Code; 
		x.action="Form_Vehicle_Actions.php?actionmode=delete_vehicleitems";
		x.submit();
	}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Vehicle Items</title>


<script type="text/javascript" src="dropdown.js"></script>
<link rel="stylesheet" href="default.css" type="text/css" />
<link rel="stylesheet" href="dropdown.css" type="text/css" />
<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;
}
.style11 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; font-size: 10px;}
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #FFFFFF ;font-size: 10px;}

</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='vehiclemovementitems' method='post'>
<input type=hidden name='modedt' value='$modedt'>
<input type=hidden name='vehicle_id' value='$vehicle_id'>


HERE;

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

echo"<table border=0 width='100%'>";
echo '<tr><td colspan="9" align="left" valign="top">';


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


print <<< HERE
		<tr><th height="15" colspan="9" align="center" valign="top"><span class="style3">Add Items</span></th></tr>
		<tr bgcolor='#F7F7F7' >	
			 <td colspan='9' align='center'><font size='1' color='#FF0000' face='Verdana'><b>$message</b></font></td></tr>			 
       <tr>
      <td>
HERE;



if ($vehiclemovementitems_id != ''){
$querydt= " select vehiclemovementitems_id, vehiclemovement.vehicle_id
			,vehiclemovementitems_note
			,vehicle.vehicle_platenumber,vehicle_make,items.item_description
			,items.item_code,items.item_description,vehiclemovementitems_quantity
			from vehiclemovementitems 
			left join items on items.item_code = vehiclemovementitems.item_code
			left join vehiclemovement on vehiclemovement.vehiclemovement_id = vehiclemovementitems.vehiclemovement_id
			left join vehicle on vehicle.vehicle_id = vehiclemovement.vehicle_id
			 where vehiclemovementitems_id='".$vehiclemovementitems_id."' ";
		
	
    $resultdt = mysql_query($querydt, $connection)  or die(mysql_error());
	while($rowdt=mysql_fetch_row($resultdt)){
        $vehiclemovementitems_id=$rowdt[0];
		$vehicle_id=$rowdt[1];
		$vehiclemovementitems_note=$rowdt[2];
		$vehicle_platenumber=$rowdt[3];
		$vehicle_make=$rowdt[4];
		$item_code=$rowdt[6];
		$item_description=$rowdt[7];
		$vehiclemovementitems_quantity=$rowdt[8];
	}
}

echo"
<input type=hidden name='vehiclemovement_id' value='$vehiclemovement_id'>

<input type=hidden name='message' value='$message'>
<input type=hidden name='vehiclemovementitems_id' value='$vehiclemovementitems_id'>
";

$querydt= " select vehiclemovementitems_id,vehicle_platenumber, vehicle_make, vehicle_platenumber 
			, vehiclemovementitems_note ,vehiclemovementitems_quantity,items.item_description,items.item_code
			from vehiclemovementitems 
			left join vehiclemovement on vehiclemovement.vehiclemovement_id = vehiclemovementitems.vehiclemovement_id
			left join vehicle on vehicle.vehicle_id = vehiclemovement.vehicle_id
			left join items on items.item_code = vehiclemovementitems.item_code
		    where vehiclemovement.vehiclemovement_id='".$vehiclemovement_id."' ";



	echo"<table border='0' style='table-layout:fixed' align='left' valign='top'>
		  <col width=160>
		  <col width=120>
		  <col width=400>";

		  $query=" select vehicle_platenumber,vehicle_make from vehicle ,vehiclemovement
					where vehiclemovement.vehiclemovement_id= '".$vehiclemovement_id."'
					and vehicle.vehicle_id = vehiclemovement.vehicle_id
					";
					
		  $result = mysql_query($query, $connection) or die(mysql_error());
		  $row=mysql_fetch_array($result);
		  
		  
echo "<tr bgcolor='#F7F7F7'><td colspan=4><span class='style11'>Vehicle:   ".$row[0]." ".$row[1]."&nbsp;</span></td></tr>";

echo"<tr bgcolor='#F7F7F7'><td valign='center' align='left' ><span class='style11'>Items&nbsp;<span class='style26'></span></span></td>";


{
echo"<td >
<input type=text name='item_code' value='$item_code' style='width:150px'></td><td>
<input type='text' name='item_description'  value='$item_description' size='13' style='width:250px'>";
echo"</label>";	
echo"<img src='img/btnopen.jpg' title=' Select Vehicle '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick=showitems()>";
echo"</label></td></tr>";
}


echo"<tr bgcolor=#F7F7F7><td><span class='style11'>Quantity</span></td><td colspan=2><input type=text name='vehiclemovementitems_quantity' value='$vehiclemovementitems_quantity'  $status>";
echo"</td></tr>";				


	
echo"<tr bgcolor=#F7F7F7 ><td><span class='style11'>Note</span></td><td colspan=2><textarea  name='vehiclemovementitems_note' $status style='width:400px;height:50px'>$vehiclemovementitems_note</textarea></td></tr>";

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


			
	echo"<tr><td ><table border=0 align=left width=100%> <tr bgcolor=#D8D8D8 height='35'>";
		
	

	echo"<td align='center'><input type='button' name='btnPost' id='btnPost' value='Submit Record' ";//post
	echo" onclick='SubmitRecord();' $style	title='Save Changes' /></td>";

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


		echo"<tr><td valign='top' colspan=5>";
echo "<table style='table-layout:fixed' border=0>
		<col width=20>
		<col width=20>
		<col width=100>
		<col width=300>
		<col width=100>
		<col width=200>
		";
		
		
echo "<tr bgcolor='#F7F7F7'><td>&nbsp;</td><td>&nbsp;</td>
<td><span class='style27'>Item&nbsp;<span class='style26'></span></span></td>
<td><span class='style27'>&nbsp;<span class='style26'></span></span></td>
		<td><span class='style27'>Quantity&nbsp;<span class='style26'></span></span></td>
		<td><span class='style27'>Note &nbsp;<span class='style26'></span></span></td>
		
      </tr>";
	  
	 

//echo $querydt;
$resultdt = mysql_query($querydt, $connection) or die(mysql_error());
while($rowsdt=mysql_fetch_array($resultdt)){
			    
	$ct+=1;

	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";	
						
				
	echo "<tr ".$Color." >";
	echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateDetail('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
	echo "	<td align='center' valign='center'><span class='style15'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteDetail('".$rowsdt[0]."') title='Delete Record'  ></span></td>";
	echo "	<td align='left'><span class='style15'>".$rowsdt[7]."</span></td>";
	echo "	<td align='left'><span class='style15'>".$rowsdt[6]."</span></td>";
	echo "	<td align='left'><span class='style15'>".$rowsdt[5]."</span></td>";
	echo "	<td align='left'><span class='style15'>".$rowsdt[4]."</span></td>";
	
	
	echo "</tr>";
						
}	
	  
echo"</table>";						
		

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


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

HERE;

?>