<?php
include('../../includes/checkSession.php');
include('../../includes/con2pma3.php');
include('../includes/header_in.php');
?>
<style>
    .fixed, .first{display:none}
    .bck{font-size: 18px !important; line-height:13px !important}
    #add-descipline{padding:0 !important}
.bfc-cycle {width:14%}

.action-icons {padding-right:8px !important}
.bfc-action {width:12%}
.bfc-actions {width:32%}
.bfc-brieffrom {width:11%}
.bfc-brieffrom {width:17%}
.bfc-cycle1 {width:14%}
.bfc-cycle1 {display:none}
.bfc-datecreated {width:12%}
.bfc-datecreated {display:none}
.bfc-datename {width:31%}
.bfc-datename {width:50%}
.bfc-developed {width:18%}
.bfc-developed {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") {
                    if (!isset($_REQUEST['Edit'])) {
                        ?>
                        <div class="add-formpage">
                            <form id="form" name="form2" method="post" action="../../DB/03-scope/PDRIDB.php" onsubmit="return validatescopePDRI()">
                                <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 label-assign" style="padding-right:0px;">

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

                                            <label>Name | Rev*:</label></div>
                                        <div class="col-sm-2-2 field-assign " style="padding-left:0px;">
                                            <input name="pdriname" type="text"  id="pdriname" style="width:78% !important" placeholder="Name" />
                                            <input name="pdrirev" type="text"  id="pdrirev" style="width:20% !important"  placeholder="Rev"/>
                                       </div>

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

                                            <label>Client*:</label></div>
                                        <div class="col-sm-2-2 field-assign " style="padding-left:0px;">
                                            <select name="clientname"  id="clientname">
                                                <?php
                                                $result = mysql_query("SELECT clientCode, clientSerial, clientName, clientContactName 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["clientName"] . "</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 {

                        $pdriID = $_REQUEST['Edit'];
                        $result = mysql_query("SELECT * FROM pdri where pdri_id='$pdriID'");
                        $row = mysql_fetch_array($result, MYSQL_ASSOC);
                        $project_id = $row["project_id"];
                        $client_id = $row["client_id"];
                        $pdri_name = $row["pdri_name"];
                        $pdri_rev = $row["pdri_rev"];
                        ?>
                        <div class="edit-formpage">
                            <form id="form" name="form2" method="post" action="../../DB/03-scope/PDRIDB.php?Edit=<?php echo $pdriID; ?>" onsubmit="return validatescopePDRI()">

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

                                            <label>Name | Rev*:</label></div>
                                            
                                             <div class="col-sm-2-2 field-assign " style="padding-left:0px;">
                                            <input name="pdriname" type="text"  id="pdriname" value="<?php echo $pdri_name; ?>" style="width:78% !important" placeholder="Name" />
                                            <input name="pdrirev" type="text" value="<?php echo $pdri_rev;?>"  id="pdrirev" style="width:20% !important"  placeholder="Rev"/>
                                       </div>
                                        
                                        <div class="col-sm-1-8 label-assign" style="padding-right:0px;">

                                            <label>Client*:</label></div>
                                        <div class="col-sm-2-2 field-assign " style="padding-left:0px;">
                                            <select name="clientname"  id="clientname">
                                                <?php
                                                $result = mysql_query("SELECT clientCode, clientSerial, clientName, clientContactName FROM client where companySerial = '$id' AND clientStatus='1'");
                                                //echo $result."ll";
                                                while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                                                    $clientSerial = $row["clientSerial"];
                                                    if ($client_id == $clientSerial) {
                                                        echo "<option selected='selected' value='$clientSerial'>" . $row["clientName"] . "</option>";
                                                    } else {
                                                        echo "<option value='$clientSerial'>" . $row["clientName"] . "</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" >
                                <b>
                                    <i class="fa fa-tasks"></i>List OF PDRI
                                </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="add-descipline"><span class="icon-plus_box  bck"></span></a>
                                        <a onclick="hideform()" style="cursor:pointer" class="hideform-btn " id="add-descipline"><span class="icon-minus_box  bck"></span></a>

                                    <?php } else {
                                        ?>
                                        <a onclick="showeditform()" style="cursor:pointer"  class="eform-btn " id="add-descipline"><i class="fa fa-pencil-square-o green-icon"></i></a>
                                        <a onclick="hideeform()" style="cursor:pointer" class="hideeform-btn " id="add-descipline"><span class="icon-minus_box  bck"></span></a>

                                    <?php }
										 }
                                    ?>


                                </span>

                            


                        </div>

                      <table id="active_descipline_tbl"  cellspacing="0" style="position:relative !important" width="100%">
                            <thead>  


                                <tr >
                                    <th class="first"></th>
                                    <th class="assign-dated " align="left" valign="top" bgcolor="#E2E2E2" scope="col">Date Created<br />
                                        (yyyy.mm.dd)
                                    </th>
                                    <th class="assign-id" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Project 
                                        Name<br />Client Name</th>
                                    <th class="assign-list" align="left" valign="top" bgcolor="#E2E2E2" scope="col">PDRI Name/<br />
                                        Revision</th>
                                    <th class="assign-issue" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Prepared<br />
                                        By</th>
                                    <th class="assign-code" align="left" valign="top" bgcolor="#E2E2E2" scope="col"><span class="bfc-cycle">Sent<br />
Status</span></th>
                                    <th class=" ini-actions action-icons" align="right" valign="top" bgcolor="#E2E2E2" scope="col"> Actions<br />
                                      Status  </th>
                                </tr>
                            </thead>
                            </thead>
                            <tbody>
                                <?php
                                $result = mysql_query("SELECT pdri.*,projects.projectName,client.clientCode FROM projects,client,pdri where pdri.companyID='$id' AND pdri.pdri_status='1' AND projects.projectSerial=pdri.project_id AND client.clientSerial=pdri.client_id  ORDER BY creationDate DESC,  pdri_name ASC");
                                while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                                    $PreparedBy = "";
    if ($row["pdri_PreparedBy"] == 0) {
        $resultPre = mysql_query("SELECT firstName, lastName FROM login where loginId='" . $id . "'");
        $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["pdri_PreparedBy"] . "'");
        $PreparedBy .= mysql_result($resultPre, 0, 0);
        $PreparedBy .=" " . mysql_result($resultPre, 0, 1);
    }

                                    
                                    ?>

                                    <tr >
                                        <td class="first"></td>
                                        <td class="assign-dated " align="left" valign="top"  scope="col"><?php echo $row["creationDate"]; ?></td>
                                        <td class="assign-id" align="left" valign="top"><?php echo $row["projectName"]; ?><span class="assign-code"> / <?php echo $row["clientCode"]; ?></span></td>
                                        <td class="assign-list"  align="left" valign="top" ><?php echo $row["pdri_name"]; ?><br /><?php echo $row["pdri_rev"]; ?></td>
                                        <td class="assign-issue" align="left" valign="top" ><?php echo $PreparedBy; ?><br /></td>
                                        <td class="assign-code" align="left" valign="top" ><span class="WBSl-remarks">
                                          <?php if($row["pdri_status"]==3){?>
                                          Sent for Review
                                          <?php } else echo "Not Sent for Review" ?>
                                      </span></td>
                                        <td class=" ini-actions action-icons" align="right" valign="top" >
                                            <a href="PDRI-ONLINE.php?pid=<?php echo $row["pdri_id"]; ?>">
                                                <img style="margin-top:3px" src="../images/icon-insert.jpg" width="15" height="15" border="0" /></a>
 <?php if ($uacc == "Full Control") { ?>
                                                <div class="close-icon"> <a href="javascript:void(0)" onclick="showConfirm('<?php echo $row["pdri_id"]; ?>')">
                                                        <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="PDRI.php?Edit=<?php echo $row["pdri_id"]; ?>">
                                                        <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/PDRIDB.php?InActive=<?php echo $row['pdri_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 } ?> 
                                      </td>

                                        <?php
                                        $typid = $row["pdri_id"];
                                        $path = "03-scope";
                                        $type = "PDRI";
                                        $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> &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">Date Created<br />
                                (yyyy.mm.dd)
                                </th></td>
                            <td class="bfc-brieffrom"  align="left" valign="top" bgcolor="#E2E2E2" scope="col"> Brief <br />Type</td>
                            <td class="bfc-datename"  align="left" valign="top" bgcolor="#E2E2E2" scope="col">ID - Title (REV)<br />
                                Project      Name/ 
                                Client Name</td>
                            <td class="bfc-developed" width="18%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Prepared <br />By</td>
                            <td class="bfc-cycle"  align="left" valign="top" bgcolor="#E2E2E2" scope="col">Sent<br />
Status
</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 pdri.*,projects.projectName,client.clientCode FROM projects,client,pdri where pdri.companyID='$id' AND pdri.pdri_status='0' AND projects.projectSerial=pdri.project_id AND client.clientSerial=pdri.client_id  ORDER BY creationDate DESC, pdri_name ASC");
                                while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                                    $PreparedBy = "";
    if ($row["pdri_PreparedBy"] == 0) {
        $resultPre = mysql_query("SELECT firstName, lastName FROM login where loginId='" . $id . "'");
        $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["pdri_PreparedBy"] . "'");
        $PreparedBy .= mysql_result($resultPre, 0, 0);
        $PreparedBy .=" " . mysql_result($resultPre, 0, 1);
    }

                                    
                                    ?>

                            <tr >
                                <td class="bfc-datecreated" align="left" valign="top"  scope="col"><span class="assign-dated "><?php echo $row["creationDate"]; ?></span></td>
                                <td class="bfc-brieffrom" align="left" valign="top" ><span class="assign-id"><?php echo $row["projectName"]; ?><span class="assign-code"> / <?php echo $row["clientCode"]; ?></span></span><br /></td>
                                <td class="bfc-datename" align="left" valign="top" ><span class="assign-list"><?php echo $row["pdri_name"]; ?><br />
                                <?php echo $row["pdri_rev"]; ?></span></td>
                                <td class="bfc-developed " align="left" valign="top" ><span class="assign-issue"><?php echo $PreparedBy; ?></span></td>
                                <td class="bfc-cycle" align="left" valign="top" ><span class="WBSl-remarks">
                                  <?php if($row["pdri_status"]==3){?>
Sent for Review
<?php } else echo "Not Sent for Review" ?>
                                </span></td>
                                <td class="bfc-actions action-icons" valign="top"><?php if ($uacc == "Full Control") { ?>
                                        <a href="../../DB/03-scope/PDRIDB.php?Active=<?php echo $row['pdri_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 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="notes">' + d.details + '</div>';
    }



   
    active_descipline_table = $('#active_descipline_tbl').DataTable({
        "bJQueryUI": false,
        "bAutoWidth": false,
        "columns": [
            {
                "className": 'details-control',
                "orderable": false,
                "defaultContent": '',
            },
            {"data": "assign-dated"},
            {"data": "assign-id"},
            {"data": "assign-list"},
            {"data": "assign-issue"},
            {"data": "assign-code"},
            {"data": "ini-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": [3]}]
    });
	 $('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 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/PDRIDB.php?del=" + did;

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

