<?php 
session_start();
include('../includes/con2db.php');
$id = $_SESSION['id'];
$WID=$_REQUEST['WID'];
$WBSIDitem = $_REQUEST['WBSID'];
if(isset($_REQUEST['pItem']))
$pItem = $_REQUEST['pItem'];
else
$pItem=0;

	  
	  ?>
<form id="IITEMForm" name="IITEMForm" method="post" action="../DB/GWBSITEMDB-G.php?WID=<?php echo $WID ?>">
<h1>Insert <?php if(isset($_REQUEST['pItem'])) echo "Sub";?> ITEM</h1>
  <table width="100%" border="0">
    <tr>
      <td colspan="1" align="left" scope="col" class="a1">WBS Work Package:</td>
      <td> <div align="left">
        <select class="a11" name="PNode" id="PNodeIE" onchange="LoadItemList(this.value,0)">
          <?php

	  $result = mysql_query("SELECT * FROM globalwbs where gwbslist_id = '$WID' && companyID = '$id' ORDER BY WBSIDA ASC,WBSIDA ASC,WBSIDB ASC,WBSIDC ASC,WBSIDD ASC,WBSIDE ASC");
	  $count =0;
		
   		while($row = mysql_fetch_array($result , MYSQL_ASSOC))
  		{
			$WBSID = $row["WBSID"];
	
		$count ++;	
			
			if($WBSIDitem==$WBSID){
					echo "<option selected='selected' value='$WBSID'>".$row["WBSIDA"].".".$row["WBSIDB"].".".$row["WBSIDC"].".".$row["WBSIDD"].".".$row["WBSIDE"]." - ".$row["description"]."</option>";
			}
			else
			{
					echo "<option value='$WBSID'>".$row["WBSIDA"].".".$row["WBSIDB"].".".$row["WBSIDC"].".".$row["WBSIDD"].".".$row["WBSIDE"]." - ".$row["description"]."</option>";
				}
		}		
?>
        </select>
        </span></span></div></td>
      <td colspan="2" align="left" scope="row">&nbsp;</th>
    </tr>
    <tr>
      <td align="left" valign="top" class="a1" scope="col">Items:</td>
      <td align="left" valign="top" class="a1"><select class="a1" name="itemList" size="1" id="itemList">
       <option value="0">Select</option>
        <?php 
		
        $result21 = mysql_query("SELECT * FROM globalitems where companyID = '$id' && itemParent = '0' && WBSID = '$WBSIDitem' ORDER BY itemID ASC");
		
   		while($row5 = mysql_fetch_array($result21 , MYSQL_ASSOC))
  		{
			$d = $row5['description'];
			$i = $row5['itemID'];
			if( $i == $pItem)
     	echo " <option selected='selected' value='$i'> $d </option>";
      	else
	  	echo " <option value='$i'> $d </option>";
     
		}
  		?>
      </select> </td>
      <th colspan="2" align="left" valign="top" class="a1" scope="row">&nbsp;</th>
    </tr>
    <tr>
      <td align="left" valign="top" class="a1" scope="col"><label for="unitselect"></label>        
        Item or Sub-item:          </td>
      <td colspan="3" align="left" valign="top" class="a11" scope="col">
        <input name="description" type="text" class="a11" id="description"  size="70" />
      </td>
    </tr>
    <tr>
      <td align="left" valign="top" class="a1" scope="col">Notes(if any):</td>
      <td colspan="3" align="left" valign="top" class="a11">
        <textarea name="writeupitem" cols="69" rows="3" class="a11" id="writeupitem"></textarea>
      
        <input type="image" src="../images/icon-save.png"  width="15" height="15"  />
      </td>
    </tr>
    <tr>
      <th align="left" valign="top" class="a1" scope="col">&nbsp;</th>
      <th align="left" valign="top" class="a1">&nbsp;</th>
      <th align="left" valign="top" class="a1" scope="row">&nbsp;</th>
      <th align="left" valign="top" class="a1">&nbsp;</th>
    </tr>
  </table>
</form>
<script language="javascript">
LoadItemList(<?php echo $WBSIDitem?>,<?php echo $pItem;?>);
</script>