<?
session_start();
$selelag = $HTTP_SESSION_VARS["SelLanguage"];
if (empty($selelag)) header("location:../break.php");
require("../config/".$selelag);
require("../_ConnectString.php");
require("../_function.php");
//require("../top/top.php");
require("../_image.php");
require("../_search/_telnet_search.php");
require("../_search/_datamining.php");
require("../_read_source/_telnet.php");
require("../_read_source/_ipcontrol.php");
require_once("../cd_pos.php");

$_SearchPath = "../_search/telnet_search_list.php";

if ((isset($HTTP_SESSION_VARS["LoginID_Sess"])) && (isset($HTTP_SESSION_VARS["OperateRole_Sess"])) && (isset($HTTP_SESSION_VARS["GroupNo_Sess"]))){

	$QUERY_START_DATETIME	= $HTTP_POST_VARS["QUERY_START_DATETIME"];  
	$QUERY_END_DATETIME		= $HTTP_POST_VARS["QUERY_END_DATETIME"];
	$QUERY_IP		= $HTTP_POST_VARS["QUERY_IP"];
	$QUERY_IP_1	    = $HTTP_POST_VARS["QUERY_IP_1"];
	$QUERY_USER		= $HTTP_POST_VARS["QUERY_USER"];  
	$QUERY_SERVER	= $HTTP_POST_VARS["QUERY_SERVER"];
	$QUERY_SIZE		= $HTTP_POST_VARS["QUERY_SIZE"];
	$QUERY_ID		= $HTTP_POST_VARS["QUERY_ID"];
	$QUERY_ACCOUNT	= $HTTP_POST_VARS["QUERY_ACCOUNT"];

	$sizepage      = $HTTP_POST_VARS["sizepage"];       //--每頁筆數
	$RunAs         = $HTTP_POST_VARS["RunAs"];			//--刪除
	$Checked       = $HTTP_POST_VARS["Checked"];
	$SortField     = $HTTP_POST_VARS["SortField"];      //--排序欄位
	$SortType      = $HTTP_POST_VARS["SortType"];       //--排序方式
	$strWhere	   = $HTTP_POST_VARS["strWhere"];		//--search all
	$TELNET		   = $HTTP_POST_VARS['TELNET'];			//--全文檢索 -auto 值
	$mime		   = $HTTP_POST_VARS['mime'];			//--全文檢索 flag
	$digital	   = $HTTP_POST_VARS['digital'];	    //--數位資產 flag
	$to_page	   = $HTTP_POST_VARS['to_page'];	

	//相關變數初始化 
	if (!isset($to_page) || empty($to_page)){
		$to_page = 1;
	}//End : if (相關變數初始化)

	if (!isset($sizepage) || empty($sizepage)){
		$sizepage = $HTTP_SESSION_VARS["size_page"];
	}

	if ($Ip_Name == '')  $Ip_Name = '_IP';
	$ErrorMsg = "";
	$_Disabled = "";
	//$bgcolorCol = "bgcolor=\"#A0C6E5\"";

	//--判斷點選那一個顯示模式
	switch ($Ip_Name){
		case "_IP":
			$chk_IP = "checked";
			break;
		case "_NAME":
			$chk_NAME = "checked";
			break;
	}

	//--畫面設定排序時使用
	if ($SortField == "") $SortField = $DB_TELNET_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++){
			$strSQL = "Select * From ".$DB_TELNET." where ".$DB_TELNET_AUTO."='".$chkbox[$i]."'";
			$intSQL = mysql_query($strSQL);
			$rowSQL = mysql_fetch_array($intSQL);
			$DelFilePath = $DATAS_PATH_TELNET.$rowSQL[$DB_TELNET_DBTAG]."/".$rowSQL[$DB_TELNET_DBNAME];

			if (file_exists($DelFilePath)){
				system("echo rm -f $DelFilePath  >> /tmp/dc.cmd ");
			}

			$strDEL = "Delete From ".$DB_TELNET." where ".$DB_TELNET_AUTO."='".$chkbox[$i]."'";
			$intDEL = mysql_query($strDEL);
			if (!$intDEL) $flag = 1;
		}

		if ($flag){
			$ErrorMsg = $TELNETM_DELFAIL;
		}
		else{
			mysql_query("OPTIMIZE TABLE TELNET");
			$ErrorMsg = $TELNETM_DELSUCCESS;
		}
	}

	//-- System super user(PROGRAM ENTRY PLACE)
	$strSQL = "Select count(*) From ".$DB_TELNET;
	if ($mime == 1)
	{
		$strSQL = $strSQL." Where ".$DB_TELNET_AUTO." in (".$TELNET.")";
	}
	else{
		if(fn_NotShowIP()!="''")$strSQL = $strSQL." Where ".$DB_TELNET_IP." not in (".fn_NotShowIP().")";
		else $strSQL = $strSQL." Where 1=1 ";
		if ($HTTP_SESSION_VARS['GroupNo_Sess']!=0){
			$strSQL = $strSQL." and ".$DB_TELNET_IP." in (".fn_IPcontrol($HTTP_SESSION_VARS['GroupNo_Sess']).")";
		}
		if($strWhere["TELNET"] != "") $strSQL = $strSQL.stripcslashes($strWhere["TELNET"]);
	}

	$condition = fn_searchTelnet($QUERY_START_DATETIME,$QUERY_END_DATETIME,$QUERY_IP,$QUERY_IP_1,$QUERY_ID,$QUERY_ACCOUNT);
    $strSQL = $strSQL.$condition;

	//計算符合文章總數 & 初始化分頁變數
    include($_PAGE_PATH);

	//--為了畫面排序的sql語法
	$strSQL = "Select ".$DB_TELNET_AUTO.",".$DB_TELNET_DATETIME.",".$DB_TELNET_IP.",".$DB_TELNET_MAC.",".$DB_TELNET_USER.",".$DB_TELNET_PASS.",".$DB_TELNET_ACCOUNT.",".$DB_TELNET_DBTAG.",".$DB_TELNET_DBNAME.",".$DB_TELNET_SERVER.",".$DB_TELNET_SIZE;
	$strSQL = $strSQL. " From ".$DB_TELNET;
	if ($mime == 1)
	{
		$strSQL = $strSQL.fn_Datamining($TELNET,$DB_TELNET_AUTO,$m,$n,$to_page);
		$m = 0;
	}
	else{
		if(fn_NotShowIP()!="''")$strSQL = $strSQL." Where ".$DB_TELNET_IP." not in (".fn_NotShowIP().")";
		else $strSQL = $strSQL." Where 1=1 ";

		if ($HTTP_SESSION_VARS['GroupNo_Sess']!=0){
			$strSQL = $strSQL." and ".$DB_TELNET_IP." in (".fn_IPcontrol($HTTP_SESSION_VARS['GroupNo_Sess']).")";
		}
		if($strWhere["TELNET"] != "") $strSQL = $strSQL.stripcslashes($strWhere["TELNET"]);
	}

    $strSQL = $strSQL.$condition;
	
	//PRINT $strSQL;
	$strSQL = $strSQL." Order by ".$SortField." ".$SortType." limit ".$m.", ".$n;
	$intResult = mysql_query($strSQL);
	
	//<--組show畫面字串
	if (mysql_num_rows($intResult) == 0){
		$TelnetList = "<tr height=\"30\" class=\"NoData\"><td colspan=\"";
		if (($HTTP_SESSION_VARS["OperateRole_Sess"]=="Super")&&($HTTP_SESSION_VARS["GroupNo_Sess"]=='0')){
			if(fn_ad()) $TelnetList = $TelnetList."10"; else $TelnetList = $TelnetList."9";
		}else{
			if(fn_ad()) $TelnetList = $TelnetList."9"; else $TelnetList = $TelnetList."8";
		}
		include("../no_data.php");
		$TelnetList = $TelnetList."\"".$NoDataList;
		$_Disabled = "disabled";
	}
	else{
		$TelnetList = "";
		$chkCount = ($to_page-1)*$sizepage+1;
		while ($row = mysql_fetch_array($intResult)){
			if ($chkCount%2 == 1){
				$TelnetList = $TelnetList."<tr  align=\"center\" class=\"Tr_Do\" onmouseover=\"this.className='Tr_Do_Out'\" onmouseout=\"this.className='Tr_Do_Over'\">";
			}else{
				$TelnetList = $TelnetList."<tr  align=\"center\" class=\"Tr_De\" onmouseover=\"this.className='Tr_De_Out'\" onmouseout=\"this.className='Tr_De_Over'\">";
			}

			$TelnetList = $TelnetList."<td title=\"".$row[_AUTO]."\">".$chkCount."</td>\n";
			
			//--datetime
			$TelnetList = $TelnetList."<td align=\"center\"><a href=\"#\" onClick=\"ChangeCondition('_DATETIME','".$row[$DB_TELNET_DATETIME]."');\">".fn_DateTime($row[$DB_TELNET_DATETIME])."</a></td>\n";
			
			//--IP
			switch ($Ip_Name){
				case "_IP":
					$TelnetList = $TelnetList."<td align=\"center\"><a href=\"#\" onClick=\"ChangeCondition('_IP','".$row[$DB_TELNET_IP]."');\"><p title=\"".$row[$DB_TELNET_MAC]."\">".$row[$DB_TELNET_IP]."</p></a></td>\n";
					break;
				case "_NAME":
					$SQL = "Select * From ".$DB_IPCONTROL." Where ".$DB_IPCONTROL_IP." = '".$row[$DB_TELNET_IP]."'";
					$Result = mysql_query($SQL);
					//print $SQL;
					if (mysql_num_rows($Result)>0){
						$row_sub = mysql_fetch_array($Result);
						$row_username = $row_sub[$DB_IPCONTROL_USERNAME];
						$TelnetList = $TelnetList."<td align=\"center\"><p title=\"".$row[$DB_TELNET_MAC]."\"><a href=\"#\" onClick=\"ChangeCondition('_IP','".$row[$DB_TELNET_IP]."');\">";
						if ($row_sub[$DB_IPCONTROL_USERNAME] != '***') $TelnetList = $TelnetList.$row_sub[$DB_IPCONTROL_USERNAME]; else $TelnetList = $TelnetList.$row[$DB_TELNET_IP];
						$TelnetList = $TelnetList."</a></p></td>";
					}
					else{
						$TelnetList = $TelnetList."<td align=\"center\"><p title=\"".$row[$DB_TELNET_MAC]."\"><a href=\"#\" onClick=\"ChangeCondition('_IP','".$row[$DB_TELNET_IP]."');\">".$row[$DB_TELNET_IP]."</a></p></td>";
					}
					break;
			}

			//--user
			$TelnetList = $TelnetList."<td align=\"center\">".$row[$DB_TELNET_USER]."</td>\n";
			
			//--pass
			$TelnetList = $TelnetList."<td align=\"center\">".$row[$DB_TELNET_PASS]."</td>\n";
			
			//--SERVER
			$TelnetList = $TelnetList."<td align=\"center\">".$row[$DB_TELNET_SERVER]."</td>";

			if (fn_ad()){
				$TelnetList = $TelnetList."<td align=\"center\"><a href=\"#\" onClick=\"ChangeCondition('_ACCOUNT','".$row[$DB_TELNET_ACCOUNT]."')\">".$row[$DB_TELNET_ACCOUNT]."</a></td>\n";
            }	
		//--轉換 DBTAG 的格式
		$_DBTAG ='';
		$_DBTAG =str_replace("-","_",$row[$DB_TELNET_DBTAG]);
		$_DBTAG =str_replace(":","_",$_DBTAG);			

			//--file
			//--檢查subject是否有檔，有檔才有連結
			//--檢查subject是否有檔，有檔才有連結
			if (file_exists($CD_DIR.":\\".$_DBTAG."\\".$row[$DB_TELNET_DBNAME])){
			$TelnetList = $TelnetList."<td align=\"center\"><a href=\"#\" onClick=\"fn_OpenWin('play.php?_TELNET=".$CD_DIR.":/".$_DBTAG."/".$row[$DB_TELNET_DBNAME]."','WinNew','left=200,top=80,scrollbars=no,resizable=yes,width=640,height=550')\" class=\"UU\">".$TELNET_FILENAME."</a></td>\n";
			}else{
				$TelnetList = $TelnetList."<td align=\"center\">".$TELNET_FILENAME_SHOW."</td>\n";
			}

			$TelnetList = $TelnetList."<td align=\"right\">\n";
			//判斷檔案大小的單位
			if ($row[$DB_TELNET_SIZE]<1000){
				$TelnetList = $TelnetList.$row[$DB_TELNET_SIZE]."B";
			}
			elseif (($row[$DB_TELNET_SIZE])<1000000&&($row[$DB_TELNET_SIZE])>=1000){
				$TelnetList = $TelnetList.(round($row[$DB_TELNET_SIZE]/100)/10)."K";
			}
			else{
				$TelnetList = $TelnetList.(round($row[$DB_TELNET_SIZE]/100000)/10)."M";
			}//End : if(判斷檔案大小的單位)
			$TelnetList = $TelnetList."</td>\n";

			$TelnetList = $TelnetList."</tr>\n";
			$chkCount++;
		}//組show畫面字串-->
	}
}
else{
	include("../no_privilege.php");
}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link href="../Display/display.css" type="text/css" rel="stylesheet">
<Script language=JavaScript src="../inc/fun.js"></Script>
<Script Language="JavaScript">
//--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();

}

//--DELETE DATA
function checkDEL(){
<?if ($_Disabled == ""){?>
	if (!MainCheck()){
		alert("<?echo $TELNETM_NOTSELECT;?>");
		return;
	}

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

<?if ($ErrorMsg != ""){?>
	fn_ErrorMsg('<?echo $ErrorMsg?>')
<?}?>
</Script>
</head>

<body onLoad="fix();" onScroll="fix();" onResize="fix();">
<form name="frm" action="telnet.php" method="post">
<input type="hidden" name="strWhere[TELNET]" value="<?echo stripcslashes($strWhere["TELNET"]);?>">
<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="Checked" value="<? echo $Checked?>"><!--set checkbox checked or no-->
<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_SIZE" value="<?echo ($QUERY_SIZE);?>">
<input type="hidden" name="QUERY_SERVER" value="<?echo ($QUERY_SERVER);?>">
<input type="hidden" name="QUERY_USER" value="<?echo ($QUERY_USER);?>">
<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_ACCOUNT" value="<?echo $QUERY_ACCOUNT;?>">
<input type="hidden" name="to_page" value="<?echo $to_page;?>"><!--current page-->
<input type="hidden" name="mime" value="<?echo $mime;?>">
<input type="hidden" name="TELNET" value="<?echo $TELNET;?>">
<input type="hidden" name="digital" value="<?echo $digital;?>">

<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>
	  &nbsp;&nbsp;<a href="telnet.php"  title="<?echo $TELNET_TELNET;?>"><img src="../<?echo $DIR_IMAGE.$TELNETP_TELNET;?>" border="0" align="top"><?echo $TELNET_TELNET_SHOW;?></a>
      <?if (($HTTP_SESSION_VARS["OperateRole_Sess"]=="Super")&&($HTTP_SESSION_VARS["GroupNo_Sess"]=='0')){?>
		   | <a href="javascript:checkDEL();"  title="<?echo $TELNET_DEL;?>"><img src="../<?echo $DIR_IMAGE.$TELNETP_DEL;?>" border="0" align="top"><?echo $TELNET_DEL_SHOW;?></a>
	<?}?>
	  | <a href="javascript:fn_OpenWin('<?echo $_SearchPath;?>?Status=telnet&digital=<?echo $digital;?>','NewWin','width=400,height=200,left=320,top=200,menubar=no,toolbar=no,location=no,directories=no,scrollbars=yes,status=no,resizable=yes,fullscreen=no');"  title="<?echo $TELNET_SEARCH;?>"><img src="../<?echo $DIR_IMAGE.$TELNETP_SEARCH;?>" align="top" border="0"> <?echo $TELNET_SEARCH_SHOW;?></a>
	</td>
	<td align="right" valign="middle">
	  <span  class="ShowMode" title="<?echo $TELNET_SHOWMODE;?>"><?echo $TELNET_SHOWMODE_SHOW;?> : </span>
	  <input type="radio" name="Ip_Name" value="_IP" <? echo $chk_IP;?> onclick="document.frm.submit();">
	  <span title="<?echo $TELNET_IP;?>"><?echo $TELNET_IP_SHOW;?></span>
	  <input type="radio" name="Ip_Name" value="_NAME" <?echo $chk_NAME;?> onclick="document.frm.submit();">
	  <span title="<?echo $TELNET_NAME;?>"><?echo $TELNET_NAME_SHOW;?></span> | 
	  <span class="EveryPage" title="<?echo $TELNET_PAGEVIEW;?>"><?echo $TELNET_PAGEVIEW_SHOW;?> : 
	  <input type="text" size="1" name="sizepage" value="<?echo $sizepage?>" class="Text_P">
	  <input type="button" name="bntPageSize" value="<?echo $TELNETB_OK_SHOW;?>" onClick="ChangePageSize();" class="Btn_C" title="<?echo $TELNETB_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="3%"><span title="<?echo $TELNET_NO;?>"><?echo $TELNET_NO_SHOW;?></span></td>

    <td width="10%" <?echo $colDate;?>>
      <a href="javascript:ChangeSort('_DATETIME','<? echo $sortDate;?>');"  title="<?echo $TELNET_DATETIME;?>"><?echo $TELNET_DATETIME_SHOW;?><? echo $imgDate;?></a>
	</td>
	<td 
		<? if ($Ip_Name == '_IP'){?>
			<?echo $colIP;?>>
			<a href="javascript:ChangeSort('_IP','<?echo $sortIP;?>');"  title="<?echo $TELNET_IP;?>"><?echo $TELNET_IP_SHOW;?><? echo $imgIP;?></a>
		  <?}elseif ($Ip_Name == '_NAME'){
			echo $colNAME.">"."<span title=\"".$TELNET_NAME."\">Name</span>";
		}?>
	</td>
    <td width="15%" <?echo $colUser?>>
	  <a href="javascript:ChangeSort('_USER','<? echo $sortUser;?>');"  title="<?echo $TELNET_USER;?>"><?echo $TELNET_USER_SHOW;?><? echo $imgUser;?></a>
	</td>
    <td width="15%"><span  title="<?echo $TELNET_PASS;?>"><?echo $TELNET_PASS_SHOW;?></span></td>
    <td width="20%" <?echo $colServer;?>>
	  <a href="javascript:ChangeSort('_SERVER','<? echo $sortServer;?>');"  title="<?echo $TELNET_SERVER;?>"><?echo $TELNET_SERVER_SHOW;?><? echo $imgServer;?></a>
	</td>
	<? if (fn_ad()){?>
		<td width="8%" <?echo $colAccount;?>>
			<a href="javascript:ChangeSort('_ACCOUNT', '<?echo $sortAccount;?>');"  title="<?echo $TELNET_ACCOUNT;?>"><?echo $TELNET_ACCOUNT_SHOW;?><?echo $imgAccount;?>
		</td>
		<?}?>
    <td width="10%"><span  title="<?echo $TELNET_FILENAME;?>"><?echo $TELNET_FILENAME_SHOW;?></span></td>
	<td width="5%" <?echo $colSize;?> align="right">
	  <a href="javascript:ChangeSort('_SIZE','<? echo $sortSize;?>');"  title="<?echo $TELNET_SIZE;?>">
	  <? echo $imgSize;?><?echo $TELNET_SIZE_SHOW;?>></a>
	</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="3%"></td>

    <td width="10%"></td>
	<td></td>
    <td width="15%"></td>
    <td width="15%"></td>
    <td width="20%"></td>
	<? if (fn_ad()){?>
		<td width="8%"></td>
		<?}?>
    <td width="10%"></td>
	<td width="5%"></td>
  </tr>
  <?echo $TelnetList;?>
  <tr> 
    <td colSpan="
	<?
		if (($HTTP_SESSION_VARS["OperateRole_Sess"]=="Super")&&($HTTP_SESSION_VARS["GroupNo_Sess"]=='0')){
			if(fn_ad()) echo "10"; else echo "9";
		}else{
			if(fn_ad()) echo "9"; else echo "8";
		}
	?>
	" 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>
