<?php
include('../../includes/checkSession.php');
include('../../includes/con2pma3.php');
$companyID = $_SESSION['id'];
?>

<html><head><meta charset="utf-8"><title>pmAnywhere - Scope Module</title>
   <link href="03-00Scope-Styles0.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>
</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 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['sid'])?$_GET['sid']: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);
}

?>

<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">SPECIFICATIONS</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  
				if(!isset($_GET['iid'])){
				$WID = isset($_GET['WID'])?$_GET['WID']:0;
			  
					  $result1 = mysql_query("SELECT * FROM globalwbs where WBSID ='$WID' && companyID = '$cid'  ORDER BY WBSIDA ASC,WBSIDB ASC,WBSIDC ASC,WBSIDD ASC,WBSIDE ASC");
				$row1wbs = mysql_fetch_array($result1 , MYSQL_ASSOC);
					
				?>
				
				
				<?php echo $row["title"]; ?> - <?php echo $row1wbs["sortCode"]; ?> - <?php echo $row1wbs["description"]; 
                
                }
				
                else
                {
					$WID = isset($_GET['WID'])?$_GET['WID']:0;
					$iid = isset($_GET['iid'])?$_GET['iid']:0;
					$result123 = mysql_query("SELECT * FROM globalitems where WBSID = '$WID' && itemID='$iid' ORDER BY itemID ASC");
		
   		$row1item = mysql_fetch_array($result123 , MYSQL_ASSOC);
				 echo $row["title"]; ?> - <?php echo $row1item["sortCode"]; ?> - <?php echo $row1item["description"]; 
                       
                }
                ?>
                
                </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">
        <h2 align="center">GENERAL</h2>
    </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 name="save2" type="image" class="imgbtn" title="Save" onClick="submittextform('<?php echo $row['id'] ?>')" src="img/save.png" width="15" height="15" /></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">
            <h2 align="center">PRODUCTS</h2>
        </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">
            <h2 align="center">EXECUTION</h2>
        </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'); ?>
