Example #1
0
function SavePlanItems()
{
    $obj = new PLN_PlanItems();
    if (isset($_POST["record"])) {
        $st = stripslashes(stripslashes($_POST["record"]));
        $data = json_decode($st);
        $obj->RowID = $data->RowID;
        $obj->PlanID = $data->PlanID;
        $obj->ElementID = $data->ElementID;
        $xml = new SimpleXMLElement('<root/>');
        $elems = array_keys(get_object_vars($data));
        foreach ($elems as $el) {
            if (strpos($el, "element_") === false) {
                continue;
            }
            $str = $data->{$el};
            if (strlen($str) > 10 && substr($str, 10) == "T00:00:00") {
                $str = substr($str, 0, 10);
            }
            if (strlen($str) == 10 && $str[4] == "-" && $str[7] == "-") {
                $str = preg_replace('/\\-/', "/", $str);
            }
            $xml->addChild($el, $str);
        }
        $obj->ElementValue = $xml->asXML();
    } else {
        $obj->PlanID = $_POST["PlanID"];
        $obj->ElementID = $_POST["ElementID"];
        $dt = PdoDataAccess::runquery("select RowID from PLN_PlanItems where PlanID=? AND ElementID=?", array($obj->PlanID, $obj->ElementID));
        if (count($dt) > 0) {
            $obj->RowID = $dt[0]["RowID"];
        }
        $xml = new SimpleXMLElement('<root/>');
        foreach ($_POST as $key => $value) {
            if (strpos($key, "element_") === false) {
                continue;
            }
            $xml->addChild($key, $value);
        }
        $obj->ElementValue = $xml->asXML();
    }
    if ($obj->RowID > 0) {
        $result = $obj->EditItem();
    } else {
        $result = $obj->AddItem();
    }
    $elemObj = new PLN_Elements($obj->ElementID);
    $obj2 = new PLN_PlanSurvey();
    $obj2->PlanID = $obj->PlanID;
    $obj2->GroupID = $elemObj->GroupID;
    $obj2->ActType = "EDIT";
    $obj2->ActDate = PDONOW;
    $obj2->ActPersonID = $_SESSION["USER"]["PersonID"];
    $result = $obj2->AddRow();
    echo Response::createObjectiveResponse($result, "");
    die;
}