<?
include_once('../hdr_general.php');
/* **************************************************************************************************** */
if (!isset($_REQUEST["module"])) $_REQUEST["module"] = "general";
if (!isset($_REQUEST["task"])) $_REQUEST["task"] = "main";
$pubmodule = $_REQUEST["module"];
$pubtask = $_REQUEST["task"];
$pubitemid = $_REQUEST["itemid"];
$pubsubid = $_REQUEST["subid"];
$publevel = $_REQUEST["level"];
if ($publevel=="") $publevel="0";
/* **************************************************************************************************** */
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../css/<?=$_SESSION['Xcssfile'];?>" type="text/css" media=all>
<title>Purchasing Online (ZIKAY)</title>

<script type="text/javascript">

function trade_tree_select(node,tlevel) {
  var parentfield = document.getElementById('parent'+node);
  var tradefield = document.getElementById('trade'+node);
  var codefield = document.getElementById('code'+node);
  var descfield = document.getElementById('desc'+node);
  var desc2field = document.getElementById('desc2'+node);
  var unitfield = document.getElementById('unit'+node);
  opener.document.forms[0].item_subtradepkey.value = parentfield.value;
  opener.document.forms[0].item_subsubtradepkey.value = tradefield.value;
  opener.document.forms[0].item_code.value = codefield.value;
  //opener.document.forms[0].item_description.value = descfield.value;
  opener.document.forms[0].item_description.value = desc2field.innerHTML;
  opener.document.forms[0].item_unit.value = unitfield.value;
  if (tlevel==3) {
    opener.document.forms[0].item_level.value = "3";
    opener.document.forms[0].item_subtradepkey.value = tradefield.value;
    opener.document.forms[0].item_subsubtradepkey.value = "";
  } else if (tlevel==4) {
    opener.document.forms[0].item_level.value = "4";
  }
  self.close();
}

function updateSelect(seedurl) {
}

function cancelSelect() {
  self.close();
}

</script>


</head>
<body leftmargin=5 topmargin=5 style="background: #dddddd;">
<table border=0 cellspacing=0 cellpadding=0 width=578>

<tr valign=top>
<td valign=top width=100%>

  <?
  include_once('../models/tradeModel.php');
  $mytradeModel=new tradeModel;

  if ($pubsubid!="") {
    $trade_list = $mytradeModel->getlist_tradesbyparent($pubsubid,"","tradecode");
  } else {
    if ($publevel!="") {
      //$trade_list = $mytradeModel->getlist_tradesbylevel($publevel,"","tradecode");
      if ($publevel=="3") {
        $trade_list = $mytradeModel->getlist_subtradesbytopparent("456b685e3475eb3c9cb1948e3d430318", "tradecode");
      } else if ($publevel=="4") {
        $trade_list = $mytradeModel->getlist_subsubtradesbytopparent("456b685e3475eb3c9cb1948e3d430318", "tradecode");
      }
    } else {
      $trade_list = $mytradeModel->getlist_tradesbylevel(4,"","tradecode");
    }
  }
  ?>
<div id="range">
  <table border=1 cellspacing=1 cellpadding=2 width=568 style="border: 1px inset;">

  <tr valign=top>
  <td valign=top width=928 class=listheader style="border-bottom: 1px solid;">
  
	<!-- -->


	<!-- -->
  Select Trade :
  <!--
  <form><input type="button" value="Search" name="Search" onClick="showModelessDialog('testfind.html', window,'dialogWidth:385px; dialogHeight:165px; scroll:no; status:no; help:no;');"></form>
  -->
  <script type="text/javascript" language="JavaScript" src="find.js">
  </script>

  </td>
  </tr>

  <? $catindex=0; ?>
  <? foreach ($trade_list as $mytrade) { ?>

   
  
  
    <tr valign=top>
    <td valign=top width=928 class=newscontent style="border-bottom: 1px solid;">
      <table border=0 cellspacing=0 cellpadding=0 width=558>
      <tr valign=top>
      <td valign=top class=newscontent width=498>
      <input name="parent<?=$mytrade['tradepkey'];?>" type="hidden" value="<?=htmlentities($mytrade['tradeparentpkey']);?>">
      <input name="trade<?=$mytrade['tradepkey'];?>" type="hidden" value="<?=htmlentities($mytrade['tradepkey']);?>">
      <input name="code<?=$mytrade['tradepkey'];?>" type="hidden" value="<?=htmlentities($mytrade['tradecode']);?>">
      <input name="desc<?=$mytrade['tradepkey'];?>" type="hidden" value="<?=escape($mytrade['tradedescription']);?>">
	  
	   
	  
	  
	  
	  
	  
	  
      <span name="desc2<?=$mytrade['tradepkey'];?>" id="desc2<?=$mytrade['tradepkey'];?>" style="display: none;"><?=stripslashes($mytrade['tradedescription']);?></span>
   
	  <input name="unit<?=$mytrade['tradepkey'];?>" type="hidden" value="<?=$mytrade['tradeunit'];?>">
	  
      <img id="item<?=$mytrade['tradepkey'];?>" src="../gfx/tree/item.png" border=0 width=16 height=16 title="Item" alt="Item" align=left style="display: block;">
     
	 
	 
	  <?php 
	  
	   ///////////////////// filter tambahan
	  if($_GET['level'] == 3) 
		{
		$flt1 = "SELECT * FROM zikay_pmsv5.mbl_items WHERE item_projectpkey ='".$pubprojectpkey."' AND item_subtradepkey ='".$mytrade['tradepkey']."'";
		$flt2 = mysql_query($flt1);
		$flt3 = mysql_fetch_assoc($flt2);
        
	  
	  }
	  ?>
	 
	 
	  
	  &nbsp;&nbsp;<b><?=$mytrade['tradecode']."</b> - ".$mytrade['tradedescription'];?>&nbsp;&nbsp;
	  
	  <br /> 
	  
	  
      </td>
      <td valign=top class=newscontent width=60>
	  
	 <?php if($flt3['item_pkey'] != "" )
		{ 
		echo "<img src=\"../gfx/tree/stop.jpg\" border=0 widht=16 height=16 alt=\"Material Already Select in previos MBL. Please go to Update MBL.\""; 
		} else {?>
	 
	 
      <img src="../gfx/tree/b_select.png" border=0 width=16 height=16 title="Select" alt="Select" style="display: inline; cursor: pointer;" onClick="javascript:trade_tree_select('<?=$mytrade['tradepkey'];?>',<?=$publevel;?>);">&nbsp;<br>
       <?php } ?>
	  
	  
	  
	  </td>
      </tr>
      </table>

    </td>
    </tr>

  <? } ?>

  </table>
</div>
</td>
</tr>
</table>

</body>
</html>
