function abm_rel_rel($do, $rel_id, $rel_type_id)
{
    global $DBCFG;
    //sanitize
    $rel_id = secure_data($rel_id, "int");
    $rel_type_id = secure_data($rel_type_id, "int");
    $userId = $_SESSION[$_SESSION["CFGURL"]][ssuser_id];
    switch ($do) {
        case 'ALTA':
            //check if the type relation exist
            $ARRAYdataRelation = ARRAYdataRelation($rel_id);
            $ARRAYtypeRelations = ARRAYtypeRelations($ARRAYdataRelation[t_relacion], $rel_type_id);
            if (count($ARRAYtypeRelations["{$ARRAYdataRelation['t_relacion']}"]) == '1') {
                $sql = SQL("update", " {$DBCFG['DBprefix']}tabla_rel set rel_rel_id='{$rel_type_id}', cuando=now(),uid='{$userId}' where id='{$rel_id}'");
            }
            break;
        case 'BAJA':
            $sql = SQL("update", " {$DBCFG['DBprefix']}tabla_rel set rel_rel_id='NULL', cuando=now(),uid='{$userId}' where id='{$rel_id}'");
            break;
        default:
    }
    return array("rel_id" => $rel_id);
}
                    echo ' ' . $_POST[code_tema] . ': ' . MSG_ERROR_CODE . ' (' . LABEL_Termino . ' ' . $task[tema] . ')';
                    break;
            }
        }
    }
    //gestión de codigo de tema
    if ($_POST["edit_tema_id"]) {
        $tema_id = str_replace("edit_tema", "", $_POST["edit_tema_id"]);
        //additional secure check
        $string_term = trim($_POST["edit_tema"]);
        if (is_numeric($tema_id) && strlen($string_term) > 0) {
            $task = abm_tema('mod', $string_term, $tema_id);
        }
        $arrayTerm = ARRAYverTerminoBasico($tema_id);
        echo $arrayTerm[tema];
    }
    //abm for relations defined by user
    if ($_POST["edit_rel_id"]) {
        $rel_id = str_replace("edit_rel_id", "", $_POST["edit_rel_id"]);
        //eliminar relación ==
        if ($_POST[rel_rel_id] == '0') {
            $task = abm_rel_rel("BAJA", $rel_id, $_POST[rel_rel_id]);
        } elseif (is_numeric($_POST[rel_rel_id])) {
            $task = abm_rel_rel("ALTA", $rel_id, $_POST[rel_rel_id]);
        }
        $arrayRelData = ARRAYdataRelation($task[rel_id]);
        $labelRel = LABELrelTypeSYS($arrayRelData[t_relation]);
        //reverse or not view of the relation
        echo $_POST[relativeLabel] == 'X' ? $labelRel[rx_code] . $arrayRelData[rr_code] : $labelRel[r_code] . $arrayRelData[rr_code];
    }
}