<?php
include('../../includes/checkSession.php');
include('../../includes/con2pma3.php');
include('../includes/header_in.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']; 
?>

<script type="text/javascript">
function numformat()
{
	 var num = document.form1.specCode.value;
	 num = num.trim();
	var n = num.length;
	if(n==2||n==5||n==8){
		document.form1.specCode.value=num+'.';
	}
	//alert(n);
}
function isNumber(evt) {//only allow 0-9 and .   
    evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;		
    if (charCode > 31 && ((charCode != 46 && charCode < 48) || charCode > 57)) {
        return false;
    }
    return true;
}

window.onload = function () {
    setCursor(document.getElementById('specCode'), 0, 0)
}

function setCursor(el, st, end) {
    if (el.setSelectionRange) {
        el.focus();
        el.setSelectionRange(st, end);
    } else {
        if (el.createTextRange) {
            range = el.createTextRange();
            range.collapse(true);
            range.moveEnd('character', end);
            range.moveStart('character', st);
            range.select();
        }
    }
}
function code_check(){				
if(document.getElementById('specCode').value!=''){
	specCode=document.getElementById('specCode').value;
			var pcount = 0;
	<?php  $result = mysql_query("SELECT DISTINCT specCode FROM globalmf where companyID= '$id'");
   		while($row = mysql_fetch_array($result , MYSQL_ASSOC))
  		{
  		 ?>
			 if(specCode=='<?php echo $row["specCode"]?>')
		 	 pcount++; 
		<?php
			}
  		?>

		if(pcount>0)
		{
			alert("This Spec Code/ Sub-Code already exist.Please enter an other Spec Code/ Sub-Code.");
			return false;
			
			}
			return validateMF2();
}
else{
	return validateMF2();
}
			//return true;
}
function codeedit_check(){				
if(document.getElementById('specCode').value!=''){
	specCode=document.getElementById('specCode').value;
			var pcount = 0;
	<?php  $result = mysql_query("SELECT DISTINCT specCode FROM globalmf");
   		while($row = mysql_fetch_array($result , MYSQL_ASSOC))
  		{
  		 ?>
			 if(specCode=='<?php echo $row["specCode"]?>')
		 	 pcount++; 
		<?php
			}
  		?>

		if(pcount>1)
		{
			alert("This Spec Code/ Sub-Code already exist.Please enter an other Spec Code/ Sub-Code.");
			return false;
			
			}
			return validateMF2();
}
else{
	return validateMF2();
}
			//return true;
}
</script>
<img src="../images/icon-heading.gif" width="12" height="13" border="0" /><span class="lbrownlll7"> Create Divisions and Sub Divisions for Masterformat:</span>
 <?php if(!isset($_REQUEST['Edit'])){?>
 <span class="a11">
 ( <?php	  
	  $result = mysql_query("SELECT * FROM mflist where MFList_id = '$WID' && MFList_companyid = '$id'");
	  $MFList_name ="";
   		while($row = mysql_fetch_array($result , MYSQL_ASSOC))
  		{
			$MFList_name = $row["MFList_name"];		

		}?>
 <span><?php echo $MFList_name;?></span>
 <input type="hidden" name="MFN" id="MFN" class="ablks1" value="<?php echo $WID;?>" />
 )
 </span>
 <form method="post" enctype="multipart/form-data" name="form1" id="form1" action="GMFDB.php?WID=<?php echo $WID.$var ?>" onsubmit="return code_check()">
  <table width="100%" border="0">
    <tr>
      <th width="20%" align="left" valign="top" class="ablks1" scope="col">&nbsp;</th>
      <th width="80%" align="left" valign="top" class="ablks1">&nbsp;</th>
    </tr>
    <tr>
      <th align="left" valign="top" class="ablks5" scope="col">Division/ Sub-Division:</th>
      <th align="left" valign="top" class="a11" scope="col"><label for="speccode1"></label>
        <label for="specSubCode"></label>
      <input name="specCode" type="text" class="ablks1" id="specCode" onkeyup="numformat()" onkeypress="return isNumber(event)" maxlength="11"/> 
     </th>
    </tr>
    <tr>
      <th align="left" valign="top" class="ablks5" scope="col"><span class="a12">Division Name*:</span></th>
      <th align="left" valign="top" class="a11"> <input name="specname" type="text" class="ablks1" id="specname" value="">      
      <input type="image" src="../images/icon-save.png"  width="12" height="12" border="0"  /> <?php
  if (isset($_REQUEST["msg"])){  ?>
   <span class="fbrownl1">
     <?php echo $_REQUEST["msg"];?> </span>
  <?php }?></th>
    </tr>
    <tr>
      <th align="left" valign="top" class="ablks1" scope="col">&nbsp;</th>
      <th align="left" valign="top" class="ablks1">&nbsp;</th>
    </tr>
  </table>
</form>
<?php } else { 

$MFIDs = $_REQUEST['Edit'];

   		$result = mysql_query("SELECT * FROM globalmf where companyID = '$id' && MFID = '$MFIDs'");
   		$row = mysql_fetch_array($result , MYSQL_ASSOC);

			 $specCode = $row["specCode"];			
			 $gmf_name= $row["gmf_name"];
			 $creationDate= $row["creationDate"];		 
	         $parent= $row["parent"];
?>
<form method="post" enctype="multipart/form-data" name="form1" id="form1" action="GMFDB.php?Edit=<?php echo $_REQUEST['Edit']; ?>&WID=<?php echo $WID.$var ?>" onsubmit="return codeedit_check()">
  <table width="100%" border="0">
    <tr>
      <th width="20%" align="left" valign="top" class="ablks1" scope="col">&nbsp;</th>
      <th width="80%" align="left" valign="top" class="ablks1">&nbsp;</th>
    </tr>    
    <tr>
      <th align="left" valign="top" class="ablks5" scope="col">Division/ Sub-Division:</th>
      <th align="left" valign="top" class="a11" scope="col"><label for="specCode"></label>
        <label for="specSubCode"></label>
      <input name="specCode" type="text" class="ablks1" id="specCode" value="<?php echo $specCode ?>" onkeyup="numformat()" onkeypress="return isNumber(event)" maxlength="11"/></th>
    </tr>
    <tr>
      <th align="left" valign="top" class="ablks5" scope="col"><span class="a12">Division Name*:</span></th>
      <th align="left" valign="top" class="a11"> <input name="specname" type="text" class="ablks1" id="specname" value="<?php echo $gmf_name ?>"/>
        
      <input type="image" src="../images/icon-save.png"  width="12" height="12" border="0" /></th>
    </tr>
    <tr>
      <th align="left" valign="top" class="ablks1" scope="col">&nbsp;</th>
      <th align="left" valign="top" class="ablks1">&nbsp;</th>
    </tr>
  </table>
</form>
<?php }?>
<hr />
<br />
<img src="../images/icon-heading.gif" width="12" height="13" border="0" /><span class="lbrownlll7"> Divisions and Sub-Divisions for Masterformat</span>: <span class="a11">(
<?php	  
	  $result = mysql_query("SELECT * FROM mflist where MFList_id = '$WID' && MFList_companyid = '$id'");
	  $MFList_name ="";
   		while($row = mysql_fetch_array($result , MYSQL_ASSOC))
  		{
			$MFList_name = $row["MFList_name"];		

		}?>
<span><?php echo $MFList_name;?></span>
<input type="hidden" name="MFN2" id="MFN2" class="ablks1" value="<?php echo $WID;?>" />
) </span><span class="ablks1"><br />
<br />
</span>
<table width="100%" border="0" class="table1">
  <tr class="fbrownl7">
    <td width="12%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Date Created<br />
      (yyyy.mm.dd)
      </th>
    <td width="34%" align="left" valign="top" bgcolor="#E2E2E2" scope="col"> Division       Code/<br />
Sub-Division Code</td>
    <td width="44%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Division/ Sub-Division<br />
    Name</td>
    <td width="10%" align="right" valign="top" bgcolor="#E2E2E2" scope="col">Edit<br />
Delete</td>
  </tr>
  <?php
		 $result = mysql_query("SELECT * FROM globalmf where companyID = '$id' && gmflist_id= '$WID' ORDER BY specCode ASC");
   		while($row = mysql_fetch_array($result , MYSQL_ASSOC))
  		{

			$MFIDA = $row["MFIDA"];
	  		$MFIDB = $row["MFIDB"];
	  		$MFIDC = $row["MFIDC"];
	  		$MFIDD = $row["MFIDD"];	  		
			$MFID = $row["MFID"];
		//if($MFIDB==0 && $MFIDC==0 && $MFIDD==0 && $MFIDE==0)
		//{
  		?>  
  <tr class="ablks1">
    <td align="left" valign="top" scope="col"><?php echo $row["creationDate"]; ?></td>
    <td align="left" valign="top" ><?php echo $row["specCode"]; ?></td>
    <td align="left" valign="top" ><?php echo $row["gmf_name"]; ?></td>
    <td align="right" valign="top" >&nbsp;<a href="MasterFormat2.php?Edit=<?php echo $row["MFID"]; ?>&WID=<?php echo $WID.$var ?>"><img src="../images/icon-edit1.png" width="15" height="15" border="0"/></a>&nbsp; <a href="GMFDB.php?del=<?php echo $row["MFID"]; ?>&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'); ?>
