<?php
require '../conf/config.php';
require './common.php';
require './commonDB.php';
////////////////////////////////// Connecting with DB
if( !$conn = new mysqli($host, $user, $pswd, $db)) {
    error_log("Connection failed.\n");
    exit;
}

(isset($_POST['prm_fa_gene']) && !empty($_POST['prm_fa_gene'])) ? $prm_gene=$_POST['prm_fa_gene']:returnError("Error");
$flag = false;
$query = "select 'dummy',pos,end,chr from sys_track where id=? and parent=1";
//$query = "select name,pos,end,chr from sys_track where name=? limit 1";
$stmt = $conn->stmt_init();
$stmt->prepare($query);
$stmt->bind_param("s", $prm_gene);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($row0,$row1,$row2,$row3);
$res = array("valid" => false);
if ($stmt->fetch()) {
/*
    $flag = true;
    $st = $row1;
    $ed = $row2;
    $chr = $row3;
*/
    $res["valid"] = true;
    $res["chr"] = $row3;
    $res["start"] = $row1;
    $res["end"] = $row2;
    $res["regs"] = getCDSLength($conn, $prm_gene);
    $res["gene"] = $prm_gene;
}
//$stmt->free_result();
$stmt->close();

/*
if($flag){
   echo $st.",".$ed.",".$chr;
}else{
   echo false;
}
*/
echo json_encode($res);

function returnError($str){
    echo $str;
}
?>
