Пример #1
0
*/
/**
 * filename, brief description, date of creation, by whom
 * @copyright (C) 2005-2010 University of Sydney Digital Innovation Unit.
 * @link: http://HeuristNetwork.org
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
 * @package Heurist academic knowledge management system
 * @todo
 **/
header("Cache-Control: no-cache, must-revalidate");
// HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// Date in the past
session_cache_limiter('no-cache');
define('SAVE_URI', 'disabled');
define('SEARCH_VERSION', 1);
require_once dirname(__FILE__) . "/../../common/connect/applyCredentials.php";
require_once dirname(__FILE__) . "/../../common/php/dbMySqlWrappers.php";
require_once dirname(__FILE__) . "/../../records/disambig/findFuzzyRecordMatches.php";
$data = json_decode(@$_POST["data"] ? $_POST["data"] : base64_decode(@$_GET["data"]), true);
$details = @$data["details"];
$types = @$data["types"];
$id = @$data["id"] ? $data["id"] : null;
$fuzziness = @$data["fuzziness"] ? $data["fuzziness"] : null;
if (!$details || !$types) {
    print json_format(array("error" => "invalid arguments"));
    return;
}
mysql_connection_select(DATABASE);
$matches = findFuzzyMatches($details, $types, $id, $fuzziness);
print json_format(array("matches" => $matches));
if (!is_logged_in()) {
    return;
}
mysql_connection_overwrite(DATABASE);
mysql_query('set @logged_in_user_id = ' . get_user_id());
$checkSimilar = array_key_exists("check-similar", $_POST);
if ($checkSimilar) {
    $rec_id = intval(@$_POST["recID"]);
    $rec_types = array(intval(@$_POST["rectype"]));
    $fields = array();
    foreach ($_POST as $key => $val) {
        if (preg_match('/^type:(\\d+)/', $key, $matches)) {
            $fields["t:" . $matches[1]] = $val;
        }
    }
    $matches = findFuzzyMatches($fields, $rec_types, $rec_id);
    if (count($matches)) {
        print '({ matches: ' . json_format($matches) . ' })';
        return;
    }
}
$rtyID = @$_POST['rectype'] ? $_POST['rectype'] : (defined('RT_NOTE') ? RT_NOTE : null);
if (!$rtyID && @$_POST['recID']) {
    $res = mysql_query("select rec_RecTypeID from Records where rec_ID = " . $_POST['recID']);
    if ($res) {
        $rtyID = mysql_fetch_row($res);
        $rtyID = $rtyID[0];
    }
}
$TL = array();
$query = 'SELECT trm_ID, trm_Label, trm_ParentTermID, trm_OntID, trm_Code FROM defTerms';