<?php
include('../../includes/checkSession.php');
include('../../includes/con2pma3.php');
include('../includes/header_in.php');


$order_type = "ASC";
$order_par = "projectCode";
if (isset($_REQUEST['otype'])) {
    $order_type = $_REQUEST['otype'];
}

if (isset($_REQUEST['opar'])) {
    $order_par = $_REQUEST['opar'];
}
?>
<style>
       .imgview{
        height: 16px;
    width: 16px;
    margin-left: 4px;
    margin-top: 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:8%}
    .bfc-brieffrom{width:11%}
    .bfc-datename{width:31%}
    .bfc-developed{width:18%}
    .bfc-cycle{width:14%}
    .bfc-action{width:12%}
    .add-briefClient{display:none}
    .fixed{display:none}
    .bck{font-size:18px !important; line-height:13px;}
    #add-descipline{padding:0 !important}
    #briefClist{float:right}
     .dataTable thead i{
        margin-top: -5px;
    }
    select{width:100% !important}
    .dataTable, .FixedHeader_Header {width:100% !important}
    div.FixedHeader_Cloned th,
div.FixedHeader_Cloned td {
	background-color: white !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%}
    }
</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") {
    if (!isset($_REQUEST['Edit'])) {
        ?>

                        <div class="add-formpage">
                            <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>
                                <form method="post" enctype="multipart/form-data" name="form1" id="form1" action="../../DB/03-scope/SpecsDB.php" onsubmit="return validatescopeSpecs()">

                                    <div class="formRow">
                                        <div class="col-sm-1-8 label-assign" style="padding-right:0px;">
                                            <label>Project Name*:</label> </div>
                                        <div class="col-sm-2-2 briefc-field"  style="padding-left:0px;">
                                            <select name="projname"  id="projname" class="single-select">         
                                                <?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="col-sm-1-8 label-assign" style="padding-right:0px;">
                                            <label>Client*:</label> </div>
                                        <div class="col-sm-2-2 briefc-field"  style="padding-left:0px;">
                                            <select name="clientname"  id="clientname" class="single-select">          
                                                <?php
                                                $result = mysql_query("SELECT clientSerial, clientName, clientCode FROM client where companySerial = '$id' AND clientStatus=1");
                                                //echo $result."ll";
                                                while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                                                    $clientSerial = $row["clientSerial"];
                                                    echo "<option value='$clientSerial'>" . $row["clientCode"] . " - " . $row["clientName"] . "</option>";
                                                }
                                                ?>
                                            </select> </div>
                                    </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 briefc-field"  style="padding-left:0px;">
                                            <select name="Specmf"  id="Specmf" class="single-select">        
                                                <?php
                                                $result = mysql_query("SELECT MFList_id, MFList_name FROM mflist where MFList_companyid = '$id'");
                                                //echo $result."ll";
                                                while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                                                    $MFList_id = $row["MFList_id"];
                                                    echo "<option value='$MFList_id'>" . $row["MFList_id"] . " - " . $row["MFList_name"] . "</option>";
                                                }
                                                ?>
                                            </select> </div>
                                        <div class="col-sm-1-8 label-assign" style="padding-right:0px;">
                                            <label>Title of Listing*:</label> </div>
                                        <div class="col-sm-2-2 briefc-field"  style="padding-left:0px;">
                                            <input name="briefname" type="text"  id="briefname" value="" size="40" class="single-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>
                                </form>
                            </div>
                        </div>
                    <?php
                    } else {

                        $SpID = $_REQUEST['Edit'];
                        $result = mysql_query("SELECT * FROM specs where SPECID ='$SpID'");

                        $row = mysql_fetch_array($result, MYSQL_ASSOC);

                        $specID = $row['SPECID'];
                        $title = $row['title'];
                        $spec_project = $row['spec_project'];
                        $spec_client = $row['spec_client'];
                        $spec_master = $row['spec_master'];
                        $sowProject = $row['sowProject'];
                        ?>
                        <div class="edit-formpage">
                                
                            <div class="widget">

                                <div class="whead">

                                    <h6>

                                        <i class="fa fa-pencil-square-o"></i>

                                        Edit

                                    </h6>

                                    <strong><a href="javascript:void(0)" onclick="hideeform()" class="teamclose"><i class="fa fa-times"></i></a></strong> </div>
                                 
                        <form method="post" enctype="multipart/form-data" name="form1" id="form1" action="../../DB/03-scope/SpecsDB.php?Edit=<?php echo $specID; ?>" onsubmit="return validatescopeSpecs()">
                                  <div class="formRow">
                                        <div class="col-sm-1-8 label-assign" style="padding-right:0px;">
                                            <label>Project Name*:</label> </div>
                                        <div class="col-sm-2-2 briefc-field"  style="padding-left:0px;">
                                       <select name="projname"  id="projname">          
        <?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 = $rows['projectSerial'];
            if ($rows["projectSerial"] == $spec_project)
                echo "<option selected='selected' value='$projectSerial'>" . $rows["projectCode"] . " - " . $rows["projectName"] . "</option>";
            else
                echo "<option value='$projectSerial'>" . $rows["projectCode"] . " - " . $rows["projectName"] . "</option>";
        }
        ?>
                                        </select></div>
                                        <div class="col-sm-1-8 label-assign" style="padding-right:0px;">
                                            <label>Client*:</label> </div>
                                        <div class="col-sm-2-2 briefc-field"  style="padding-left:0px;">
                                          <select name="clientname"  id="clientname">          
        <?php
        $result = mysql_query("SELECT clientSerial, clientName, clientCode FROM client where companySerial = '$id' AND clientStatus=1");
        //echo $result."ll";
        while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            $clientSerial = $row['clientSerial'];
            if ($row["clientSerial"] == $spec_client)
                echo "<option selected='selected' value='$clientSerial'>" . $row["clientName"] . " - " . $row["clientContactName"] . "</option>";
            else
                echo "<option value='$clientSerial'>" . $row["clientName"] . " - " . $row["clientContactName"] . "</option>";
        }
        ?>
                                        </select> </div>
                                    </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 briefc-field"  style="padding-left:0px;">
                                            <select name="Specmf"  id="Specmf">        
        <?php
        $result = mysql_query("SELECT MFList_id, MFList_name FROM mflist where MFList_companyid = '$id'");
        //echo $result."ll";
        while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            $MFList_id = $row["MFList_id"];
            if ($row["clientSerial"] == $spec_master)
                echo "<option value='$MFList_id'>" . $row["MFList_id"] . " - " . $row["MFList_name"] . "</option>";
            else
                echo "<option value='$MFList_id'>" . $row["MFList_id"] . " - " . $row["MFList_name"] . "</option>";
        }
        ?>
                                        </select></div>
                                        <div class="col-sm-1-8 label-assign" style="padding-right:0px;">
                                            <label>Title of Listing*:</label> </div>
                                        <div class="col-sm-2-2 briefc-field"  style="padding-left:0px;">
                                             <input name="briefname" type="text"  id="briefname" value="<?php echo $title; ?>" size="40" />
                                        </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>
                            
                      
                        </form>
                   </div>
            </div>
    <?php }
} ?>
              <div class="table-subject">

            <!--  -->

            <div class="widget">
                <div class="whead">
                    <h6 id="active-desciplines" >
                        <b>
                            <i class="fa fa-book"></i>                    
                            Specs
                        </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>
                        <?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>

                    <span class="tOptions" style="border: none;padding: 8px 12px 6px;">

                    </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">Project<br />
                            Code </th>
                   <th class="bfc-brieffrom"  align="left" valign="top" bgcolor="#E2E2E2" scope="col">Date Created<br />
                            (yyyy.mm.dd)
                            </th>
                          <th class="bfc-datename"  align="left" valign="top" bgcolor="#E2E2E2" scope="col">Specifications Listing ID/ Title/ Codes<br />
                            Project      Name/ 
                            Client Name</th>
                            <th class="bfc-developed" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Work Flow/<br /> 
                            Assignments
                        </th>
                       <th class="bfc-cycle" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Work Flow/<br />
                            Status<br /></th>
                        <th class="bfc-actions action-icons" align="right" valign="top" bgcolor="#E2E2E2" scope="col">Actions<br />
                            Status
                            </th>
                    </tr>
                    </thead>
                    <tbody>
<?php
$result = mysql_query("SELECT DISTINCT projects.projectName,projects.projectCode,client.clientName,mflist.MFList_name,specs.spec_preparedby,specs.title,specs.SPECID,specs.spec_project,specs.spec_client,specs.companyID,specs.dateCreated,spec_status
FROM projects,client,specs,mflist
WHERE specs.spec_project = projects.projectSerial
AND specs.spec_client = client.clientSerial
AND specs.spec_master = mflist.MFList_id
AND specs.companyID = '$id' AND specs.spec_status=1 ORDER BY $order_par $order_type");

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $PreparedBy = "";
    if ($row["spec_preparedby"] == $row["companyID"]) {
        $resultPre = mysql_query("SELECT firstName, lastName FROM login where loginId='" . $row["spec_preparedby"] . "'");
        $PreparedBy .= mysql_result($resultPre, 0, 0);
        $PreparedBy .=" " . mysql_result($resultPre, 0, 1);
    } else {
        $resultPre = mysql_query("SELECT internal_personnel_firstName, internal_personnel_lastName FROM internal_personnel where internal_personnel_id='" . $row["spec_preparedby"] . "'");
        $PreparedBy .= mysql_result($resultPre, 0, 0);
        $PreparedBy .=" " . mysql_result($resultPre, 0, 1);
    }
    ?>
                        <tr >
                            <td class="first"></td>
                            <td class="bfc-datecreated"  align="left" valign="top" scope="col"><?php echo $row['projectCode']; ?></td>
                            <td  class="bfc-brieffrom" align="left" valign="top" scope="col"><?php echo $row['dateCreated']; ?></td>
                            <td  class="bfc-datename" align="left" valign="top" >SPEC-<?php echo $row['SPECID']; ?> - <?php echo $row['title']; ?><br />
    <?php echo $row['projectName']; ?> /
    <?php echo $row['clientName']; ?>
                                <br />
                                <?php echo $row['MFList_name']; ?></td>
                            <td class="bfc-developed" align="left" valign="top" >RR</td>
                            <td class="bfc-cycle" align="left" valign="top" >Listing Created</td>
                            <td class="bfc-actions action-icons" align="right" valign="top"> 
                                 <?php if ($uacc == "Full Control") { ?>
                                                <div class="close-icon"> <a href="javascript:void(0)" onclick="showConfirm('<?php echo $row["SPECID"]; ?>')">
                                                        <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="Specs1.php?Edit=<?php echo $row["SPECID"]; ?>">
                                                        <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 } ?>
                                 <?php if ($uacc == "Full Control") { ?><div class="eye-icon"><a href="../../DB/03-scope/SpecsDB.php?InActive=<?php echo $row['SPECID']; ?>">
                                                        <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 } ?> 
                                <div class="edit-icon">
                                 <a href="Specs2PVall.php?BID=<?php echo $row["SPECID"];; ?>">  
        <img class="imgview" src="../includes/images/icons/icon-view.png" title="View detail">
    </a>
              </div>                
                                
           <div class="edit-icon"></div>
                            </td>
                         <?php
                               $typid = $row["SPECID"];
                               $path = "03-scope";
                              $type = "Specs1";
                                $attach = 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> &nbsp;| 
                        <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">Project<br />
            Code <img src="../images/icon-down.png" width="12" height="8" border="0" /></td>
        <td class="bfc-brieffrom"  align="left" valign="top" bgcolor="#E2E2E2" scope="col">Date Created<br />
            (yyyy.mm.dd)
            </th></td>
        <td  class="bfc-datename" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Specifications Listing ID/ Title/ Codes<br />
            Project      Name/ 
            Client Name</td>
        <td class="bfc-developed"  align="left" valign="top" bgcolor="#E2E2E2" scope="col">Work Flow/<br /> 
            Assignments
        </td>
        <td class="bfc-cycle"  align="left" valign="top" bgcolor="#E2E2E2" scope="col">Work Flow/<br />
            Status<br /></td>
        <td  class="bfc-actions action-icons"  align="right" valign="top" bgcolor="#E2E2E2" scope="col"> Unhide</td>
    </tr>
</thead>
<tbody>
    <?php
    $result = mysql_query("SELECT DISTINCT projects.projectName,projects.projectCode,client.clientName,mflist.MFList_name,specs.spec_preparedby,specs.title,specs.SPECID,specs.spec_project,specs.spec_client,specs.companyID,specs.dateCreated,spec_status
FROM projects,client,specs,mflist
WHERE specs.spec_project = projects.projectSerial
AND specs.spec_client = client.clientSerial
AND specs.spec_master = mflist.MFList_id
AND specs.companyID = '$id' AND specs.spec_status=0 ORDER BY $order_par $order_type");

    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $PreparedBy = "";
        if ($row["spec_preparedby"] == $row["companyID"]) {
            $resultPre = mysql_query("SELECT firstName, lastName FROM login where loginId='" . $row["spec_preparedby"] . "'");
            $PreparedBy .= mysql_result($resultPre, 0, 0);
            $PreparedBy .=" " . mysql_result($resultPre, 0, 1);
        } else {
            $resultPre = mysql_query("SELECT internal_personnel_firstName, internal_personnel_lastName FROM internal_personnel where internal_personnel_id='" . $row["spec_preparedby"] . "'");
            $PreparedBy .= mysql_result($resultPre, 0, 0);
            $PreparedBy .=" " . mysql_result($resultPre, 0, 1);
        }
        ?>
        <tr >
            <td class="bfc-datecreated" align="left" valign="top" scope="col"><?php echo $row['projectCode']; ?></td>
            <td class="bfc-brieffrom" align="left" valign="top" scope="col"><?php echo $row['dateCreated']; ?></td>
            <td class="bfc-datename" align="left" valign="top" >SPEC-<?php echo $row['SPECID']; ?> - <?php echo $row['title']; ?><br />
                <?php echo $row['projectName']; ?> /
                <?php echo $row['clientName']; ?>
                <br />
    <?php echo $row['MFList_name']; ?></td>
            <td class="bfc-developed" align="left" valign="top" >RR</td>
            <td class="bfc-cycle" align="left" valign="top" >Listing Created</td>
            <td class="bfc-actions action-icons" align="right" valign="top">  <?php if ($uacc == "Full Control") { ?>
                    <a href="../../DB/03-scope/SpecsDB.php?Active=<?php echo $row['SPECID']; ?>"><img border="0" src="../images/icon-look.jpg" width="22" height="14" title="Active" alt="Active"/></a><?php } else { ?>
                    <img src="../images/icon-look.jpg" width="22" height="14" border="0" title="Active" alt="Active" />
        <?php } ?> </td>
        </tr>
<?php } ?>
   
</table>

  </div>
            </div>
        </div>
    </footer>
<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, 'asc']],
        "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/SpecsDB.php?del=" + did;

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