}
    $head_object->parent_id = $parent_id;
    $head_object->attribute_type = "Head";
    if ($rem_head_att == false) {
        $head_object->save();
    } else {
        $head_object->mark_deleted($head_object->id);
    }
    //end if controller information only
}
//New or Update DataSet Attribute Body////////////////////////////////////////////
if (!empty($_REQUEST['direction'])) {
    //only update controller information, ignore attribute stuff
} else {
    $rem_body_att = false;
    $body_object = new DataSet_Attribute();
    if (!empty($_REQUEST['body_att_id']) && $_REQUEST['body_att_id'] != "") {
        $body_object->retrieve($_REQUEST['body_att_id']);
        $body_is_update = true;
        //check to see if we are removing this attribute (Unchecking);
        if (empty($_POST['modify_body'])) {
            //set remove attribute flag
            $rem_body_att = true;
        }
        //end if update nested
    } else {
        //Still no body attribute, keep it this way
        if (empty($_POST['modify_body'])) {
            //set remove attribute flag
            $rem_body_att = true;
        }
for ($i = 0; $i <= 5; $i++) {
    $layout_id = $format_object2->get_layout_id_from_parent_value("{sc}0{sc}" . $i . "");
    $body_object = new DataSet_Attribute();
    $body_object->parent_id = $layout_id;
    foreach ($scalar_body_array as $key => $value) {
        $body_object->{$key} = $value;
    }
    $body_object->save();
    $head_object = new DataSet_Attribute();
    $head_object->parent_id = $layout_id;
    foreach ($scalar_head_array as $key => $value) {
        $head_object->{$key} = $value;
    }
    $head_object->save();
    //end the for loop on scalar
}
//////////////////Fill the Total Revenue Columns
$layout_id = $format_object->get_layout_id_from_parent_value("Total Revenue");
$body_object = new DataSet_Attribute();
$body_object->parent_id = $layout_id;
foreach ($scalar_body_array as $key => $value) {
    $body_object->{$key} = $value;
}
$body_object->save();
$layout_id = $format_object2->get_layout_id_from_parent_value("Total Revenue");
$body_object = new DataSet_Attribute();
$body_object->parent_id = $layout_id;
foreach ($scalar_body_array as $key => $value) {
    $body_object->{$key} = $value;
}
$body_object->save();