<?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'])
{
	header('Location:item_list.php');
}
if($_REQUEST['Save']!='')
{
	if($_REQUEST['code']=='FG')
	{
	$max_size='500';
	$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;
		}
	}
}

$sql="Insert into item_master SET
id='',
CategoryID='".$_REQUEST['code']."',  
SubCategoryID ='".$_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 ='".$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']."',
make='".$_REQUEST['make']."',   
grade='".$_REQUEST['grade']."',   
color='".$_REQUEST['color']."',        
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']."', 
CompanyId='".$_SESSION['ACGCompanyId']."',
created_date='".FormatDateForSQL(date('d/m/Y'))."' ";
//echo "<pre>";
//print_r($sql); exit;
$result=DB_query($sql,$db);
$last_id=DB_Last_Insert_Id($db,"item_master","id");

/*if($_REQUEST['code']!='FG')
{
	for($M=0;$M<count($_REQUEST['count_rows']);$M++)
	{
		$specifications_sql="Insert into item_specification set
									proc_id='".$_REQUEST['StockID']."',  
									manufacture='".$_REQUEST['make'][$M]."',    
									color='".$_REQUEST['color'][$M]."',     
									grade='".$_REQUEST['grade'][$M]."',
									size='".$_REQUEST['size'][$M]."',    
									gsm='".$_REQUEST['gsm'][$M]."' ";
		$specs_result=DB_query($specifications_sql,$db);
	}
	
}*/

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['code']=='FG')
{
	$Last_id=DB_Last_Insert_ID($db,'item_master','id');
	if($Last_id!='')
	{
		for($k=1;$k<$_REQUEST['cnt'];$k++)
		{
			$item_color="Insert into item_color_master SET
							item_master_id='".$Last_id."', 
							color='".$_REQUEST['colorno'][$k]."',
							color_no='".$k."'";
							//echo "<pre>";
							//print_r($item_color);
			$result=DB_query($item_color,$db);
		}
	}
}

prnMsg( _('Item inserted successfully'),'success');
echo "<script>location.href='index.php?route=item_list&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_REQUEST['Submit'])
{
echo "<script>location.href='index.php?route=item_master&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."&item_cat=".$_REQUEST['item_cat']."'</script>";

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

if($_REQUEST['item_cat']!='' && $_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);
	 
	$code=$myrow['CategoryID']; 
	$itemcodeval =$myrow['SubCategoryID']; 
	$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'];
	$make=$myrow['make'];   
	$grade=$myrow['grade'];   
	$color=$myrow['color'];           
	$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'];
	
	//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'];
	$make=$_REQUEST['make'];   
	$grade=$_REQUEST['grade'];   
	$color=$_REQUEST['color'];        
	$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']; 
	
	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."',CompanyId='".$_SESSION['ACGCompanyId']."' where StockID ='".$_REQUEST['StockID']."' ";
$update_result=DB_query($update_image,$db);
	}
		//SubCategoryID ='".$_REQUEST['itemcodeval']."',
	$update_sql="Update item_master set   
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']."',  
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']."',
make='".$_REQUEST['make']."',   
grade='".$_REQUEST['grade']."',   
color='".$_REQUEST['color']."',         
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']."',
CompanyId='".$_SESSION['ACGCompanyId']."'
where id='".$_REQUEST['id']."' and CategoryID='".$_REQUEST['item_cat']."'";
//echo "<pre>";
//print_r($update_sql); exit;
$update_res=DB_query($update_sql,$db);

/*if($_REQUEST['item_cat']!='FG')
{
		$delete_specs_sql="Delete from item_specification where proc_id='".$_REQUEST['StockID']."'";
		$delete_result=DB_query($delete_specs_sql,$db);
	
	for($M=0;$M<count($_REQUEST['count_rows']);$M++)
	{
		$insert_specs="Insert into item_specification set
										proc_id='".$_REQUEST['StockID']."',  
										manufacture='".$_REQUEST['make'][$M]."',    
										color='".$_REQUEST['color'][$M]."',     
										grade='".$_REQUEST['grade'][$M]."',
										size='".$_REQUEST['size'][$M]."',   
										gsm='".$_REQUEST['gsm'][$M]."' ";
		$insert_result=DB_query($insert_specs,$db);
		//echo "<pre>";
		//print_r($insert_specs);
	}
	
}*/


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);
	} 
}
prnMsg( _('Item Updated successfully'),'success');
echo "<script>location.href='index.php?route=item_list&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']." '</script>";
}
?>
<script language="javascript" type="text/javascript">
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 url="stockNumber.php";
	url=url+"?itemcode="+str;
	//alert(url);
	//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 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 />
<?php if($_REQUEST['action']=='') {?>
<form action="" method="post">
<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>
<p align="center"><input type="submit" name="Submit" value="Proceed"  /></p>
</form>
<?php }?>
<?php if($_REQUEST['item_cat']!='')
{
 ?>
<form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="code" value="<?php echo $code;?>" />
<?php if($image_pdf!='') {?>

<table border="0" align="center">
<tr>
<td><fieldset>
<img src="uploaded_images/<?php echo $image_pdf;?>" width="90" height="140"/></fieldset>
</td>
</tr>
</table>

<?php } ?>
<?php 
if($_REQUEST['item_cat']=='FG') 
{?>
<table width="100%" border="0" cellspacing="1" cellpadding="2" align="center" style="border:1px solid #CCC;" bgcolor="#FFFFFF">
  <tr>
    <td valign="top"><table width="100%" border="0" cellspacing="1" cellpadding="3">
	<tr>
    <th width="45%"><strong>ITEM SUB GROUP </strong></th>
    <td>
	<div id="change"><?php 
	$sql1='select categoryid,id,categorydescription from stockcategory where stockmaincategory ="'.$_REQUEST['item_cat'].'"';
	 	$result1 = DB_query($sql1,$db);?>
	  <select name="itemcodeval" id="itemcodeval" onchange="putnumber(this.value)" style="width: 100%">
	    <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 CODE</strong></th>
    <td><input type="text" id="StockID" name="StockID" value="<?php echo $StockID;?>" readonly="readonly" style="width: 100%"> </td>
  </tr>
  <tr>
    <th ><strong>STATE</strong></th>
    <td>
	<select name="state" id="state" onchange="generate_itemname(this.value)" style="width: 100%">
	<option value="000">Select</option>
	<?php 
	$state_sql=DB_query("select * from state_master",$db);
	while($state_res=DB_fetch_array($state_sql)){
	?>
	<option value="<?php echo $state_res['id'];?>"<?php echo ($state==$state_res['id']?'selected':'')?>><?php echo $state_res['state'];?></option>
	<?php } ?>
	</select>	</td>
  </tr>
  
  
  <tr>
    <th ><strong>ITEM NAME</strong></th>
    <td><div id="item"><input name="item_name" type="text" class="cap" id="item_name" style="width: 100%"value="<?php echo $item_name;?>" size="25" />
    </div></td>
  </tr>
   <tr>
    <th ><strong>ITEM DESCRIPTION </strong></th>
    <td>
<input name="item_desc" type="text" class="cap" id="item_desc" style="width: 100%"onfocus="get_description()" value="<?php echo $item_desc;?>" size="25"/></td>
  </tr>
   <tr>
     <th><strong>LABEL</strong></th>
     <td nowrap="nowrap"><strong>Height</strong>
     <input name="height" type="text" id="height" value="<?php echo $height;?>" size="8" class="number"/>
     <strong>Width</strong>
     <input name="width" type="text" id="width" value="<?php echo $width;?>" size="8" class="number"/></td>
   </tr>
  <tr></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>UPS</strong></th>
    <td><input name="ups" type="text" class="cap" id="ups" value="<?php echo $ups;?>" style="width: 100%"/></td>
  </tr>
  <tr>
    <th ><strong>FOIL SIZE </strong></th>
    <td><input name="foil_size" type="text" class="cap" id="foil_size" value="<?php echo $foil_size;?>" style="width: 100%"/></td>
  </tr>
  <tr>
    <th ><strong>PAPER SIZE </strong></th>
    <td>
	<select name="paper_size" class="cap" id="paper_size" style="width:100%">
	<option value="000">Select</option>
	<?php 
	$size_sql=DB_query("select * from size_master",$db);
	while($size_res=DB_fetch_array($size_sql))
	{
	?>
	<option value="<?php echo $size_res['id'];?>"<?php echo ($paper_size==$size_res['id']?'selected':'');?>><?php echo stripslashes($size_res['name']);?></option>
	<?php }?>
	</select></td>
  </tr>
  <tr>
    <th ><strong>PAPER NAME </strong></th>
    <td><input name="paper_name" type="text" class="cap" style="width: 100%"id="paper_name" value="<?php echo $paper_name;?>" /></td>
  </tr>
  <tr>
    <th ><strong>PRINT SIZE </strong></th>
    <td>
	<select name="print_size" id="print_size" class="cap" style="width:100%">
	<option value="0">Select</option>
	<?php
	$pr_sql=DB_query("Select * from printsize_master",$db);
	while($pr_res=DB_fetch_array($pr_sql)){
	?>
	<option value="<?php echo $pr_res['id'];?>" <?php echo ($print_size==$pr_res['id']?'selected':'')?>><?php echo stripslashes($pr_res['size']);?></option>
	<?php } ?>
	</select>  </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>
    </td>
  </tr>
    </table></td>
    <td valign="top" style="border-left:1px solid #CCC; border-right:1px solid #CCC;"><table width="100%" border="0" cellspacing="1" cellpadding="3" >
	<tr>
    <th  width="60%"><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>FRT/BR</strong></th>
        <td><input name="frt_br" type="text" class="cap" style="width:100%;" id="frt_br" value="<?php echo $frt_br;?>" /></td>
      </tr>
  <tr>
    <th ><strong>IMAGE ATTACHMENT </strong></th>
    <td>
	<input name="fg_photo" type="file" id="fg_photo" value="" /></td>
  </tr>
  <tr>
    <th ><strong>EMBOSSING</strong></th>
    <td>
	<select name="embossing" id="embossing" style="width:100%">
	<option value="000">Select</option>
	<option value="YES" <?php echo ($embossing=='YES'?'selected':'')?>>YES</option>
	<option value="NO" <?php echo ($embossing=='NO'?'selected':'')?>>NO</option>
	</select></td>
  </tr>
  <tr>
    <th ><strong>SPOT</strong></th>
    <td><select name="spot" id="spot" style="width:100%">
	<option value="000">Select</option>
      <option value="YES" <?php echo ($spot=='YES'?'selected':'')?>>YES</option>
      <option value="NO" <?php echo ($spot=='NO'?'selected':'')?>>NO</option>
    </select>   </td>
  </tr>
  <tr>
    <th ><strong>PARTY CODE </strong></th>
    <td><input name="party" type="text" class="cap" style="width:100%;" id="party" value="<?php echo $party;?>" /></td>
  </tr>
  <tr>
    <th ><strong>OVERPRINT</strong></th>
    <td><select name="overprint" id="overprint" style="width:100%">
	<option value="000">Select</option>
      <option value="YES" <?php echo ($overprint=='YES'?'selected':'')?>>YES</option>
      <option value="NO" <?php echo ($overprint=='NO'?'selected':'')?>>NO</option>
    </select>    </td>
  </tr>
  <tr>
    <th ><strong>SHADE FOIL</strong></th>
    <td><input name="foil" type="text" class="cap" style="width:100%;" id="foil" value="<?php echo $foil;?>" /></td>
  </tr>
  <tr>
    <th ><strong>CUT</strong></th>
    <td><select name="cut" id="cut" style="width:100%">
	<option value="000">Select</option>
        <option value="POLAR"<?php echo($cut=='POLAR'?'selected':'')?>>POLAR</option>
        <option value="DIE"<?php echo($cut=='DIE'?'selected':'')?>>DIE</option>
      </select>    </td>
  </tr>
  <tr>
    <th ><strong>VARNISH</strong></th>
    <td nowrap="nowrap">
	<?php if($varnish=='')
			{$s="selected"; $q=''; $d="disabled";} 
			else 
			{$s=''; $q="selected"; $d='';}?>
	<select name="varnish_yn" id="varnish_yn" style="width:50px" onchange="get_option1(this.value)">
    <option value="YES" <?php echo $q;?>>YES</option>
    <option value="NO" <?php echo $s;?>>NO</option>
    </select>
	<select name="varnish" id="varnish" style="width:70%" <?php echo $d;?>>
      <option value="000">Select</option>
      <option value="GLOSS" <?php echo($varnish=='GLOSS'?'selected':'')?>>GLOSS</option>
      <option value="MATT" <?php echo($varnish=='MATT'?'selected':'')?>>MATT</option>
    </select></td>
  </tr>
  <tr>
    <th ><strong>UV</strong></th>
    <td nowrap="nowrap">
	<?php if($uv==''){$s="selected"; $q=''; $d="disabled";} else {$s=''; $q="selected"; $d='';}?>
	<select name="uv_yn" id="uv_yn" style="width:50px" onchange="get_option2(this.value)">
      <option value="YES" <?php echo $q;?>>YES</option>
      <option value="NO" <?php echo $s;?>>NO</option>
    </select>
	 <select name="uv" id="uv" style="width:70%" <?php echo $d;?>>
	<option value="000">Select</option>
	<option value="GLOSS" <?php echo($uv=='GLOSS'?'selected':'')?>>GLOSS</option>
	<option value="MATT" <?php echo($uv=='MATT'?'selected':'')?>>MATT</option>
	</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" id="field_<?php echo $i;?>" value="<?php echo $field[$i];?>" /></td>
	</tr>
<?php 		
$i++;	}
  ?>
  <input type="hidden" name="CTR" value="<?php echo $i;?>" />
  </table></td>
  <td valign="top"><table width="100%" border="0" cellspacing="1" cellpadding="3">
    <?php for($i=1; $i<9; $i++) 
	{
	?>
	<tr>
      <th nowrap="nowrap"><strong>COLOR <?php echo $i;?> </strong></th>
      <td><select name="colorno[<?php echo $i;?>]" id="colorno_<?php echo $i;?>" style="width:100%">
	  <option value="000">Select</option>
	  <?php 
	  $color_sql=DB_query("select * from product_color",$db);
	  while($color_res=DB_fetch_array($color_sql)){
	  ?>
	  <option value="<?php echo $color_res['id'];?>"<?php echo $colorno[$i]==$color_res['id']?'selected':''?>><?php echo $color_res['color'];?></option>
	  <?php } ?>
	  </select></td>
    </tr>
	<?php } ?>
	<input type="hidden" name="cnt" value="<?php echo $i;?>" />
  </table></td>
  </tr>
</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"/>
<?php } ?>
<input type="reset" name="reset" value="Reset" /></p>
<?php }
else
{?>
<table width="80%" border="0" cellspacing="1" cellpadding="0" align="center" style="border:1px solid #CCC;" bgcolor="#FFFFFF">
  <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="div">
      <?php 
	$sql1='select categoryid,categorydescription from stockcategory where stockmaincategory ="'.$_REQUEST['item_cat'].'"';
	 	$result1 = DB_query($sql1,$db);?>
      <select id="itemcodeval" name="itemcodeval" onchange="putnumber(this.value)" style="width:100%">
        <option value="000">Select Sub Category</option>
        <?php 
		while($myrow1=DB_Fetch_array($result1))
		{?>
        <option value="<?php echo $myrow1['categoryid'];?>"<?php echo($itemcodeval==$myrow1['categoryid']?'selected':'');?>><?php echo $myrow1['categorydescription'];?></option>
        <?php 	} ?>
      </select>
    </div></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 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 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>ANILOX</strong></th>
    <td><input name="anilox" type="text" class="cap" id="anilox" value="" /></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>
<!-- <tr><td colspan="2"><div align="center">
  <input type="button"  class="crmbutton small delete"  onclick="addRow('dataTable')" value="Add" />
  &nbsp;
   <input type="button" class="crmbutton small delete"  onclick="deleteRow('dataTable')" value="Delete" />
</div></td></tr> -->
<tr>
<td colspan="2">

<table width="100%" border="0" cellspacing="1" cellpadding="2" align="center" style="border:1px solid #CCC" bgcolor="#FFFFFF">
  <tr>
    <th colspan="5"><div align="center"><strong>ITEM SPECIFICATIONS </strong></div></th>
    </tr>
  <tr>
    <th><strong>MAKE</strong></th>
    <th><strong>GRADE</strong></th>
    <th><strong>COLOR</strong></th>
	<th><strong>SIZE</strong></th>
	<th><strong>GSM</strong></th>
    </tr>
   <tbody id="dataTable">
  <tr>
  <!-- <th><input type="checkbox" name="chk" /><input type="hidden" value="" id="count_rows" name="count_rows[]"></th> -->
    <td><select name="make" id="make" style="width:100%">
      <option value="0">Select</option>
      <?php 
  $make_sql=DB_query("select * from product_manufacture",$db);
  while($make_res=DB_fetch_array($make_sql))
  {
  ?>
      <option value="<?php echo $make_res['id']?>"<?php echo ($make==$make_res['id']?'selected':'')?>><?php echo $make_res['manufacturer'];?></option>
      <?php } ?>
    </select></td>
    <td><select name="grade" id="grade" style="width:100%">
  <option value="0">Select</option>
  <?php 
  $grade_sql=DB_query("select * from product_grade",$db);
  while($grade_res=DB_fetch_array($grade_sql))
  {
  ?>
  <option value="<?php echo $grade_res['id'];?>"<?php echo ($grade==$grade_res['id']?'selected':'')?>><?php echo $grade_res['grade'];?></option>
  <?php } ?>
  </select></td>
    <td><select name="color" id="color" style="width:100%">
      <option value="0">Select</option>
      <?php 
  $color_sql=DB_query("select * from product_color",$db);
  while($color_res=DB_fetch_array($color_sql))
  {
  ?>
      <option value="<?php echo $color_res['id'];?>"<?php echo ($color==$color_res['id']?'selected':'')?>><?php echo $color_res['color'];?></option>
      <?php } ?>
    </select></td>
	<td>
	<select name="size" id="size" style="width:100%">
        <option value="0">Select</option>
        <?php
	$size_sql=DB_query("select * from size_master",$db);
	while($res=DB_fetch_array($size_sql)) {
	?>
        <option value="<?php echo $res['id'];?>"<?php echo ($size==$res['id']?'selected':'')?>><?php echo $res['name'];?></option>
        <?php } ?>
    </select>
	</td>
	<td>
	<select name="gsm" id="gsm" style="width:100%">
	<option value="0">Select</option>
	<?php
	$gsm_sql=DB_query("Select * from gsm",$db);
	while($gsm_row=DB_fetch_array($gsm_sql))
	{
	?>
	<option value="<?php echo $gsm_row['id'];?>"<?php echo ($gsm==$gsm_row['id']?'selected':'')?>><?php echo $gsm_row['gsm'];?></option>
	<?php }?>
	</select>
	</td>
    </tr>
	</tbody>
</table>
</td>
</tr>
</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" />
<?php } ?>
<input type="submit" name="Cancel" value="Cancel"/></p>
<?php 
} ?>
</form>
<?php 
}
include('includes/footer.inc');
?>
<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();
}
</script>
