<?
session_start();
$selelag = $HTTP_SESSION_VARS["SelLanguage"];
if (empty($selelag)) header("location:../break.php");
require("../config/".$selelag);
require("../_ConnectString.php");       //--連接參數設定值
require("../_image.php");
require("../_function.php");
require("../_search/_p2p_search.php");

if ((isset($HTTP_SESSION_VARS["LoginID_Sess"])) && (isset($HTTP_SESSION_VARS["OperateRole_Sess"])) && (isset($HTTP_SESSION_VARS["GroupNo_Sess"]))){
	$strSQL="Select 0 from P2P";
	$Result=mysql_query($strSQL);
	if(!$Result){
		print "<html><title></title><head>";
		print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">";
		print "<center><b><font size=\"10\" color=\"red\"><span title=\"".$L_BREAK."\">Your ISO image version  is old,<BR>there is no P2P data!</span></font></b></center>";
		print "</head></html>";
		exit();
	}
	$QUERY_START_DATETIME	= $HTTP_POST_VARS["QUERY_START_DATETIME"];  
	$QUERY_END_DATETIME		= $HTTP_POST_VARS["QUERY_END_DATETIME"];
	$QUERY_MAC		= $HTTP_POST_VARS["QUERY_MAC"];
	$QUERY_PMAC		= $HTTP_POST_VARS["QUERY_PMAC"];
	$QUERY_IP			= $HTTP_POST_VARS["QUERY_IP"];
	$QUERY_IP_1		= $HTTP_POST_VARS["QUERY_IP_1"];
	$QUERY_PIP	 		= $HTTP_POST_VARS["QUERY_PIP"];
	$QUERY_PORT	= $HTTP_POST_VARS["QUERY_PORT"];
	$QUERY_PPORT	= $HTTP_POST_VARS["QUERY_PPORT"];
	$QUERY_ID				= $HTTP_POST_VARS["QUERY_ID"];
	$QUERY_TOOL		= $HTTP_POST_VARS["QUERY_TOOL"];
	$QUERY_DIR			= $HTTP_POST_VARS["QUERY_DIR"];  
	$QUERY_NAME		= $HTTP_POST_VARS["QUERY_NAME"];
	$QUERY_FILENAME		= $HTTP_POST_VARS["QUERY_FILENAME"];
	$strWhere	   = $HTTP_POST_VARS["strWhere"];		//--search all
	$P2P						= $HTTP_POST_VARS['P2P'];			//--全文檢索 -auto 值
	$mime						= $HTTP_POST_VARS['mime'];			//--全文檢索 flag

	$RunAs         = $HTTP_POST_VARS["RunAs"];			
	$Checked       = $HTTP_POST_VARS["Checked"];
	$SortField     = $HTTP_POST_VARS["SortField"];      
	$SortType      = $HTTP_POST_VARS["SortType"];      
	$Ip_Name       = $HTTP_POST_VARS["Ip_Name"];     
	$to_page	   = $HTTP_POST_VARS['to_page']; 

	$_SearchPath="../_search/p2p_search_list.php";
	//相關變數初始化 
	if (!isset($to_page) || empty($to_page)){
		$to_page = 1;
	}
	if (!isset($sizepage) || empty($sizepage)){
		$sizepage = $HTTP_SESSION_VARS["size_page"];
	}

	if (empty($Ip_Name))  $Ip_Name = '_IP';
	$ErrorMsg = "";
	$_Disabled = "";

	switch ($Ip_Name){
		case "_IP":
			$chk_IP = "checked";
			break;
		case "_NAME":
			$chk_NAME = "checked";
			break;
	}

	if ($SortField == "") $SortField = "_AUTO";
	include($_SORT_PATH);

	if ($RunAs == 'UpdatePageSize'){
		if ($sizepage){ 
			$HTTP_SESSION_VARS["size_page"] = $sizepage;
		}
	}

	if($RunAs == "Delete"){
		$flag = 0;
		for($i=0; $i<count($chkbox); $i++){
			$strDEL = "Delete From P2P where _AUTO ='".$chkbox[$i]."'";
			$intDEL = mysql_query($strDEL);		
			if (!$intDEL) $flag = 1;
		}
		if ($flag){
			$ErrorMsg = $FTPM_DELFAIL;
		}
		else{
			mysql_query("OPTIMIZE TABLE P2P");
			$ErrorMsg = $FTPM_DELSUCCESS;
		}
	}

	//--count Start
	$strSQL="Select count(0) from  P2P ";

	if ($mime == 1)
	{
		$strSQL = $strSQL." Where _AUTO in (".$P2P.")";
	}
	else{
		if(fn_NotShowIP()!="''")$strSQL = $strSQL." Where _IP not in (".fn_NotShowIP().")";
		else $strSQL = $strSQL." Where 1=1 ";
		if ($HTTP_SESSION_VARS['GroupNo_Sess']!=0){
			$strSQL = $strSQL." and _IP in (".fn_IPcontrol($HTTP_SESSION_VARS['GroupNo_Sess']).")";
		}
		if($strWhere["P2P"] != "") $strSQL = $strSQL.stripcslashes($strWhere["P2P"]);
	}
	$condition=fn_searchP2P($QUERY_ID,$QUERY_START_DATETIME,$QUERY_END_DATETIME,$QUERY_MAC,$QUERY_PMAC,$QUERY_IP,$QUERY_IP_1,$QUERY_PIP,$QUERY_PORT,$QUERY_PPORT,$QUERY_TYPE,$QUERY_TOOL,$QUERY_NAME,$QUERY_DIR);
	$strSQL .= $condition;
	//print $strSQL."<br>";
	
    include($_PAGE_PATH);
	//--count End

	$strSQL="Select * from  P2P ";
	if ($mime == 1)
	{
		$strSQL = $strSQL." Where _AUTO in (".$P2P.")";
	}
	else{
		if(fn_NotShowIP()!="''")$strSQL = $strSQL." Where _IP not in (".fn_NotShowIP().")";
		else $strSQL = $strSQL." Where 1=1 ";
		if ($HTTP_SESSION_VARS['GroupNo_Sess']!=0){
			$strSQL = $strSQL." and _IP in (".fn_IPcontrol($HTTP_SESSION_VARS['GroupNo_Sess']).")";
		}
		if($strWhere["P2P"] != "") $strSQL = $strSQL.stripcslashes($strWhere["P2P"]);
	}
	$condition=fn_searchP2P($QUERY_ID,$QUERY_START_DATETIME,$QUERY_END_DATETIME,$QUERY_MAC,$QUERY_PMAC,$QUERY_IP,$QUERY_IP_1,$QUERY_PIP,$QUERY_PORT,$QUERY_PPORT,$QUERY_TYPE,$QUERY_TOOL,$QUERY_NAME,$QUERY_DIR);

	$strSQL.= $condition;
	$strSQL.= " Order by ".$SortField." ".$SortType." limit ".$m.", ".$n;
	//print $strSQL;
	$Result=mysql_query($strSQL);
	$List="";
	$chkCount = ($to_page-1)*$sizepage+1; 
	//<--組show畫面字串
	if (mysql_num_rows($Result) == 0){
		include("../no_data.php");
		$List = "<tr class=\"NoData\"><td colspan=\"12\" ";
		$List.=$NoDataList;
		$_Disabled = "disabled";
	}
	else{
		while ($row=mysql_fetch_array($Result)){
			if ($chkCount%2 == 1){
				$List = $List."<tr  align=\"center\" class=\"Tr_Do\" onmouseover=\"this.className='Tr_Do_Out'\" onmouseout=\"this.className='Tr_Do_Over'\">";
			}else{
				$List = $List."<tr  align=\"center\" class=\"Tr_De\" onmouseover=\"this.className='Tr_De_Out'\" onmouseout=\"this.className='Tr_De_Over'\">";
			}
			$List.="<td align=\"center\"  title=\"".$row[_AUTO]."\">".$chkCount."</td>";

			$List.="<td align=\"center\"><a href=\"#\" onClick=\"ChangeCondition('_TIMESTAMP','".$row["_TIMESTAMP"]."');\">".$row["_TIMESTAMP"]."</td>";

			## Clinet IP
			switch ($Ip_Name){
			case "_IP":
				$List.="<td align=\"center\"><p title=\"".$row["_MAC"]."\"><a href=\"#\" onClick=\"ChangeCondition('_IP','".$row["_IP"]."');\">".$row["_IP"]."</a></td>\n";
				break;
			case "_NAME":
				$SQL = "Select * From IPCONTROL  Where ip = '".$row["_IP"]."'";
			    $Result_s = mysql_query($SQL);
                if (mysql_num_rows($Result_s)>0){
					$row_sub = mysql_fetch_array($Result_s);
					$row_username = $row_sub["username"];
					$List.="<td align=\"center\"><p title=\"".$row["_MAC"]."\"><a href=\"#\" onClick=\"ChangeCondition('_IP','".$row["_IP"]."');\">";
					if ($row_sub["username"] != '***')$List.=$row_sub["username"];
					else $List.=$row["_IP"];
					$List.="</a></td>";
				}
				else{
					$List.="<td align=\"center\"><a href=\"#\" onClick=\"ChangeCondition('_SIP','".$row["_IP"]."');\">".$row["_IP"]."</a></td>\n";
				}
				break;
			}
			## Clinet PROT
			$List.="<td align=\"center\"><a href=\"#\" onClick=\"ChangeCondition('_PORT','".$row["_PORT"]."');\">".$row["_PORT"]."</td>";		
			##Peer IP
			$List.="<td align=\"center\"><p title=\"".$row["_SRC_MAC"]."\"><a href=\"#\" onClick=\"ChangeCondition('_PIP','".$row["_SRC_IP"]."');\">".$row["_SRC_IP"]."</td>";
			##Peer port
			$List.="<td align=\"center\"><a href=\"#\" onClick=\"ChangeCondition('_PPORT','".$row["_SRC_PORT"]."');\">".$row["_SRC_PORT"]."</td>";
			##Tool
			$List.="<td align=\"center\"><a href=\"#\" onClick=\"ChangeCondition('_TOOL','".$row["_TOOLS"]."');\">".$row["_TOOLS"]."</td>";
			##File Name
			if (strlen($row["_FILENAME"])>55){    
				$CUT_FILE=substr($row["_FILENAME"],0,55)."..."; 
			}
			else {
				$CUT_FILE = $row["_FILENAME"];
			}

			$List.="<td align=\"center\" title=\"".$row["_FILENAME"]."\">".($row["_FILENAME"]==''?"None":$CUT_FILE)."</td>";

			//--Acttion(1-upload 0-download)
			$List.="<td align=\"center\" ><a href=\"#\" onClick=\"ChangeCondition('_DIR','".$row["_DIR"]."');\">";
			if ($row["_DIR"] == 1) $List.=$P2P_UPLOAD_SHOW; 
			else $List.=$P2P_DOWNLOAD_SHOW;
			$List.="</a></td>\n";
			##AD
			if (fn_ad()){
				$List.="<td align=\"center\"><a href=\"#\" onClick=\"ChangeCondition('_ACCOUNT','".$row["_ACCOUNT"]."')\">".$row["_ACCOUNT"]."</a></td>\n";
            }			
			$List.="</tr>";
			$chkCount++;
		}
	}
}
else{
	include("../no_privilege.php");
}
?>
<html>
<title></title>
<head>
<link href="../Display/display.css" type="text/css" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<SCRIPT language=JavaScript src="../inc/fun.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
//--DELETE DATA
function checkDEL(){
<?if ($_Disabled == ""){?>
	if (!MainCheck()){
		alert("<?echo $P2PM_NOTSELECT;?>");
		return;
	}

	if (confirm("<?echo $P2PM_CHECKDEL;?>")){
		document.frm.RunAs.value = "Delete";
		document.frm.submit();
	}
<?}?>
}

//--Check input pagesize num	
function ChangePageSize(){
	var flag = "";
	switch(CheckNum(document.frm.sizepage)){
		case "1":
			alert("<?echo $NUMBERM_INPUTISNULL;?>");
			flag = "1";
		break;
		case "2":
			alert("<?echo $NUMBERM_INPUTISZERO;?>");
			flag = "1";
		break;
		case "3":
			alert("<?echo $NUMBERM_INPUTBIG100;?>");
			flag = "1";
		break;
		case "4":
			alert("<?echo $NUMBERM_INPUTNOTNUM;?>");
			flag = "1";
		break;
	}
	
	if (flag == 1){
		document.frm.sizepage.focus();
		return;
	}
	document.frm.RunAs.value = "UpdatePageSize";
	document.frm.submit();
}


</SCRIPT>	
</head>
 <body onLoad="fix();" onScroll="fix();" onResize="fix();"> 
<form name="frm" action="p2p.php" method="post">
<input type="hidden" name="RunAs" value="">
<input type="hidden" name="SortField" value="<? echo $SortField ?>"><!--sort column-->
<input type="hidden" name="SortType" value="<? echo  $SortType ?>"><!--sort type-->
<input type="hidden" name="to_page" value="<?echo $to_page;?>"><!--current page-->
<input type="hidden" name="Checked" value="<? echo $Checked?>"><!--set checkbox checked or no-->
<input type="hidden" name="QUERY_MAC" value="<?echo $QUERY_MAC;?>">
<input type="hidden" name="QUERY_PMAC" value="<?echo $QUERY_PMAC;?>">
<input type="hidden" name="QUERY_IP" value="<?echo $QUERY_IP;?>">
<input type="hidden" name="QUERY_IP_1" value="<?echo $QUERY_IP_1;?>">
<input type="hidden" name="QUERY_PIP" value="<?echo $QUERY_PIP;?>">
<input type="hidden" name="QUERY_PORT" value="<?echo $QUERY_PORT;?>">
<input type="hidden" name="QUERY_PPORT" value="<?echo $QUERY_PPORT;?>">
<input type="hidden" name="QUERY_TYPE" value="<?echo $QUERY_TYPE;?>">
<input type="hidden" name="QUERY_START_DATETIME" value="<?echo $QUERY_START_DATETIME;?>">
<input type="hidden" name="QUERY_END_DATETIME" value="<?echo $QUERY_END_DATETIME;?>">
<input type="hidden" name="QUERY_TOOL" value="<?echo $QUERY_TOOL;?>">
<input type="hidden" name="QUERY_NAME" value="<?echo $QUERY_NAME;?>">
<input type="hidden" name="QUERY_DIR" value="<?echo $QUERY_DIR;?>">
<input type="hidden" name="QUERY_FILENAME" value="<?echo $QUERY_NAME;?>">

<input type="hidden" name="mime" value="<?echo $mime;?>">
<input type="hidden" name="P2P" value="<?echo $P2P;?>">


<span id="bar" style="position:absolute;z-index:2;  width:100%; height:100%" align="center">
<table  width="100%" cellSpacing="0" cellPadding="0" border="0">
  <tr  id="Tr_F">
    <td valign="middle">
	  &nbsp;&nbsp;<img src="../<?echo $DIR_IMAGE.$P2PP_P2P;?>" border="0" align="top"><a href="p2p.php"  title="<?echo $P2P_P2P;?>"><?echo $P2P_P2P_SHOW;?></a> |
	  <a href="javascript:fn_OpenWin('<?echo $_SearchPath;?>?digital=<?echo $digital;?>','NewWin','width=400,height=420,left=300,top=190,menubar=no,toolbar=no,location=no,directories=no,scrollbars=yes,status=no,resizable=yes,fullscreen=no');"  title="<?echo $P2P_SEARCH;?>"><img src="../<?echo $DIR_IMAGE.$POP3P_SEARCH;?>" align="middle" border="0"><?echo $P2P_SEARCH_SHOW?></a>
 	</td>
	<td align="right" valign="middle" > 
	  <span class="ShowMode" title="<?echo $P2P_SHOWMODE;?>"><?echo $P2P_SHOWMODE_SHOW;?> : </span>
	  <input type="radio" name="Ip_Name" value="_IP" <? echo $chk_IP;?> onclick="document.frm.submit();">
	  <span title="<?echo $P2P_IP;?>"><?echo $P2P_IP_SHOW;?></span>
	  <input type="radio" name="Ip_Name" value="_NAME" <?echo $chk_NAME;?> onclick="document.frm.submit();">
	  <span title="<?echo $P2P_NAME;?>"><?echo $P2P_NAME_SHOW;?></span> | 
	  <span  class="EveryPage" title="<?echo $P2P_PAGEVIEW?>"><?echo $P2P_PAGEVIEW_SHOW?> :</span>
	  <input type="text" size="1" name="sizepage" value="<?echo $sizepage?>" class="Text_P">
	  <input type="button" name="bntPageSize" value="<?echo $P2PB_OK_SHOW;?>" onClick="ChangePageSize();" class=" Btn_C"  title="<?echo $P2PB_OK;?>">&nbsp;
	</td>
	</tr>
	</table>
	<!--  blank TABLE-->
<table width="100%" class="BlankTb">
	<tr  height="24">
		<td ></td>
	</tr>
</table>

<table class="TitleTb">
  <tr  id="Tr_T">
	<td width="2%"  title="<?echo $P2P_NO?>"><?echo $P2P_NO_SHOW?></td>

	<td width="8%" <?echo $colDate;?>><a href="javascript:ChangeSort('_TIMESTAMP','<? echo $sortStart;?>');"  title="<?echo $P2P_DATETIME?>"><?echo $P2P_DATETIME_SHOW?><?echo $imgDate;?></a></td>


	<td width="10%" 
	  <? if ($Ip_Name == '_IP'){?>
	    <?echo $colIP;?>>
		<a href="javascript:ChangeSort('_IP','<?echo $sortIP;?>');"  title="<?echo $P2P_IP;?>"><?echo $P2P_IP_SHOW?><? echo $imgIP;?></a>
	  <?}elseif ($Ip_Name == '_NAME'){
		echo $colNAME.">"."<span title=\"".$P2P_NAME."\">".$P2P_NAME_SHOW."</span>";
	  }?>
	</td>

	<td width="6%" <?echo $colSport;?>><a href="javascript:ChangeSort('_PORT','<? echo $sortSport;?>');"  title="<?echo $P2P_PORT?>"><?echo $P2P_PORT_SHOW?><?echo $imgSport;?></a></td>

	<td width="10%" <?echo $colDip;?>><a href="javascript:ChangeSort('_SRC_IP','<? echo $sortDip;?>');"  title="<?echo $P2P_PIP?>"><?echo $P2P_PIP_SHOW?><?echo $imgDip;?></a></td>

	<td width="8%" <?echo $colDport;?>><a href="javascript:ChangeSort('_SRC_PORT','<? echo $sortDport;?>');"  title="<?echo $P2P_PPORT?>"><?echo $P2P_PPORT_SHOW?><?echo $imgDport;?></a></td>

	<td width="10%" <?echo $colTools;?>><a href="javascript:ChangeSort('_TOOLS','<? echo $sortTools;?>');"  title="<?echo $P2P_TOOL?>"><?echo $P2P_TOOL_SHOW?><?echo $imgTools;?></a></td>

	<td <?echo $colFile;?>><a href="javascript:ChangeSort('_FILENAME','<? echo $sortFile;?>');"  title="<?echo $P2P_FILENAME?>"><?echo $P2P_FILENAME_SHOW?><?echo $imgFile;?></a></td>

	<td width="6%" <?echo $colDIR;?>><a href="javascript:ChangeSort('_DIR','<? echo $sortDir;?>');"  title="<?echo $P2P_ACCOUNT?>">DIR<?echo $imgDir;?></a></td>

    <? if (fn_ad()){?>
		<td width="6%" <?echo $colAccount;?>>
			<a href="javascript:ChangeSort('_ACCOUNT', '<?echo $sortAccount;?>');"  title="<?echo $FTP_ACCOUNT;?>"><?echo $FTP_ACCOUNT_SHOW;?><?echo $imgAccount;?>
		</td>
	<?}?>
    </tr>
  </table>
</span>

<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr  id="Tr_F"><td height="24"></td></tr>
</table>

<table class="DataTb" >
  <tr class="Tr_Do">
	<td width="2%"></td>
	<td width="8%"></td>
	<td width="10%"></td>
	<td width="6%"></td>
	<td width="10%"></td>
	<td width="8%"></td>
	<td width="10%"></td>
	<td ></td>
	<td width="6%"></td>
    <? if (fn_ad()){?>
	<td width="6%"></td>
	<?}?>

  </tr>
 <!--show screen-->
<?echo $List;?>
  <tr bgcolor="<?echo $titletrbgcol;?>">
      <td colSpan="13"  align="center">
		  <table width="100%"  border="0" cellspacing="0" cellpadding="0">
			<tr id="Tr_P"><? include("../list_page.php");?></tr>
		  </table>
	  </td>
  </tr>	
 </table>
 </form>
</body>
</html>