<?php 
$PageSecurity = 11;
$title = _('Item Maintenance');
include('includes/SQL_CommonFunctions.inc');
$date=date('d/m/Y');
?>
<script type="text/javascript" src="js/dynamicRow.js"></script>
<script language="javascript" type="text/javascript">
var xmlHttp
function get_url()
{
	var str=document.getElementById("category").value;
	alert(str);
	if(str!='')
	{
	location.replace("item_master.php?type="+str);
	}
}

function get_option1(str)
{
	if(str=='NO')
	{
		document.getElementById("varnish").disabled=true;
	}
	else
	{
		document.getElementById("varnish").disabled=false;
	}
	
}
function get_option2(str)
{
	if(str=='NO')
	{
		document.getElementById("uv").disabled=true;
	}
	else
	{
		document.getElementById("uv").disabled=false;
	}
	
}

</script>
<style type="text/css">
.cap{
text-transform:uppercase
};
</style>
<?php 
if($_REQUEST['Cancel'])
{
	echo "<script>location.href='index.php?route=Inventory/maintenance/item_master_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}

if($_REQUEST['Save']!='')
{
	if($_REQUEST['code']=='FG')
	{
	$max_size='300';
	$flag=0;
	function extension($filename)
	{
		$name_brk=explode('.',$filename);
		return  $name_brk[1];
	}
	
	$name=$_FILES['fg_photo']['name'];
	$type=extension($name);
	
	if($type!='jpg' && $type!='jpeg' && $type!='png' && $type!='gif')
	{
		echo "<strong>Invalid Extension! Kindly please check the image before uploading</strong>";
		$flag=1;
	}
	else
	{
		$tmp_name=$_FILES['fg_photo']['tmp_name'];
		//echo $tmp_name; exit;
		
		if($_FILES['fg_photo']['size']>$max_size*1024)
		{
			echo "<strong>Sorry! Size Limit Exceeded</strong>";
			$flag=1;
		}
		else
		$new_name=$_REQUEST['StockID'].'.'.$type;
		$path="uploaded_images/".$new_name;
		$file_copy=copy($tmp_name,$path);
		if(!$file_copy)
		{
			echo "<strong>Copy Unsuccessful</strong>";
			$flag=1;
		}
	}
}
$queryCheck=DB_fetch_array(DB_query("select * from item_master where item_name='".htmlspecialchars($_REQUEST['item_name'],ENT_QUOTES)."'",$db));
		if($queryCheck['item_name']!=$_REQUEST['item_name'])
		{
/*************************************************************/



/*************************************************************/			
$product_description = htmlspecialchars($_REQUEST['item_name'], ENT_QUOTES);
$item_code = htmlspecialchars($_REQUEST['StockID'], ENT_QUOTES);
$item_desc = htmlspecialchars($_REQUEST['item_desc'], ENT_QUOTES);			
	echo $_REQUEST['itemcodeval'];
	
  $sql="Insert into item_master SET
id='',
CategoryID='".$_REQUEST['item_cat']."',  
SubCategoryID ='".$_REQUEST['itemcodeval']."', 
StockID ='".$item_code."', 
item_name ='".$product_description."', 
item_desc='".$item_desc."',
state='".$_REQUEST['state']."',
height ='".$_REQUEST['height']."', 
width ='".$_REQUEST['width']."',  
teeth ='".$_REQUEST['teeth']."',  
ups ='".$_REQUEST['ups']."',    
foil_size ='".$_REQUEST['foil_size']."', 
paper_size ='".$_REQUEST['paper_size']."', 
paper_name ='".$_REQUEST['paper_name']."',
print_size ='".$_REQUEST['print_size']."',
frt_br  ='".$_REQUEST['frt_br']."',
color_no='".$_REQUEST['color_no']."',  
image_pdf ='".$new_name."', 
embossing='".$_REQUEST['embossing']."',  
spot ='".$_REQUEST['spot']."',   
party ='".$_REQUEST['party']."',  
varnish ='".$_REQUEST['varnish']."', 
uv  ='".$_REQUEST['uv']."',
overprint='".$_REQUEST['overprint']."',  
foil='".$_REQUEST['foil']."',    
cut='".$_REQUEST['cut']."',     
item_no ='".$_REQUEST['item_no']."', 
flexo_offset ='".$_REQUEST['flexo_offset']."',   
unit='".$_REQUEST['unit']."',  
size ='".$_REQUEST['size']."',   
length='".$_REQUEST['length']."',  
gsm='".$_REQUEST['gsm']."',     
od='".$_REQUEST['od']."',        
serial_no ='".$_REQUEST['serial_no']."', 
orig_local ='".$_REQUEST['orig_local']."', 
type_name='".$_REQUEST['type_name']."',  
shade='".$_REQUEST['shade']."',   
running_roll='".$_REQUEST['running_roll']."',  
volume ='".$_REQUEST['volume']."', 
bcm='".$_REQUEST['bcm']."',     
quality ='".$_REQUEST['quality']."',
tolerance ='".$_REQUEST['tolerance']."', 
created_date='".FormatDateForSQL(date('d/m/Y'))."' ";

$result=DB_query($sql,$db);
$last_id=DB_Last_Insert_Id($db,"item_master","id");

$_SESSION['success_msg']="Saved Successfully";
echo "<script>location.href='index.php?route=Inventory/maintenance/item_master_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
else {
	echo "<script> alert(' Item Name IS EXIST.');</script>";
}

if(isset($_REQUEST['field_id']))
{
for($n=1;$n<$_REQUEST['CTR'];$n++)
{
$sql2="Update item_master set ".
$_REQUEST['field_id'][$n]."='".$_REQUEST['field'][$n]."' where id='".$last_id."' ";
$result2=DB_query($sql2,$db);
//echo "<pre>";
//print_r($sql2); exit;

if($_REQUEST['field'][$n]!='')
{
$update_item_setup="update item_master_setup set status='1' where field='".$_REQUEST['field_id'][$n]."'";
$update_setup_res=DB_query($update_item_setup,$db);
}
}
}

//echo "<pre>";
//print_r($sql2);
//exit;






}
/*if($_REQUEST['Submit'])
{

echo "<script>location.href='index.php?route=Inventory/maintenance/item_master_add&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."&item_cat=".$_REQUEST['item_cat']."'</script>";

//header('Location: item_master.php?item_cat='.$_REQUEST['item_cat']);
}*/

if($_REQUEST['action']=='edit' && $_REQUEST['id']!='')
{
	 $sql="select * from item_master where id='".$_REQUEST['id']."' ";
	 $result=DB_query($sql,$db);
	 $myrow=DB_fetch_array($result);
	 
	 //echo "<pre>";
	// print_r($myrow);
	 
	 $code1=$myrow['CategoryID'];
	if(is_numeric($code1)) 
	{
	$code=$myrow['CategoryID'];	
	}
	else {
	$code=$s->getField('stockmaincategory','stockmaincategoryid ',$myrow['CategoryID'],'id');	
	}
	$itemcodeval1=$myrow['SubCategoryID']; 
	if(is_numeric($itemcodeval1)) 
	{
	$itemcodeval=$myrow['SubCategoryID'];	
	}
	else {
	$itemcodeval=$s->getField('stockcategory','categoryid ',$myrow['SubCategoryID'],'id');	
	}
	$StockID =$myrow['StockID']; 
	$item_name =$myrow['item_name'];
	$item_desc =$myrow['item_desc'];
	$state =$myrow['state'];
	$height =$myrow['height']; 
	$width =$myrow['width'];  
	$teeth =$myrow['teeth'];  
	$ups =$myrow['ups'];    
	$foil_size =$myrow['foil_size']; 
	$paper_size =$myrow['paper_size']; 
	$paper_name =$myrow['paper_name']; 
	$print_size =$myrow['print_size']; 
	$frt_br  =$myrow['frt_br'];
	$color_no=$myrow['color_no'];  
	$image_pdf =$myrow['image_pdf']; 
	$embossing=$myrow['embossing'];  
	$spot =$myrow['spot'];   
	$party =$myrow['party'];  
	$varnish =$myrow['varnish']; 
	$uv  =$myrow['uv'];
	$overprint=$myrow['overprint'];  
	$foil=$myrow['foil'];    
	$cut=$myrow['cut'];     
	$item_no =$myrow['item_no']; 
	$flexo_offset =$myrow['flexo_offset'];   
	$unit=$myrow['unit'];  
	$size =$myrow['size'];   
	$length=$myrow['length'];  
	$gsm=$myrow['gsm'];     
	$od=$myrow['od'];        
	$serial_no =$myrow['serial_no']; 
	$orig_local =$myrow['orig_local']; 
	$type_name=$myrow['type_name'];  
	$shade=$myrow['shade'];   
	$running_roll=$myrow['running_roll'];  
	$volume =$myrow['volume']; 
	$bcm=$myrow['bcm'];     
	$quality =$myrow['quality'];
	$tolerance =$myrow['tolerance'];
	//echo "select * from item_master_setup where item_master='".$myrow['CategoryID']."'";
	$item_setup=DB_query("select * from item_master_setup where item_master='".$myrow['CategoryID']."'",$db);
	$Z=1;
	while($item_setup_res=DB_fetch_array($item_setup))
	{
		$field_id[$Z]=$item_setup_res['field'];
		//echo "<br>".$field_id[$Z];
		$field_sql="Select ".$field_id[$Z]." from item_master where id='".$_REQUEST['id'] ."' ";
		$field_result=DB_query($field_sql,$db);
		$field_row=DB_fetch_array($field_result);
		$field[$Z]=$field_row[''.$field_id[$Z].''];
		//echo $field[$Z];
		$Z++;
	}	
	 
	if($code=='FG')
	{
		$get_color="Select * from item_color_master where item_master_id='".$_REQUEST['id']."'";
		$get_res=DB_query($get_color,$db);
		$cr=1;
		while($get_row=DB_fetch_array($get_res))
		{
			$colorno[$cr]=$get_row['color'];
			$cr++;
		}
	}
}
else
{
	$code=$_REQUEST['item_cat']; 
	$itemcodeval =$_REQUEST['itemcodeval']; 
	$StockID =$_REQUEST['StockID']; 
	$item_name =$_REQUEST['item_name']; 
	$item_desc =$_REQUEST['item_desc']; 
	$state =$_REQUEST['state'];
	$height =$_REQUEST['height']; 
	$width =$_REQUEST['width'];  
	$teeth =$_REQUEST['teeth'];  
	$ups =$_REQUEST['ups'];    
	$foil_size =$_REQUEST['foil_size']; 
	$paper_size =$_REQUEST['paper_size']; 
	$paper_name =$_REQUEST['paper_name']; 
	$print_size =$_REQUEST['print_size']; 
	$frt_br  =$_REQUEST['frt_br'];
	$color_no=$_REQUEST['color_no'];  
	$image_pdf =$_REQUEST['image_pdf']; 
	$embossing=$_REQUEST['embossing'];  
	$spot =$_REQUEST['spot'];   
	$party =$_REQUEST['party'];  
	$varnish =$_REQUEST['varnish']; 
	$uv  =$_REQUEST['uv'];
	$overprint=$_REQUEST['overprint'];  
	$foil=$_REQUEST['foil'];    
	$cut=$_REQUEST['cut'];     
	$item_no =$_REQUEST['item_no']; 
	$flexo_offset =$_REQUEST['flexo_offset'];   
	$unit=$_REQUEST['unit'];  
	$size =$_REQUEST['size'];   
	$length=$_REQUEST['length'];  
	$gsm=$_REQUEST['gsm'];     
	$od=$_REQUEST['od'];        
	$serial_no =$_REQUEST['serial_no']; 
	$orig_local =$_REQUEST['orig_local']; 
	$type_name=$_REQUEST['type_name'];  
	$shade=$_REQUEST['shade'];   
	$running_roll=$_REQUEST['running_roll'];  
	$volume =$_REQUEST['volume']; 
	$bcm=$_REQUEST['bcm'];     
	$quality =$_REQUEST['quality']; 
	$tolerance =$_REQUEST['tolerance'];
	for($j=1;$j<9;$j++)
	{
		$colorno[$j]=$_REQUEST['colorno'];
	}
	
	for($cnt1=1;$cnt1<$_REQUEST[''];$cnt1++)
	{
		$field_id[$cnt1]=$_REQUEST['field_id'];
		$field[$cnt1]=$_REQUEST['[field'];
	}
	
}
if($_REQUEST['Update']!='')
{
	
	if($_FILES['fg_photo']['name']!='')	
	{
		$max_size='300';
		$flag=0;
		function extension($filename)
		{
			$name_brk=explode('.',$filename);
			return  $name_brk[1];
		}
	
		$name=$_FILES['fg_photo']['name'];
		$type=extension($name);
	
		if($type!='jpg' && $type!='jpeg' && $type!='png' && $type!='gif')
		{
			echo "<strong>Invalid Extension! Kindly please check the image before uploading</strong>";
			$flag=1;
		}
		else
		{
			$tmp_name=$_FILES['fg_photo']['tmp_name'];
			//echo $tmp_name; exit;
		
			if($_FILES['fg_photo']['size']>$max_size*1024)
			{
				echo "<strong>Sorry! Size Limit Exceeded</strong>";
				$flag=1;
			}
			else
			$new_name=$_REQUEST['StockID'].'.'.$type;
			$path="uploaded_images/".$new_name;
			$file_copy=copy($tmp_name,$path);
			if(!$file_copy)
		{
			echo "<strong>Copy Unsuccessful</strong>";
			$flag=1;
		}
	}
$update_image="Update item_master set image_pdf='".$new_name."' where StockID ='".$_REQUEST['StockID']."' ";
$update_result=DB_query($update_image,$db);
	}
		$product_description = htmlspecialchars($_REQUEST['item_name'], ENT_QUOTES);
		
		$item_desc = htmlspecialchars($_REQUEST['item_desc'], ENT_QUOTES);
		 $update_sql="Update item_master set 
CategoryID='".$_REQUEST['item_cat']."',  
SubCategoryID ='".$_REQUEST['itemcodeval']."', 		 
item_name ='".$product_description."',
item_desc ='".$item_desc."',  
state ='".$_REQUEST['state']."',  
height ='".$_REQUEST['height']."', 
width ='".$_REQUEST['width']."',  
teeth ='".$_REQUEST['teeth']."',  
ups ='".$_REQUEST['ups']."',    
foil_size ='".$_REQUEST['foil_size']."', 
paper_size ='".$_REQUEST['paper_size']."', 
paper_name ='".$_REQUEST['paper_name']."',
print_size ='".$_REQUEST['print_size']."', 
frt_br  ='".$_REQUEST['frt_br']."',
color_no='".$_REQUEST['color_no']."',  
embossing='".$_REQUEST['embossing']."',  
spot ='".$_REQUEST['spot']."',   
party ='".$_REQUEST['party']."',  
varnish ='".$_REQUEST['varnish']."', 
uv  ='".$_REQUEST['uv']."',
overprint='".$_REQUEST['overprint']."',  
foil='".$_REQUEST['foil']."',    
cut='".$_REQUEST['cut']."',     
item_no ='".$_REQUEST['item_no']."', 
flexo_offset ='".$_REQUEST['flexo_offset']."',   
unit='".$_REQUEST['unit']."',  
size ='".$_REQUEST['size']."',   
length='".$_REQUEST['length']."',  
gsm='".$_REQUEST['gsm']."',     
od='".$_REQUEST['od']."',        
serial_no ='".$_REQUEST['serial_no']."', 
orig_local ='".$_REQUEST['orig_local']."', 
type_name='".$_REQUEST['type_name']."',  
shade='".$_REQUEST['shade']."',   
running_roll='".$_REQUEST['running_roll']."',  
volume ='".$_REQUEST['volume']."', 
bcm='".$_REQUEST['bcm']."',     
quality ='".$_REQUEST['quality']."',
tolerance ='".$_REQUEST['tolerance']."'
where id='".$_REQUEST['id']."' and CategoryID='".$_REQUEST['item_cat']."'";
//echo "<pre>";
//print_r($update_sql); exit;
$update_res=DB_query($update_sql,$db);

$_SESSION['success_msg']="Update Successfully";
echo "<script>location.href='index.php?route=Inventory/maintenance/item_master_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";

}




for($X=1;$X<$_REQUEST['CTR'];$X++)
{
$update_sql2="Update item_master set ".
$_REQUEST['field_id'][$X]."='".$_REQUEST['field'][$X]."' where id='".$_REQUEST['id']."' ";
$up_result2=DB_query($update_sql2,$db);
}


if($_REQUEST['item_cat']=='FG')
{
	for($k=1;$k<$_REQUEST['cnt'];$k++)
	{
	 $update_color="Update item_color_master 
	 SET color='".$_REQUEST['colorno'][$k]."' 
	 where item_master_id='".$_REQUEST['id']."' and color_no='".$k."'"; 
	$res=DB_query($update_color,$db);
	} 
}

?>
<script language="javascript" type="text/javascript">

function checkvalidation()
{
if(document.getElementById("itemcodeval").value=='000')
{
alert("Must Select Sub Category");
document.getElementById("itemcodeval").focus();	
return false;
}	
if(document.getElementById("unit").value=='000')
{
alert("Must Select Unit");
document.getElementById("unit").focus();	
return false;
}
return true;		
	
	
	
}




function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}
function putnumber(str)
{ 
	
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		    alert ("Your browser does not support AJAX!");
		    return;
		  } 
		 
	var cat=document.getElementById("itemcodeval").value;
	var sub=document.getElementById("item_cat").value;  
	
	var url="stockNumber1.php";
	url=url+"?itemcode="+str+"&catid="+cat+"&sub="+sub;
	//alert(url);
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=NumberChanged2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function putnumber1(str)
{ 
	
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		    alert ("Your browser does not support AJAX!");
		    return;
		  } 
		  
	var cat=document.getElementById("item_cat").value;  
	var url="stocknumber.php";
	url=url+"?catid="+str+"&sub="+cat;
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=NumberChanged2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function NumberChanged2() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	    document.getElementById("StockID").value=xmlHttp.responseText;
	}
}


function putnumber2()
{ 
	var str=document.getElementById("item_name").value;
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		    alert ("Your browser does not support AJAX!");
		    return;
		  } 
		 
	var cat=document.getElementById("itemcodeval").value;
	var sub=document.getElementById("item_cat").value;  
	//alert(cat);
	//alert(sub);
	var url="stockNumber.php";
	url=url+"?itemcode="+str+"&catid="+cat+"&sub="+sub;
	//alert(url);
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=NumberChanged2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function check_runroll(str)
{
	if (str.length==0)
  {
  document.getElementById("flexo_id").innerHTML="";
  return;
  }
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("flexo_id").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_run_roll.php?q="+str,true);
xmlhttp.send();
}
function get_description()
{
	document.getElementById("item_desc").value=document.getElementById("item_name").value;
}

</script>
<h2 align="center"><strong>Item Master</strong></h2>
<br />

<!--<p align="center"><input type="submit" name="Submit" value="Proceed"  /></p>-->



<form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="code" value="<?php echo $code;?>" />
<?php if($_REQUEST['action']=='Add') {?>

<table width="15%" border="0" cellspacing="1" cellpadding="2" align="center">
  <tr>
    <th><strong>CHOOSE ITEM CATEGORY</strong></th>
  </tr>
  <tr>
    <td><select name="item_cat" id="item_cat" onchange="main_cat(this.value)">
	<option value="000">Select</option>
	<?php
	$query=DB_query("select * from stockmaincategory",$db);
	while($result=DB_fetch_array($query))
	{
	?>
	<option value="<?php echo $result['id'];?>"<?php echo ($_REQUEST['item_cat']==$result['id']?'selected':'')?>><?php echo $result['stockmaincategoryname'];?></option>
	<?php } ?>
	</select>
	</td>
  </tr>

  
</table>

<?php } ?>

<div align="center">&nbsp;</div>



		
	
<table width="100%" border="0" cellspacing="1" cellpadding="0" align="center" style="border:1px; solid #CCC;" bgcolor="#FFFFFF">
    <?php if($_REQUEST['action']=='edit') { ?>
    <tr><td>&nbsp;</td><td>
	<?php 
	$query=DB_query("select * from stockmaincategory where id='".$myrow['CategoryID']."'",$db);
	$result=DB_fetch_array($query);
	?>
	 <select name="item_cat" id="item_cat" onchange="main_cat(this.value)">
	<option value="000">Select</option>
	<?php
	$query=DB_query("select * from stockmaincategory",$db);
	while($result=DB_fetch_array($query))
	{
	?>
	<option value="<?php echo $result['id'];?>"<?php echo ($myrow['CategoryID']==$result['id']?'selected':'')?>><?php echo $result['stockmaincategoryname'];?></option>
	<?php } ?>
	</select>    	
    </td></tr>
	<tr>
    <td valign="top" width="50%" style="border-right:1px solid #CCC; border-bottom:1px solid #CCC;"><table width="100%" border="0" cellspacing="1" cellpadding="2" align="center">
     <tr>
    <th width="47%" ><strong>ITEM SUB GROUP </strong></th>
    <td width="53%"><div id="change"><input type="hidden" name="item_cat" id="item_cat" value="<?php echo $code; ?>">
      <?php 
	   $sql1="select categoryid,id,categorydescription from stockcategory where stockmaincategory ='".$_REQUEST['item_cat']."'";
	 	$result1 = DB_query($sql1,$db);?>
      <select id="itemcodeval" name="itemcodeval"  style="width:100%"   onchange="putnumber2(this.value)"  >
        <option value="000">Select Sub Category</option>
        <?php 
		while($myrow1=DB_Fetch_array($result1))
		{?>
        <option value="<?php echo $myrow1['id'];?>"<?php echo($itemcodeval==$myrow1['id']?'selected':'');?>><?php echo $myrow1['categorydescription'];?></option>
        <?php 	} ?>
      </select>
    </div>
  </td>
  </tr>
  <tr>
    <th ><strong>ITEM NAME</strong></th>
    <td><input name="item_name" type="text" class="cap" style="width:100%" id="item_name" value="<?php echo $item_name;?>" size="25" /></td>
  </tr>
  <tr>
    <th ><strong>ITEM CODE</strong></th>
    <td><input type="text" id="StockID" name="StockID" style="width:100%" value="<?php echo $StockID;?>" readonly="readonly"/></td>
  </tr>
  
  <tr>
    <th ><strong>ITEM DESCRIPTION </strong></th>
    <td><input name="item_desc" type="text" class="cap"  style="width:100%"id="item_desc" value="<?php echo $item_desc;?>" size="25" /></td>
  </tr>
  <tr>
    <th ><strong>ITEM NO. </strong></th>
    <td><input name="item_no" type="text" class="cap" style="width:100%" id="item_no" value="<?php echo $item_no;?>" size="25" /></td>
  </tr>
  <tr>
    <th ><strong>FLEXO/OFFSET</strong></th>
    <td>
	<select name="flexo_offset" id="flexo_offset" onchange="check_runroll(this.value)" style="width:100%">
	<option value="000">Select</option>
	<option value="Flexo"<?php echo ($flexo_offset=='Flexo'?'selected':'')?>>Flexo</option>
	<option value="Offset"<?php echo ($flexo_offset=='Offset'?'selected':'')?>>Offset</option>
	</select>	</td>
  </tr>
  <tr>
    <th ><strong>UNIT</strong></th>
    <td>
	<select name="unit" id="unit" style="width:100%">
	<option value="000">Select</option>
	<?php 
	$query=DB_query("select * from unitsofmeasure",$db);
	while($uom=DB_fetch_array($query)){
	?>
	<option value="<?php echo $uom['unitid'];?>"<?php echo ($unit==$uom['unitid']?'selected':'')?>><?php echo $uom['unitname'];?></option>
	<?php } ?>
	</select>  </tr>
  
  <tr>
    <td nowrap="nowrap"><strong>WIDTH - <input name="width" type="text" class="cap" id="width"  style="width:70%" value="<?php echo $width;?>" size="8" />
    </strong></td>
    <td nowrap="nowrap"><strong>LENGTH</strong> - <strong>
      <input name="length" type="text" class="cap" id="length" value="<?php echo $length;?>" size="8" style="width:68%" />
    </strong></td>
  </tr>
  <tr>
    <th ><strong>OD</strong></th>
    <td><input name="od" type="text" class="cap" id="od" value="<?php echo $od;?>"  style="width:100%" /></td>
  </tr>
   <tr>
        <th><strong>SERIAL NO. </strong></th>
        <td><input name="serial_no" type="text" class="cap" id="serial_no" value="<?php echo $serial_no;?>" style="width:100%" /></td>
      </tr>
</table></td>
<td valign="top" style=" border-bottom:1px solid #CCC;"><table width="100%" border="0" cellspacing="1" cellpadding="2" align="center">
      <tr>
        <th width="50%"><strong>ORIGINAL/LOCAL</strong></th>
        <td><select name="orig_local" id="orig_local" style="width:100%">
		<option value="000">Select</option>
		<option value="Original"<?php echo ($orig_local=='Original'?'selected':'')?>>Original</option>
		<option value="Local"<?php echo ($orig_local=='Local'?'selected':'')?>>Local</option>
		</select></td>
      </tr>
  <tr>
    <th><strong>TYPE </strong></th>
    <td>
	<select name="type_name" id="type_name" style="width:100%" class="cap">
	<option value="000">Select</option>
	<?php 
  $type_sql=DB_query("select * from type_master",$db);
  while($type_res=DB_fetch_array($type_sql))
  {
  ?>
  <option value="<?php echo $type_res['id'];?>"<?php echo ($type_name==$type_res['id']?'selected':'')?>><?php echo $type_res['name'];?></option>
  <?php } ?>
	</select>
</td>
  </tr>
  <tr>
    <th><strong>SHADE</strong></th>
    <td><input name="shade" type="text" class="cap" style="width:100%" id="shade" value="<?php echo $shade;?>" /></td>
  </tr>
  <tr>
    <th><div id="flexo_id"><strong>RUNNING METER/ROLL</strong></div></th>
    <td><input name="running_roll" type="text" style="width:100%" class="cap" id="running_roll" value="<?php echo $running_roll;?>" /></td>
 </tr>
  <tr>
    <th><strong>VOLUME</strong></th>
    <td>
	<select name="volume" id="volume" style="width:100%" class="cap">
	<option value="000">Select</option>
	<?php 
	$vol_sql=DB_query("select * from volume_master",$db);
  while($vol_res=DB_fetch_array($vol_sql))
  {
	?>
	<option value="<?php echo $vol_res['id'];?>"<?php echo ($volume==$vol_res['id']?'selected':'')?>><?php echo $vol_res['name'];?></option>
  <?php } ?>
	</select>
	</td>
  </tr>
  <tr>
    <th><strong>TEETH</strong></th>
    <td><input name="teeth" type="text" class="cap" id="teeth" value="<?php echo $teeth;?>"  style="width:100%"/></td>
  </tr>
  <tr>
    <th><strong>BCM</strong></th>
    <td><input name="bcm" type="text" class="cap" id="bcm" value="<?php echo $bcm;?>"  style="width:100%" /></td>
  </tr>
  <tr>
    <th><strong>UPS</strong></th>
    <td><input name="ups" type="text" class="cap" id="ups" value="<?php echo $ups;?>" style="width:100%" /></td>
  </tr>
  <tr>
    <th height="26"><strong>QUALITY</strong></th>
    <td>
	<select name="quality" id="quality" style="width:100%" class="cap">
	<option value="000">Select</option>
	<?php 
	$q_sql=DB_query("select * from quality_master",$db);
  while($q_res=DB_fetch_array($q_sql))
  {
	?>
	<option value="<?php echo $q_res['id'];?>"<?php echo ($quality==$q_res['id']?'selected':'')?>><?php echo $q_res['name'];?></option>
  <?php } ?>
	</select>
	</td>
  </tr>
  
  <?php 
	$get_column_sql=DB_query("Select * from item_master_setup where item_master='".$_REQUEST['item_cat']."' ",$db);
	$i=1;
	while($column_res=DB_fetch_array($get_column_sql))
	{
	?>
	<tr>
	<th><strong><div style="text-transform:uppercase"><?php echo $column_res['field_label'];?></div><input type="hidden" name="field_id[<?php echo $i;?>]" value="<?php echo $column_res['field'];?>" /></strong></th>
	<td><input name="field[<?php echo $i;?>]" type="text" class="cap" style="width:100%" id="field_<?php echo $i;?>" value="<?php echo $field[$i];?>" /></td>
	</tr>
<?php 		
$i++;	}
  ?>
  <input type="hidden" name="CTR" value="<?php echo $i;?>" />
  <tr>
    <th><strong>MRN Tolerance</strong></th>
    <td><input name="tolerance" type="text" class="cap" id="tolerance" value="<?php echo $tolerance;?>" />&nbsp;%</td>
  </tr>

</table></td>
</tr>
<?php } ?>
    <?php 
	
	if($_REQUEST['action']=='Add')
	{
	
	?>
    <tr>
    <td valign="top" width="50%" style="border-right:1px solid #CCC; border-bottom:1px solid #CCC;"><table width="100%" border="0" cellspacing="1" cellpadding="2" align="center">
     <tr>
    <th width="47%" ><strong>ITEM SUB GROUP </strong></th>
    <td width="53%"><div id="change"><input type="hidden" name="item_cat" id="item_cat" value="<?php echo $code; ?>">
      <?php 
	   $sql1="select categoryid,id,categorydescription from stockcategory where stockmaincategory ='".$_REQUEST['item_cat']."'";
	 	$result1 = DB_query($sql1,$db);?>
      <select id="itemcodeval" name="itemcodeval"  style="width:100%"   onchange="putnumber(this.value)"  >
        <option value="000">Select Sub Category</option>
        <?php 
		while($myrow1=DB_Fetch_array($result1))
		{?>
        <option value="<?php echo $myrow1['id'];?>"<?php echo($itemcodeval==$myrow1['id']?'selected':'');?>><?php echo $myrow1['categorydescription'];?></option>
        <?php 	} ?>
      </select>
    </div></td>
  </tr>
  <tr>
    <th ><strong>ITEM NAME</strong></th>
    <td><input name="item_name" type="text" class="cap" style="width:100%" id="item_name" value="<?php echo $item_name;?>" size="25" onchange="putnumber2(this.value)"/></td>
  </tr>
  <tr>
    <th ><strong>ITEM CODE</strong></th>
    <td><input type="text" id="StockID" name="StockID" style="width:100%" value="<?php echo $StockID;?>" readonly="readonly" /></td>
  </tr>
  
  <tr>
    <th ><strong>ITEM DESCRIPTION </strong></th>
    <td><input name="item_desc" type="text" class="cap"  style="width:100%"id="item_desc" value="<?php echo $item_desc;?>" size="25" /></td>
  </tr>
  <tr>
    <th ><strong>ITEM NO. </strong></th>
    <td><input name="item_no" type="text" class="cap" style="width:100%" id="item_no" value="<?php echo $item_no;?>" size="25" /></td>
  </tr>
  <tr>
    <th ><strong>FLEXO/OFFSET</strong></th>
    <td>
	<select name="flexo_offset" id="flexo_offset" onchange="check_runroll(this.value)" style="width:100%">
	<option value="000">Select</option>
	<option value="Flexo"<?php echo ($flexo_offset=='Flexo'?'selected':'')?>>Flexo</option>
	<option value="Offset"<?php echo ($flexo_offset=='Offset'?'selected':'')?>>Offset</option>
	</select>	</td>
  </tr>
  <tr>
    <th ><strong>UNIT</strong></th>
    <td>
	<select name="unit" id="unit" style="width:100%">
	<option value="000">Select</option>
	<?php 
	$query=DB_query("select * from unitsofmeasure",$db);
	while($uom=DB_fetch_array($query)){
	?>
	<option value="<?php echo $uom['unitid'];?>"<?php echo ($unit==$uom['unitid']?'selected':'')?>><?php echo $uom['unitname'];?></option>
	<?php } ?>
	</select>  </tr>
  
  <tr>
    <td nowrap="nowrap"><strong>WIDTH - <input name="width" type="text" class="cap" id="width"  style="width:70%" value="<?php echo $width;?>" size="8" />
    </strong></td>
    <td nowrap="nowrap"><strong>LENGTH</strong> - <strong>
      <input name="length" type="text" class="cap" id="length" value="<?php echo $length;?>" size="8" style="width:68%" />
    </strong></td>
  </tr>
  <tr>
    <th ><strong>OD</strong></th>
    <td><input name="od" type="text" class="cap" id="od" value="<?php echo $od;?>"  style="width:100%" /></td>
  </tr>
   <tr>
        <th><strong>SERIAL NO. </strong></th>
        <td><input name="serial_no" type="text" class="cap" id="serial_no" value="<?php echo $serial_no;?>" style="width:100%" /></td>
      </tr>
</table></td>
<td valign="top" style=" border-bottom:1px solid #CCC;"><table width="100%" border="0" cellspacing="1" cellpadding="2" align="center">
      <tr>
        <th width="50%"><strong>ORIGINAL/LOCAL</strong></th>
        <td><select name="orig_local" id="orig_local" style="width:100%">
		<option value="000">Select</option>
		<option value="Original"<?php echo ($orig_local=='Original'?'selected':'')?>>Original</option>
		<option value="Local"<?php echo ($orig_local=='Local'?'selected':'')?>>Local</option>
		</select></td>
      </tr>
  <tr>
    <th><strong>TYPE </strong></th>
    <td>
	<select name="type_name" id="type_name" style="width:100%" class="cap">
	<option value="000">Select</option>
	<?php 
  $type_sql=DB_query("select * from type_master",$db);
  while($type_res=DB_fetch_array($type_sql))
  {
  ?>
  <option value="<?php echo $type_res['id'];?>"<?php echo ($type_name==$type_res['id']?'selected':'')?>><?php echo $type_res['name'];?></option>
  <?php } ?>
	</select>
</td>
  </tr>
  <tr>
    <th><strong>SHADE</strong></th>
    <td><input name="shade" type="text" class="cap" style="width:100%" id="shade" value="<?php echo $shade;?>" /></td>
  </tr>
  <tr>
    <th><div id="flexo_id"><strong>RUNNING METER/ROLL</strong></div></th>
    <td><input name="running_roll" type="text" style="width:100%" class="cap" id="running_roll" value="<?php echo $running_roll;?>" /></td>
 </tr>
  <tr>
    <th><strong>VOLUME</strong></th>
    <td>
	<select name="volume" id="volume" style="width:100%" class="cap">
	<option value="000">Select</option>
	<?php 
	$vol_sql=DB_query("select * from volume_master",$db);
  while($vol_res=DB_fetch_array($vol_sql))
  {
	?>
	<option value="<?php echo $vol_res['id'];?>"<?php echo ($volume==$vol_res['id']?'selected':'')?>><?php echo $vol_res['name'];?></option>
  <?php } ?>
	</select>
	</td>
  </tr>
  <tr>
    <th><strong>TEETH</strong></th>
    <td><input name="teeth" type="text" class="cap" id="teeth" value="<?php echo $teeth;?>"  style="width:100%"/></td>
  </tr>
  <tr>
    <th><strong>BCM</strong></th>
    <td><input name="bcm" type="text" class="cap" id="bcm" value="<?php echo $bcm;?>"  style="width:100%" /></td>
  </tr>
  <tr>
    <th><strong>UPS</strong></th>
    <td><input name="ups" type="text" class="cap" id="ups" value="<?php echo $ups;?>" style="width:100%" /></td>
  </tr>
  <tr>
    <th height="26"><strong>QUALITY</strong></th>
    <td>
	<select name="quality" id="quality" style="width:100%" class="cap">
	<option value="000">Select</option>
	<?php 
	$q_sql=DB_query("select * from quality_master",$db);
  while($q_res=DB_fetch_array($q_sql))
  {
	?>
	<option value="<?php echo $q_res['id'];?>"<?php echo ($quality==$q_res['id']?'selected':'')?>><?php echo $q_res['name'];?></option>
  <?php } ?>
	</select>
	</td>
  </tr>
  
  <?php 
	$get_column_sql=DB_query("Select * from item_master_setup where item_master='".$_REQUEST['item_cat']."' ",$db);
	$i=1;
	while($column_res=DB_fetch_array($get_column_sql))
	{
	?>
	<tr>
	<th><strong><div style="text-transform:uppercase"><?php echo $column_res['field_label'];?></div><input type="hidden" name="field_id[<?php echo $i;?>]" value="<?php echo $column_res['field'];?>" /></strong></th>
	<td><input name="field[<?php echo $i;?>]" type="text" class="cap" style="width:100%" id="field_<?php echo $i;?>" value="<?php echo $field[$i];?>" /></td>
	</tr>
<?php 		
$i++;	}
  ?>
  <input type="hidden" name="CTR" value="<?php echo $i;?>" />
  
  <tr>
    <th><strong>MRN Tolerance</strong></th>
    <td><input name="tolerance" type="text" class="cap" id="tolerance" value="<?php echo $tolerance;?>" />&nbsp;%</td>
  </tr>
  <!--<tr>
    <th><strong>HOT FOIL CYLINDER </strong></th>
    <td><input name="hot_foil" type="text" class="cap" id="hot_foil" value="" /></td>
  </tr>
  <tr>
    <th><strong>PRINT CYLINDER </strong></th>
    <td><input name="print_cylinder" type="text" class="cap" id="print_cylinder" value="" /></td>
  </tr>
  <tr>
    <th><strong>DIE</strong></th>
    <td><input name="die" type="text" class="cap" id="die" value="" /></td>
  </tr>
  <tr>
    <th><strong>PLATE</strong></th>
    <td><input name="plate" type="text" class="cap" id="plate" value="" /></td>
  </tr>-->
</table></td>
</tr>
<?php } ?>
</table>



<p align="center">
<?php 
if($_REQUEST['action']=='edit' && $_REQUEST['id']!='')
{?>
<input type="submit" name="Update" value="Update" />
<?php 
}else{
?>
<input type="submit" name="Save" value="Save"  onclick="return checkvalidation();"/>
<?php } ?>
<input type="submit" name="Cancel" value="Cancel"/></p>

</form>

<script language="javascript" type="text/javascript">
function generate_itemname(str)
{
	var cat=document.getElementById("itemcodeval").value;
	
	if (str.length==0)
  {
  document.getElementById("item").innerHTML="";
  return;
  }
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("item").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_item_name.php?q="+str+"&p="+cat,true);
xmlhttp.send();
}

function main_cat(str)
{
	
	
	if (str.length==0)
  {
  document.getElementById("change").innerHTML="";
  return;
  }
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("change").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_item_subgroup.php?q="+str,true);
xmlhttp.send();
}








</script>
