function dataSimpleChkUpdateTterm($method, $tterm_uri)
{
    require_once 'vocabularyservices.php';
    switch ($method) {
        case 'tematres':
            return getURLdata($tterm_uri);
            break;
        default:
            return getURLdata($tterm_uri);
            break;
    }
}
function HTMLformAssociateTargetTerms($ARRAYtermino, $term_id = "0")
{
    $sql = SQLtargetVocabulary("1");
    $rows = '<div class="container" id="bodyText">';
    $rows .= '<a class="topOfPage" href="index.php?tema=' . $ARRAYtermino["idTema"] . '" title="' . LABEL_Anterior . '">' . LABEL_Anterior . '</a>';
    if (SQLcount($sql) == '0') {
        //No hay vocabularios de referencia, solo vocabulario principal
        $rows .= HTMLalertNoTargetVocabulary();
    } else {
        //Hay vobularios de referencia
        $array_vocabularios = array();
        while ($array = $sql->FetchRow()) {
            if ($array[vocabulario_id] !== '1') {
                //vocabularios que no sean el vocabulario principal
                array_push($array_vocabularios, $array[tvocab_id] . '#' . FixEncoding($array[tvocab_label]));
            }
        }
        $arrayOptions = strlen($ARRAYtermino["code"]) > 0 ? array('string#' . ucfirst(LABEL_string2search), 'reverse#' . ucfirst(LABEL_reverseMappign), 'code#' . LABEL_CODE) : array('string#' . ucfirst(LABEL_string2search), 'reverse#' . ucfirst(LABEL_reverseMappign));
        $display = in_array($_GET[search_by], array('reverse', 'code')) ? 'style="display: none;"' : '';
        $string2search = $_GET[string2search] ? XSSprevent($_GET[string2search]) : $ARRAYtermino["titTema"];
        $rows .= '<form class="" role="form" name="alta_tt" id="alta_tt" action="index.php" method="get">';
        $rows .= '	<div class="row">
		    <div class="col-sm-12">
		        <legend>' . ucfirst(LABEL_relacion_vocabulario) . ' <a href="index.php?tema=' . $ARRAYtermino["idTema"] . '">' . $ARRAYtermino["titTema"] . '</a></legend>
		    </div>
		    <!-- panel  -->

		    <div class="col-lg-7">
		        <div class="panel panel-default">
		            <div class="panel-body form-horizontal">

		            <div class="form-group">
		            <label for="tvocab_id" class="col-sm-3 control-label">' . ucfirst(FORM_LABEL_nombre_vocabulario) . '</label>
		                <div class="col-sm-9">
		                    <select class="form-control" id="tvocab_id" name="tvocab_id">
		                    ' . doSelectForm($array_vocabularios, $_GET["tvocab_id"]) . '
		                    </select>
		                </div>
		            </div>';
        //Configurar opcion búsqueda por código
        $rows .= '<div class="form-group">
		<label for="search_by" class="col-sm-3 control-label">' . ucfirst(LABEL_selectMapMethod) . '</label>
				<div class="col-sm-9">
						<select class="form-control" id="search_by" name="search_by" onChange="mostrar(this.value);">
						' . doSelectForm($arrayOptions, $_GET["search_by"]) . '
						</select>
				</div>
		</div>';
        $rows .= '<div id="by_string" class="form-group" ' . $display . '>
		                    <label for="string2search" class="col-sm-3 control-label">' . ucfirst(LABEL_Buscar) . '</label>
		                    <div class="col-sm-9">
		                        <input type="text" class="form-control" required type="search" required id="string2search" name="string2search" value="' . $string2search . '">
		                    </div>
            </div>

		                <div class="form-group">
		                    <div class="col-sm-12 text-right">
		                     <button type="submit" class="btn btn-primary" value="' . LABEL_Buscar . '"/>' . ucfirst(LABEL_Buscar) . '</button>
		                      <button type="button" class="btn btn" name="cancelar" type="button" onClick="location.href=\'index.php?tema=' . $ARRAYtermino["idTema"] . '\'" value="' . ucfirst(LABEL_Cancelar) . '"/>' . ucfirst(LABEL_Cancelar) . '</button>
		                    </div>
		                </div>
		            </div>
		        </div>
		    </div> <!-- / panel  -->';
        $rows .= '<input type="hidden" name="tema" value="' . $ARRAYtermino["idTema"] . '"/>
				<input type="hidden" name="taskterm" value="findTargetTerm"/>';
        $rows .= '</form>';
    }
    $rows .= '</div>';
    if ($string2search && $_GET["tvocab_id"]) {
        require_once T3_ABSPATH . 'common/include/vocabularyservices.php';
        $arrayVocab = ARRAYtargetVocabulary($_GET["tvocab_id"]);
        switch ($_GET["search_by"]) {
            case 'string':
                $dataTerm = getURLdata($arrayVocab[tvocab_uri_service] . '?task=search&arg=' . urlencode($string2search));
                break;
            case 'code':
                $dataTerm = getURLdata($arrayVocab[tvocab_uri_service] . '?task=fetchCode&arg=' . urlencode($ARRAYtermino["code"]));
                break;
            case 'reverse':
                $dataTerm = getURLdata($arrayVocab[tvocab_uri_service] . '?task=fetchSourceTerms&arg=' . rawurlencode($ARRAYtermino["titTema"]));
                break;
            default:
                $dataTerm = getURLdata($arrayVocab[tvocab_uri_service] . '?task=search&arg=' . urlencode($string2search));
                break;
        }
        $rows .= HTMLtargetVocabularySearchResult($dataTerm, $_GET[string2search], $arrayVocab, $ARRAYtermino["idTema"]);
    }
    //fin de if buscar
    $rows .= '   </div>';
    $rows .= '<script type="text/javascript">
	function mostrar(id) {
		((id == "string") ?	$("#by_string").show() : $("#by_string").hide());
	}
	</script>';
    return $rows;
}
function do_target_temaXcode($tema_id, $code, $tvocab_id)
{
    global $DBCFG;
    $userId = $_SESSION[$_SESSION["CFGURL"]][ssuser_id];
    // 	check valid data
    $tema_id = secure_data($tema_id, "int");
    $tvocab_id = secure_data($tvocab_id, "int");
    $code = secure_data($code, "alnum");
    // 	retrieve data about target vocabulary
    $arrayVocab = ARRAYtargetVocabulary($tvocab_id);
    require_once T3_ABSPATH . 'common/include/vocabularyservices.php';
    $dataTterm = getURLdata($arrayVocab[tvocab_uri_service] . '?task=fetchCode&arg=' . $code);
    $tterm_id = (int) $dataTterm->result->term->term_id;
    $tterm_string = (string) $dataTterm->result->term->string;
    if ((int) $dataTterm->result->term->term_id > 0) {
        $arrayTterm["tterm_uri"] = $arrayVocab["tvocab_uri_service"] . '?task=fetchTerm&arg=' . $tterm_id;
        $arrayTterm["tterm_url"] = $arrayVocab["tvocab_url"] . '?tema=' . $tterm_id;
        $arrayTterm["tterm_string"] = secure_data($tterm_string, "ADOsql");
        $sql = SQLo("insert", "into {$DBCFG['DBprefix']}term2tterm (tema_id,tvocab_id,tterm_url,tterm_uri,tterm_string,cuando,uid)\r\n\t\t\t\tvalues (?,?,?,?,{$arrayTterm['tterm_string']},now(),?)", array($tema_id, $arrayVocab[tvocab_id], $arrayTterm[tterm_url], $arrayTterm[tterm_uri], $userId));
        $target_relation_id = $sql[cant];
    }
    return array("tterm_id" => $target_relation_id);
}
function getForeingStrings($tvocab_uri_service, $task, $array_terms)
{
    $arrayTtermData = array();
    if (!in_array($task, array('fetchAlt', 'fetchDown', 'fetchRelated', 'fetchTerms'))) {
        return array();
    }
    if (count($array_terms) < 1) {
        return array();
    }
    foreach ($array_terms as $term) {
        $dataTerm = getURLdata($tvocab_uri_service . '?task=' . $task . '&arg=' . $term["term_id"]);
        if ($dataTerm->resume->cant_result > "0") {
            foreach ($dataTerm->result->term as $value) {
                $i = ++$i;
                $term_id = (int) $value->term_id;
                $string = (string) $value->string;
                $arrayTtermData[$term_id] = array("term_id" => $term_id, "string" => $string, "source_string" => $term["string"], "source_term_id" => $term["term_id"]);
            }
        }
    }
    return $arrayTtermData;
}