<?php   
$PageSecurity = 1;

$table='prd_process_master_details';


if($_REQUEST['Save'] && $_REQUEST['action']!='Edit')
{
$data['processid']=$_REQUEST['process'];
$data['box_req']=$_REQUEST['box_required'];
$s->RecordInsert($table,$data);
$Lastreq_id=DB_Last_Insert_ID($db,'prd_process_master_details','id');

for($i=0;$i<count($_REQUEST['boxname']);$i++)
{
 $data1['parentid']=$Lastreq_id;
 $data1['box_name']=$_REQUEST['boxname'][$i];
 $data1['valuereq']=$_REQUEST['valuereq'][$i];
 $s->RecordInsert('prd_process_master_details2',$data1);
 $Lastreq_id1=DB_Last_Insert_ID($db,'prd_process_master_details2','id');
 $boxname=$_REQUEST['boxname'][$i];
 for($k=0;$k<count($_REQUEST['boxvalue'][$i]);$k++)
 {
 
 $data12['parentid1']=$Lastreq_id;  
 $data12['parentid']=$Lastreq_id1;
 $data12['box_value']=$_REQUEST['boxvalue'][$i][$k];
  $s->RecordInsert('prd_process_details3',$data12);
   
  
  
 }
 
 
 
 
 
}


$s->pageLocation('index.php?route=Production/Plant/Production_process_parameter_details&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}
	
if(!$_REQUEST['Save'] && $_REQUEST['action']=='Edit')
{
	$condition="id='".$_REQUEST['sample_name_id']."'";
	$allready=$s->GetRecord($table,$condition);
	$Select=DB_query($allready,$db);
	$RData=DB_fetch_array($Select);
   $process=$RData['processid'];	
	$description=$RData['box_req'];
	
   
   $sql21=DB_query("select * from prd_process_master_details2 where parentid='".$_REQUEST['sample_name_id']."' order by id ASC",$db);
  
	while($row12=DB_fetch_array($sql21))
   {
   $boxname[]=$row12['box_name'];
   $boxvalue[]=$row12['valuereq'];
    $boxid[]=$row12['id'];
    $i=0;
   $sql2=DB_query("select * from prd_process_details3 where parentid='".$row12['id']."' order by id ASC",$db);
	while($row122=DB_fetch_array($sql2))
   {
   
   $boxvalue_data[$row12['box_name']][]=$row122['box_value'];
     }
  }
  
  
	
	
}	
if($_REQUEST['Save'] && $_REQUEST['action']=='Edit')
{
$data['processid']=$_REQUEST['process'];
$data['box_req']=$_REQUEST['box_required'];
 $cond="id='".$_REQUEST['sample_name_id']."'";
	$update= $s->EditRecord($table, $data, $cond);
	$row=DB_query($update,$db);
	$Lastreq_id=$_REQUEST['sample_name_id'];
   $del=DB_query("delete from prd_process_master_details2 
    where parentid='".$_REQUEST['sample_name_id']."'",$db);
   
   $del1=DB_query("delete from prd_process_details3 
    where parentid1='".$_REQUEST['sample_name_id']."'",$db);
   
for($i=0;$i<count($_REQUEST['boxname']);$i++)
{
 $data1['parentid']=$Lastreq_id;
 $data1['box_name']=$_REQUEST['boxname'][$i];
 $data1['valuereq']=$_REQUEST['valuereq'][$i];
 $s->RecordInsert('prd_process_master_details2',$data1);
 $Lastreq_id1=DB_Last_Insert_ID($db,'prd_process_master_details2','id');
 $boxname=$_REQUEST['boxname'][$i];
 for($k=0;$k<count($_REQUEST['boxvalue'][$i]);$k++)
 {
 
 $data12['parentid1']=$Lastreq_id;  
 $data12['parentid']=$Lastreq_id1;
 $data12['box_value']=$_REQUEST['boxvalue'][$i][$k];
  $s->RecordInsert('prd_process_details3',$data12);
   
  
}
}
  
  //prnMsg( _('Record Updated successfully'),'success');
 $s->pageLocation('index.php?route=Production/Plant/Production_process_parameter_details&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}

if($_REQUEST['action']=='del')
{
	$condition="id='".$_REQUEST['sample_name_id']."'";
   $condition1="parentid='".$_REQUEST['sample_name_id']."'";
	$s->DeleteRecord($table,$condition);
   $s->DeleteRecord('prd_process_master_details2',$condition1);
	prnMsg( _('Record deleted successfully'),'success');
	$s->pageLocation('index.php?route=Production/Plant/Production_process_parameter_details&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}

?>


<div style="display:none" id="div_id">
</div>
<link rel="stylesheet" href="css/new_mxerp1.css">

<div class="body_contain">
<div class="tab_div">
<form action="" method="post">
<table width="100%" border="1" cellspacing="3" cellpadding="3" align="center">
  <tr class="row1">
    <td colspan="8" class="tabledata1"><h1>Production Process Mapping with Parameter</h1></td>
  </tr>  
  <tr class="row1">    
	<td class="tabledata1"><strong>Process Parameter </strong><font color="#FF0000">*</font></td>
    <td class="tabledata1" >
     <input type="hidden" name="process1" id="process1" value="<?php echo $_REQUEST['sample_name_id']; ?>">
     <select name="process" id="process"  style="width:100%;">
	<option value="0">Select</option>
	<?php 
	$sql_tax_service1=DB_query("select * from Prd_process_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($row12=DB_fetch_array($sql_tax_service1))
	{
	$t1='';
	if($process==$row12['id'])
$t1="selected";	
	  ?>
	<option value="<?php echo $row12['id']; ?>" <?php echo $t1; ?>><?php echo $row12['description']; ?></option>
	<?php } ?>
	
	</select></td>
	
	
    <td class="tabledata1"><strong>Box Required</strong><font color="#FF0000">*</font></td>
    <td class="tabledata1" ><input type="text" name="box_required" id="description" style="width:100%;" value="<?php echo $description; ?>" onkeyup="showtabledata(this.value)" ></td>    
   </tr>
   <tr class="row1">
   
   <td  colspan="4" class="tabledata1" id="boxdata">
    <table width="100%" border="1" cellspacing="3" cellpadding="3" align="center">
     <tr><td class="tabledata">Box Name Here</td><td class="tabledata">Box Req</td>
     <td class="tabledata">Box Value</td>
     </tr>
    <?php for($i=0;$i<$description;$i++)
    {     
     
     //echo $boxname[$i];
     ?>
     
   <tr><td><input type="text" name="boxname[]" value="<?php echo $boxname[$i]; ?>" style="width:100%"
             id="boxname_<?php echo $i; ?>"     >
     <input type="hidden" id="prd_detail2_<?php echo $i; ?>" value="<?php echo $boxid[$i] ?>">
    </td> 
   <td><input type="text" name="valuereq[]" id="valreq_<?php echo $i; ?>" value="<?php echo $boxvalue[$i]; ?>"         style="width:100%" onkeyup="showboxvaleue(<?php echo $i; ?>)"></td>
   <td id="boxdata1_<?php echo $i; ?>">
   <table width=100%" border="0" cellspacing="3" cellpadding="3" align="center">
 
   <?php for($t=0;$t<$boxvalue[$i];$t++)
   {
    
    if($boxvalue_data[$boxname[$i]][$t]!='')
     $boxval=$boxvalue_data[$boxname[$i]][$t];
    else
      $boxval='';
    
    ?>
   
   <tr><td><input type="text" name="boxvalue[<?php echo $i; ?>][]" style="width:100%"
             id="boxvalue_<?php echo $i; ?>" value="<?php echo $boxval; ?>"     ></td> 
   </tr>
   <?php } ?>  
    </table></td>
   
   </tr>
    <?php } ?> 
    </table>
    
    
   </td>
	   
  </tr>
     
  <tr class="row1">
    
    <td colspan="4" style="text-align:center"> 
	
      <input type="submit" name="Save" value="Save" class="search" >    </td>
  </tr>
</table>
</form>
</div></div>
<?php include("Viewproduction_process_parameter_details.php") ?> 
<script>
 function showtabledata(i)
 {
if(document.getElementById("process").value==0)
 {
 alert("Must Select Process first");
 }
 else
  {
 if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{		
			document.getElementById("boxdata").innerHTML=xmlhttp.responseText;
		
	}
	}
	var process1=document.getElementById("process1").value;
	xmlhttp.open("GET","ajax_dynamic_box_creation.php?str="+i+"&process="+process1,true);
	xmlhttp.send();
  }
}
 
 
  
function showboxvaleue(str)
{
 
    var values1=document.getElementById("valreq_"+str).value;
//alert(site1);
	var name=document.getElementById("boxname_"+str).value;
  
   var id1=document.getElementById("prd_detail2_"+str).value;
  
  if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{		
			document.getElementById("boxdata1_"+str).innerHTML=xmlhttp.responseText;
		
	}
	}
	
	xmlhttp.open("GET","ajax_dynamic_box_value.php?str="+values1+"&process="+name+"&id="+id1+"&rec="+str,true);
	xmlhttp.send();
  
}
 
 
	
	
	

</script> 

