<?
session_start();
if(strlen($user)<=0)
{
 print "<script> alert('You are not logged in') </script>";
 include("logout.php");
 return;
}
include("opendb.php");
if($sv)
{
 if(!checkdate($m,$d,$y))
{
 print "<script>alert('Invalid Date'); history.back(1);</script>";
 return;
}
$dt=$y.'-'.$m.'-'.$d;

 $sql="insert into mach_location (mcode,brcode,engineer,date,cust,hmr) values('$mser','$brcode1','$engineer', '$dt','$cust','$hmr')";
mysqli_query($db,$sql)or die('err1'.mysqli_error());

$sql="update minput set engineer='$engineer',cust='$cust',brcode='$brcode1' where msno='$mser'";
print $sql;
mysqli_query($db,$sql)or die('err1'.mysqli_error());

$sql="update mdet set cname='$cust' where mcsno='$mser'";

mysqli_query($db,$sql)or die('err1'.mysqli_error());

print "<font color=green><b> Data has been saved</font>";
}
$result=mysqli_query($db,"select * from mach_location order by mcode");
?>
<script>
var branch=new Array();
branch[0]='';
var engi=new Array();
engi[0]='';
var cus=new Array();
cus[0]='';

function getVal()
{
 var k=document.f1.mser.selectedIndex;
 document.f1.a.value=branch[k];
 document.f1.e.value=engi[k];
 document.f1.c.value=cus[k];
}

</script>
<link rel="stylesheet" href="style.css" type="text/css" />
<center>
<form name='f1' action='<?print $PHP_SELF?>'>
<table>
<tr bgcolor='steelblue' height=25><td colspan=2 align=center><font color=white><b>SHIFT MACHINE</td></tr>
<tr><td>Select M Ser No </td><td><select name='mser' onChange=getVal()>
<option></option>
<?
$rr=mysqli_query($db,"select msno,brcode,engineer,cust,code from minput order by brcode")or die(mysqli_error());
$i=1;
while($locrow=mysqli_fetch_row($rr))
{
 print "\n<option value='$locrow[0]'>$locrow[0]</option>";
 $brr=mysqli_query($db,"select brname from branch where brcode='$locrow[1]'");
 $brrow=mysqli_fetch_row($brr);
   print "\n<script> branch[$i]='$brrow[0]'; </script>";

 $brr=mysqli_query($db,"select empname from empmaster where empcode='$locrow[2]'");
 $brrow=mysqli_fetch_row($brr);
   print "\n<script> engi[$i]='$brrow[0]'; </script>";

 $brr=mysqli_query($db,"select acname from customer where code='$locrow[3]'");
 $brrow=mysqli_fetch_row($brr);
   print "\n<script> cus[$i]='$brrow[0]'; </script>";

 $i++;
}
?>
</select></td></tr>
<tr><td>Branch </td><td><input type=text name='a' readonly style={border:none;background-color:aliceblue} size=40></td></tr>
<tr><td>Engineer </td><td><input type=text name='e' readonly style={border:none;background-color:aliceblue} size=40></td></tr>

<tr><td>Customer </td><td><input type=text name='c' readonly style={border:none;background-color:aliceblue} size=40></td></tr>

<tr height=25><td colspan=2 align=center bgcolor='steelblue'><font color=white><b>CHANGE TO</td></tr>
<tr><td>Branch </td><td><select name='brcode1'>
<?
 $brr=mysqli_query($db,"select brcode,brname from branch order by brname");
 while($brrow=mysqli_fetch_row($brr))
 {
   print "\n<option value='$brrow[0]'>$brrow[1]</option>";
 }
?>
</select>
</td></tr>

<tr><td>Engineer </td><td><select name='engineer'>
<?
 $brr=mysqli_query($db,"select empcode,empname from empmaster order by empname");
 while($brrow=mysqli_fetch_row($brr))
 {
   print "\n<option value='$brrow[0]'>$brrow[1]</option>";
 }
?>
</select>
</td></tr>

<tr><td>Customer </td><td><select name='cust'>
<?
 $brr=mysqli_query($db,"select code,acname from customer order by cname");
 while($brrow=mysqli_fetch_row($brr))
 {
   print "\n<option value='$brrow[0]'>$brrow[1]</option>";
 }
?>
</select>
</td></tr>
<tr><td>Date of Shifting </td><td> dd <input type=text name='d' size=2 value='<?print date('d')?>'> 
mm <input type=text name='m' size=2 value='<?print date('m')?>'> 
yy <input type=text name='y' size=4 value='<?print date('Y')?>'> </td></tr>

<tr><td>HMR</td><td><input type=text name='hmr'></td></tr>
<tr><td colspan=2 height=25 bgcolor='steelblue' align=center>
     <input type=submit value='Save' name='sv'> <input type=button value='Cancel' onClick=document.location='blank.html'>
 </td></tr>
</table>
</form>
