<?php
include('../../includes/checkSession.php');
include('../../includes/con2pma3.php');
include('../includes/header_in.php');
?>
<script type="text/javascript">
function ImportMF(str)
{
if (str=="" || str=="4" || str=="-1")
  {
  document.getElementById("import").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		document.getElementById("import").style.display='';
		document.getElementById("import").innerHTML=xmlhttp.responseText;
	}
  }
  if (str=="2")
  {
xmlhttp.open("GET","importMFfromPM.php",true);
  }
else if (str=="3")
  { 
xmlhttp.open("GET","importMFfromCSV.php",true);
  }
xmlhttp.send();
}
</script>
<style>
         .imgview{
        height: 18px;
    width: 16px;
    margin-left: 4px;
    margin-top: 0px;
    margin-right:3px;
}
    .briefc-field{width:35%}
    .briefc-field .single-select{width:100%}
    .briefc-field .double-select, .briefc-field #briefCfrom{width:49%}
    .first{display:none}
    .formRow select#projname,.formRow select#clientname{width:100%}
    .bfc-datecreated{width:12%}
    .bfc-brieffrom{width:11%}
    .bfc-datename{width:40%}
    .bfc-developed{width:10%}
    .bfc-cycle{width:10%}
    .bfc-action{width:12%}
    .add-briefClient{display:none}
    .fixed{display:none}
    .bck{font-size:18px !important;}
    #add-descipline{padding:0 !important}
    #briefClist{float:right}
    .action-icons {padding-right:8px !important}
    input#briefCname{width:84% !important}
    input#briefCrev{width:15% !important}
    #active-desciplines{padding: 1px 5px !important;}
    @media (max-width:480px){
        .bfc-datecreated{display:none}
        .bfc-brieffrom{width:17%}
        .bfc-datename{width:50%}
        .bfc-developed{display:none}
        .bfc-cycle{display:none}
        .bfc-actions{width:32%}
    }
.bfc-datename1 {width:31%}
.bfc-datename1 {width:50%}
.bfc-datecreated1 {width:12%}
.bfc-datecreated1 {display:none}
.bfc-developed1 {width:18%}
.bfc-developed1 {display:none}
</style>
<script src="../includes/js/fixedheader.js"></script>
<section class="content">
    <div class="container">
        <div class="row">
            <div class="main-content">
                <!--<h5>-->
                <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="form2" name="form2" method="post" action="../../DB/03-scope/MasterFormatDB.php" enctype="multipart/form-data">
                                
                                <div class="widget">
                                    <div class="whead">
                                        <h6>
                                            <i class="fa fa-plus-circle"></i>
                                            Add 
                                        </h6>
                                        <strong><a href="javascript:void(0)" onclick="$('.add-briefClient').hide('slow')" class="teamclose"><i class="fa fa-times"></i></a></strong>
                                    </div>

                                    <div class="formRow">
                                        <div class="col-sm-1-8 label-assign" style="padding-right:0px;">
                                            <label>Masterformat Type*: </label> </div>

                                        <div class="col-sm-2-2 field-assign"  style="padding-left:0px;">
                                            <select required="required" name="importmasterformat" id="importmasterformat" onchange="ImportMF(this.value)" >
         <option value="" selected="selected">Select a Masterformat Type</option>
          <!--<option value="1">Import from Another Project</option>-->
          <option value="2">Import from pmAnywhere</option>
          <option value="3">Import from my CSV File</option>
          <option value="4">Create from Scratch</option>
        </select><span id="import"></span>
                                        </div>

                                        <div class="col-sm-1-8 label-assign" style="padding-right:0px;">
                                            <label>Master Format Name*:</label> </div>
                                        <div class="col-sm-2-2 briefc-field"  style="padding-left:0px;">
                                             <input name="masterformatname" type="text" id="masterformatname" required="required"/> 
                                        </div>
  
                                   </div>
                                         <div class="formRow">
                                        <div class="col-sm-1-8 label-assign" style="padding-right:0px;">
                                        <label> Project Code/ Name*:</label></div>
                                    <div class="col-sm-2-2 field-assign" style="padding-left:0px;">
                                        <select name="projname"  id="projname" required="required">
                                            <option value="">Select</option>
                                            <?php
                                            $result = mysql_query("SELECT projectSerial,projectCode, projectName FROM projects where companySerial = '$id' AND projStatus=1");
                                            while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                                                $projectSerial = $row['projectSerial'];
                                                echo "<option value='$projectSerial'>" . $row["projectCode"] . " - " . $row["projectName"] . "</option>";
                                            }
                                            ?>
                                        </select></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>
                        <?php
                    } else {

                        $WID = $_REQUEST['Edit'];
						$result = mysql_query("SELECT MFList_name, MFList_for_project FROM mflist where MFList_id='$WID'");
						$row = mysql_fetch_array($result , MYSQL_ASSOC);
						$MFList_name = $row["MFList_name"];
                        ?>
                        <div class="edit-formpage">
                            <form id="form" name="form2" method="post" action="../../DB/03-scope/MasterFormatDB.php?Edit=<?php echo $WID; ?>">
                                <div class="widget">
                                    <div class="whead">
                                        <h6>
                                            <div class="fs1 iconb" data-icon=""></div>
                                            Edit </h6>
                                        <strong><a href="javascript:void(0)" onclick="$('.edit-deciplane').hide('slow')" class="teamclose"><i class="fa fa-times"></i></a></strong>

                                    </div>
                                    <div class="formRow">
                                        <div class="col-sm-1-8 label-assign" style="padding-right:0px;">
                                            <label>Master Format Name*:</label></div>
                                        <div class="col-sm-2-2 field-assign"  style="padding-left:0px;">
                    <input name="masterformatname" type="text" id="masterformatname" value="<?php echo $MFList_name;?>" required="required" />
                                        </div>

                                        <div class="col-sm-1-8 label-assign" style="padding-right:0px;">
                                        <label> Project Code/ Name*:</label></div>
                                    <div class="col-sm-2-2 field-assign" style="padding-left:0px;">
                                        <select name="projname"  id="projname" required="required">
                                            <option value="">Select</option>
                                            <?php
                                            $result = mysql_query("SELECT projectSerial,projectCode, projectName FROM projects where companySerial = '$id' AND projStatus=1");
                                            while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                                                $projectSerial = $row['projectSerial'];
                                                echo "<option value='$projectSerial'>" . $row["projectCode"] . " - " . $row["projectName"] . "</option>";
                                            }
                                            ?>
                                        </select></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>

                    <?php }
                }
                ?>

                <div class="table-subject">
                    <div class="widget">
                        <div class="whead">
                            <h6 id="active-desciplines" style="margin-top:8px;" >
                                <b><i class="fa fa-users"></i>Active Master Formats </b> 
                              </h6>
                          <span style="line-height: 35px;">
                                <a onclick="bottomfooterfunc()" href="#hidden-data" class="hidden-entry" >
                                    <!--                            Go to Hidden List-->
                                    <span class="icon-eye_box bck"></span> 
                                </a>&nbsp;
<?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>
                        <table   cellspacing="0"  style="position:relative !important" width="100%" id="active_descipline_tbl">
                            <thead>

                                <tr >
                                    <th class="first"></th>
                                    <th class="bfc-datecreated"   align="left" valign="top" bgcolor="#E2E2E2" scope="col">Date Created<br />
                                        (yyyy.mm.dd)
                                    </th>
                                    <th class="bfc-brieffrom"  align="left" valign="top" bgcolor="#E2E2E2" scope="col">Master Format<br />
      ID</th>
                                    <th class="bfc-datename"  align="left" valign="top" bgcolor="#E2E2E2" scope="col">Master Format <br />
    Name</th>
    <th class="bfc-developed"  align="left" valign="top" bgcolor="#E2E2E2" scope="col">Project <br />
    Name</th>
                                    <th class="bfc-cycle" width="18%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Master Format<br />
      Type</th>
                                    
                                    <th class="bfc-actions action-icons"  align="right" valign="top" bgcolor="#E2E2E2" scope="col"> Actions<br />
                                        Status</th>
                                </tr>
                            </thead>
                            <tbody>
                                 <?php
                                $resultw = mysql_query("SELECT *, projects.projectName FROM mflist,projects where mflist.MFList_for=1 AND mflist.MFList_companyid = '$id' AND projects.projectSerial=mflist.MFList_for_project");
                                while ($row = mysql_fetch_array($resultw, MYSQL_ASSOC)) {
                                    ?>
                                    <tr >
                                        <td class="first"></td>
                                        <td class="bfc-datecreated" align="left" valign="top"  scope="col"><?php echo $row['MFList_datecreation']; ?></td>
                                        <td class="bfc-brieffrom" align="left" valign="top" ><?php echo $row['MFList_id']; ?></td>
                                        <td class="bfc-datename" align="left" valign="top" ><?php echo $row['MFList_name']; ?></td>
                                        <td class="bfc-developed" align="left" valign="top" ><?php echo $row["projectName"]; ?></td>
                                        
                                      <td class="bfc-cycle" align="left" valign="top" ><?php if($row['MFList_type'] =='1') echo "From Another Project"; else if($row['MFList_type'] =='2')  echo "From pmAnywhere"; else if($row['MFList_type'] =='3') echo "From my CSV File"; else if($row['MFList_type'] =='4') echo "From Scratch";?></td>
                                        
                                        <td class="bfc-actions action-icons" walign="right" valign="top">
 											<div class="close-icon">
                                            <a href="javascript:void(0)" onclick="deleteMF('<?php echo $row["MFList_id"]?>')">
                                                    <div class="glyph">
                                                            <div class="fs1 iconb" data-icon="" title="Delete"></div>
                                                    </div>
                                            </a>
                                            </div>
                                            <div class="edit-icon">
                                            <a href="MasterFormat1.php?Edit=<?php echo $row["MFList_id"]; ?>">
                                                   <div class="glyph">
                                                       <div class="fs1 iconb" data-icon="" title="Edit"></div>
                                                    </div>
                                                </a>
                                             </div>
                                            
                                             <?php if ($uacc == "Full Control") { ?>
                                                    <div class="eye-icon">   
                                                        <a href="../../DB/03-scope/MasterFormatDB.php?InActive=<?php echo $row['MFList_id']; ?>">
                                                            <div class="glyph">
                                                                <div class="fs1 iconb" data-icon="" title="Hide" ></div>
                                                            </div>
                                                        </a> 
                                                    </div>
    <?php } else { ?>
                                                    <div class="glyph">
                                                        <div class="fs1 iconb" data-icon="" title="Hide" ></div>
                                                    </div>

    <?php }  ?>  
                                            <a href="MasterFormat2.php?WID=<?php echo $row['MFList_id']; ?>">
                                                <i style="text-align:right; float:right" class="fa fa-folder-o"></i>
                                            </a>
                                            
                                            <a style="text-align:right" href="../../DB/03-scope/MasterFormatDB.php?export=<?php echo $row['MFList_id']; ?>">
                                            <i style="text-align:right; float:right; color:#008000" class="fa fa-download"></i>
                                            </a>
                                            
                                            
                                           
                                          
                                        </td>
                                        <?php
                                        $typid = $row["MFList_id"];
                                        $path = "03-scope";
                                        $type = "MasterFormat1";
                                        $attach = 0;
                                        $reminder = 0;
                                        $note = 1;
                                        include('../includes/noterow2.php');
                                        ?>
                                    </tr>


<?php } ?>
                            </tbody>
                        </table>
                    </div>
                </div>



            </div>

            <div class="divider"><span></span></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="#hidden-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 class="bottom-footer" id="hidden-data">
                <table cellpadding="0" cellspacing="0" width="100%" class="tDark" id="hidden-entry">
                    <thead>
                        <tr >
                            <td class="bfc-datecreated"   align="left" valign="top" bgcolor="#E2E2E2" scope="col">Date Created<br />
                                (yyyy.mm.dd)
                                </th></td>
                            <td class="bfc-brieffrom"  align="left" valign="top" bgcolor="#E2E2E2" scope="col"> Master Format<br />
                          ID</td>
                            <td class="bfc-datename"  align="left" valign="top" bgcolor="#E2E2E2" scope="col">Master Format<br />
                                Name</td>
                            <td class="bfc-developed" width="18%" align="left" valign="top" bgcolor="#E2E2E2" scope="col"><span class="bfc-datename1">Master Format<br /> 
                              Type
</span></td>
                            <td class="bfc-action action-icons"  align="right" valign="top" bgcolor="#E2E2E2" scope="col">Action <br>Status</td>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $result = mysql_query("SELECT * FROM mflist where mflist.MFList_for=0 AND mflist.MFList_companyid = '$id'  ORDER BY MFList_name ASC");
                        while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                           
                                    ?>

                            <tr >
                                <td class="bfc-datecreated" align="left" valign="top"  scope="col"><?php echo $row['MFList_datecreation']; ?></td>
                                <td class="bfc-brieffrom" align="left" valign="top" ><?php echo $row["MFList_id"]; ?><br /></td>
                                <td class="bfc-datename" align="left" valign="top" ><span class="bfc-datename1"><?php echo $row['MFList_name']; ?></span></td>
                                <td class="bfc-developed " align="left" valign="top" >
                                  <?php if($row['MFList_type'] =='1') echo "From Another Project"; else if($row['MFList_type'] =='2')  echo "From pmAnywhere"; else if($row['MFList_type'] =='3') echo "From my CSV File"; else if($row['MFList_type'] =='4') echo "From Scratch";?>
                                </td>
                                <td class="bfc-actions action-icons" valign="top"><?php if ($uacc == "Full Control") { ?>
                                        <a href="../../DB/03-scope/MasterFormatDB.php?Active=<?php echo $row['MFList_id']; ?>">
                                            <div class="glyph">
                                                <div class="fs1 iconb" data-icon="" title="Hide" ></div>
                                            </div>
                                        </a>
    <?php } else { ?>
                                        <div class="glyph">
                                            <div class="fs1 iconb" data-icon="" title="Hide" ></div>
                                        </div>
                            <?php } ?></td>
                            </tr>
<?php } ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</footer>

<script>

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

        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/MasterFormatDB.php?del="+id;

            } 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 >' + d.details + '</div>';
    }

    active_descipline_table = $('#active_descipline_tbl').DataTable({
        "bJQueryUI": false,
        "bAutoWidth": false,
        "columns": [
            {
                "className": 'details-control',
                "orderable": false,
                "defaultContent": '',
            },
            {"data": "bfc-datecreated"},
            {"data": "bfc-brieffrom"},
            {"data": "bfc-datename"},
            {"data": "bfc-developed"},
			{"data": "bfc-cycle"},
            
            {"data": "bfc-actions"},
            {"data": "details", "visible": false}
            
        ],
        "order": [[1, 'desc']],
        "lengthMenu": [[-1, 10, 25, 50], ["All", 10, 25, 50]],
        "sPaginationType": "full_numbers",
        "sDom": '<"tOptions" f><"top">rt<"bottom" pil><"clear">',
        "oLanguage": {
            "sLengthMenu": "<span class='showentries'>Show entries:</span> _MENU_"
        },
        "aoColumnDefs": [{"bSortable": false, "aTargets": [7]}]
    });

    $('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).child(format(active_descipline_table.row(i).data())).show();
        }
        ;


    });




    function bottomfooterfunc()
    {
        $(".bottom-footer").toggle("slow");
    }

    function showConfirm(did) {
        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/BriefClient1DB.php?del=" + did;

            } else {
                return 0;
            }
        });
    }
</script>
<?php include('../includes/footer.php'); ?>