<html>
<head>
<? 
session_start();
include("test.php");
include("opendb.php");

include("calstock.php");

if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}

?>

</head>
<body>
<?
  if($updflg=='2'){

	$date=date('Y-m-d');

 	$i=0;
  	foreach($obs as $a){

   		$obs[$i]=$a;
  		$i++;
 	}

$qry=mysqli_query($db,"select * from observation_repo where jcno='$jcno' and brcode='$brcode'");
  if(mysqli_num_rows($qry)>0){
       $row2=mysqli_fetch_array($qry);
	$date=$row2[3];
	mysqli_query($db,"delete from observation_repo where jcno='$jcno' and brcode='$brcode'");
  }
 	 $j=0; 
  	for($k=0;$k<$i;$k++){

     		if($obs[$k]!=''){

    			 mysqli_query($db,"insert into observation_repo values('','$jcno','$obs[$k]','$date','$brcode')");
     			 $j++;
     		}

   	}

 	if($j>0){
 
   		echo "observation report has been added";
   		echo "<script> document.getElementById('updflg').value=1;</script>";
          
             ?> [<a href='print_observ_repo.php?jcno=<? echo $jcno; ?>'  target='blank' style="color:#FFCC66">Print </a>] <?

             

 	} 
 	else{

    		 echo "Invalid observation report";
 	}

  }
  else
  {
 	echo "Already Saved";
	 echo "<script> document.location='estimatenew.php';</script>";
 } 

?>
</body>
</html>