<?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' AND gmflist_id='$WID'");
   		while($row = mysql_fetch_array($result , MYSQL_ASSOC))
  		{
  		 ?>
			 if(specCode=='<?php echo $row["specCode"]?>')
		 	 pcount++; 
		<?php
			}
  		?>

		if(pcount>0)
		{
			alert("This Division Code/ Sub-Code already exist.Please enter an other Division 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>
<style type="text/css">
    .fixed{display:none !important}
    div.FixedHeader_Cloned th,
    div.FixedHeader_Cloned td {
        background-color: white !important;
    }
    .first{
        display: none;
    }
    /*    .fixed{
            width: auto !important;
        }*/
    .dataTable, .FixedHeader_Header {width:100% !important}
    .dataTable thead i{
        margin-top: -5px;
    }
</style>
<script src="../includes/js/fixedheader.js"></script>
<style>
    .addon-label{width:13%}
    .addon-field{width:20%}
</style>
<section class="content">
    <div class="container">
        <div class="row">
            <div class="main-content">
                <h5>
                    <?php if (isset($_REQUEST["msg"])) { ?>
                        <?php echo $_REQUEST["msg"]; ?>
                    <?php } ?>
                </h5>

                <?php if ($uacc == "Full Control") { ?>
                    <?php if (!isset($_REQUEST['Edit'])) { ?>
                        <div class="add-formpage">
                            <form id="form1" name="form1" method="post" action="../../DB/03-scope/GMFDB.php?WID=<?php echo $WID.$var ?>" onsubmit="return code_check()">
                                <fieldset>
                                    <div class="widget">
                                        <div class="whead">
                                            <h6>
                                                <i class="fa fa-plus-circle"></i>
                                                Add </h6>
                                            <strong><a href="javascript:void(0)" onclick="hideform()" class="teamclose"><i class="fa fa-times"></i></a></strong>

                                        </div>
                                        <div class="formRow">
                                            <div class="col-sm-1-8 addon-label" style="padding-right:0px; width:20%">
                                                <label>Division/ Sub-Division Code*:</label></div>
                                            <div class="col-sm-2-2 addon-field" style="padding-left:0px;">
                                            <input name="specCode" type="text" id="specCode" onkeyup="numformat()" onkeypress="return isNumber(event)" maxlength="11"/>
                                          </div>
                                            <div class="col-sm-1-8 addon-label" style="padding-right:0px; width:20% !important">
                                                <label> Division/ Sub-Division Name*:</label></div>
                                            <div class="col-sm-2-2 addon-field" style="padding-left:0px; width:38% !important">
                                            <input name="specname" type="text"  id="specname" value=""/>
                                          </div>
                                            
                                            <div class="grid2 submit-btn save-bottom"> 
                                                <button type="submit" class="btn btn-success"><i class="fa fa-check-square"></i> </button>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="clear"></div>
                                    <div class="divider"><span></span></div>
                                </fieldset>  
                            </form>
                        </div>


                        <?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"];		 
						 
						 
                        ?>

                        <div class="edit-formpage">
                            <form id="form1" name="form1"  method="post" action="../../DB/03-scope/GMFDB.php?Edit=<?php echo $MFIDs; ?>&WID=<?php echo $WID; ?>" onsubmit="return code_check()">
                                <div class="widget">
                                    <div class="whead">
                                        <h6>
                                            <i class="fa fa-pencil-square-o"></i>
                                            Edit</h6>
                                        <span style="float:right"><a href="javascript:void(0)" onclick="hideeform()" style="font-size:16px; padding:5px 24px; display:inline-block"><i class="fa fa-times"></i></a></span>

                                    </div>
                                    <div class="formRow">
                                        <div class="col-sm-1-8 addon-label" style="padding-right:0px; width:20%">
                                            <label>Division/ Sub-Division Code*:</label></div>
                                        <div class="col-sm-2-2 addon-field" style="padding-left:0px;">
                                            <input name="specCode" type="text" id="specCode" value="<?php echo $specCode ?>" onkeyup="numformat()" onkeypress="return isNumber(event)" maxlength="11"/></div>
                                        <div class="col-sm-1-8 addon-label" style="padding-right:0px;">
                                            <label>Division/ Sub-Division Name*:</label></div>
                                        <div class="col-sm-2-2 addon-field" style="padding-left:0px;">
                                            <input name="specname" type="text" id="specname" value="<?php echo $gmf_name ?>"/> </div>
                                       
                                        <div class="grid2 submit-btn save-bottom"> 
                                            <button type="submit" class="btn btn-success"><i class="fa fa-check-square"></i> </button>
                                        </div>
                                    </div>
                                </div>
                            </form><div class="divider"><span></span></div>

                        </div>

                        <?php
                    }
                }
                ?>
                <div class="table-subject">

                    <!--  -->

                    <div class="widget">
                        <div class="whead">
                            <h6 id="active-desciplines" >
                                <b>
                                    <i class="fa fa-pie-chart"></i>
                                    Create Divisions and Sub Divisions for Masterformat 
									
 
 ( <?php	  
	  $result = mysql_query("SELECT MFList_name 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> )
                                </b> 
                            </h6>
                     <span style="line-height: 35px;">
                        
                        <?php if ($uacc == "Full Control") { ?>
                        <?php if(!isset($_REQUEST['Edit'])) {?>
                        <a onclick="showaddform()" style="cursor:pointer"  class="addform-btn " id=""><span class="icon-plus_box  bck"></span></a>
                        <a onclick="hideform()" style="cursor:pointer" class="hideform-btn " id=""><span class="icon-minus_box  bck"></span></a>
                        
                             <?php } else {
                              ?>
                          <a onclick="showeditform()" style="cursor:pointer"  class="eform-btn " id=""><i class="fa fa-pencil-square-o green-icon"></i></a>
                        <a onclick="hideeform()" style="cursor:pointer" class="hideeform-btn " id=""><span class="icon-minus_box  bck"></span></a>
                        
                              <?php 
                          }?>
                        <?php } ?>
                    </span>


                        </div>
                        <div>
                            <!-- <div class="scroll"> -->
                            <table cellpadding="0" cellspacing="0" class="" style="width:100%;position:relative !important"  id="active_descipline_tbl">
                                <thead>
                                    <tr>
                                        <th class="first"></th>
                                        <th class="date-create add-dcreated" >
                                            Date Created
                                            <br />
                                            (yyyy.mm.dd) <i class="fa fa-sort"></i>
                                        </th>
                                        <th  class="add-description" align="left" valign="top" bgcolor="#E2E2E2" scope="col">
                                            Division       Code/<br />
Sub-Division Code <i class="fa fa-sort"></i>
                                        </th>
                                        <th  class="add-percent"  align="left" valign="top" bgcolor="#E2E2E2" scope="col">
                                            Division/ Sub-Division<br />
    Name<i class="fa fa-sort"></i>
                                        </th>
                                        <th class="add-actions action-icon" style="text-align:right">
                                            Actions</br>
                                            Status 
                                        </th>

                                        
                                        <!-- <th></th> -->
                                    </tr>
                                </thead>
                                <tbody>
                                    <?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"];
			
                                        ?>  

                                        <tr >
                                            <td class="first"></td>
                                            <td class="add-dcreated" align="left" valign="middle" scope="col"></th><?php echo $row["creationDate"]; ?></td>
                                            <td class="add-description" align="left" valign="middle" ><?php echo $row["specCode"]; ?></td>
                                            <td class="add-percent"align="left" valign="middle" scope="col"><?php echo $row["gmf_name"]; ?></td>
                                            <td class="add-actions action-icons" align="right" valign="middle">

    <?php if ($uacc == "Full Control") { ?>
                                                    <div class="close-icon">  <a href="javascript:void(0)" onclick="deleteAddon(<?php echo $row["MFID"] ?>, <?php echo $WID?>)">
                                                            <div class="glyph">
                                                                <div class="fs1 iconb" data-icon="" title="Delete"></div>
                                                            </div>
                                                        </a> </div>
    <?php } else { ?> <div class="glyph">
                                                        <div class="fs1 iconb" data-icon="" title="Delete"></div>
                                                    </div> 
                                                <?php } ?>
    <?php if ($uacc == "Full Control") { ?>
                                                    <div class="edit-icon">
                                                        <a href="MasterFormat2.php?Edit=<?php echo $row["MFID"]; ?>&WID=<?php echo $WID?>">
                                                            <div class="glyph">
                                                                <div class="fs1 iconb" data-icon="" title="Edit"></div>
                                                            </div>
                                                        </a> </div>
    <?php } else { ?>
                                                    <div class="glyph">
                                                        <div class="fs1 iconb" data-icon="" title="Edit"></div>
                                                    </div>
                                                <?php } ?>
    

                                            </td>

                                        </tr>

<?php } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <div class="divider"><span></span></div>
        </div>
    </div>

    <!--  -->


</div>
</div>
</div>
</div>
</section>
<footer>
    <div class="container">
        <div class="row">
            <div class="top-footer">
                <div class="instructions-cont">
                    <i class="fa fa-info-circle"></i>
                    <h6>Instructions </h6>
                    <!--<span>
                        <a onclick="bottomfooterfunc()" href="#addonhidden-data" class="hidden-entry" >View The Hidden List</a>|
                        <a href="#active-desciplines">Go to Active List</a></span>-->
                </div>
                <div class="left-warning"> Deletion is permanent and can not be retrieved.  If a  parameter has been used at other places, deletion might cause problems.  A 
                    parameter can be deleted only after its usage is removed from other places.  
                    If you dont want to see an entry or a parameter, you can hide it instead of deleting it.  A Hidden entry or parameter will  show as &quot;HIDDEN&quot; at all places where it was used before.  
                    <!--Table of Hidden Values is given below--> 
                </div>
            </div>
            
        </div>
    </div>
</footer>
<script>

//    function bottomfooterfunc() {
//        $('#addonhidden-data').toggle('slow');
//    }
    function deleteAddon(id,wid) {

        alertify.confirm("This record will be deleted and cannot be retrieved. Press OK to Delete.", function (e) {
            if (e) {
                window.location.href = "../../DB/03-scope/GMFDB.php?del=" + id+"&WID="+wid;

            } else {
                return 0;
            }
        });
    }
</script>
<script type="text/javascript">

// i = showing 1 of 2 pages
// f = filter or search
// p = pages buttons
// l = records per page drop down

    function format(d) {
        // `d` is the original data object for the row
        console.log(d.details);
        return '<div class="notesDIV">' + d.details + '</div>';
    }

    active_descipline_table = $('#active_descipline_tbl').DataTable({
        "bJQueryUI": false,
        "bAutoWidth": false,
		
        "columns": [
            {
                "className": 'details-control',
                "orderable": false,
                "defaultContent": '',
            },
            {"data": "date_created"},
            {"data": "client_code"},
            {"data": "contact_name"},
            {"data": "action"}
        ],
        "order": [[1, 'asc']],
        "lengthMenu": [[50, 100, -1], [50, 100, "All"]],
        "sPaginationType": "full_numbers",
        "sDom": '<"tOptions" f><"top">rt<"bottom" pil><"clear">',
        "oLanguage": {
            "sLengthMenu": "<span class='showentries'>Show entries:</span> _MENU_"
        },
        "aoColumnDefs": [{"bSortable": false, "aTargets": [4]}]
    });

    $('div.dataTables_filter input[type=search]').attr('placeholder', 'Type to Start Search');
    var active_descipline_table1 = $('#active_descipline_tbl').DataTable();
    new $.fn.dataTable.FixedHeader(active_descipline_table1, {
        bottom: true
    });
    $('.details-control').ready(function () {

        no_of_records = active_descipline_table.page.info().recordsTotal;
        for (var i = 0; i < no_of_records; i++) {
            active_descipline_table.row(i).show();
        }
        ;


    });

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