<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../../index.html'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
?>
<style>
td,th,body{font-size:14;font-family:'arial narrow';letter-spacing:1}
</style>
<?
$i=1;
 $re1=mysqli_query($db,"select distinct invno,engineer,customer,entrydate,vatorcst from spareinvoice where brcode='$brcode' group by invno")or die(mysqli_error($db));
  print "<form name='f1' action='' method='post'>";
 print "<font color=red>Enter Password </font><input type=password name='pswd'><table border=1 id='myTable'><th>Inv No <th>Date <th>Inv Type<th>Customer<th>Engineer";
 while($row=mysqli_fetch_array($re1))
 {

  print "<tr><td><input type=text name='invno[]' readonly value='$row[0]' size=5></td>";
  print "<td><input type=text readonly name='invdate[]' value='".($row[entrydate])."' size=10></td>";
  print "<td><center>".$row[vatorcst]."</td>";
  print "<td><input type=text name='cust[]' value='".$row[customer]."'></td>";
 //$sql="select empname,design,brcode from payroll.empmaster where design like '%eng%' order by empname";
 //echo $sql;
 //echo "<br>";
 print "<td> <select name='eng[]' class='eng' id='$i' onchange='chkthis(this.value,this,this.id)'><option>$row[1]</option><option>Counter</option>";

  $engres=mysqli_query($db,"select empname from payroll.empmaster where design like '%eng%' order by empname");
 while($engrow=mysqli_fetch_row($engres))
 {
  print "<option>$engrow[0]</option>";
 }
 print "</select></td><input type='hidden' name='hideng[]' id='hideng$i' value=''></tr>";
 $i++;
 }
 print "<tr><td colspan=6 align=center><input type=button value='Update' name='upd' onclick='sv_chengineer()'></td></tr>";
 print "</table></form>";

 //return;

/*
 $brres1=mysqli_query($db,"select distinct b.brname,a.brcode from spareinvoice a,branch b where a.brcode=b.brcode order by b.brname")or die(mysqli_error($db));
print "<form action='$PHP_SELF'>";
print "<center>Select Branch <select name=br>";
while($brrow=mysqli_fetch_row($brres1))
{
 print "<option>$brrow[0]</option>";
}
print "</select>";
print "<input type=submit value='Show' name='show'></form>";
*/
?>
<script type="text/javascript">
function chkthis(str,r,itid)
{
var stvl=document.getElementById(itid).value;
document.getElementById("hideng"+itid).value=stvl;
}

function sv_chengineer()
{
var invn1= document.getElementsByName('invno[]');
var invdt1=document.getElementsByName('invdate[]');
var custnm1=document.getElementsByName('cust[]');
var engnm1=document.getElementsByName('hideng[]');
i=0;
var invno=[];
var invdate=[];
var custname=[];
var engname=[];
for(k=0;k<engnm1.length;k++)
{
//alert(partcode1[k].value);
	if(engnm1[k].value)
	{
	invno.push(invn1[k].value);
	invdate.push(invdt1[k].value);
	custname.push(custnm1[k].value);
	engname.push(engnm1[k].value);

		i++;
	}
}
var invcd=invno.join("||");
var invdtcd=invdate.join("||");
var cnamecd=custname.join("||");
var engnmcd=engname.join("||");
var passwdvl=document.f1.pswd.value;
var url="updeng.php?invno="+invcd+"&&invdate="+invdtcd+"&&cust="+cnamecd+"&&eng="+engnmcd+"&&pswd="+passwdvl;
document.location=url,true;
}
</script>


<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../../index.html'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
if($pswd=='engineer')
{

$invno=explode('||',$invno);
$invdate=explode('||',$invdate);
$cust =explode('||',$cust);
$eng =explode('||',$eng);

 $i=0;
foreach($invno as $a)
{
 $invno[$i]=$a;
 $i++;
}
 $i=0;
foreach($invdate as $a)
{
 $invdate[$i]=$a;
 $i++;
}
 $i=0;
foreach($cust as $a)
{
 $cust[$i]=$a;
 $i++;
}


 $i=0;
foreach($eng as $a)
{
 $eng[$i]=$a;
 $i++;
}

 for($j=0;$j<$i;$j++)
 {
  $sql="update spareinvoice set engineer='$eng[$j]' where invno='$invno[$j]' and entrydate='$invdate[$j]' and customer='$cust[$j]' and brcode='$brcode'";
  mysqli_query($db,$sql)or die(mysqli_error($db));
//echo $sql;
//echo "<br>";
 }
}
else
{
  print "invalid password";
}

?>
<style>
	td,th,body{font-size:14;font-family:'arial narrow';letter-spacing:1}
</style>
<script>
 document.location='cheng.php';
</script>