<?php include('../includes/header.php');
$var = "";
if(isset($_REQUEST['Check']))
{
	session_name("AdminSession");	
	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 = "";
}
$WID = $_REQUEST['WID']; 
 ?>
<link rel="stylesheet" href="../popupjquery/general.css" type="text/css" media="screen" />
	<script src="../popupjquery/popup.js" type="text/javascript"></script>
<table>
<tr>
<td><form id="form1" name="form1" method="post" action="GWBSDB.php?AddBefore=1&WID=<?php echo $WID.$var?>">
    <div id="popupContact">
    <a id="popupContactClose">x</a>
      <h1>Add WBS before WBS</h1>
      <table width="100%">
  <tr>
    <td><font color="#666666" size="1">ADD BEFORE WBS</font></td>
    <td><span id="WBSLID"></span><input type="hidden" name="WBSL" id="PNode" class="" readonly="readonly" />
      </td>
  </tr>
  <tr>
    <td width="40%"><font color="#666666" size="1">DESCRIPTION</font></td>
    <td><input name="WBSD" type="text" id="WBSD" size="40" /></td>
  </tr>
  <tr>

    <td><input type="submit" name="Submit1" value="Save" /> </td>
<td>&nbsp;</td>
</tr>
</table>
	</div>
    </form>
	<div id="backgroundPopup"></div>
</td>
</tr>
</table>
<img src="../images/icon-heading.gif" width="12" height="13" border="0" /><span class="lbrownlll7"> Create  a Work Breakdown Structure</span>
(<?php 
$resultWBSname = mysql_query("SELECT WBSList_code FROM wbslist where WBSList_id='$WID'");
$rowWBSname = mysql_fetch_array($resultWBSname , MYSQL_ASSOC); 
echo $rowWBSname['WBSList_code'];
		?>)
        <?php if(!isset($_REQUEST['Edit'])){?>
<form method="post" enctype="multipart/form-data" name="form1" id="form1" action="GWBSDB.php?WID=<?php echo $WID.$var ?>" onsubmit="return validateWBS2()">
  <table width="100%" border="0">
    <tr class="ablks1">
      <th width="16%" align="left" valign="top" class="ablks1" scope="col">&nbsp;</th>
      <th width="84%" align="left" valign="top" class="ablks1">&nbsp;</th>
    </tr>
    <tr class="ablks1">
      <th align="left" valign="top" class="ablks5" scope="col">WBS Level:</th>
      <th align="left" valign="top" class="a11" scope="col"><label for="WBSL2"></label>
        <select name="WBSL" class="ablks1" id="WBSL2">
        <?php
	  $result = mysql_query("SELECT * FROM globalwbs where companyID = '$id' && gwbslist_id='$WID' ORDER BY WBSIDA ASC,WBSIDA ASC,WBSIDB ASC,WBSIDC ASC,WBSIDD ASC,WBSIDE ASC");
	  $count =0;
		echo "<option value='0.0.0.0.0'>0.0.0.0.0 - ROOT</option>";
   		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"];
			$WBSdes = $row["description"];
		

		$count ++;
			if ($WBSIDE==0)
  		 echo "<option value='$WBSID'>".$WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE." - ".$WBSdes."</option>";
		}		

?>
      </select></th>
    </tr>
 <tr class="ablks1">
      <th align="left" valign="top" class="ablks5" scope="col">WBS  Description*:</th>
      <th align="left" valign="top" class="ablks1" scope="col"><label for="importmasterformatfile"></label>
        <label for="WBSD"></label>
        <input name="WBSD" type="text" class="ablks1nor" id="WBSD" size="100" />
        <label for="importfilename"></label></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 { 

$WBSIDs = $_REQUEST['Edit'];

   		$result = mysql_query("SELECT * FROM globalwbs where companyID = '$id' && WBSID = '$WBSIDs'");
   		$row = mysql_fetch_array($result , MYSQL_ASSOC);

			 $sortCode = $row["sortCode"];
			 $description= $row["description"];
			 $creationDate= $row["creationDate"];
			 $writeupwbs = $row["writeupwbs"];	  
	  $parent= $row["parent"];
?><form method="post" enctype="multipart/form-data" name="form1" id="form1" action="GWBSDB.php?Edit=<?php echo $_REQUEST['Edit']; ?>&WID=<?php echo $WID.$var ?>" onsubmit="return validateWBS2()">
  <table width="100%" border="0">
    <tr class="ablks1">
      <th width="16%" align="left" valign="top" class="ablks1" scope="col">&nbsp;</th>
      <th width="84%" align="left" valign="top" class="ablks1">&nbsp;</th>
    </tr>
    <tr class="ablks1">
      <th align="left" valign="top" class="ablks5" scope="col">WBS Level:</th>
      <th align="left" valign="top" class="a11" scope="col"><label for="WBSL2"></label>
        </th>
    </tr>
 <tr class="ablks1">
      <th align="left" valign="top" class="ablks5" scope="col">WBS  Description*:</th>
      <th align="left" valign="top" class="ablks1" scope="col"><label for="importmasterformatfile"></label>
        <label for="WBSD"></label>
        <input name="WBSD" type="text" class="ablks1nor" id="WBSD" size="100" value="<?php echo $description ?>" />
        <label for="importfilename"></label></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 $writeupwbs; ?>" /> <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"> (<a href="WBS2PV1.php?WID=<?php echo $WID; ?>" target="_blank">Print View with Notes</a>) (<a href="WBS2PV2.php?WID=<?php echo $WID; ?>" target="_blank">Print View without Notes</a>) (Export)<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"> Insert/items<br />
      edit/
Del</td>
  </tr>  
  <?php
		 $result = mysql_query("SELECT * FROM globalwbs where companyID = '$id' && gwbslist_id= '$WID' 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)
		{
        $textt=$WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE;
  		?>

  
  <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"><a href="javascript:void(0)" onclick="insertingWBS(<?php echo $WBSID;?>,'<?php echo $textt;?>');"><img src="../images/icon-insert.jpg" width="15" height="15" border="0" /></a> <a href="WBSITEM1.php?WBSID=<?php echo $WBSID; ?>&WID=<?php echo $WID.$var ?>"><img src="../images/icon-items.png" width="17" height="17" border="0" /></a> <a href="WBS2.php?Edit=<?php echo $row["WBSID"]; ?>&WID=<?php echo $WID.$var ?>"><img src="../images/icon-edit1.png" width="15" height="15" border="0"/></a> <a href="GWBSDB.php?del=<?php echo $row["WBSID"]; ?>&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"/></a></td>
  </tr>
   <?php }
		else if($WBSIDC==0 && $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;<?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"><a href="javascript:void(0)" onclick="insertingWBS(<?php echo $WBSID;?>,'<?php echo $WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE; ?>');"><img src="../images/icon-insert.jpg" width="15" height="15" border="0" /></a> <a href="WBSITEM1.php?WBSID=<?php echo $WBSID; ?>&WID=<?php echo $WID.$var ?>"><img src="../images/icon-items.png" width="17" height="17" border="0" /></a> <a href="WBS2.php?Edit=<?php echo $row["WBSID"]; ?>&WID=<?php echo $WID.$var ?>"><img src="../images/icon-edit1.png" width="15" height="15" border="0"/></a> <a href="GWBSDB.php?del=<?php echo $row["WBSID"]; ?>&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"/></a></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"><a href="javascript:void(0)" onclick="insertingWBS(<?php echo $WBSID;?>,'<?php echo $WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE; ?>');"><img src="../images/icon-insert.jpg" width="15" height="15" border="0" /></a> <a href="WBSITEM1.php?WBSID=<?php echo $WBSID; ?>&WID=<?php echo $WID.$var ?>"><img src="../images/icon-items.png" width="17" height="17" border="0" /></a> <a href="WBS2.php?Edit=<?php echo $row["WBSID"]; ?>&WID=<?php echo $WID.$var ?>"><img src="../images/icon-edit1.png" width="15" height="15" border="0"/></a> <a href="GWBSDB.php?del=<?php echo $row["WBSID"]; ?>&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"/></a></td>
  </tr>
  <?php } 	
else if($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;&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"><a href="javascript:void(0)" onclick="insertingWBS(<?php echo $WBSID;?>,'<?php echo $WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE; ?>');"><img src="../images/icon-insert.jpg" width="15" height="15" border="0" /></a> <a href="WBSITEM1.php?WBSID=<?php echo $WBSID; ?>&WID=<?php echo $WID.$var ?>"><img src="../images/icon-items.png" width="17" height="17" border="0" /></a> <a href="WBS2.php?Edit=<?php echo $row["WBSID"]; ?>&WID=<?php echo $WID.$var ?>"><img src="../images/icon-edit1.png" width="15" height="15" border="0"/></a> <a href="GWBSDB.php?del=<?php echo $row["WBSID"]; ?>&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"/></a></td>
    </tr>
    <?php }
else{
	?>
  <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;&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"><a href="javascript:void(0)" onclick="insertingWBS(<?php echo $WBSID;?>,'<?php echo $WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE; ?>');"><img src="../images/icon-insert.jpg" width="15" height="15" border="0" /></a> <a href="WBSITEM1.php?WBSID=<?php echo $WBSID; ?>&WID=<?php echo $WID.$var ?>"><img src="../images/icon-items.png" width="17" height="17" border="0" /></a> <a href="WBS2.php?Edit=<?php echo $row["WBSID"]; ?>&WID=<?php echo $WID.$var ?>"><img src="../images/icon-edit1.png" width="15" height="15" border="0"/></a> <a href="GWBSDB.php?del=<?php echo $row["WBSID"]; ?>&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"/></a></td>
    </tr>
     <?php } ?>
       <?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"><a href="javascript:void(0)" onclick="insertingWBS(<?php echo $WBSID;?>,'<?php echo $WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE; ?>');"><img src="../images/icon-insert.jpg" width="15" height="15" border="0" /></a> <a href="WBSITEM1.php?WBSID=<?php echo $WBSID; ?>&WID=<?php echo $WID.$var ?>"><img src="../images/icon-items.png" width="17" height="17" border="0" /></a> <a href="WBSITEM1.php?Edit=<?php echo $row["itemID"]; ?>&WBSID=<?php echo $row["WBSID"]; ?>&WID=<?php echo $WID.$var ?>&rdir=WBS2"><img src="../images/icon-edit1.png" width="15" height="15" border="0"/></a> <a href="GWBSDB.php?del=<?php echo $row["WBSID"]; ?>&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"/></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"><a href="javascript:void(0)" onclick="insertingWBS(<?php echo $WBSID;?>,'<?php echo $WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE; ?>');"><img src="../images/icon-insert.jpg" width="15" height="15" border="0" /></a> <a href="WBSITEM1.php?WBSID=<?php echo $WBSID; ?>&WID=<?php echo $WID.$var ?>"><img src="../images/icon-items.png" width="17" height="17" border="0" /></a> <a href="WBSITEM1.php?Edit=<?php echo $row1["itemID"]; ?>&WBSID=<?php echo $row["WBSID"]; ?>&WID=<?php echo $WID.$var ?>&rdir=WBS2"><img src="../images/icon-edit1.png" width="15" height="15" border="0"/></a> <a href="GWBSDB.php?del=<?php echo $row["WBSID"]; ?>&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"/></a></td>
    </tr>
    <?php }
		}
		} ?>
        
        
</table>
<?php include('../includes/footer.php');?>
