<?php
include('../../includes/checkSession-out.php');
include('../../includes/con2pma3.php');

    $uid = $_SESSION['user_id'];
    $cid = $_SESSION['id'];
    $task = isset($_POST['task']) ? $_POST['task'] : "";

    switch ($task) {
        case "changedesc":
            $headingid = isset($_POST['headingid']) ? $_POST['headingid'] : "";
            $textid = isset($_POST['bdescid']) ? $_POST['bdescid'] : 0;
            $bText = $_POST['btext-'.$headingid];//
            $text = isset($bText) ? $bText : "";//

            $scope = isset($_POST['scopename']) ? $_POST['scopename'] : "";
            $bid = isset($_POST['brief_id']) ? $_POST['brief_id'] : 0;

            if ($textid > 0) {
                $q = "UPDATE scope_brief_description SET description = '$text' WHERE id= '$textid'";
                $res = mysql_query($q);
                if ($res) {
                    echo $text;
                } else
                    echo '0';
            }
            else {
                $q = "INSERT INTO scope_brief_description SET heading_id ='$headingid',
              scope_type = '$scope',
              brief_type='',
              user_id='$uid',
                  brief_id ='$bid',
              company_id='$cid',
              
              description = '$text'";
                $res = mysql_query($q);

                if ($res) {
                    echo $text;
                } else {
                    echo '0';
                }
            }
            break;
        case "newheading":
            $heading = isset($_POST['nheading']) ? $_POST['nheading'] : "";
            $scope = isset($_POST['scopename']) ? $_POST['scopename'] : "";
            $bid = isset($_POST['brief_id']) ? $_POST['brief_id'] : 0;
            $brief_type = isset($_POST['brieftype']) ? $_POST['brieftype'] : "";
            $parent_id = isset($_POST['parent_id']) ? $_POST['parent_id'] : "";
            if ($heading != "") {

                $q = "INSERT INTO scope_brief SET heading ='$heading',
                scope_type = '$scope',
                brief_type ='$brief_type',
                brief_id='$bid',
                user_id='$uid',
                parent='$parent_id',
                company_id='$cid', is_editable =1 ";
                $res = mysql_query($q);

                if ($res) {
                    echo 1;
                } else {
                    echo 0;
                }
            }

            break;
            case "newmainheading":
            $heading = isset($_POST['nheading']) ? $_POST['nheading'] : "";
            $scope = isset($_POST['scopename']) ? $_POST['scopename'] : "";
            $bid = isset($_POST['brief_id']) ? $_POST['brief_id'] : 0;
            $brief_type = isset($_POST['brieftype']) ? $_POST['brieftype'] : "";
            $parent_id = isset($_POST['parent_id']) ? $_POST['parent_id'] : 0;
            if ($heading != "") {

                $q = "INSERT INTO scope_brief SET heading ='$heading',
                scope_type = '$scope',
                brief_type ='$brief_type',
                brief_id='$bid',
                user_id='$uid',
                parent='$parent_id',
                company_id='$cid', is_editable =1 ";
                $res = mysql_query($q);

                if ($res) {
                    echo 1;
                } else {
                    echo 0;
                }
            }

            break;

        case "editheading":
            $headingtext = isset($_POST['headingtext']) ? $_POST['headingtext'] : "";
            $headingid = isset($_POST['headingid']) ? $_POST['headingid'] : 0;
            if ($headingtext == "") {
                echo "Heading is required";
            } elseif ($headingid > 0 && $headingtext != "") {
                $q = "UPDATE scope_brief SET heading = '$headingtext' WHERE id= '$headingid'";
                $res = mysql_query($q);
                if ($res) {
                    echo $headingtext;
                } else
                    echo '0';
            }

            break;


        case "deleteheading":
            $id = isset($_POST['hid']) ? $_POST['hid'] : 0;
            if ($id > 0) {
                $q = "DELETE FROM scope_brief WHERE id = $id";
                $res = mysql_query($q);
                if ($res) {
                    echo "1";
                } else {
                    echo "0";
                }
            } else {
                echo "0";
                exit;
            }
            break;
        default:
            break;
    }

?> 