<?
function search($QUERY_START_DATETIME,$QUERY_END_DATETIME,$QUERY_IP,$QUERY_IP_1,$QUERY_OWNER,$QUERY_WHOM,$QUERY_ID,$QUERY_ACCOUNT,$QUERY_CONTENT,$QUERY_STAUTS){
	$_path = "../_read_source/_".$QUERY_STAUTS.".php";
	require($_path);
	
	if($QUERY_STAUTS == "msn"){
		$_DATE  		= $DB_MSN_DATE;
		$_IP			= $DB_MSN_IP;
		$_OWNER			= $DB_MSN_OWNER;
		$_WHOM			= $DB_MSN_WHOM;
		$_AUTO		    = $DB_MSN_AUTO;
		$_ACCOUNT		= $DB_MSN_ACCOUNT;
	}
	elseif($QUERY_STAUTS == "icq"){
		$_DATE	    	= $DB_ICQ_DATE;
		$_IP     		= $DB_ICQ_IP;
		$_OWNER			= $DB_ICQ_OWNER;
		$_WHOM			= $DB_ICQ_WHOM;
		$_AUTO		    = $DB_ICQ_AUTO;
		$_ACCOUNT		= $DB_ICQ_ACCOUNT;
	}
	elseif($QUERY_STAUTS == "yahoo"){
		$_DATE	    	= $DB_YAHOO_TIMESTAMP;
		$_IP     		= $DB_YAHOO_IP;
		$_OWNER			= $DB_YAHOO_OWNER;
		$_WHOM			= $DB_YAHOO_WHOM;
		$_AUTO		    = $DB_YAHOO_AUTO;
		$_ACCOUNT		= $DB_YAHOO_ACCOUNT;
	}
	elseif($QUERY_STAUTS == "qq"){
		$_DATE	    	= $DB_QQ_TIMESTAMP;
		$_IP     		= $DB_QQ_IP;
		$_OWNER			= $DB_QQ_OWNER;
		$_WHOM			= $DB_QQ_WHOM;
		$_AUTO		    = $DB_QQ_AUTO;
		$_ACCOUNT		= $DB_QQ_ACCOUNT;
	}
	elseif($QUERY_STAUTS == "googletalk"){
		$_DATE	    	= $DB_GOOGLETALK_TIMESTAMP;
		$_IP     		= $DB_GOOGLETALK_IP;
		$_OWNER			= $DB_GOOGLETALK_OWNER;
		$_WHOM			= $DB_GOOGLETALK_WHOM;
		$_AUTO		    = $DB_GOOGLETALK_AUTO;
		$_ACCOUNT		= $DB_GOOGLETALK_ACCOUNT;
	}		
				
    if ($QUERY_ID != '') {
		$strSQL = $strSQL." and ".$_AUTO." = '".$QUERY_ID."'";
	}
	elseif($QUERY_CONTENT != ''){
		switch ($QUERY_STAUTS){
			case "msn":
				$tabname="MSN_MSG";
				$colname="_MESG";
			break;
			case "icq":
				$tabname="ICQ_MSG";
				$colname="_MESG";
			break;
			case "yahoo":
				$tabname="YAHOO_MSG";
				$colname="_CONTEXT";
			break;
			case "qq":
				$tabname="QQ_MSG";
				$colname="_CONTEXT ";
			break;
			case "googletalk":
				$tabname="QQ_MSG";
				$colname="_CONTEXT ";
			break;
		}
		$msgSQL="Select DISTINCT _IDX from ".$tabname." Where ".$colname." like '%".$QUERY_CONTENT."%'";
		//print $msgSQL."<br>";

		$intResult=mysql_query($msgSQL);
		$row_num = mysql_num_rows($intResult);
		if($row_num==0)$queryauto="''";
		else{
			$flag=1;
			while ($row=mysql_fetch_array($intResult)){
				if($flag){
					$queryauto="'".$row["_IDX"]."'";
					$flag=0;
				}
				else{
					$queryauto.=",'".$row["_IDX"]."'";
				}
			}
		}
		$strSQL=$strSQL." AND _AUTO in (".$queryauto.")";
	}
	else{
		//if ($QUERY_START_DATETIME == '') $QUERY_START_DATETIME = "19000000000000";
		//if ($QUERY_END_DATETIME == '') $QUERY_END_DATETIME = "20371231235959";
		
		if (($QUERY_START_DATETIME != '')||($QUERY_END_DATETIME != ''))$strSQL = " and ".$_DATE." between '".$QUERY_START_DATETIME."' and '".$QUERY_END_DATETIME."'";

		if ($QUERY_IP_1 != '') { 
			if ($QUERY_IP != '') $strSQL=$strSQL." and ".$_IP." = '".$QUERY_IP."'";
        }
		else{
			if ($QUERY_IP != '') $strSQL=$strSQL." and ".$_IP." like '".$QUERY_IP."%'";
		}

		if ($QUERY_OWNER != '') $strSQL=$strSQL." and ".$_OWNER." like '%".$QUERY_OWNER."%'";
		if ($QUERY_WHOM != '') $strSQL=$strSQL." and ".$_WHOM." like '%".$QUERY_WHOM."%'";

		if($QUERY_ACCOUNT != ''){
			$strSQL = $strSQL." and ".$_ACCOUNT."='".$QUERY_ACCOUNT."'";
		}
	}
	return $strSQL;
}
?>