<?php

 require '../conf/config.php';

 //////////////////////////////////  Connecting with DB
 $conn = mysql_connect($host, $user, $pswd);
 $db = mysql_select_db($db);

 ////////////////////////////////////////////////////////// Parameters
 (isset($_GET['prm_keyword']) && !empty($_GET['prm_keyword'])) ? $prm_keyword=$_GET['prm_keyword'] : returnError("Error");
 (isset($_GET['prm_chr']) && !empty($_GET['prm_chr'])) ? $prm_chr=$_GET['prm_chr'] : returnError("Error");
 (isset($_GET['prm_zoom']) && !empty($_GET['prm_zoom'])) ? $prm_zoom=$_GET['prm_zoom'] : returnError("Error");

	$prm_keyword=mysql_real_escape_string($prm_keyword);
 
 ////////////////////////////////////////////////////////// Searching locus id
 //$query = "SELECT id, pos, (end-pos+1) FROM sys_track WHERE chr='".$prm_chr."' AND id LIKE '%".$prm_keyword."%' LIMIT 1";
 $query = "SELECT id, pos, (end-pos+1), chr FROM sys_track WHERE id LIKE '%".$prm_keyword."%' LIMIT 1";
 $result = mysql_query ( $query ) or ( "Error " . mysql_error () );
 $row = mysql_fetch_row($result, MYSQL_NUM);

// $p1=(int)((int)$row[1]/_cvtZoom($prm_zoom));
 $pos=(int)((int)$row[1]/_cvtZoom($prm_zoom));
 if ($row[2]%_cvtZoom('1k')){
   $p2=(int)((int)$row[2]/_cvtZoom($prm_zoom));
 } else {
   $p2=(int)((int)$row[2]/_cvtZoom($prm_zoom))-1;
 }
 //$rtnString=$row[0]."|".$pos;
 $rtnString=$row[0]."|".$pos."|".$row[3];
 echo $rtnString;


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

 function _cvtZoom($str) {
   preg_match("/^[0-9]+/", $str, $r1);
   preg_match('/[b,k]$/', $str, $r2);
   $v=$r1[0];
   if($r2[0] == "b"){
     $r=1*(int)$v;
   } else {
     $r=1000*(int)$v;
   }
   return (int)$r;
 }

?>

