<?php include('../includes/header.php');
$var = "";
if(isset($_REQUEST['Check']))
{
	session_name("AdminSession");
	//session_start();
	if (isset($_SESSION['loggedin']) && ($_SESSION['loggedin']==true))
	{

		$id = 0;
		$var = "&Check=1";
	}
	else
	header("location: ../Admin/index.php?msg=YOU ARE NOT LOGGED IN");
}
else
{
	//include('../includes/checkSession.php');
	$id = $_SESSION['id'];
	$var = "";
}
//include('../includes/con2db.php');
$WID = $_REQUEST['WID'];
$WBSID = $_REQUEST['WBSID'];
?>
<img src="../images/icon-heading.gif" width="12" height="13" border="0" /><span class="lbrownlll7"> Create an Item or a s-item in Work Breakdown Structure</span>
(<?php
$resultWBSname = mysql_query("SELECT description FROM globalwbs where WBSID='$WBSID'");
$rowWBSname = mysql_fetch_array($resultWBSname , MYSQL_ASSOC);
echo $rowWBSname['description'];
		?>)
        <?php if(!isset($_REQUEST['Edit'])){?>
<form method="post" enctype="multipart/form-data" name="form1" id="form1" action="GWBSITEMDB.php?WBSID=<?php echo $WBSID.$var ?>&WID=<?php echo $WID.$var ?>" onsubmit="return validateWBSITEM1()">
  <table width="100%" border="0">
    <tr class="ablks1">
      <th width="19%" align="left" valign="top" class="ablks1" scope="col">&nbsp;</th>
      <th width="81%" align="left" valign="top" class="ablks1">&nbsp;</th>
    </tr>
    <tr class="ablks1">
      <th align="left" valign="top" class="ablks5" scope="col">WBS Level/ Description:</th>
      <th align="left" valign="top" class="a11" scope="col"><?php
	  $result = mysql_query("SELECT * FROM globalwbs where WBSID = '$WBSID' && companyID = '$id' ORDER BY WBSIDA ASC,WBSIDA ASC,WBSIDB ASC,WBSIDC ASC,WBSIDD ASC,WBSIDE ASC");
	  $WBSDesc ="";
	  $WBS ="";
   		while($row = mysql_fetch_array($result , MYSQL_ASSOC))
  		{
			$WBSDesc = $row["WBSIDA"].".".$row["WBSIDB"].".".$row["WBSIDC"].".".$row["WBSIDD"].".".$row["WBSIDE"]." - ".$row["description"];
			$WBS =$row["WBSIDA"].".".$row["WBSIDB"].".".$row["WBSIDC"].".".$row["WBSIDD"].".".$row["WBSIDE"];		

		}?>
      <span><?php echo $WBSDesc;?></span><input type="hidden" name="PNode" id="PNode" class="ablks1" value="<?php echo $WBSID;?>" />       
        </th>
    </tr>
 <tr class="ablks1">
      <th align="left" valign="top" class="ablks5" scope="col">ITEM/ Description:</th>
      <th align="left" valign="top" class="ablks1" scope="col"><select class="ablks1" name="itemList" size="1" id="itemList">
        <option value="0">Select</option>
        <?php
        $result2 = mysql_query("SELECT * FROM globalitems where itemParent = '0' && WBSID = '$WBSID' ORDER BY itemID ASC");
   		while($row = mysql_fetch_array($result2 , MYSQL_ASSOC))
  		{?>
        <option value="<?php echo $row['itemID']?>"> <?php echo $WBS." - ".$row["description"]?></option>
            <?php
		}
  		?>
      </select></th>
    </tr>
 <tr class="ablks1">
   <th align="left" valign="top" class="ablks5" scope="col">ITEM/ S-ITEM Description*:</th>
   <th align="left" valign="top" class="ablks1" scope="col"><input name="WBSD" type="text" class="ablks1nor" id="WBSD" size="100" /></th>
 </tr>
 <tr class="ablks1">
      <th align="left" valign="top" class="ablks5" scope="col">Notes (if any):</th>
      <th align="left" valign="top" class="ablks1" scope="col"><label for="WBSN"></label>
      <input name="WBSN" type="text" class="ablks1nor" id="WBSN" size="100" /> <input type="image" src="../images/icon-save.png"  width="15" height="15" border="0"  /><?php
  if (isset($_REQUEST["msg"])){  ?>
   <span class="fbrownl1">
     <?php echo $_REQUEST["msg"];?> </span>
  <?php }?></th>
    </tr>
 <tr class="ablks1">
   <th align="left" valign="top" class="ablks1" scope="col">&nbsp;</th>
   <th align="left" valign="top" class="ablks1">&nbsp;</th>
 </tr>
 <tr class="ablks1">
      <th colspan="2" align="left" valign="top" class="ablks1" scope="col"><hr /></th>
    </tr>
  </table>
</form><br />
<?php } else {	
	$rdir = $_REQUEST['rdir'];
$itemID = $_REQUEST['Edit'];
$resultit = mysql_query("SELECT * FROM globalitems where itemID = '$itemID'");
   		$row = mysql_fetch_array($resultit , MYSQL_ASSOC);	

			 $WBSIDitem = $row["WBSID"];
			 $sortCode = $row["sortCode"];
			 $description= $row["description"];
			 $writeupitem = $row["writeupitem"];
			 $p = $row['itemParent'];
			 $dateCreated= $row["dateCreated"];	  
	 		 $unitID= $row["unitID"]; 
			 ?>
             <form method="post" enctype="multipart/form-data" name="form1" id="form1" action="GWBSITEMDB.php?Edit=<?php echo $_REQUEST['Edit']; ?>&WBSID=<?php echo $WBSID.$var ?>&WID=<?php echo $WID.$var ?>&rdir=<?php echo $rdir;?>" onsubmit="return validateWBSITEM1()">
  <table width="100%" border="0">
    <tr class="ablks1">
      <th width="19%" align="left" valign="top" class="ablks1" scope="col">&nbsp;</th>
      <th width="81%" align="left" valign="top" class="ablks1">&nbsp;</th>
    </tr>
    <tr class="ablks1">
      <th align="left" valign="top" class="ablks5" scope="col">WBS Level/ Description:</th>
      <th align="left" valign="top" class="a11" scope="col"><?php
	  $result = mysql_query("SELECT * FROM globalwbs where WBSID = '$WBSID' && companyID = '$id' ORDER BY WBSIDA ASC,WBSIDA ASC,WBSIDB ASC,WBSIDC ASC,WBSIDD ASC,WBSIDE ASC");
	  $WBSDesc ="";
	  $WBS ="";
   		while($row = mysql_fetch_array($result , MYSQL_ASSOC))
  		{
			$WBSDesc = $row["WBSIDA"].".".$row["WBSIDB"].".".$row["WBSIDC"].".".$row["WBSIDD"].".".$row["WBSIDE"]." - ".$row["description"];
			$WBS =$row["WBSIDA"].".".$row["WBSIDB"].".".$row["WBSIDC"].".".$row["WBSIDD"].".".$row["WBSIDE"];		

		}?>
      <span><?php echo $WBSDesc;?></span><input type="hidden" name="PNode" id="PNode" class="ablks1" value="<?php echo $WBSID;?>" />       
        </th>
    </tr>
 <tr class="ablks1">
      <th align="left" valign="top" class="ablks5" scope="col">ITEM/ Description:</th>
      <th align="left" valign="top" class="ablks1" scope="col"><select class="ablks1" name="itemList" size="1" id="itemList">
        <option value="0">Select</option>
        <?php
        $result2 = mysql_query("SELECT * FROM globalitems where itemParent = '0' && WBSID = '$WBSID' ORDER BY itemID ASC");
   		while($row = mysql_fetch_array($result2 , MYSQL_ASSOC))
  		{?>
        <option value="<?php echo $row['itemID']?>" <?php if($row['itemID']==$p){?>selected="selected" <?php }?>> <?php echo $WBS." - ".$row["description"]?></option>
            <?php
		}
  		?>
      </select></th>
    </tr>
 <tr class="ablks1">
   <th align="left" valign="top" class="ablks5" scope="col">ITEM/ S-ITEM Description*:</th>
   <th align="left" valign="top" class="ablks1" scope="col"><input name="WBSD" type="text" class="ablks1nor" id="WBSD" size="100" value="<?php echo $description;?>"/></th>
 </tr>
 <tr class="ablks1">
      <th align="left" valign="top" class="ablks5" scope="col">Notes (if any):</th>
      <th align="left" valign="top" class="ablks1" scope="col"><label for="WBSN"></label>
      <input name="WBSN" type="text" class="ablks1nor" id="WBSN" size="100" value="<?php echo $writeupitem;?>"/> <input type="image" src="../images/icon-save.png"  width="15" height="15" border="0"  /></th>
    </tr>
 <tr class="ablks1">
   <th align="left" valign="top" class="ablks1" scope="col">&nbsp;</th>
   <th align="left" valign="top" class="ablks1">&nbsp;</th>
 </tr>
 <tr class="ablks1">
      <th colspan="2" align="left" valign="top" class="ablks1" scope="col"><hr /></th>
    </tr>
  </table>
</form><br />
             <?php
}
	  ?>
<img src="../images/icon-heading.gif" width="12" height="13" border="0" /><span class="lbrownlll7"> Work Breakdown Structure</span><span class="ablks1"><br />
<br />
</span>
<table width="100%" border="0" class="table1">
  <tr class="fbrownl7">
    <td width="9%"  align="left" valign="top" bgcolor="#E2E2E2" scope="col">Date Created<br />
      (yyyy.mm.dd)
      </th>
    <td width="6%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">WBS<br />
    SortCode</td>
    <td width="11%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">WBS <br />
      Level</td>
    <td width="34%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">WBS <br />
      Description</td>
    <td width="32%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">WBS <br />
      Notes</td>   
    <td width="8%" align="right" valign="top" bgcolor="#E2E2E2" scope="col"> edit/
Del</td>
    </tr>
  
  <?php
		 $result = mysql_query("SELECT * FROM globalwbs where WBSID ='$WBSID' && companyID = '$id' ORDER BY WBSIDA ASC,WBSIDA ASC,WBSIDB ASC,WBSIDC ASC,WBSIDD ASC,WBSIDE ASC");		

   		while($row = mysql_fetch_array($result , MYSQL_ASSOC))
  		{
			$WBSIDA = $row["WBSIDA"];
	  		$WBSIDB = $row["WBSIDB"];
	  		$WBSIDC = $row["WBSIDC"];
	  		$WBSIDD = $row["WBSIDD"];
	  		$WBSIDE = $row["WBSIDE"];
			$WBSID = $row["WBSID"];
		if($WBSIDB==0 && $WBSIDC==0 && $WBSIDD==0 && $WBSIDE==0){
  		?> 
  <tr class="lbrownlll7">
    <td align="left" valign="top" bgcolor="#F4F4F4" ><?php echo $row["creationDate"]; ?></td>
    <td align="left" valign="top" bgcolor="#F4F4F4" ><?php echo $row["sortCode"]; ?></td>
    <td align="left" valign="top" bgcolor="#F4F4F4" ><?php echo $WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE; ?></td>
    <td align="left" valign="top" bgcolor="#F4F4F4" ><?php echo $row["description"]; ?></td>
    <td align="left" valign="top" bgcolor="#F4F4F4" class="egrayl1" ><?php echo $row["writeupwbs"]; ?></td>
    <td align="right" valign="top" bgcolor="#F4F4F4" class="ablks1">&nbsp;</td>
    </tr>
     <?php
		} else if($WBSIDC==0 && $WBSIDD==0 && $WBSIDE==0){
  ?>
  <tr class="lbrownlll7">
    <td align="left" valign="top" ><?php echo $row["creationDate"]; ?></td>
    <td align="left" valign="top" ><?php echo $row["sortCode"]; ?></td>
    <td align="left" valign="top" >&nbsp;&nbsp;<?php echo $WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE; ?></td>
    <td align="left" valign="top" >&nbsp;&nbsp;<?php echo $row["description"]; ?></td>
    <td align="left" valign="top" class="egrayl1" ><?php echo $row["writeupwbs"]; ?></td>
    <td align="right" valign="top" class="ablks1">&nbsp;</td>
    </tr>
    <?php } else  if($WBSIDD==0 && $WBSIDE==0){
  ?>
  <tr class="ibrownll7">
    <td align="left" valign="top" ><?php echo $row["creationDate"]; ?></td>
    <td align="left" valign="top" ><?php echo $row["sortCode"]; ?></td>
    <td align="left" valign="top" >&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE; ?></td>
    <td align="left" valign="top" >&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row["description"]; ?></td>
    <td align="left" valign="top" class="egrayl1"><?php echo $row["writeupwbs"]; ?></td>
    <td align="right" valign="top" class="ablks1">&nbsp;</td>
    </tr>
    <?php } else  if($WBSIDE==0){?>
  <tr class="fbrownl7">
    <td align="left" valign="top" ><?php echo $row["creationDate"]; ?></td>
    <td align="left" valign="top" ><?php echo $row["sortCode"]; ?></td>
    <td align="left" valign="top" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE; ?></td>
    <td align="left" valign="top" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row["description"]; ?></td>
    <td align="left" valign="top" class="egrayl1"><?php echo $row["writeupwbs"]; ?></td>
    <td align="right" valign="top" class="ablks1">&nbsp;</td>
    </tr>
    <?php } else{?>
  <tr class="cbrowns7">
    <td align="left" valign="top" ><?php echo $row["creationDate"]; ?></td>
    <td align="left" valign="top" ><?php echo $row["sortCode"]; ?></td>
    <td align="left" valign="top" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE; ?></td>
    <td align="left" valign="top" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row["description"]; ?></td>
    <td align="left" valign="top" class="egrayl1"><?php echo $row["writeupwbs"]; ?></td>
    <td align="right" valign="top" class="ablks1">&nbsp;</td>
    </tr>
  <?php }
		 $result1 = mysql_query("SELECT * FROM globalitems where WBSID = '$WBSID' && itemParent = '0' ORDER BY itemID ASC");
   		while($row = mysql_fetch_array($result1 , MYSQL_ASSOC))
  		{
  		?>
  <tr class="dblkl7">
    <td align="left" valign="top" ><?php echo $row["dateCreated"]; ?></td>
    <td align="left" valign="top" ><?php echo $row["sortCode"]; ?></td>
    <td align="left" valign="top" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php $items = $row["itemID"]; echo  $WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE.".".$row["itemID"]; ?></td>
    <td align="left" valign="top" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row["description"]; ?></td>
    <td align="left" valign="top" class="egrayl1"><?php echo $row["writeupitem"]; ?></td>
    <td align="right" valign="top" class="ablks1"><a href="WBSITEM1.php?Edit=<?php echo $row["itemID"]; ?>&WBSID=<?php echo $WBSID.$var ?>&WID=<?php echo $WID.$var ?>&rdir=WBSITEM1"><img src="../images/icon-edit1.png" width="15" height="15" border="0" title="Edit" alt="Edit"/></a> <a href="GWBSITEMDB.php?del=<?php echo $row["itemID"]; ?>&WBSID=<?php echo $WBSID.$var ?>&WID=<?php echo $WID.$var ?>" onclick="return confirm('This deleted information cannot be retrieved. Press OK to Delete.')"><img src="../images/icon-del1.png" width="16" height="16" border="0" title="Delete" alt="Delete"/></a></td>
    </tr>
    <?php 
		 $result123 = mysql_query("SELECT * FROM globalitems where WBSID = '$WBSID' && itemParent = '$items' ORDER BY itemID ASC");
   		while($row1 = mysql_fetch_array($result123 , MYSQL_ASSOC))
  		{
  		?>
  <tr class="ablks2">
    <td align="left" valign="top" ><?php echo $row1["dateCreated"]; ?></td>
    <td align="left" valign="top" ><?php echo $row1["sortCode"]; ?></td>
    <td align="left" valign="top" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo  $WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE.".".$row1["itemID"];?></td>
    <td align="left" valign="top" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row1["description"]; ?></td>
    <td align="left" valign="top" class="egrayl1"><?php echo $row1["writeupitem"]; ?></td>
    <td align="right" valign="top" class="ablks1"><a href="WBSITEM1.php?Edit=<?php echo $row1["itemID"]; ?>&WBSID=<?php echo $WBSID.$var ?>&WID=<?php echo $WID.$var ?>&rdir=WBSITEM1"><img src="../images/icon-edit1.png" width="15" height="15" border="0" title="Edit" alt="Edit"/></a> <a href="GWBSITEMDB.php?del=<?php echo $row1["itemID"]; ?>&WBSID=<?php echo $WBSID.$var ?>&WID=<?php echo $WID.$var ?>" onclick="return confirm('This deleted information cannot be retrieved. Press OK to Delete.')"><img src="../images/icon-del1.png" width="16" height="16" border="0" title="Delete" alt="Delete"/></a></td>
    </tr>
  <?php }

		}

		} ?>

</table>
<?php include('../includes/footer.php');?>
