<? session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}

include("../opendb.php");
if($submit)
{
 if(strlen($config)<=0 || strlen($mcode)<=0)
  {
     print "<script> alert('In sufficient entry'); history.back(1);  </script>";
     return;
  }
 $code=substr($config,0,3).substr(time(),7,3); 
 $code=str_replace(' ','-',$code);
 $re=mysqli_query($db,"select * from veh_master where config='$config' and brcode='$brcode'");
  if(mysqli_num_rows($re)>0)
  {
     print "Duplicate entry ". $mcode;
     print "<script> alert('Duplicate entry $mcode'); history.back(1);  </script>";
     return;
  }
  
 $sql="insert into veh_master (mcode,config,gvw,wbase,tyrefr,tyrerr,cat,brcode,clas,mnam,hpower,fuel,cyl,capa,uweight,axlefr,axlerr,axleoth,axletan,cbody,tbody,sconfig,active) values ('$mcode','$config','$gvw','$wbase','$tyrefr','$tyrerr','$cat','$brcode','$clas','$mnam','$hpower','$fuel','$cyl','$capa','$uweight','$axlefr','$axlerr','$axleoth','$axletan','$cbody','$tbody','$sconfig','Y')";
 mysqli_query($db,$sql)or die(mysqli_error());
 print "<font color='Green'> Data has been saved</font>";
}

?>
<script>
function valid()
{
  submitOK="true";

 if(document.f1.mcode.value.length<=0)
 {
   submitOK="false";
   alert('Invalid Model Code');
 }

 if(document.f1.config.value.length<=0)
 {
   submitOK="false";
   alert('Invalid Configuration');
 }

  if(submitOK=="true")
   return true;
  else
   return false;
}


function chkey(abc)
{
 yy=abc.value
 if(yy.indexOf('  ')>-1) 
  {
    alert('Multiple space is not allowed');
    abc.value='';
  }
 if(yy.indexOf("'")>-1) 
  {
    alert("\' is not allowed");
    abc.value='';
  }
}
</script>

<style>
body,td{font-family:'arial narrow';letter-spacing:1;font-size:13.89}
tr{background-color:c1d7bb}
.mnu{margin-left:5}
</style>
<body bgcolor='ivory'>

<CENTER>
<BR>
<FORM name='f1' ACTION='<?print $PHP_SELF?>' METHOD='POST' onSubmit="return valid()">
<table cellspacing=1 cellpadding=1 bgcolor=green>
<tr><td align=center>
<table>
<tr><td colspan=2 align=center>VEHICLE MASTER</TD></TR>
<tr><td><font color='red'>Model Code </td><td><input type=text name='mcode' size=40 onKeyDown=chkey(this);></td></tr>
<tr><td><font color='red'>Configuration </td><td><input type=text name='config' size=40 onKeyDown=chkey(this)></td></tr>
<tr><td><font color='red'>Sale Cert Configuration </td><td><input type=text name='sconfig' size=40 onKeyDown=chkey(this)></td></tr>
<tr><td>G V W </td><td><input type=text name='gvw' size=40></td></tr>
<tr><td>W Base </td><td><input type=text name='wbase' size=40></td></tr>
<tr><td>Tyre FR </td><td><input type=text name='tyrefr' size=40></td></tr>
<tr><td>Tyre RR </td><td><input type=text name='tyrerr' size=40></td></tr>
<tr><td>Category </td><td><input type=text name='cat' size=40></td></tr>
<tr><td>Class </td><td><input type=text name='clas' size=40></td></tr>
<tr><td>Makers Name </td><td><input type=text name='mnam' size=40></td></tr>
<tr><td>Horse Power </td><td><input type=text name='hpower' size=40></td></tr>
<tr><td>Fuel Used </td><td><input type=text name='fuel' size=40></td></tr>
<tr><td>No.of Cylinders </td><td><input type=text name='cyl' size=40></td></tr>
<tr><td>Seating Capacity </td><td><input type=text name='capa' size=40></td></tr>
<tr><td>Unladen Weight </td><td><input type=text name='uweight' size=40></td></tr>
<tr><td>Front axle </td><td><input type=text name='axlefr' size=40></td></tr>
<tr><td>Rear axle </td><td><input type=text name='axlerr' size=40></td></tr>
<tr><td>Any othe axle </td><td><input type=text name='axleoth' size=40></td></tr>
<tr><td>Tandem axle</td><td><input type=text name='axletan' size=40></td></tr>
<tr><td>Colour of Body </td><td><input type=text name='cbody' size=40></td></tr>
<tr><td>Type of Body </td><td><input type=text name='tbody' size=40></td></tr>



<TR><TD COLSPAN=2 ALIGN=CENTER><INPUT TYPE=SUBMIT NAME='submit' VALUE='  SAVE  '></TD></TR>

</table>
</td></tr>
</table>
</FORM>
<br>
<form action='<?print $PHP_SELF?>'>
 Search Configuration <input type=text name='sea1' size=10> <input type=submit value='Search' name='sea'>
</form>
<style>
.x{font-size:14}
</style>

</table>
<?
print "<table cellspacing=1 cellpadding=1 border=1 style={font-size:13}>";
print "<th> No.<th>Model Code <th>Configuration <th>GVW <th>W Base <th>Tyre FR <th>Tyre RR <th>Category <th>Edit";

if($sea)
{
$result=mysqli_query($db,"select * from veh_master where config like '%$sea1%' and brcode='$brcode' order by mcode")or die(mysqli_error());
if(mysqli_num_rows($result)<=0)
{
 print "</table><br><font color='red'>Record not found </font>";
 return;
}

$i=1;
while($row=mysqli_fetch_row($result))
{
 print "\n<tr class=x><td>".$i++."</td><td>$row[1]</td><td>$row[2]</td>";
 print "<td>$row[3]</td><td>$row[4]</td><td>$row[5]</td><td>$row[6]</td><td>$row[7]</td>";
 print "<td><a href='editvehmas.php?code=$row[0]'><img src='../img/signit.gif' border=0></a></td></tr>";
}
}
else
{
$i=1;
$result=mysqli_query($db,"select * from veh_master where brcode='$brcode' order by config")or die(mysqli_error());
while($row=mysqli_fetch_row($result))
{
 print "\n<tr class=x><td>".$i++."</td><td>$row[1]</td><td>$row[2]</td>";
 print "<td>$row[3]</td><td>$row[4]</td><td>$row[5]</td><td>$row[6]</td><td>$row[7]</td>";
 print "<td><a href='editvehmas.php?code=$row[0]'> <img src='../img/signit.gif' border=0></a></td></tr>";
}
}
?>
</table>

<script>
function edit(x,y)
{
 value=prompt("Enter Configuration for "+x);
 if(value)
 document.location="editvehmaster.php?code="+y+"&config="+value;
}


</script>



