<commit_before><?php 
/* 
 * NOTE that this page does not go to great lengths to protect user input,
 * since the user is already a logged-in administrator.
 */
// open and load site variables
require('../Site.conf');

// check for a valid (non-empty) query
if (!isset($_POST["matched_name"])) {
	echo "{'ERROR': 'no name submitted in POST!'}";
	return;
}

// connect to mySQL server and select the Fossil Calibration database
$connection=mysql_connect($SITEINFO['servername'],$SITEINFO['UserName'], $SITEINFO['password']) or die ('Unable to connect!');
mysql_select_db('FossilCalibration') or die ('Unable to select database!');

// look for matching node (NCBI, then FCD) that uses this exact name



// check list of names against this query
// TODO: show un-published names only to logged-in admins/reviewers
$query="SELECT taxonid, 'NCBI' AS source
	FROM NCBI_names
	WHERE name LIKE '". mysql_real_escape_string($_POST["matched_name"]) ."'
    LIMIT 1;";
$match_list=mysql_query($query) or die ('Error  in query: '.$query.'|'. mysql_error());	
$node_data = mysql_fetch_assoc($match_list);

if (!$node_data) {
    // fall back to FCD names *if* no NCBI node was found
    $query="SELECT taxonid, 'FCD' AS source
        FROM FCD_names
        WHERE name LIKE '". mysql_real_escape_string($_POST["matched_name"]) ."'".
        // non-admin users should only see *Published* publication names
        ((isset($_SESSION['IS_ADMIN_USER']) && ($_SESSION['IS_ADMIN_USER'] == true)) ? "" :  
            " AND is_public_name = 1"
        )
        ." LIMIT 1;";
    $match_list=mysql_query($query) or die ('Error  in query: '.$query.'|'. mysql_error());	
    $node_data = mysql_fetch_assoc($match_list);
}

// return populated fields (or empty, if no matching node was found)
?>
<input type="text" readonly="readonly" style="width: 15%; color: #999; text-align: center;" 
       name="hintNodeSource_<?= $_POST["side"] ?>[]" id="hintNodeSource_<?= $_POST["side"] ?>_<?= $_POST["position"] ?>" value="<?= (!$node_data) ? 'ERROR' : $node_data['source'] ?>" />

<input type="text" readonly="readonly" style="width: 15%; color: #999; text-align: center;" 
       name="hintNodeID_<?= $_POST["side"] ?>[]" id="hintNodeID_<?= $_POST["side"] ?>_<?= $_POST["position"] ?>" value="<?= (!$node_data) ? 'ERROR' : $node_data['taxonid'] ?>" /><commit_msg>Fix fetch of taxon source+ID from a "unique" name.<commit_after><?php 
/* 
 * NOTE that this page does not go to great lengths to protect user input,
 * since the user is already a logged-in administrator.
 */
// open and load site variables
require('../Site.conf');

// check for a valid (non-empty) query
if (!isset($_POST["matched_name"])) {
	echo "{'ERROR': 'no name submitted in POST!'}";
	return;
}

// connect to mySQL server and select the Fossil Calibration database
$connection=mysql_connect($SITEINFO['servername'],$SITEINFO['UserName'], $SITEINFO['password']) or die ('Unable to connect!');
mysql_select_db('FossilCalibration') or die ('Unable to select database!');

// look for matching node (NCBI, then FCD) that uses this exact name



// check list of names against this query
// TODO: show un-published names only to logged-in admins/reviewers
$query="SELECT taxonid AS nameid, 'NCBI' AS source
	FROM NCBI_names
	WHERE name LIKE '". mysql_real_escape_string($_POST["matched_name"]) ."'
     OR uniquename LIKE '". mysql_real_escape_string($_POST["matched_name"]) ."'
    LIMIT 1;";
$match_list=mysql_query($query) or die ('Error  in query: '.$query.'|'. mysql_error());	
$node_data = mysql_fetch_assoc($match_list);

if (!$node_data) {
    // fall back to FCD names *if* no NCBI node was found
    $query="SELECT node_id AS nameid, 'FCD' AS source
        FROM FCD_names
        WHERE name LIKE '". mysql_real_escape_string($_POST["matched_name"]) ."'
     OR uniquename LIKE '". mysql_real_escape_string($_POST["matched_name"]) ."'".
        // non-admin users should only see *Published* publication names
        ((isset($_SESSION['IS_ADMIN_USER']) && ($_SESSION['IS_ADMIN_USER'] == true)) ? "" :  
            " AND is_public_name = 1"
        )
        ." LIMIT 1;";
    $match_list=mysql_query($query) or die ('Error  in query: '.$query.'|'. mysql_error());	
    $node_data = mysql_fetch_assoc($match_list);
}

// return populated fields (or empty, if no matching node was found)
?>
<input type="text" readonly="readonly" style="width: 15%; color: #999; text-align: center;" 
       name="hintNodeSource_<?= $_POST["side"] ?>[]" id="hintNodeSource_<?= $_POST["side"] ?>_<?= $_POST["position"] ?>" value="<?= (!$node_data) ? 'ERROR' : $node_data['source'] ?>" />

<input type="text" readonly="readonly" style="width: 15%; color: #999; text-align: center;" 
       name="hintNodeID_<?= $_POST["side"] ?>[]" id="hintNodeID_<?= $_POST["side"] ?>_<?= $_POST["position"] ?>" value="<?= (!$node_data) ? 'ERROR' : $node_data['nameid'] ?>" />
{'fraction_non_alphanumeric': 0.17647058823529413, 'fraction_numerical': 0.0053104575163398695, 'mean_word_length': 4.453229398663697, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5549043', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1549, 'n_words': 452}