function fetchTermUp($tema_id)
 {
     $sql = SQLarbolTema($tema_id);
     /*
     Si hay resultados
     */
     if (SQLcount($sql) > 0) {
         while ($array = $sql->FetchRow()) {
             $i = ++$i;
             $result["result"][$array[tema_id]] = array("term_id" => $array[tema_id], "string" => $array[tema], "isMetaTerm" => $array[isMetaTerm], "relation_type_id" => $array[t_relacion], "order" => $i);
         }
     }
     return $result;
 }
function SQLupdateTemaTresVersion($ver2ver)
{
    global $DBCFG;
    $prefix = $DBCFG['DBprefix'];
    switch ($ver2ver) {
        case '1_6x1_7':
            $sql1_6x1_7 = SQL("ALTER", " TABLE `" . $prefix . "tema` ADD `isMetaTerm` BOOLEAN NOT NULL DEFAULT FALSE,ADD INDEX ( `isMetaTerm` ) ");
            $ctrl = ARRAYfetchValueXValue('config', 'CFG_SEARCH_METATERM');
            if (!$ctrl[value_id]) {
                $sql1_6x1_7a = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t('config', 'CFG_SEARCH_METATERM', NULL, '0')");
            }
            $ctrl = ARRAYfetchValueXValue('config', 'CFG_ENABLE_SPARQL');
            if (!$ctrl[value_id]) {
                $sql1_6x1_7b = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t('config', 'CFG_ENABLE_SPARQL', NULL, '0')");
            }
            $ctrl = ARRAYfetchValueXValue('config', 'CFG_SUGGESTxWORD');
            if (!$ctrl[value_id]) {
                $sql1_6x1_7c = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t('config', 'CFG_SUGGESTxWORD', NULL, '1')");
            }
            $logTask["1_6x1_7"] = SQLcount($sql1_6x1_7a);
            break;
        case '1_5x1_6':
            $sql1_5x1_6 = SQL("ALTER", " TABLE `" . $prefix . "term2tterm` ADD INDEX `target_terms` ( `tterm_string` ) ");
            $sql1_5x1_6a = SQL("ALTER", " TABLE `" . $prefix . "usuario` ADD `user_activation_key` VARCHAR( 60 ) NULL , ADD INDEX ( `user_activation_key` ) ");
            $sql1_5x1_6b = SQL("ALTER", " TABLE `" . $prefix . "usuario` CHANGE `pass` `pass` VARCHAR( 60{$ver2ver} ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT ''");
            $logTask["1_5x1_6"] = SQLcount($sql1_6x1_6);
            break;
        case '1_4x1_5':
            $sql1_4x1_5a = SQL("ALTER", " TABLE `" . $prefix . "tvocab` CHANGE `tvocab_tag` `tvocab_tag` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
            $sql1_4x1_5b = SQL("ALTER", " TABLE `" . $prefix . "values` CHANGE `value_code` `value_code` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL");
            $sql1_4x1_5b = SQL("ALTER", " TABLE `" . $prefix . "values` CHANGE `value` `value` longtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL");
            $sql1_4x1_5b = SQL("ALTER", " TABLE `" . $prefix . "values` CHANGE `value_type` `value_type` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL");
            $sql1_4x1_5c = SQL("ALTER", "TABLE `" . $prefix . "tabla_rel` ADD `rel_rel_id` INT( 22 ) NULL AFTER `t_relacion` ,ADD INDEX ( `rel_rel_id` )");
            $sql1_4x1_5d = SQL("CREATE", " TABLE IF NOT EXISTS `" . $prefix . "uri` (\r\n\t\t`uri_id` int(22) NOT NULL AUTO_INCREMENT,\r\n\t\t`tema_id` int(22) NOT NULL,\r\n\t\t`uri_type_id` int(22) NOT NULL,\r\n\t\t`uri` tinytext NOT NULL,\r\n\t\t`uid` int(22) NOT NULL,\r\n\t\t`cuando` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\r\n\t\tPRIMARY KEY (`uri_id`),\r\n\t\tKEY `tema_id` (`tema_id`)\r\n\t\t) DEFAULT CHARSET=utf8 ENGINE=MyISAM  COMMENT='external URIs associated to terms';");
            if ($sql1_4x1_5c) {
                $ctrl = ARRAYfetchValue('4', 'SP');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('4', 'Spelling variant', NULL, 'SP')");
                }
                $ctrl = ARRAYfetchValue('4', 'MS');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('4', 'MisSpelling', NULL, 'MS')");
                }
                $ctrl = ARRAYfetchValue('3', 'P');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('3', 'Partitive', NULL, 'P')");
                }
                $ctrl = ARRAYfetchValue('3', 'I');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('3', 'Instance', NULL, 'I')");
                }
                $ctrl = ARRAYfetchValue('4', 'H');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('4', 'Hidden label', NULL, 'H')");
                }
                $ctrl = ARRAYfetchValue('4', 'AB');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('4', 'Abbreviation', NULL, 'AB')");
                }
                $ctrl = ARRAYfetchValue('4', 'FT');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('4', 'Full form of the term', NULL, 'FT')");
                }
                $ctrl = ARRAYfetchValue('URI_TYPE', 'broadMatch');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('URI_TYPE', 'broadMatch', NULL, 'broadMatch')");
                }
                $ctrl = ARRAYfetchValue('URI_TYPE', 'closeMatch');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('URI_TYPE', 'closeMatch', NULL, 'closeMatch')");
                }
                $ctrl = ARRAYfetchValue('URI_TYPE', 'exactMatch');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('URI_TYPE', 'exactMatch', NULL, 'exactMatch')");
                }
                $ctrl = ARRAYfetchValue('URI_TYPE', 'relatedMatch');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('URI_TYPE', 'relatedMatch', NULL, 'relatedMatch')");
                }
                $ctrl = ARRAYfetchValue('URI_TYPE', 'narrowMatch');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('URI_TYPE', 'narrowMatch', NULL, 'narrowMatch')");
                }
                $ctrl = ARRAYfetchValue('DATESTAMP', 'NOTE_CHANGE');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('DATESTAMP', now(), NULL, 'NOTE_CHANGE')");
                }
                $ctrl = ARRAYfetchValue('DATESTAMP', 'TERM_CHANGE');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('DATESTAMP', now(), NULL, 'TERM_CHANGE')");
                }
                $ctrl = ARRAYfetchValue('DATESTAMP', 'TTERM_CHANGE');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('DATESTAMP', now(), NULL, 'TTERM_CHANGE')");
                }
                $ctrl = ARRAYfetchValue('DATESTAMP', 'THES_CHANGE');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('DATESTAMP', now(), NULL, 'THES_CHANGE')");
                }
                $ctrl = ARRAYfetchValue('METADATA', 'dc:contributor');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('METADATA', NULL, 2, 'dc:contributor')");
                }
                $ctrl = ARRAYfetchValue('METADATA', 'dc:publisher');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('METADATA', NULL, 5, 'dc:publisher')");
                }
                $ctrl = ARRAYfetchValue('METADATA', 'dc:rights');
                if (!$ctrl[value_id]) {
                    $sqlvalue = SQL("insert", "into `" . $prefix . "values` (`value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t\t\t('METADATA', NULL, 9, 'dc:rights')");
                }
            }
            $result5 = SQL("insert", "into `" . $prefix . "values` (`value_id`, `value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t(15, 't_nota', 'Nota catalográfica', 5, 'NC'),\r\n\t\t(16, 'config', '_USE_CODE', 1, '1'),\r\n\t\t(17, 'config', '_SHOW_CODE', 1, '1'),\r\n\t\t(18, 'config', 'CFG_MAX_TREE_DEEP', NULL, '3'),\r\n\t\t(19, 'config', 'CFG_VIEW_STATUS', NULL, '0'),\r\n\t\t(20, 'config', 'CFG_SIMPLE_WEB_SERVICE', NULL, '1'),\r\n\t\t(21, 'config', 'CFG_NUM_SHOW_TERMSxSTATUS', NULL, '200'),\r\n\t\t(22, 'config', 'CFG_MIN_SEARCH_SIZE', NULL, '2'),\r\n\t\t(23, 'config', '_SHOW_TREE', '1', '1'),\r\n\t\t(24, 'config', '_PUBLISH_SKOS', '1', '0')");
            $logTask["1_3x1_4"] = SQLcount($result5);
            break;
        case '1_1x1_2':
            $result61 = SQL("CREATE", " TABLE IF NOT EXISTS `" . $prefix . "term2tterm` (\r\n\t\t`tterm_id` int(22) NOT NULL AUTO_INCREMENT,\r\n\t\t`tvocab_id` int(22) NOT NULL,\r\n\t\t`tterm_url` varchar(200) NOT NULL,\r\n\t\t`tterm_uri` varchar(200) NOT NULL,\r\n\t\t`tterm_string` varchar(250) NOT NULL,\r\n\t\t`cuando` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\r\n\t\t`cuando_last` timestamp NULL DEFAULT NULL,\r\n\t\t`uid` int(22) NOT NULL,\r\n\t\t`tema_id` int(22) NOT NULL,\r\n\t\tPRIMARY KEY (`tterm_id`),\r\n\t\tKEY `tvocab_id` (`tvocab_id`,`cuando`,`cuando_last`,`uid`),\r\n\t\tKEY `tema_id` (`tema_id`),\r\n\t\tKEY `tterm_string` (`tterm_string`)\r\n\t\t) DEFAULT CHARSET=utf8 ENGINE=MyISAM");
            $result62 = SQL("CREATE", " TABLE IF NOT EXISTS `" . $prefix . "tvocab` (\r\n\t\t`tvocab_id` int(22) NOT NULL AUTO_INCREMENT,\r\n\t\t`tvocab_label` varchar(150) NOT NULL,\r\n\t\t`tvocab_tag` varchar(5) NOT NULL,\r\n\t\t`tvocab_lang` VARCHAR( 5 ),\r\n\t\t`tvocab_title` varchar(200) NOT NULL,\r\n\t\t`tvocab_url` varchar(250) NOT NULL,\r\n\t\t`tvocab_uri_service` varchar(250) NOT NULL,\r\n\t\t`tvocab_status` tinyint(1) NOT NULL,\r\n\t\t`cuando` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\r\n\t\t`uid` int(22) NOT NULL,\r\n\t\tPRIMARY KEY (`tvocab_id`),\r\n\t\tKEY `uid` (`uid`),\r\n\t\tKEY `status` (`tvocab_status`)\r\n\t\t) DEFAULT CHARSET=utf8 ENGINE=MyISAM ;");
            $result622 = SQL("ALTER", " TABLE `" . $prefix . "notas` ADD FULLTEXT `notas` (`nota`);");
            $result5 = SQL("insert", "into `" . $prefix . "values` (`value_id`, `value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t(15, 't_nota', 'Nota catalográfica', 5, 'NC'),\r\n\t\t(16, 'config', '_USE_CODE', 1, '1'),\r\n\t\t(17, 'config', '_SHOW_CODE', 1, '1'),\r\n\t\t(18, 'config', 'CFG_MAX_TREE_DEEP', NULL, '3'),\r\n\t\t(19, 'config', 'CFG_VIEW_STATUS', NULL, '0'),\r\n\t\t(20, 'config', 'CFG_SIMPLE_WEB_SERVICE', NULL, '1'),\r\n\t\t(21, 'config', 'CFG_NUM_SHOW_TERMSxSTATUS', NULL, '200'),\r\n\t\t(22, 'config', 'CFG_MIN_SEARCH_SIZE', NULL, '2'),\r\n\t\t(23, 'config', '_SHOW_TREE', '1', '1'),\r\n\t\t(24, 'config', '_PUBLISH_SKOS', '1', '0')");
            $logTask["1_1x1_2"] = $result61 + $result62 + $result622;
            break;
        case '1x1_2':
            //update to 1.1
            $result60 = SQL("ALTER", " TABLE `" . $prefix . "tema` ADD `code` VARCHAR( 30 ) NULL COMMENT 'code_term' AFTER `tema_id`");
            $result601 = SQL("ALTER", " TABLE `" . $prefix . "tema` ADD INDEX ( `code` )");
            $result61 = SQL("CREATE", " TABLE IF NOT EXISTS `" . $prefix . "term2tterm` (\r\n\t\t`tterm_id` int(22) NOT NULL AUTO_INCREMENT,\r\n\t\t`tvocab_id` int(22) NOT NULL,\r\n\t\t`tterm_url` varchar(200) NOT NULL,\r\n\t\t`tterm_uri` varchar(200) NOT NULL,\r\n\t\t`tterm_string` varchar(250) NOT NULL,\r\n\t\t`cuando` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\r\n\t\t`cuando_last` timestamp NULL DEFAULT NULL,\r\n\t\t`uid` int(22) NOT NULL,\r\n\t\t`tema_id` int(22) NOT NULL,\r\n\t\tPRIMARY KEY (`tterm_id`),\r\n\t\tKEY `tvocab_id` (`tvocab_id`,`cuando`,`cuando_last`,`uid`),\r\n\t\tKEY `tema_id` (`tema_id`),\r\n\t\tKEY `tterm_string` (`tterm_string`)\r\n\t\t) DEFAULT CHARSET=utf8 ENGINE=MyISAM");
            $result62 = SQL("CREATE", " TABLE IF NOT EXISTS `" . $prefix . "tvocab` (\r\n\t\t`tvocab_id` int(22) NOT NULL AUTO_INCREMENT,\r\n\t\t`tvocab_label` varchar(150) NOT NULL,\r\n\t\t`tvocab_tag` varchar(5) NOT NULL,\r\n\t\t`tvocab_lang` VARCHAR( 5 ),\r\n\t\t`tvocab_title` varchar(200) NOT NULL,\r\n\t\t`tvocab_url` varchar(250) NOT NULL,\r\n\t\t`tvocab_uri_service` varchar(250) NOT NULL,\r\n\t\t`tvocab_status` tinyint(1) NOT NULL,\r\n\t\t`cuando` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\r\n\t\t`uid` int(22) NOT NULL,\r\n\t\tPRIMARY KEY (`tvocab_id`),\r\n\t\tKEY `uid` (`uid`),\r\n\t\tKEY `status` (`tvocab_status`)\r\n\t\t) DEFAULT CHARSET=utf8 ENGINE=MyISAM ;");
            $result622 = SQL("ALTER", " TABLE `" . $prefix . "notas` ADD FULLTEXT `notas` (`nota`);");
            $result5 = SQL("insert", "into `" . $prefix . "values` (`value_id`, `value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t(15, 't_nota', 'Nota catalográfica', 5, 'NC'),\r\n\t\t(16, 'config', '_USE_CODE', 1, '1'),\r\n\t\t(17, 'config', '_SHOW_CODE', 1, '1'),\r\n\t\t(18, 'config', 'CFG_MAX_TREE_DEEP', NULL, '3'),\r\n\t\t(19, 'config', 'CFG_VIEW_STATUS', NULL, '0'),\r\n\t\t(20, 'config', 'CFG_SIMPLE_WEB_SERVICE', NULL, '1'),\r\n\t\t(21, 'config', 'CFG_NUM_SHOW_TERMSxSTATUS', NULL, '200'),\r\n\t\t(22, 'config', 'CFG_MIN_SEARCH_SIZE', NULL, '2'),\r\n\t\t(23, 'config', '_SHOW_TREE', '1', '1'),\r\n\t\t(24, 'config', '_PUBLISH_SKOS', '1', '0')");
            $logTask["1x1_2"] = SQLcount($result61) + SQLcount($result62) + SQLcount($result622) + SQLcount($result60) + SQLcount($result601);
            break;
        case '1x1_2':
            //update to 1.1
            $result60 = SQL("ALTER", " TABLE `" . $prefix . "tema` ADD `code` VARCHAR( 20 ) NULL COMMENT 'code_term' AFTER `tema_id`");
            $result601 = SQL("ALTER", " TABLE `" . $prefix . "tema` ADD INDEX ( `code` )");
            $result61 = SQL("CREATE", " TABLE IF NOT EXISTS `" . $prefix . "term2tterm` (\r\n\t\t`tterm_id` int(22) NOT NULL AUTO_INCREMENT,\r\n\t\t`tvocab_id` int(22) NOT NULL,\r\n\t\t`tterm_url` varchar(200) NOT NULL,\r\n\t\t`tterm_uri` varchar(200) NOT NULL,\r\n\t\t`tterm_string` varchar(250) NOT NULL,\r\n\t\t`cuando` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\r\n\t\t`cua\r\n\t\t` int(22) NOT NULL,\r\n\t\t`tema_id` int(22) NOT NULL,\r\n\t\tPRIMARY KEY (`tterm_id`),\r\n\t\tKEY `tvocab_id` (`tvocab_id`,`cuando`,`cuando_last`,`uid`),\r\n\t\tKEY `tema_id` (`tema_id`),\r\n\t\tKEY `tterm_string` (`tterm_string`)\r\n\t\t) DEFAULT CHARSET=utf8 ENGINE=MyISAM");
            $result62 = SQL("CREATE", " TABLE IF NOT EXISTS `" . $prefix . "tvocab` (\r\n\t\t`tvocab_id` int(22) NOT NULL AUTO_INCREMENT,\r\n\t\t`tvocab_label` varchar(150) NOT NULL,\r\n\t\t`tvocab_tag` varchar(5) NOT NULL,\r\n\t\t`tvocab_lang` VARCHAR( 5 ),\r\n\t\t`tvocab_title` varchar(200) NOT NULL,\r\n\t\t`tvocab_url` varchar(250) NOT NULL,\r\n\t\t`tvocab_uri_service` varchar(250) NOT NULL,\r\n\t\t`tvocab_status` tinyint(1) NOT NULL,\r\n\t\t`cuando` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\r\n\t\t`uid` int(22) NOT NULL,\r\n\t\tPRIMARY KEY (`tvocab_id`),\r\n\t\tKEY `uid` (`uid`),\r\n\t\tKEY `status` (`tvocab_status`)\r\n\t\t) DEFAULT CHARSET=utf8 ENGINE=MyISAM ;");
            $result5 = SQL("insert", "into `" . $prefix . "values` (`value_id`, `value_type`, `value`, `value_order`, `value_code`) VALUES\r\n\t\t(15, 't_nota', 'Nota catalográfica', 5, 'NC'),\r\n\t\t(16, 'config', '_USE_CODE', 1, '1'),\r\n\t\t(17, 'config', '_SHOW_CODE', 1, '1'),\r\n\t\t(18, 'config', 'CFG_MAX_TREE_DEEP', NULL, '3'),\r\n\t\t(19, 'config', 'CFG_VIEW_STATUS', NULL, '0'),\r\n\t\t(20, 'config', 'CFG_SIMPLE_WEB_SERVICE', NULL, '1'),\r\n\t\t(21, 'config', 'CFG_NUM_SHOW_TERMSxSTATUS', NULL, '200'),\r\n\t\t(22, 'config', 'CFG_MIN_SEARCH_SIZE', NULL, '2'),\r\n\t\t(23, 'config', '_SHOW_TREE', '1', '1'),\r\n\t\t(24, 'config', '_PUBLISH_SKOS', '1', '0')");
            $result622 = SQL("ALTER", " TABLE `" . $prefix . "notas` ADD FULLTEXT `notas` (`nota`);");
            $logTask["1x1_2"] = SQLcount($result61) + SQLcount($result62) + SQLcount($result622) + SQLcount($result60) + SQLcount($result601);
            break;
        default:
            return false;
            break;
    }
    return $logTask;
}
function REMTerms($terms_id = array(), $onlyFreeTerms = 1)
{
    $i_term = count($terms_id);
    $i_delete = 0;
    for ($i = 0; $i < sizeof($terms_id); ++$i) {
        $ctrl = 1;
        if ($onlyFreeTerms == 1) {
            $sqlCtrl = SQLcheckFreeTerm($terms_id[$i]);
            $ctrl = SQLcount($sqlCtrl);
        }
        if ($ctrl == '1') {
            borra_t($terms_id[$i]);
            $i_delete = ++$i_delete;
        }
    }
    return array("terms" => $i_term, "error" => $i_term - $i_delete, "success" => $i_delete);
}
function HTMLformVerTerminosSinBT($taskterm = 'null', $terms_id = array())
{
    //borrado masivo de términos libres
    if ($taskterm == 'deleteTerms') {
        $task = REMTerms($terms_id, 0);
    }
    //tesauro_id = 1;
    $sql = SQLtermsNoBT(1);
    $rows .= '<div>';
    $rows .= '<h3>' . ucfirst(LABEL_termsNoBT) . ' (' . SQLcount($sql) . ') </h3>';
    if (is_array($task)) {
        if ($task["error"] > 0) {
            $rows .= '<p class="error">' . $task["error"] . ' ' . MSG_termsNoDeleted . ' </p>';
        } else {
            $rows .= '<p class="success">' . $task["success"] . ' ' . MSG_termsDeleted . ' </p>';
        }
    }
    if (SQLcount($sql) > 0) {
        $rows .= '<div><input id="filter" type="text" class="form-control" placeholder="' . ucfirst(LABEL_type2filter) . '"></div>';
        $rows .= '<form role="form"  id="delete_free_terms" name="delete_free_terms" action="index.php?verT=NBT" method="post">';
        $rows .= '<div class="table-responsive"> ';
        $rows .= '<table class="table table-striped table-bordered table-condensed table-hover">
		<thead>
		<tr>
			<th></th>
			<th>' . ucfirst(LABEL_Termino) . '</th>
			<th>' . ucfirst(LABEL_nonPreferedTerms) . '</th>
			<th>' . ucfirst(LABEL_relatedTerms) . '</th>
		</tr>
		</thead>
		<tbody class="searchable">';
        while ($array = $sql->FetchRow()) {
            $css_class_MT = $array["isMetaTerm"] == 1 ? ' class="metaTerm" ' : '';
            $rows .= '<tr>';
            $rows .= '     <td align="center"><input type="checkbox" name="deleteTerms_id[]" id="term_' . $array["tema_id"] . '" title="' . ucfirst(MENU_BorrarT) . ' ' . $array["tema"] . ' " value="' . $array["tema_id"] . '" /></td>';
            $rows .= '     <td><label class="check_label" title="' . $value["tema"] . ' " for="term_' . $array["tema_id"] . '"><a ' . $css_class_MT . ' title="' . $array[tema] . '" href="index.php?tema=' . $array["tema_id"] . '">' . $array[tema] . '</a></label> </td>';
            $rows .= '      <td>' . $array["cant_UF"] . '</td>';
            $rows .= '      <td>' . $array["cant_RT"] . '</td>';
            $rows .= '  </tr>';
        }
        $rows .= '        </tbody></table>';
        $rows .= '</div>';
        $rows .= '<p class="warning">' . MSG__warningDeleteTerm2row . '</p>';
        $rows .= '<div class="submit_form" align="center">';
        $rows .= '	<input type="hidden" id="taskterm" name="taskterm" value="deleteTerms"/>';
        $rows .= '  	<input  class="submit ui-corner-all" type="submit" name="boton" value="' . ucfirst(MENU_BorrarT) . '"/>';
        $rows .= '</div>';
        $rows .= '</form>';
    }
    //if cant
    $rows .= '</div>';
    return $rows;
}
function loadConfigValues($renew = "0")
{
    global $arrayCFGs;
    //renovar valores
    if ($renew == '1') {
        global $DBCFG;
        $sql = SQL("select", "v.value_id,v.value_type,v.value,v.value_code,v.value_order\r\n\t\t\t\t\t\tfrom {$DBCFG['DBprefix']}values v\r\n\t\t\t\t\t\twhere v.value_type='config'");
        if (SQLcount($sql) > 0) {
            $NEWarrayCFGs = array();
            while ($array = $sql->FetchRow()) {
                switch ($array[value]) {
                    case 'CFG_MAX_TREE_DEEP':
                        $array[value_code] = in_array($array[value_code], array(1, 2, 3, 4, 5, 6)) ? $array[value_code] : $arrayCFGs[$array[value]];
                        break;
                    case 'CFG_MIN_SEARCH_SIZE':
                        $array[value_code] = in_array($array[value_code], array(1, 2, 3, 4, 5, 6)) ? $array[value_code] : $arrayCFGs[$array[value]];
                        break;
                    case 'CFG_NUM_SHOW_TERMSxSTATUS':
                        $array[value_code] = in_array($array[value_code], array(50, 100, 150, 200, 250)) ? $array[value_code] : $arrayCFGs[$array[value]];
                        break;
                    default:
                        $array[value_code] = in_array($array[value_code], array(1, 0)) ? $array[value_code] : $arrayCFGs[$array[value]];
                }
                $NEWarrayCFGs[$array["value"]] = $array["value_code"];
            }
        }
    }
    //define default values
    foreach ($arrayCFGs as $key => $value) {
        $value = isset($NEWarrayCFGs["{$key}"]) ? $NEWarrayCFGs["{$key}"] : $value;
        $_SESSION[$_SESSION["CFGURL"]]["{$key}"] = $value;
    }
}
function HTMLURI4term($tema_id)
{
    $sql = SQLURIxterm($tema_id);
    if (SQLcount($sql) > 0) {
        $rows = '<ul class="list-unstyled">';
        while ($array = $sql->FetchRow()) {
            if ($_SESSION[$_SESSION["CFGURL"]]["ssuser_id"]) {
                $delLink = '<a type="button" class="btn btn-danger btn-xs" id="elimina_' . $array["uri_id"] . '" title="' . LABEL_borraRelacion . '"  href="index.php?uri_id=' . $array[uri_id] . '&amp;tema=' . $tema_id . '&amp;taskrelations=delURIterm" onclick="return askData();"><span class="glyphicon glyphicon-remove"></span></a> ';
            }
            $rows .= '<li>' . $delLink . ' ' . ucfirst($array["uri_value"]) . ' <a href="' . $array["uri"] . '" target="_blank" title="' . ucfirst($array[uri_value]) . '">' . $array["uri"] . '</a>';
            $rows .= '</li>';
        }
        $rows .= '</ul>';
    }
    return $rows;
}