<?php
include('../../includes/checkSession.php');
include('../../includes/con2pma3.php');
include('../includes/header_in.php');
?>
<style>
    .fixed, .first{display:none}
</style>
<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="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">
                                                <?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 the Index*:</label></div>
                                        <div class="col-sm-2-2 field-assign " style="padding-left:0px;">
                                            <input name="pdriname" type="text"  id="pdriname" />
                                        </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>

                                    <div class="formRow">

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

                                            <label>Prepared By*:</label></div>
                                        <div class="col-sm-2-2 field-assign " style="padding-left:0px;">
                                            <select name="preparedby"  id="preparedby">
                                                <?php
                                                $members_result = mysql_query("SELECT internal_personnel_id, internal_personnel_firstName, internal_personnel_lastName FROM internal_personnel where internal_personnel_company_id = '$id' AND internal_personnel_status='1'");
                                                while ($row = mysql_fetch_array($members_result, MYSQL_ASSOC)) {
                                                    $internal_personnel_id = $row["internal_personnel_id"];
                                                    echo "<option value='$internal_personnel_id'>" . $row["internal_personnel_firstName"] . " " . $row["internal_personnel_lastName"] . "</option>";
                                                }
                                                ?>
                                            </select></div>
                                        <div class="col-sm-1-8 label-assign" style="padding-right:0px;">

                                            <label>Checked By*: </label></div>
                                        <div class="col-sm-2-2 field-assign " style="padding-left:0px;">
                                            <select name="checkedby"  id="checkedby">
                                                <?php
                                                $members_result1 = mysql_query("SELECT internal_personnel_id, internal_personnel_firstName, internal_personnel_lastName FROM internal_personnel where internal_personnel_company_id = '$id' AND internal_personnel_status='1'");
                                                while ($row = mysql_fetch_array($members_result1, MYSQL_ASSOC)) {
                                                    $internal_personnel_id = $row["internal_personnel_id"];
                                                    echo "<option value='$internal_personnel_id'>" . $row["internal_personnel_firstName"] . " " . $row["internal_personnel_lastName"] . "</option>";
                                                }
                                                ?>
                                            </select></div>
                                        <div class="col-sm-1-8 label-assign" style="padding-right:0px;">

                                            <label>Approved By*:</label></div>
                                        <div class="col-sm-2-2 field-assign " style="padding-left:0px;">
                                            <select name="approvedby"  id="approvedby">
                                                <?php
                                                $members_result2 = mysql_query("SELECT internal_personnel_id, internal_personnel_firstName, internal_personnel_lastName FROM internal_personnel where internal_personnel_company_id = '$id' AND internal_personnel_status='1'");
                                                while ($row = mysql_fetch_array($members_result2, MYSQL_ASSOC)) {
                                                    $internal_personnel_id = $row["internal_personnel_id"];
                                                    echo "<option value='$internal_personnel_id'>" . $row["internal_personnel_firstName"] . " " . $row["internal_personnel_lastName"] . "</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_PreparedBy = $row["pdri_PreparedBy"];
                        $pdri_CheckedBy = $row["pdri_CheckedBy"];
                        $pdri_ApprovedBy = $row["pdri_ApprovedBy"];
                        ?>
                    <div class="edit-formpage">
                        <form id="form" name="form2" method="post" action="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">
                                            <?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 the Index*:</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; ?>"/>
                                        </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>

                                    <div class="formRow">

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

                                            <label>Prepared By*:</label></div>
                                        <div class="col-sm-2-2 field-assign " style="padding-left:0px;">
                                            <select name="preparedby"  id="preparedby">
                                            <?php
                                            $members_result = mysql_query("SELECT internal_personnel_id, internal_personnel_firstName, internal_personnel_lastName FROM internal_personnel where internal_personnel_company_id = '$id' AND internal_personnel_status='1'");
                                            while ($row = mysql_fetch_array($members_result, MYSQL_ASSOC)) {
                                                $internal_personnel_id = $row["internal_personnel_id"];
                                                if ($internal_personnel_id == $pdri_PreparedBy) {
                                                    echo "<option value='$internal_personnel_id' selected='selected'>" . $row["internal_personnel_firstName"] . " " . $row["internal_personnel_lastName"] . "</option>";
                                                } else {
                                                    echo "<option value='$internal_personnel_id'>" . $row["internal_personnel_firstName"] . " " . $row["internal_personnel_lastName"] . "</option>";
                                                }
                                            }
                                            ?>
                                        </select></div>
                                        <div class="col-sm-1-8 label-assign" style="padding-right:0px;">

                                            <label>Checked By*: </label></div>
                                        <div class="col-sm-2-2 field-assign " style="padding-left:0px;">
                                            <select name="checkedby"  id="checkedby">
                                            
                                            <?php
                                            $members_result1 = mysql_query("SELECT internal_personnel_id, internal_personnel_firstName, internal_personnel_lastName FROM internal_personnel where internal_personnel_company_id = '$id' AND internal_personnel_status='1'");
                                            while ($row = mysql_fetch_array($members_result1, MYSQL_ASSOC)) {
                                                $internal_personnel_id = $row["internal_personnel_id"];
                                                if ($internal_personnel_id == $pdri_CheckedBy) {
                                                    echo "<option value='$internal_personnel_id' selected='selected'>" . $row["internal_personnel_firstName"] . " " . $row["internal_personnel_lastName"] . "</option>";
                                                } else {
                                                    echo "<option value='$internal_personnel_id'>" . $row["internal_personnel_firstName"] . " " . $row["internal_personnel_lastName"] . "</option>";
                                                }
                                            }
                                            ?>
                                        </select></div>
                                        <div class="col-sm-1-8 label-assign" style="padding-right:0px;">

                                            <label>Approved By*:</label></div>
                                        <div class="col-sm-2-2 field-assign " style="padding-left:0px;">
                                            <select name="approvedby"  id="approvedby">
                                            <?php
                                            $members_result2 = mysql_query("SELECT internal_personnel_id, internal_personnel_firstName, internal_personnel_lastName FROM internal_personnel where internal_personnel_company_id = '$id' AND internal_personnel_status='1'");
                                            while ($row = mysql_fetch_array($members_result2, MYSQL_ASSOC)) {
                                                $internal_personnel_id = $row["internal_personnel_id"];
                                                if ($internal_personnel_id == $pdri_ApprovedBy) {
                                                    echo "<option value='$internal_personnel_id' selected='selected'>" . $row["internal_personnel_firstName"] . " " . $row["internal_personnel_lastName"] . "</option>";
                                                } else {
                                                    echo "<option value='$internal_personnel_id'>" . $row["internal_personnel_firstName"] . " " . $row["internal_personnel_lastName"] . "</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">
                        <input type="hidden" id="prjfilval" class="prjfilval">
                        <span class="tOptions" style="border: none;padding: 8px 12px 6px;">

                        </span>
                  <table id="active_descipline_tbl"  cellspacing="0" style="position:relative !important" width="100%">
                      <thead>  <tr>
                                        <th class="thfirst" colspan="8" style="cursor:auto;background: #f4f4f4 !important; height:40px; width:100% !important; padding:0">
                                <div class="whead" style="width:100%;">

                                    <h6 id="active-desciplines" >

                                        <b>

                                            <i class="fa fa fa-tasks"></i>

                                            List OF PDRI 

                                        </b> 

                                        <span style="line-height: 35px;">

                                        <?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>

                                    </h6>

                                    <div class="clear"></div>

                                    <span class="filters"><?php //echo $prjList ?>
                                        <!--<input type='text' class="search-filed" id='searchdt' onkeyup="getsearch(this.value);" placeholder='Search'>-->
                                        <div class="searchLine">
<!--                                            <form onsubmit="getsearch();
                            return false;">
                                                <input type="text" name="search" class="ac search-filed" id='searchdt' onchange="setsearchtext(this.value);" placeholder="Ref | Subject" autocomplete="off"><span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span>
                                                <button type="submit" name="find"  value="" onclick="getsearch();" ><span class="icos-search"></span></button>
                                            </form>-->
                                        </div>

                                    </span>

                                </div>
                                </th>
                                </tr></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<br />
                            Name</th>
                        <th class="assign-list" align="left" valign="top" bgcolor="#E2E2E2" scope="col">PDRI<br />
                            Name</th>
                        <th class="assign-issue" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Developed<br />
                            By</th>
                        <th class="assign-code" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Client<br />
                            Code</th>
                        <th class=" ini-actions action-icons" align="right" valign="top" bgcolor="#E2E2E2" scope="col"> Start/ Edit<br />
                            Del</th>
                    </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='1' AND projects.projectSerial=pdri.project_id AND client.clientSerial=pdri.client_id  ORDER BY pdri_name ASC");
                    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                        $PreparedBy = '';
                        $CheckedBy = '';
                        $ApprovedBy = '';

                        $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);

                        $resultChecked = mysql_query("SELECT internal_personnel_firstName, internal_personnel_lastName FROM internal_personnel where internal_personnel_id='" . $row["pdri_CheckedBy"] . "'");
                        $CheckedBy .= mysql_result($resultChecked, 0, 0);
                        $CheckedBy .=" " . mysql_result($resultChecked, 0, 1);

                        $resultAppro = mysql_query("SELECT internal_personnel_firstName, internal_personnel_lastName FROM internal_personnel where internal_personnel_id='" . $row["pdri_ApprovedBy"] . "'");
                        $ApprovedBy .= mysql_result($resultAppro, 0, 0);
                        $ApprovedBy .=" " . mysql_result($resultAppro, 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" class="ablks5"><?php echo $row["projectName"]; ?></td>
                            <td class="assign-list"  align="left" valign="top" >PDRI-<?php echo $row["pdri_name"]; ?></td>
                            <td class="assign-issue" align="left" valign="top" >Prepared By:<?php echo $PreparedBy; ?><br />
                                Checked By:<?php echo $CheckedBy; ?><br />
                                Approved By:<?php echo $ApprovedBy; ?></td>
                            <td class="assign-code" align="left" valign="top" ><?php echo $row["clientCode"]; ?></td>
                            <td class=" ini-actions action-icons" align="right" valign="top" >&nbsp;<a href="PDRI-ONLINE.htm"><img src="../images/icon-insert.jpg" width="15" height="15" border="0" /></a>
                                <?php if ($uacc == "Full Control") { ?><a href="PDRI.php?Edit=<?php echo $row["pdri_id"]; ?>"><img src="../images/icon-edit1.png" width="15" height="15" border="0" alt="Edit"  title="Edit" /></a><?php } else { ?><img src="../images/icon-edit1.png" width="15" height="15" border="0" alt="Edit"  title="Edit" /><?php } ?>
                                <?php if ($uacc == "Full Control") { ?>
                                    <a href="PDRIDB.php?del=<?php echo $row["pdri_id"]; ?>" onclick="return confirm('This record will be deleted and cannot be retrieved. Press OK to Delete.')"><img src="../images/icon-del1.png" width="16" height="16" border="0" alt="Delete"  title="Delete" /></a><?php } else { ?><img src="../images/icon-del1.png" width="16" height="16" border="0" alt="Delete"  title="Delete" /><?php } ?></td>
                        
                              <?php
                        $typid = $row["pdri_id"];
                        $path = "03-scope";
                        $type = "PDRI";
                        $attach = 0;
                        $reminder = 0;
                        $note = 1;
                        include('../includes/noterow.php');
                        ?>
                        
                        </tr>
                        
                      
                    <?php } ?>  
                        </tbody>
                </table>
                  </div>

                </div>
                
                
            </div>
        </div>
    </div>
</section>
          <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": "date_created" },
    { "data": "discipline_name" },
    { "data": "discipline_code" },
    { "data": "action" },
    { "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": [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).child( format(active_descipline_table.row(i).data()) ).show();
        };
        

    } );

</script>

