<?
function fn_SearchMail($QUERY_START_DATETIME,$QUERY_END_DATETIME,$QUERY_FROM,$QUERY_TO,$QUERY_CC,$QUERY_BCC,$QUERY_SUBJECT,$QUERY_HOST,$QUERY_IP,$QUERY_IP_1,$QUERY_ID,$QUERY_ACCOUNT,$QUERY_STAUTS){
	switch($QUERY_STAUTS){
		case "pop3":
		case "smtp":
			$_path = "../_read_source/_".$QUERY_STAUTS.".php";
			break;
		case "webmails";
			$_path = "../_read_source/_webmail.php";
			break;
		case "imap";
			$_path = "../_read_source/_pop3.php";
		 break;
	}
	require($_path);
	
	if($QUERY_STAUTS == "pop3"){
		$_DATETIME		= $DB_POP3_DB_DATETIME;
		$_FROM			= $DB_POP3_FROM;
		$_TO			= $DB_POP3_TO;
		$_CC			= $DB_POP3_CC;
		$_SUBJECT		= $DB_POP3_SUBJECT;
		$_AUTO          = $DB_POP3_AUTO;
		$_IP			= $DB_POP3_SIP;
		$_ACCOUNT		= $DB_POP3_ACCOUNT;
	}
	elseif($QUERY_STAUTS == "imap"){
		$_DATETIME		= $DB_POP3_DB_DATETIME;
		$_FROM			= $DB_POP3_FROM;
		$_TO			= $DB_POP3_TO;
		$_CC			= $DB_POP3_CC;
		$_SUBJECT		= $DB_POP3_SUBJECT;
		$_AUTO          = $DB_POP3_AUTO;
		$_IP			= $DB_POP3_SIP;
		$_ACCOUNT		= $DB_POP3_ACCOUNT;
	}
	elseif($QUERY_STAUTS == "smtp"){
		$_DATETIME		= $DB_SMTP_DB_DATETIME;
		$_FROM			= $DB_SMTP_FROM;
		$_TO			= $DB_SMTP_TO;
		$_CC			= $DB_SMTP_CC;
		$_BCC			= $DB_SMTP_BCC;
		$_SUBJECT		= $DB_SMTP_SUBJECT;
		$_AUTO          = $DB_SMTP_AUTO;
		$_IP			= $DB_SMTP_SIP;
		$_ACCOUNT		= $DB_SMTP_ACCOUNT;
	}
	elseif($QUERY_STAUTS == "webmails"){
		$_DATETIME		= $DB_WEBMAIL_DATETIME;
		$_FROM			= $DB_WEBMAIL_SENDER;
		$_TO			= $DB_WEBMAIL_TO;
		$_CC			= $DB_WEBMAIL_CC;
		$_BCC			= $DB_WEBMAIL_BCC;
		$_SUBJECT		= $DB_WEBMAIL_UTF_SUBJECT;
		$_HOST			= $DB_WEBMAIL_HOST;
		$_AUTO          = $DB_WEBMAIL_AUTO;
		$_IP			= $DB_WEBMAIL_IP;
		$_ACCOUNT		= $DB_WEBMAIL_ACCOUNT;
	}


    if ($QUERY_ID != '') {
		$strSQL = $strSQL." and ".$_AUTO." = '".$QUERY_ID."'";
	}
	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 ".$_DATETIME." between '".$QUERY_START_DATETIME."' and '".$QUERY_END_DATETIME."'";

		if ($QUERY_FROM != '') $strSQL = $strSQL." and ".$_FROM." like '%".$QUERY_FROM."%'";
		if ($QUERY_TO != '') $strSQL = $strSQL." and ".$_TO." like '%".$QUERY_TO."%'";
		if ($QUERY_CC != '') $strSQL = $strSQL." and ".$_CC." like '%".$QUERY_CC."%'";
		if ($QUERY_SUBJECT != '') $strSQL = $strSQL." and ".$_SUBJECT." like '%".$QUERY_SUBJECT."%'";

		if ($QUERY_BCC != '' and ($QUERY_STAUTS == "smtp" || $QUERY_STAUTS == "webmails")){
			$strSQL = $strSQL." and ".$_BCC." like '%".$QUERY_BCC."%'";
		}

		if ($QUERY_HOST != '' and $QUERY_STAUTS == "webmails"){
			$strSQL = $strSQL." and ".$_HOST." = '".$QUERY_HOST."'";
		}

		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_ACCOUNT != ''){
			$strSQL = $strSQL." and ".$_ACCOUNT."='".$QUERY_ACCOUNT."'";
		}
	}

	return $strSQL;
}

function fn_SearchWebmail($QUERY_START_DATETIME,$QUERY_END_DATETIME,$QUERY_TAG,$QUERY_IP,$QUERY_IP_1,$QUERY_URL,$QUERY_ID,$QUERY_ACCOUNT){
	require("../_read_source/_http_page.php");
    if ($QUERY_ID != '') {
		$strSQL = $strSQL." and ".$DB_HTTP_PAGE_AUTO." = '".$QUERY_ID."'";
	}
	else{
		if ($QUERY_START_DATETIME == '') $QUERY_START_DATETIME = "19000000000000";
		if ($QUERY_END_DATETIME == '') $QUERY_END_DATETIME = "20371231235959";
		

		$strSQL = " and ".$DB_HTTP_PAGE_DATETIME." between '".$QUERY_START_DATETIME."' and '".$QUERY_END_DATETIME."'";

		if ($QUERY_IP_1 != '') { 
			if ($QUERY_IP != '') $strSQL=$strSQL." and ".$DB_HTTP_PAGE_IP." = '".$QUERY_IP."'";
        }
		else{
			if ($QUERY_IP != '') $strSQL=$strSQL." and ".$DB_HTTP_PAGE_IP." like '".$QUERY_IP."%'";
		}
		if ($QUERY_MAC != '') $strSQL = $strSQL." and ".$DB_HTTP_PAGE_MAC."='".$QUERY_MAC."'";
		if ($QUERY_TAG != '') $strSQL = $strSQL." and ".$DB_HTTP_PAGE_TAG."='".$QUERY_TAG."'";
		if ($QUERY_URL != '') $strSQL = $strSQL." and ".$DB_HTTP_PAGE_HOST." like '%".$QUERY_URL."%'";
		if($QUERY_ACCOUNT != ''){
			$strSQL = $strSQL." and ".$DB_HTTP_PAGE_ACCOUNT."='".$QUERY_ACCOUNT."'";
		}
    }
	return $strSQL;
}
?>