<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="../css/wizard.css" />
<script language="JavaScript" src="gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<?php

include('../include/db.php');
include('../include/session.php');	
include('../include/formValidations.php');


$productId = $_GET['productId'];
$type = $_GET['Type'];
$field =$_GET['field'];

$productQuery = "SELECT $field FROM nam_products WHERE productId ='". $productId. "' ";

$productResult = execsql($productQuery);
$value = mysql_result($productResult, 0, "$field");

?>
<script type="text/javascript">
function stopRKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
}
document.onkeypress = stopRKey;
</script> 

<script language="Javascript">
       <!--
       function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;
 
          return true;
       }
       //-->
    </script>

<script type="text/javascript">
<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
//-->
</script>

<?php
if ($type=="D6") {
	
//sub_cat select box
$sub_cat = file('../include/sub_cat.txt');
$options = '';
foreach ($sub_cat as $sub_cat) {
    $options .= '<option value="'.$sub_cat.'">'.$sub_cat.'</option>';
}
$sub_cat_select = '<select name=editText >  <option value="'.  $value. '" selected=selected>'.  $value .'</option>'.$options.'</select>'; 

//cat select box
$cat = file('../include/cat.txt');
$options = '';
foreach ($cat as $cat) {
    $options .= '<option value="'.$cat.'">'.$cat.'</option>';
}
$cat_select = '<select name=editText >  <option value="'.$value. '" selected=selected>'.$value.'</option>'.$options.'</select>'; 
}
?>

 
</head>
<body onload="document.getElementById(;MM_callJS('document.getElementById(\'quantityText\').focus();')"editText").focus();">
<form action="editStockItem.php" method="get" name="form1" target="_top" id="form1">

<table width="290" border="0" align="center" cellpadding="0" cellspacing="0" class="list2">
  <tr>
    <td width="290" align="center"><p><label class="std">Edit the value and click "Edit"<br />
If you don't want to change, click "cancel"</label></p>
      <?php if ($type=="T") { ?>
      <input name="editText" type="text" id="editText"  onfocus = "this.select();"   onblur="capitalize(this)" value="<?php echo $value ?>" size="40" />
	  <?php } ?> 
      <?php if ($type=="N") { ?>
      <input name="editText" type="text" id="editText"  onfocus = "this.select();"   onkeypress="return isNumberKey(event)" value="<?php echo $value ?>" size="30" />
	  <?php } ?> 
      <?php if ($type=="D") { ?>
      <select name="editText" id="editText">
        <option value="1">yes</option>
        <option value="0">no</option>
        <option value=" <?php echo $value ?> " selected="selected"><?php if($value==0) {echo "no";} else {echo "yes"; } ?></option>
     </select>
      <?php } ?>
      <?php if ($type=="D2") { ?>
      <select name="editText" id="editText">
        <option value="Depalet">Depalet</option>
        <option value="Pigment">Pigment</option>
        <option value="Skip">Skip</option>
        <option value="Wrapping and Strapping">Wrapping and Strapping</option>
        <option value="<?php echo $value ?>" selected="selected"><?php echo $value ?></option>
      </select>
    <?php } ?>
    <?php if ($type=="D3") { ?>
      <select name="editText" id="editText">
        <option value="Consumables">Consumables</option>
        <option value="Cleaning materials">Cleaning materials</option>
        <option value="Fuel">Fuel</option>
        <option value="Lubricants">Lubricants</option>
        <option value="Machine spares">Machine spares</option>
        <option value="PPE">PPE</option>
        <option value="Tools">Tools</option>
        <option value="Vortex spares">Vortex spares</option>
        <option value="Welding and Engineeing">Welding and Engineering</option>
        <option value="<?php echo $value ?>" selected="selected"><?php echo $value ?></option>
      </select>
    <?php } ?>
    <?php if ($type=="D4") { ?>
      <select name="editText" id="editText">
        <option value="kg">kg</option>
        <option value="ltr">ltr</option>
        <option value="m">m</option>
        <option value="m2">m2</option>
        <option value="no">no</option>
        <option value="pair">pair</option>
        <option value="<?php echo $value ?>"><?php echo $value ?></option>
      </select>
    <?php } ?>
    <?php if ($type=="D5") { ?>
    <textarea name="editText" id="editText" cols="30" rows="2"><?php echo $value ?></textarea>
    <?php } ?>
    <input name="edit" type="hidden" id="edit" value="1"  />
    <input name="productId" type="hidden" id="productId" value="<?php echo $productId ?>" />
    
<input name="field" type="hidden" id="field" value="<?php echo $field ?>" />
    <?php if ($type=="D6") { echo "sub cat".$sub_cat_select ."<br>" . $cat_select; } ?></td>
  </tr>
  <tr>
    <td align="center">
      <br />
      <input name="input" type="submit" value="Edit" class="imagebutton"  />
    <input name="button" type="button" id="button" class="imagebutton" onclick="MM_goToURL('parent','editStockItem.php?productId=<?php echo $productId ?>&edit=0');return document.MM_returnValue" value="Cancel" /></form>
    </td>
  </tr>
</table>

<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("ProductSelect","req","Please select a product.");
  frmvalidator.addValidation("QuantityText","req","Please enter the quantity.");
</script>
</body>
</html>