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

<html><head><meta charset="utf-8"><title>pmAnywhere - Scope Module</title>
    <link href="03-00Scope-StylesPDRI-toponly1.css" rel="stylesheet" type="text/css" />
    <!--<link href="pma3buttonstyles.css" rel="stylesheet" type="text/css" />-->
    <script src="jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="script-select-addressee.js"></script>
    <script src="ckeditor/ckeditor.js"></script>
    <!--<link href="widgEditor/css/widgEditor.css" rel="stylesheet" type="text/css" />-->
    <!--<script src="widgEditor/scripts/widgEditor.js"></script>-->

</head>



<script>

    function sendforinitiate(bid)
    {
        var c = confirm("Are you sure you want to send this document for review? It will show in the list of Initiated Documents");
        if (c)
        {
            window.location.href = "03-03Scope-01PDRI02-DB.php?send=" + bid;
        }
        else
        {
            return false;
        }
    }
</script>
<SCRIPT language=javascript>

    //--------------In case a change is made to the form , change this

    Icatnum = new Array("A", "B", "C", "D", "E")
    IIcatnum = new Array("F", "G", "H", "I", "J", "K")
    IIIcatnum = new Array("L", "M", "N", "O")

    //----------------------------------------------------------------------
    function fnshowopen(fshow) {

        if (fshow == 1)
            document.getElementById('divopenfile').style.display = "block"
        else
            document.getElementById('divopenfile').style.display = "none"

    }
    //----------------------------------------------------------------------
    function fnclicked(whichelement) {

        for (icnt = 0; icnt < document.all(whichelement).length; icnt++)

            if (document.all(whichelement)[icnt].checked) {
                document.all(whichelement + "score").innerHTML =
                    "<font color='336699' size='2'><b>" + document.all(whichelement)[icnt].value + "</b></font>"

            }

        whichalpha = whichelement.substring(0, 1)
        numsofar = whichelement.substring(1)

        subtotal = 0
        for (icnt = 1; icnt <= numsofar; icnt++)
            subtotal = subtotal + parseInt(document.all(whichalpha + icnt + "score").innerText)

        document.all(whichelement + "sub").innerHTML =
            "<font color='scarlet' size='2'><b>" + subtotal + "</b></font>"


        alphanum = fnnumber(whichalpha)

        numsofar = parseInt(numsofar) + 1

        for (icnt = numsofar; icnt <= alphanum; icnt++) {
            //alert(numsofar+"loop"+alphanum+"if"+icnt);
            subtotal = subtotal + parseInt(document.all(whichalpha + icnt + "score").innerText);

            if (parseInt(document.all(whichalpha + icnt + "sub").innerText) != 0)
                document.all(whichalpha + icnt + "sub").innerHTML =
                    "<font color='scarlet' size='2'><b>" + subtotal + "</b></font>"
        }

        newtotal = 0

        for (icnt = 1; icnt <= alphanum; icnt++){

            newtotal = newtotal + parseInt(document.all(whichalpha + icnt + "score").innerText)

        }

        document.all(whichalpha + "totscore").innerHTML =  newtotal;
        document.all(whichalpha + "totsub").innerHTML = newtotal;


        fnassigncattotals()

    }
    //----------------------------------------------------------------------
    function fnreset() {

        //document.form1.submit()

    }
    //----------------------------------------------------------------------
    function fnnumber(alphapicked) {

        switch (alphapicked) {
//--------------In case a change is made to the form , change this
            case "A" :
                numpicked = 3
                break
            case "B" :
                numpicked = 8
                break
            case "C" :
                numpicked = 2
                break
            case "D" :
                numpicked = 6
                break
            case "E" :
                numpicked = 3
                break
            case "F" :
                numpicked = 6
                break
            case "G" :
                numpicked = 13
                break
            case "H" :
                numpicked = 2
                break
            case "I" :
                numpicked = 2
                break
            case "J" :
                numpicked = 3
                break
            case "K" :
                numpicked = 6
                break
            case "L" :
                numpicked = 3
                break
            case "M" :
                numpicked = 3
                break
            case "N" :
                numpicked = 3
                break
            case "O" :
                numpicked = 6
                break

            default :
                alert("Contact the administrator to update the program")

        }

        return numpicked
    }
    //----------------------------------------------------------------------
    function fnassigncattotals() {

        cattotal = 0
        grandTotal = 0

        for (icnt = 0; icnt < Icatnum.length; icnt++) {

            cattotal = cattotal + parseInt(document.all(Icatnum[icnt] + "totscore").innerText)

        }

        document.all("Icattotscore").innerHTML =
            "<font color='CA0E00' size='3'><b>" + cattotal + "</b></font>"

        document.all("Icattotsub").innerHTML =
            "<font color='CA0E00' size='3'><b>" + cattotal + "</b></font>"

        grandTotal += cattotal;
        cattotal = 0

        for (icnt = 0; icnt < IIcatnum.length; icnt++)
            cattotal = cattotal + parseInt(document.all(IIcatnum[icnt] + "totscore").innerText)

        document.all("IIcattotscore").innerHTML = "<font color='CA0E00' size='3'><b>" + cattotal + "</b></font>";

        document.all("IIcattotsub").innerHTML = "<font color='CA0E00' size='3'><b>" + cattotal + "</b></font>";

        grandTotal += cattotal;
        cattotal = 0

        for (icnt = 0; icnt < IIIcatnum.length; icnt++)
            cattotal = cattotal + parseInt(document.all(IIIcatnum[icnt] + "totscore").innerText)

        document.all("IIIcattotscore").innerHTML = "<font color='CA0E00' size='3'><b>" + cattotal + "</b></font>";

        document.all("IIIcattotsub").innerHTML = "<font color='CA0E00' size='3'><b>" + cattotal + "</b></font>";

        grandTotal += cattotal;

        document.all("lblTotal").innerHTML = "<font color='black' size='3'><b>" + grandTotal + "</b></font>";
    }
    //----------------------------------------------------------------------
    function fnentry(pos, clist, cdelim) {

        ilcnt = 0
        ipoint = 0
        ifnentry = 0

        clocallist = clist

        while (ilcnt < pos) {

            ipoint = clocallist.indexOf(cdelim, 0)

            if (ipoint >= 0) {

                ifnentry = clocallist.substring(0, ipoint)
                clocallist = clocallist.substring(ipoint + 1)
                ilcnt = ilcnt + 1

            }

            else {

                ilcnt = pos
                ifnentry = clocallist
                clocallist = ""
            }
        }

        return ifnentry

    }
    //-----------------------------------------------------------------------


</SCRIPT>

<SCRIPT language=jscript>

    //----------------------------------------------------------------------
    function fnsave() {

        filetosave = prompt("Enter a file name to save to\nEnter the complete path", "c:\\checklist.txt")

        if (filetosave == null)
            return

        var SaveFileObj = new ActiveXObject("Scripting.FileSystemObject")
        var SaveStream = SaveFileObj.OpenTextFile(filetosave, 2, true)


        SaveStream.WriteLine(document.form1.projectname.value)

        for (icnt = 0; icnt < Icatnum.length; icnt++) {

            numperletter = fnnumber(Icatnum[icnt])

            for (jcnt = 1; jcnt <= numperletter; jcnt++) {
                SaveStream.Write(Icatnum[icnt] + jcnt + ":")

                for (kcnt = 0; kcnt < document.all(Icatnum[icnt] + jcnt).length; kcnt++)
                    if (document.all(Icatnum[icnt] + jcnt)[kcnt].checked)
                        SaveStream.Write(kcnt)

                SaveStream.WriteLine("")
            }

        }

        for (icnt = 0; icnt < IIcatnum.length; icnt++) {

            numperletter = fnnumber(IIcatnum[icnt])

            for (jcnt = 1; jcnt <= numperletter; jcnt++) {
                SaveStream.Write(IIcatnum[icnt] + jcnt + ":")

                for (kcnt = 0; kcnt < document.all(IIcatnum[icnt] + jcnt).length; kcnt++)
                    if (document.all(IIcatnum[icnt] + jcnt)[kcnt].checked)
                        SaveStream.Write(kcnt)

                SaveStream.WriteLine("")
            }

        }


        SaveStream.Close()

    }
    //----------------------------------------------------------------------
    function fnopen() {

        filetoopen = document.form1.openfile.value

        if (filetoopen == "") {
            alert("Specify a file to open")
            return
        }

        var OpenFileObj = new ActiveXObject("Scripting.FileSystemObject")
        var OpenStream = OpenFileObj.OpenTextFile(filetoopen, 1, true)

        cstring = OpenStream.ReadLine()
        document.form1.projectname.value = cstring

        while (!OpenStream.AtEndOfStream) {

            cstring = OpenStream.ReadLine()
            if (fnentry(2, cstring, ":") != "") {
                document.all(fnentry(1, cstring, ":"))[parseInt(fnentry(2, cstring, ":"))].checked = true
                fnclicked(fnentry(1, cstring, ":"))
            }
        }

        fnshowopen(0)

    }
    //----------------------------------------------------------------------


</SCRIPT>
<body style="background-color:white !important">


<?php $PID = isset($_GET['pid']) ? $_GET['pid'] : 0; ?>
<?php
$cid = $_SESSION['id'];


$result = mysql_query("SELECT pdri.*,projects.projectCode /*,client.clientName*/ FROM projects /*,client*/ ,pdri where pdri.CompanyID='$id' AND pdri.pdri_id='$PID' AND (pdri.pdri_status='1' || pdri.pdri_status='3' || pdri.pdri_status='4') AND projects.projectSerial=pdri.project_id /*AND client.clientSerial=pdri.client_id*/ ");
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$PreparedBy = "";
$bstatus = $row["pdri_status"];
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);
}
?>

<?php if ($bstatus == '3' || $bstatus == '4') { ?>
    <script>
        $(function () {
            $("input:radio").attr('disabled', true);
        });
    </script>
<?php } ?>

<style>
    .editfield{display:none}
    .pheadin-txt .panel-numbering,.pheadin-txt .htitle {font-size:14px; font-weight:bold}
    .whead{    padding: 4px 0 4px 0;}
    .panel-edit a{margin-right:7px}
    .panel-edit span{margin-left:7px}
    .panel-edit{text-align:right}
    .panel-detail{padding:0 !important}
    .content .widget > [class*="whead"] h6 {
        padding: 7px 14px 5px 3px !important;
    }
    .panel-edit .glyph{float:right}
    .delhead{float:right}
    .delhead .fa{color:#900; font-size:16px;padding-right:0px !important}
    .update_alert{width:30% !important; margin:0 auto 2px auto !important; padding:3px !important; text-align:center }
    .delhead{margin: 0 0 0 10px !important}
</style>


<div class="main-content">
    <h5>
        <?php if (isset($_REQUEST["msg"])) { ?>
            <?php echo $_REQUEST["msg"]; ?>
        <?php } ?>
    </h5>


    <div class="PDRI">
        <fieldset>
            <legend align="center">PROJECT DEFINITION RATING INDEX</legend>
            <table align="center" class="tablePDRI" style=" margin-left:10% !important" border="0" cellpadding="0">
                <tr class="tablePDRI">
                    <td class="tablePDRI" style="width:7% !important" align="left" valign="top"><strong>Project Code</strong>:</td>
                    <td class="tablePDRI" style="width:30% !important" align="left" valign="top"><?php echo $row["projectCode"]; ?></td>
                    <td class="tablePDRI" style="width:7% !important" align="left" valign="top"><strong>Title</strong></td>
                    <td class="tablePDRI" style="width:30% !important" align="left" valign="top"><?php echo $row["pdri_name"]; ?></td>
                    <td class="tablePDRI" style="width:7% !important" align="left" valign="top"><strong>ID/ Revision</strong>:</td>
                    <td class="tablePDRI" style="width:30% !important" align="left" valign="top"><?php echo "PDRI - " . $PID; ?></td>
                </tr>
                <tr class="tablePDRI">
                    <td class="tablePDRI" style="width:7% !important"  align="left" valign="top"><strong>Prepared By</strong>:</td>
                    <td class="tablePDRI" style="width:30% !important" align="left" valign="top"><?php echo $PreparedBy; ?></td>
                    <td class="tablePDRI" style="width:7% !important"  align="left" valign="top"><strong>Revision</strong>:</td>
                    <td class="tablePDRI" style="width:30% !important" align="left" valign="top"><?php echo $row["pdri_rev"]; ?></td>
                    <td class="tablePDRI" style="width:7% !important"  align="left" valign="top"><strong>Initiated</strong>:</td>
                    <td class="tablePDRI" style="width:30% !important" align="left" valign="top"><?php echo $row["creationDate"]; ?></td>
                </tr>
            </table>
        </fieldset>
    </div>



    <table width="100%" align="center" border="0" cellpadding="0">


        <tbody>

        <tr align="right">
            <td valign="top">
                <div style='float: left; text-align: left'>
			<span style="font-size: 10px; font-family: 'Lato', sans-serif;">
			<strong>Legend</strong>: 0* = Not Applicable, 1* = Complete Definition, 2* = Minor Deficiencies, 3* = Some Deficiencies, 4* = Major Deficiencies, 5* = Incomplete or Poor Definition</span></div>

                <div style='float: right; text-align: right'>

                    <?php if ($bstatus == 1)
                    { ?>
                        <input type="image" onClick="document.getElementById('pdriform').submit();" class="imgbtn" width="13" height="13" name="save1" src="img/save.png" title="Save All" />
                        &nbsp;
                        <input type="image" onClick="document.getElementById('pdriform').submit();" class="imgbtn" width="13" height="13" name="saveclose" src="img/close.png" title="Save and Close" />
                        &nbsp;
                        <a href="#">
                            <img src="img/send.png" onclick="sendforinitiate(<?php echo $PID; ?>)" width="13" height="13" alt="" title="Send for Review"/></a>
                        &nbsp;
                        <a href="03-03Scope-01PDRI02-DB.php?lock=<?php echo $PID; ?>">
                            <img src="img/lockgohome.png" width="13" height="13" alt="" title="Lock and Exit"/></a>
                    <?php } else if( $bstatus == 4 ){ ?>
                        <a href="03-03Scope-01PDRI02-DB.php?unlock=<?php echo $PID; ?>">
                            <img src="img/lockgohome.png" width="13" height="13" alt="" title="Unlock"/></a>
                    <?php }?>
                    &nbsp;
                    <a href="03-03Scope-01PDRI02-PV01.php?pid=<?php echo $row["pdri_id"]; ?>"><img src="img/print.png" width="13" height="13" alt="" title="PrintView"/></a> &nbsp;
                    &nbsp;<a href="03-03Scope-01PDRI01.php"><img src="img/deletecb.png" width="12" height="12" alt=""/></a>
                </div>
            </td>
        </tr>
    </table>




    <section class="content">
        <div class="container">


            <form name="pdriform"  id="pdriform" method="post" action="03-03Scope-01PDRI02-DB.php?pdri_id=<?php echo  $PID;?>">
                <input type="hidden" name="action" value="add">
                <?php
                $saveC1 = "A";
                $saveC2 = "1";

                $c1 = "A";

                $query = "SELECT * from pdri_rating_section WHERE status='1' ";
                $result = mysql_query($query);
                $rom ="I";
                while ($row = mysql_fetch_array($result)) {
                ?>

                <div class="widget">

                    <div class="whead">

                        <br>
                        <!--<div style='float: left; text-align: left'>-->
                        <h6> <i class="fa fa-play-circle"></i> SECTION <?php echo $rom; ?> : <?php echo $row['section_title'] ?></h6>
                        <br>



                        <div class="col-md-1 docdetail-label" style="margin-top:3px; margin-left:20px; width:8% !important">

                            <label>0*</label>
                        </div>
                        <div class="col-md-1 docdetail-label" style="margin-top:3px; width:8% !important">

                            <label>1*</label>
                        </div>
                        <div class="col-md-1 docdetail-label" style="margin-top:3px; width:8% !important">

                            <label>2*</label>
                        </div>
                        <div class="col-md-1 docdetail-label" style="margin-top:3px; width:8% !important">

                            <label>3*</label>
                        </div>
                        <div class="col-md-1 docdetail-label" style="margin-top:3px; width:8% !important">

                            <label>4*</label>
                        </div>
                        <div class="col-md-1 docdetail-label" style="margin-top:3px; width:8% !important">

                            <label>5*</label>
                        </div>
                        </a>
                        <div class="col-md-1 docdetail-label" style="margin-top:3px; width:8% !important">

                            <label>Score</label>
                        </div>
                        <div class="col-md-1 docdetail-label" style="margin-top:3px; width:8% !important">

                            <label>Sub Total</label>
                        </div>
                    </div>




                    <?php
                    $catq = "SELECT * FROM pdri_rating_categories WHERE pdri_section_id = " . $row['id'];
                    $cres = mysql_query($catq);

                    while ($row1 = mysql_fetch_array($cres)) {
                        $c2 = 1;
                        ?>
                        <div class="formRow rthead" style="padding:0px 3px !important">
                            <div class="file-head" style='font-size:12px'><?php echo $c1." : ". $row1['category_title'] ?></div>
                        </div>
                    <?php
                    $dq = "SELECT * from pdri_rating_detail WHERE category_id = " . $row1['id'] . " AND section_id = " . $row['id'];
                    $cc = mysql_query($dq);

                    while ($row2 = mysql_fetch_array($cc)) {
                    ?>
                        <div class="formRow fRow">
                            <div class='col-md-4'><?php echo $row2['rating_title'] ?></div>
                            <?php
                            //$rating_id = $row2['id'];
                            $ra = "SELECT pdri_sec_value from pdri_values WHERE pdri_id = " . $PID . " AND pdri_rating_id = " . $row2['id'];
                            $rra = mysql_query($ra);
                            $row3 = mysql_fetch_array($rra);
                            $save = "";

                            $points = explode(",", $row2['rating_points']);
                            for ($i = 0; $i < 6; $i++) {
                                ?>
                                <div class='col-md-1'><input <?php if (isset($row3[0]) && ($row3[0] == $points[$i])) { $save =  $points[$i]; ?> checked="checked"  <?php }?>id="<?php echo $c1 . $c2 ?>" name="<?php echo $c1 . $c2 ?>" onclick="fnclicked('<?php echo $c1 . $c2 ?>')" type='radio' value='<?php echo $points[$i] ?>'> <?php echo $points[$i] ?> </div>
                                <?php
                            }
                            ?>

                            <div class="col-md-1" id="<?php echo $c1 . $c2; ?>score" >0</div>
                            <div class="col-md-1" id="<?php echo $c1 . $c2; ?>sub" >0</div>
                        </div>
                    <?php

                    if (isset($row3[0]) && ($row3[0] == $save)) {

                    $saveC1 = $c1;
                    $saveC2 = $c2;
                    ?>
                        <script>
                            $( window ).load(fnclicked('<?php echo $c1 . $c2 ?>'));
                        </script>
                    <?php }
                    $c2++;
                    }
                    ?>

                        <div class="formRow fRow">
                            <div class="col-md-8 docdetail-label" id=""> <strong>CATEGORY "<?php echo $c1;?>" TOTAL</strong></div>
                            <div class="col-md-1" id=""></div>
                            <div class="col-md-1" id=""></div>
                            <div class="col-md-1" id=""></div>
                            <div class="col-md-1" id=""></div>
                            <div class="col-md-1" id=""></div>
                            <div class="col-md-1" id=""></div>
                            <div class="col-md-1" id=""></div>
                            <div class="col-md-1" id=""></div>
                            <div class="col-md-1" style="margin-left:7px" id="<?php echo $c1;?>totscore">0</div>
                            <div class="col-md-1" id="<?php echo $c1;?>totsub">0</div>
                        </div>

                        <script>
                            $( window ).load(fnclicked('<?php echo $saveC1 . $saveC2 ?>'));
                        </script>
                        <?php
                        $c1++;
                    }
                    ?>
                    <div class="formRow fRow">
                        <div class="col-md-8 docdetail-label" id=""> <strong>SECTION "<?php echo $rom; ?>" TOTAL </strong></div>
                        <div class="col-md-1" id=""></div>
                        <div class="col-md-1" id=""></div>
                        <div class="col-md-1" id=""></div>
                        <div class="col-md-1" id=""></div>
                        <div class="col-md-1" id=""></div>
                        <div class="col-md-1" id=""></div>
                        <div class="col-md-1" id=""></div>
                        <div class="col-md-1" id=""></div>
                        <div class="col-md-1" style="margin-left:7px" id="<?php echo $rom; ?>cattotscore">0</div>
                        <div class="col-md-1" id="<?php echo $rom; ?>cattotsub"  >0</div>
                    </div>
                    <?php $rom = $rom."I"; ?>
                    <?php } ?>

                    <!-- total........................................-->
                    <div class="formRow fRow">
                        <div class="col-md-8 docdetail-label" id=""> <strong>RDRI SCORE</strong></div>
                        <div class="col-md-1" id=""></div>
                        <div class="col-md-1" id=""></div>
                        <div class="col-md-1" id=""></div>
                        <div class="col-md-1" id=""></div>
                        <div class="col-md-1" id=""></div>
                        <div class="col-md-1" id=""></div>
                        <div class="col-md-1" id=""></div>
                        <div class="col-md-1" id=""></div>
                        <div class="col-md-1" style="margin-left:7px" id=""></div>
                        <div class="col-md-1" id="lblTotal">0</div>


                        <!--                            <div style="text-align:right; margin-right:50px"> <input align="right"  class="a1 a1 buttonM formSubmit bGreen" type="submit" name="Save5" id="Save5" value="Save"/></div>-->
                    </div>


                </div>


            </form>
            <p>&nbsp;</p>

            <div style="margin-left:15px" align="left"><br />
                Index created and distributed by <a href="http://construction-institute.org/">Construction Industry Institute, Austin, Texas</a>.</div>
        </div>

</div>
</section>
</body>

<script>
    $( window ).load(fnclicked('<?php echo $saveC1 . $saveC2 ?>'));

</script>
</body>
</html>
