<?php
include('../../includes/checkSession.php');
include('../../includes/con2pma3.php');
/*include('../includes/header_in.php');*/
/*include('../includes/topmenuin.php');*/
$companyID = $_SESSION['id'];
//include('1-Quality-Procedures1DB.php');
?>

<html><head><meta charset="utf-8"><title>pmAnywhere - Scope Module</title>
    <!--<link href="pma3formstyles.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>

<!-- Hope this text editor works well --->
<!--<style type="text/css" media="all">
	@import "css/info.css";
	@import "css/main.css";
	@import "css/widgEditor.css";
</style>-->
<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 documents to be assigned as an initiated document.");
        if (c)
        {
            window.location.href = "03-04Scope-01SOW01DB.php?send=" + bid;
        }
        else
        {
            return false;
        }
    }
</script>
<?php
$BID =isset($_GET['BID'])?$_GET['BID']:0;
$cid  = $_SESSION['id'];
$scope ='specs-brief';


$result = mysql_query("SELECT specs.*,projects.projectName,client.clientName FROM projects,client,specs where specs.companyID='$id' AND specs.SPECID='$BID' AND specs.spec_status='1' AND projects.projectSerial=specs.spec_project AND client.clientSerial=specs.spec_client ");
$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);
}

?>

<style>
    table.table1 th {
        background: none;
        color: lightslategray;
        border: none;
        padding-top: 5px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;
        font-weight: normal;
        font-family: 'Lato', sans-serif;
        font-size: 16px;
    }

    table.table1 td {
        background: none;
        color: lightslategray;
        border-bottom: 1px dotted #E5E5E5;
        padding-top: 3px; padding-right: 3px; padding-bottom: 0px; padding-left: 3px;
        font-weight: normal;
        font-family: 'Lato', sans-serif;
        font-size: 10px;
    }

    table.table2 th
    {
        background: -webkit-linear-gradient(top, #5ba5cb 0%, #3a70ab 100%); background: -moz-linear-gradient(top, #5ba5cb 0%, #3a70ab 100%); padding: 16px 0 0 0; background: -ms-linear-gradient(top, #5ba5cb 0%, #3a70ab 100%);
        color: #ECECFF;
        border-bottom: 1px solid #F4F4F4;
        padding-top: 5px; padding-right: 2px; padding-bottom: 5px; padding-left:5px;
        font-weight: bold;
        font-family: 'Lato', sans-serif;
        font-size: 12px;
    }

    table.table2 tr:hover{background-color:#f5f5f5}

    table.table2 td {
        background: none;
        color: dimgray;
        border-bottom: 1px dotted #C0C0C0;
        padding-top: 3px; padding-right: 3px; padding-bottom: 0px; padding-left: 3px;
        font-weight: normal;
        font-family: 'Lato', sans-serif;
        font-size: 10px;
    }

    /* For inputs in quality procedures etc*/
    table.table3 td {
        background: none;
        color: dimgray;
        border-bottom: 1px dotted #C0C0C0;
        padding-top: 3px; padding-right: 3px; padding-bottom: 0px; padding-left: 3px;
        font-weight: normal;
        font-family: 'Lato', sans-serif;
        font-size: 10px;

    }
    .button {
        text-align: center;
        text-decoration: none;
        display: inline-block;
        -webkit-transition-duration: 0.4s; /* Safari */
        transition-duration: 0.4s;
        cursor: pointer;
    }
    .button1 {
        background-color: #008CBA;
        color: white; font-size: 14px;
        border: 1px solid #008CBA;
        padding-top: 0px; padding-bottom: 0px; padding-left: 1px; padding-right: 1px;
        margin: 0px 1px;
    }

    .button1:hover {
        background-color: white;
        color: #008CBA;
    }
    .button2 {
        background-color: #008CBA;
        color: white; font-size: 10px;
        border: 1px solid #008CBA;
        padding-top: 0px; padding-bottom: 0px; padding-left: 1px; padding-right: 1px;
        margin: 0px 1px;
    }

    .button1:hover {
        background-color: white;
        color: #008CBA;
    }


    input  {
        width:85%;
        height:2em;
        vertical-align:top;
    }
    select {
        border:1px solid #ccc;
        vertical-align:top;
        height:2em;
        width:86%;
    }
    option {
        color:gray;
        width:100%;
        text-decoration:none;
    }


    input, select, textarea {
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        font-weight: normal;
        font-family: 'Lato', sans-serif;
        font-size: 10px;
        border:1px solid #ccc;
    }

    fieldset
    {
        background-color:none;
        /*max-width:500px;  */
        padding:16px;
        font-weight: bold;
        font-family: 'Lato', sans-serif;
        font-size: 16px;
    }
    legend1
    {
        margin-bottom:0px;
        margin-left:16px;
        font-weight: bold;
        font-family: 'Lato', sans-serif;
        font-size: 16px;
    }

    hr.hrstyle1 {
        border: 0;
        height: 1px;
        background-image: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));
    }
    .projectTitle{font-weight:bold; text-transform:uppercase; font-size: 16px;}
    .imgbtn{width:13px; height:13px; border:none;}
    /*input[type=text]:focus {    background-color: lightgrey;}*/
</style>
<body>
<div>
    <br><br><!-- For errors and warnings-- Save your work, before quitting.. YES | NO>
</div>




<div style="overflow-x:auto;">
<div id="formdiv" > <!--div for the form (style="display:none;")-->
    <!--<table name="entryformheading" align="center" width="80%" class="table1" border="0" cellpadding="0">
         <tr>
          <th>
          <div style='float: left; text-align: left'><button id="hideformdiv" class="button1">&#x25bc;</button>
          Add</div>
          <div style='float: right; text-align: right'>&nbsp;</div>
          </th>
        </tr>
      </table>
    <form align="center" method="post" action="1-Quality-Procedures2.php?procedure_id=<?php //echo $proce_id?>">-->
    <input type="hidden" name="save_text_id" id="save_text_id" value="<?php echo $proce_id?>" />
    <fieldset>
        <legend align="center">DETAILS OF THE SPECIFICATIONS PACKAGE</legend>
        <table name="entryform" align="center" class="table1" width="80%" border="0" cellpadding="0">
            <tr>
                <td colspan="6" align="center" valign="top"><span class="projectTitle"><?php echo $row["title"]; ?></span></td>
            </tr>
            <tr>
                <td width="9%" align="left" valign="top"><strong>Project</strong>:</td>
                <td width="28%" align="left" valign="top"><?php echo $row["projectName"]; ?></td>
                <td align="left" valign="top"><strong>Client</strong>:</td>
                <td align="left" valign="top"><?php echo $row["clientName"]; ?></td>
                <td width="7%" align="left" valign="top"><strong>Consultant</strong>:</td>
                <td width="23%" align="left" valign="top"><?php echo $row["title"]; ?></td>
            </tr>
        </table>
    </fieldset>
    <br /></div>

<table width="80%" class="table3" align="center" border="0" cellpadding="0">

    <tbody>

<tr>
    <td colspan="2">
        <h1 align="center">General</h1>
    </td>
</tr>

    <?php
    $query ="SELECT * from scope_brief WHERE scope_type='$scope' AND (company_id= 0 OR company_id = '$cid') AND (brief_id= 0 OR brief_id = '$BID') AND brief_type ='General'";
    $result = mysql_query($query);
    $k=1.1;

    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

        $query2 ="SELECT * from scope_brief_description WHERE `heading_id` = '".$row['id']."' AND `brief_id` ='".$BID."' AND company_id= '$cid'";
        $results = mysql_query($query2);
        $row2 = mysql_fetch_object($results);

        ?>

        <form method="post" action="" id="submittextfor-<?php echo $row['id']; ?>">
            <tr>        <td valign="top" colspan="2"><br>
                    <?php  ?> <h3><?php  echo $k.'. '.$row['heading']; ?></h3>  </td></tr>
            <tr>
                <td valign="top"><br>

                <td valign="top"><br>
                    <textarea   style="width:97%" class="" name="btext-<?php echo $row['id'] ?>" id="btext-<?php echo $row['id'] ?>" rows="5">
                <?php  echo ((@$row2->description) ? @$row2->description : ''); ?>
            </textarea>

                    <input type="hidden" name="bdescid" value="<?php echo @$row2->id?>">
                    <input type="hidden" name="headingid" value="<?php echo $row['id']?>">

                    <input type="hidden" name="scopename" value="<?php echo $scope?>">
                    <input type="hidden" name="task" value="changedesc">
                    <input type="hidden" name="brief_id" value="<?php echo $BID?>">

                    <br>
                    <br></td>

                             <td valign="top"><input type="image" class="imgbtn" onclick="submittextform('<?php echo $row['id'] ?>')" name="save2" src="img/save.png" title="Save" /></td>

            </tr>
        </form>
        <?php
        $k=$k+0.1;
    }
    ?>
    </tbody>


        <br />
    <form id="gnewheadingform" method="post" action="">
            <tr>
                <td valign="top"><br>
                    New Para  </td>

                <td>

                    <input type="text" name="nheading" value="" />
                    <input type="hidden" name="scopename" value="<?php echo $scope?>">
                    <input type="hidden" name="brieftype" value="General">
                    <input type="hidden" name="task" value="newheading">
                    <input type="hidden" name="brief_id" value="<?php echo $BID?>">

                </td>

                <td >
                    <input type="image" class="imgbtn" onclick="savegnewheading()" name="save2" src="img/save.png" title="Save" />
                </td>




                <br>
                <br>

            </tr>
        </form>
        <!--<div class="col-md-1 col-sm-2 panel-edit" style="float:right"><a href="#" onclick="savenewheading()"><input type="image" src="../images/icon-save7.png" width="12" height="12" border="0"></a></div> -->





</table><br><br>

<table width="80%" class="table3" align="center" border="0" cellpadding="0">

    <tbody>
    <tr>
        <td colspan="2">
            <h1 align="center">Products</h1>
        </td>
    </tr>
    <?php
    $query ="SELECT * from scope_brief WHERE scope_type='$scope' AND (company_id= 0 OR company_id = '$cid') AND (brief_id= 0 OR brief_id = '$BID') AND brief_type='Products'";
 $result = mysql_query($query);
$k = 2.1;

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

    $query2 ="SELECT * from scope_brief_description WHERE `heading_id` = '".$row['id']."' AND `brief_id` ='".$BID."' AND company_id= '$cid' ";
    $results = mysql_query($query2);
    $row2 = mysql_fetch_object($results);

    ?>

    <form method="post" action="" id="submittextfor-<?php echo $row['id']; ?>">
            <tr>        <td valign="top" colspan="2"><br>
                    <?php  ?> <h3><?php  echo $k.'. '.$row['heading']; ?></h3>  </td></tr>
            <tr>
                <td valign="top"><br>

                <td valign="top"><br>
                    <textarea   style="width:97%" class="" name="btext-<?php echo $row['id'] ?>" id="btext-<?php echo $row['id'] ?>" rows="5">
                <?php  echo ((@$row2->description) ? @$row2->description : ''); ?>
            </textarea>

                    <input type="hidden" name="bdescid" value="<?php echo @$row2->id?>">
                    <input type="hidden" name="headingid" value="<?php echo $row['id']?>">

                    <input type="hidden" name="scopename" value="<?php echo $scope?>">
                    <input type="hidden" name="task" value="changedesc">
                    <input type="hidden" name="brief_id" value="<?php echo $BID?>">

                    <br>
                    <br></td>

                <td valign="top"><input type="image" class="imgbtn" onclick="submittextform('<?php echo $row['id'] ?>')" name="save2" src="img/save.png" title="Save" /></td>

            </tr>
        </form>
        <?php
    $k=$k+0.1;
    }
    ?>
    </tbody>


    <br />
    <form id="pnewheadingform" method="post" action="">
        <tr>
            <td valign="top"><br>
                New Para  </td>

            <td>

                <input type="text" name="nheading" value="" />
                <input type="hidden" name="scopename" value="<?php echo $scope?>">
                <input type="hidden" name="brieftype" value="Products">
                <input type="hidden" name="task" value="newheading">
                <input type="hidden" name="brief_id" value="<?php echo $BID?>">

            </td>

            <td >
                <input type="image" class="imgbtn" onclick="savepnewheading()" name="save2" src="img/save.png" title="Save" />
            </td>




            <br>
            <br>

        </tr>
    </form>
    <!--<div class="col-md-1 col-sm-2 panel-edit" style="float:right"><a href="#" onclick="savenewheading()"><input type="image" src="../images/icon-save7.png" width="12" height="12" border="0"></a></div> -->





</table><br><br>


<table width="80%" class="table3" align="center" border="0" cellpadding="0">

    <tbody>

    <tr>
        <td colspan="2">
            <h1 align="center">Execution</h1>
        </td>
    </tr>
    <?php
    $query ="SELECT * from scope_brief WHERE scope_type='$scope' AND (company_id= 0 OR company_id = '$cid') AND (brief_id= 0 OR brief_id = '$BID') AND brief_type='Execution'";
    $result = mysql_query($query);
    $k=3.1;

    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

        $query2 ="SELECT * from scope_brief_description WHERE `heading_id` = '".$row['id']."' AND `brief_id` ='".$BID."' AND company_id= '$cid'";
        $results = mysql_query($query2);
        $row2 = mysql_fetch_object($results);

        ?>

        <form method="post" action="" id="submittextfor-<?php echo $row['id']; ?>">
            <tr>        <td valign="top" colspan="2"><br>
                    <?php  ?> <h3><?php  echo $k.'. '.$row['heading']; ?></h3>  </td></tr>
            <tr>
                <td valign="top"><br>

                <td valign="top"><br>
                    <textarea   style="width:97%" class="" name="btext-<?php echo $row['id'] ?>" id="btext-<?php echo $row['id'] ?>" rows="5">
                <?php  echo ((@$row2->description) ? @$row2->description : ''); ?>
            </textarea>


                    <input type="hidden" name="bdescid" value="<?php echo @$row2->id?>">
                    <input type="hidden" name="headingid" value="<?php echo $row['id']?>">
                    <input type="hidden" name="scopename" value="<?php echo $scope?>">
                    <input type="hidden" name="task" value="changedesc">
                    <input type="hidden" name="brief_id" value="<?php echo $BID?>">

                    <br>
                    <br></td>

                <td valign="top"><input type="image" class="imgbtn" onclick="submittextform('<?php echo $row['id'] ?>')" name="save2" src="img/save.png" title="Save" /></td>

            </tr>
        </form>
        <?php
        $k=$k+0.1;
    }
    ?>
    </tbody>


    <br />
    <form id="enewheadingform" method="post" action="">
        <tr>
            <td valign="top"><br>
                New Para  </td>

            <td>

                <input type="text" name="nheading" value="" />
                <input type="hidden" name="scopename" value="<?php echo $scope?>">
                <input type="hidden" name="brieftype" value="Execution">
                <input type="hidden" name="task" value="newheading">
                <input type="hidden" name="brief_id" value="<?php echo $BID?>">

            </td>

            <td >
                <input type="image" class="imgbtn" onclick="saveenewheading()" name="save2" src="img/save.png" title="Save" />
            </td>




            <br>
            <br>

        </tr>
    </form>
    <!--<div class="col-md-1 col-sm-2 panel-edit" style="float:right"><a href="#" onclick="savenewheading()"><input type="image" src="../images/icon-save7.png" width="12" height="12" border="0"></a></div> -->





</table><br><br>










<script>
    $("textarea").each(function(){
        CKEDITOR.replace($(this).attr("name"));
    });
</script>


<script>

    function submittextform(id){
        var ht = $('body .cke_editable.cke_contents_ltr').html();
        $("#btext-" + id).val(ht);
        for (instance in CKEDITOR.instances) {
            CKEDITOR.instances[instance].updateElement();
        }
        formData = $("#submittextfor-"+id).serialize();
        url = "briefActions1.php";
        $.ajax({
            url: url,
            type: 'POST',
            data: formData,
            success: function (data) {
                if (data == 0) {
                    alert("Descripton updated successfully with empty data");
                }

                else {
                    $("#btext-" + id).html(data);
                    alert("Descripton updated successfully");
                }
            },
            error: function (e) {

            }
        });

    }


    function submitheadingform(id){

        formData = $("#formforheading-"+id).serialize();
        url = "briefActions1.php";
        $.ajax({
            url: url,
            type: 'POST',
            data: formData,
            success: function (data) {


                if (data == 0) {

                    alert('error');
//                  location.reload();
                }

                else {
                    $("#headingf-" + id).html(data);
                    closeedit('heading', id);
                    $("#alert-" + id).html("Heading updated successfully");
                    $("#alert-" + id).show();
                    setTimeout(function () {
                        $("#alert-" + id).hide();
                    }, 2000);
                }
            },
            error: function (e) {

            }
        });

    }

    function savepnewheading(){

        formData = $("#pnewheadingform").serialize();
        url = "briefActions1.php";
        $.ajax({
            url: url,
            type: 'POST',
            data: formData,
            success: function (data) {
                if (data == 0) {

                    alert('error');
//                  location.reload();
                }

                else {

                   alert("Heading added successfully");

                }
            },
            error: function (e) {

            }
        });
    }

    function saveenewheading(){

        formData = $("#enewheadingform").serialize();
        url = "briefActions1.php";
        $.ajax({
            url: url,
            type: 'POST',
            data: formData,
            success: function (data) {
                if (data == 0) {

                    alert('error');
//                  location.reload();
                }

                else {
                    alert("Heading added successfully");

                }
            },
            error: function (e) {

            }
        });
    }

    function savegnewheading(){

        formData = $("#gnewheadingform").serialize();
        url = "briefActions1.php";
        $.ajax({
            url: url,
            type: 'POST',
            data: formData,
            success: function (data) {
                if (data == 0) {

                    alert('error');
//                  location.reload();
                }

                else {
                    alert("Heading added successfully");
                }
            },
            error: function (e) {

            }
        });
    }

    function deleteHeading(id){
        if (id > 0) {
            alertify.confirm("Are you sure you want to delete heading.", function (e) {
                if (e) {
                    url = "briefActions1.php";

                    $.ajax({
                        url: url,
                        type: 'POST',
                        data: {task:'deleteheading', hid:id},
                        success: function (data) {
                            if (data == 1) {
                                location.reload();
                            }

                            else {
                                alert("Something went wrong. Please try later");
                            }
                        },
                        error: function (e) {

                        }
                    });
                } else {
                    return 0;
                }


            });
        }

    }
</script>

</body>
</html>

<?php include('../includes/footer.php'); ?>
