<?
session_start();
if(strlen($user)<=0)
{
 print "<script> alert('You are not logged in') </script>";
 include("logout.php");
 return;
}

//date_add("2007-1-31", INTERVAL 1 MONTH)
include("opendb.php");
include("test.php");
if($sv)
{
 $comdate=$y.'-'.$m.'-'.$d;
 $code=substr($mcsno,0,4).date("dmys");
 str_replace(' ','-',$code);

 $re=mysqli_query($db,"select date_add('$comdate', INTERVAL $s0d DAY)")or die(mysqli_error());
 $dr=mysqli_fetch_row($re);
  $s0d=$dr[0];

 $re=mysqli_query($db,"select date_add('$comdate', INTERVAL $s0h HOUR)")or die(mysqli_error());
 $dr=mysqli_fetch_row($re);
//  $s0h=$dr[0];

 $re=mysqli_query($db,"select date_add('$comdate', INTERVAL $s1m MONTH)")or die(mysqli_error());
 $dr=mysqli_fetch_row($re);
  $s1m=$dr[0];

 $re=mysqli_query($db,"select date_add('$comdate', INTERVAL $s1h HOUR)")or die(mysqli_error());
 $dr=mysqli_fetch_row($re);
//  $s1h=$dr[0];

 $re=mysqli_query($db,"select date_add('$comdate', INTERVAL $s2m MONTH)")or die(mysqli_error());
 $dr=mysqli_fetch_row($re);
  $s2m=$dr[0];


 $re=mysqli_query($db,"select date_add('$comdate', INTERVAL $s2h HOUR)")or die(mysqli_error());
 $dr=mysqli_fetch_row($re);
//  $s2h=$dr[0];


 $re=mysqli_query($db,"select date_add('$comdate', INTERVAL $s3m MONTH)")or die(mysqli_error());
 $dr=mysqli_fetch_row($re);
  $s3m=$dr[0];


 $re=mysqli_query($db,"select date_add('$comdate', INTERVAL $s3h HOUR)")or die(mysqli_error());
 $dr=mysqli_fetch_row($re);
//  $s3h=$dr[0];


 $re=mysqli_query($db,"select date_add('$comdate', INTERVAL $s4m MONTH)")or die(mysqli_error());
 $dr=mysqli_fetch_row($re);
  $s4m=$dr[0];


 $re=mysqli_query($db,"select date_add('$comdate', INTERVAL $s4h HOUR)")or die(mysqli_error());
 $dr=mysqli_fetch_row($re);
//  $s4h=$dr[0];


 $sql="insert into mdet values('$mcsno','$model1','$engno','$model2','$hmr','$cname','$comdate','$s0d','$s0h',"
."'$s1m','$s1h','$s2m','$s2h','$s3m','$s3h','$s4m','$s4h','$code')";
 mysqli_query($db,$sql)or die(mysqli_error());
print "Data has been saved";
print "<script> window.open('showpop.php?code=$code'); </script>";
}
?>
<link rel="stylesheet" href="style.css" type="text/css" />

<center>
<!--
<form action='<?print $PHP_SELF?>'>
<table cellspacing=1 cellpadding=2 bgcolor='aliceblue'>
<tr><td colspan=6 align=center bgcolor='lightsteelblue'>MACHINE DETAILS</td></tr>
<tr><td>M/C Serial NO. </td><td><input type=text name='mcsno' ></td>
    <td>M/C Model </td><td><input type=text name='model1' ></td>
    <td>Eng. NO. </td><td><input type=text name='engno' ></td>
</tr>
<tr><td>Eng Model </td><td><input type=text name='model2' ></td>
    <td>HMR </td><td><input type=text name='hmr' ></td></tr>
<tr>
    <td>Customer </td><td colspan=5><select name='cname'>
    <?
      $re=mysqli_query($db,"select code,acname from customer order by acname")or die(mysqli_error());
      while($row=mysqli_fetch_array($re))
      {
        print "\n<option value='$row[code]'>$row[acname]</option>";
      }
    ?>
    </select>
</td>
</tr>
<tr><td>Date of Comm.</td><td colspan=2>dd<input type=text name='d' size=2>
mm<input type=text name='m' size=2>
dd<input type=text name='y' size=4 value='<?print date("Y")?>'></td></tr>
<tr><td colspan=10 align=center>
SERVICE CODE AND DUE DATES
<table cellspacing=1 cellpadding=2 bgcolor='aliceblue'>
<tr bgcolor='lightsteelblue'>
<td colspan=1 align=center >S0</td>
<td colspan=1 align=center >S1</td>
<td colspan=1 align=center >S2</td>
<td colspan=1 align=center >S3</td>
<td colspan=1 align=center >S4</td>
</tr>
<TD>Days <input type=text name='s0d' size=2 value='7'>Hrs <input type=text name='s0h' size=2 value='50'></td>
<TD>Month <input type=text name='s1m' size=2 value='1'>Hrs <input type=text name='s1h' size=3 value='250'></td>
<TD>Month <input type=text name='s2m' size=2 value='2'>Hrs <input type=text name='s2h' size=3 value='500'></td>
<TD>Month <input type=text name='s3m' size=2 value='4'>Hrs <input type=text name='s3h' size=4 value='1000'></td>
<TD>Month <input type=text name='s4m' size=2 value='6'>Hrs <input type=text name='s4h' size=4 value='1500'></td>
</table>
</td></tr>
<tr><td colspan=6 align=center bgcolor='lightsteelblue'><input type=submit value='Save' name='sv'>
 <input type=button value='Cancel' onClick=document.location='blank.html'></td></tr>
</table>
</form>
-->

<center>
<h3>Machine Input Details </h3>
<table bgcolor='lightsteelblue' cellspacing=1 cellpadding=4>
<th> No.<th>MCS No <th>M/C Model <th>Engine No. <th>Engine Model <th>Current Customer  <th> Branch<th>Comm Date<th>Action
<?
$i=1;
$re=mysqli_query($db,"select * from mdet order by mcsno");
while($row=mysqli_fetch_array($re))
{
  $rr=mysqli_query($db,"select maname from machmaster where code='$row[1]'");
  $r=mysqli_fetch_row($rr);

  $cr=mysqli_query($db,"select acname from customer where code='$row[cname]'");
  $crrow=mysqli_fetch_array($cr);

	$ssq="select brcode from minput where code='$row[code]'";

  $br=mysqli_query($db,$ssq)or die(mysqli_error());
  $brrow=mysqli_fetch_array($br);
  $ssq="select brname from branch where brcode='$brrow[0]'";
  $br2=mysqli_query($db,$ssq)or die(mysqli_error());
  $brrow2=mysqli_fetch_array($br2);
  
 print "\n<form action='editmdet.php'>\n<input type=hidden name='code' value='$row[code]'>";
 print "<tr bgcolor='aliceblue' onMouseOver=bgColor='ivory'; onMouseOut=bgColor='aliceblue'; ><td align=center>".$i++."</td><td>$row[0]</td><td>$r[0]</td><td>$row[2]</td><td>$row[3]</td>";
 print "<td>$crrow[0]</td><td>$brrow2[0]</td><td>".datetohtml($row[dcomm])."</td>";
print "<td><input type=submit value='Edit'>\n</form>";
}
?>
</table>

