<?
session_start();
$selelag = $HTTP_SESSION_VARS["SelLanguage"];
if (empty($selelag)) header("location:../break.php");
require("../config/".$selelag);
require("../_ConnectString.php");
require("../_function.php");
require("../_image.php");
require("../_read_source/_msn.php");
require("../_read_source/_msn_msg.php");
require_once("../cd_pos.php");

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

	//--連接參數設定值 
	if(strlen($HTTP_SERVER_VARS["QUERY_STRING"])>0){
		$_IDX     = $HTTP_GET_VARS[$DB_MSN_MSG_IDX];
	}
	else{
		$_IDX     = $HTTP_POST_VARS[$DB_MSN_MSG_IDX];
	}
	$sizepage					 = $HTTP_POST_VARS["sizepage"];       //--每頁筆數
	$to_page					 = $HTTP_POST_VARS['to_page'];
	$RunAs                       = $HTTP_POST_VARS["RunAs"]; 

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

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


	//--更改每頁的筆數設定
	if ($RunAs == 'UpdatePageSize'){
		if ($sizepage){ 
			$HTTP_SESSION_VARS["size_page"] = $sizepage;
		}
	}

	//-- System super user(PROGRAM ENTRY PLACE)
	$strSQL = "Select count(*) From ".$DB_MSN_MSG." Where ".$DB_MSN_MSG_IDX."='".$_IDX."'";

	//計算符合文章總數 & 初始化分頁變數
	include($_PAGE_PATH); 
	
	//--秀台頭
	$strSQL2 = "Select ".$DB_MSN_IP.",".$DB_MSN_DATE.",".$DB_MSN_OWNER." from ".$DB_MSN." where ".$DB_MSN_AUTO."='".$_IDX."'";		
	$intResult2 = mysql_query($strSQL2);
	$row2 = mysql_fetch_array($intResult2);
	
	//Accuont color
$arrcolor=array("#0000FF","#00FF00","#9900CC","#FF33CC","#FF9900","#663333","#009999","#FF6666","#00CCFF","#6600FF","#999900","#330066","#CC0099");
	$strAccount="Select  distinct _SENDER From ".$DB_MSN_MSG." Where ".$DB_MSN_MSG_IDX."='".$_IDX."'";
	$Result=mysql_query($strAccount);
	$i=0;
	while ($row3= mysql_fetch_array($Result)){
		$key=$row3[$DB_MSN_MSG_SENSER];
		if($row3[$DB_MSN_MSG_SENSER]==$row2[$DB_MSN_OWNER]){
			$color[$key]="red";
		}
		else{
			$index=$i%12;
			$color[$key]=$arrcolor[$index];
			$i++;
		}
	}

	//為了畫面排序的sql語法
	$strSQL = "Select  ".$DB_MSN_MSG_DATETIME.",".$DB_MSN_MSG_SENSER.",".$DB_MSN_MSG_MESG.",".$DB_MSN_MSG_FILENAME.",".$DB_MSN_MSG_FILESIZE.",".$DB_MSN_MSG_DB_NAME.",".$DB_MSN_MSG_DBTAG;
	$strSQL = $strSQL." From ".$DB_MSN_MSG." A";
	$strSQL = $strSQL." Where ".$DB_MSN_MSG_IDX."='".$_IDX."'";
	$strSQL = $strSQL."Order by ".$DB_MSN_MSG_DATETIME." ASC limit ".$m.", ".$n;

	$intResult = mysql_query($strSQL);
	//print $strSQL;
	//<--組show畫面字串
	$Listmsn_msg = "";  
	$chkCount = 0;

	while ($row=mysql_fetch_array($intResult)){
		//--列的顏色
		if ($chkCount%2 == 1){
			$Listmsn_msg = $Listmsn_msg."<tr class=\"Tr_Do\" onmouseover=\"this.className='Tr_Do_Out'\" onmouseout=\"this.className='Tr_Do_Over'\">";
		}else{
			$Listmsn_msg = $Listmsn_msg."<tr class=\"Tr_De\" onmouseover=\"this.className='Tr_De_Out'\" onmouseout=\"this.className='Tr_De_Over'\">";
		}
		
		$Listmsn_msg = $Listmsn_msg."<td align=\"center\">".fn_DateTime($row[$DB_MSN_MSG_DATETIME])."</td>\n";
		$Listmsn_msg = $Listmsn_msg."<td align=\"center\"><font  color=\"".$color[$row[$DB_MSN_MSG_SENSER]]."\"><B>".$row[$DB_MSN_MSG_SENSER]."</B></font></td>\n";
		$Listmsn_msg = $Listmsn_msg."<td>".urldecode($row[$DB_MSN_MSG_MESG])."</td>\n";

		//--檢查file是否有檔，有檔才有連結(會秀小圖)
		$Listmsn_msg = $Listmsn_msg."<td align=\"center\">";
		//--轉換 DBTAG 的格式
		$_DBTAG ='';
		$_DBTAG =str_replace("-","_",$row[$DB_MSN_MSG_DBTAG]);
		$_DBTAG =str_replace(":","_",$_DBTAG);

		//--檢查DATAS是否有檔，有檔才有連結
		if ((file_exists($CD_DIR.":\\".$_DBTAG."\\".$row[$DB_MSN_MSG_DB_NAME]))&& ($row[$DB_MSN_MSG_DB_NAME] != "")){
			$txtFile = $row[$DB_MSN_MSG_DB_NAME];

			$Listmsn_msg = $Listmsn_msg."<a href=\"".$CD_DIR.":\\".$_DBTAG."/".$row[$DB_MSN_MSG_DB_NAME]."\" target=\"_blank\">";
			switch(substr($txtFile,-3,3)){
				case "jpg":
				case "png":
				case "gif":
					$Listmsn_msg = $Listmsn_msg."<img src=\"".$DATAS_PATH_MSN.$row[$DB_MSN_MSG_DBTAG]."/".$row[$DB_MSN_MSG_DB_NAME]."\" border=\"0\" alt=\"".$row[$DB_MSN_MSG_FILENAME]."\" width=\"70\">";
					break;
				default:
					$Listmsn_msg = $Listmsn_msg.$row[$DB_MSN_MSG_FILENAME];
					break;
			}

			$Listmsn_msg = $Listmsn_msg."</a>";

		}
		else{
			$Listmsn_msg = $Listmsn_msg.$row[$DB_MSN_MSG_FILENAME];		
		}//End : if(檢查file是否有檔，有檔才有連結)
		$Listmsn_msg = $Listmsn_msg."</td>";

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

		$Listmsn_msg = $Listmsn_msg."</td></tr>";
		$chkCount ++;
	}
}
else{
	include("../no_privilege.php");
}	
?>
<html>
<head>
<title><?echo $MSN_MSN;?> | <?echo $row2[$DB_MSN_IP];?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<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();

}

</SCRIPT>
</head>
 <body leftmargin="0" topmargin="0" bgproperties="fixed" style="margin:0px;" onLoad="fix();" onScroll="fix();" onResize="fix();">
<form name="frm" action="msn_msg.php" method="post">
<input type="hidden" name="RunAs" value="">
<input type="hidden" name="_IDX" value="<?echo $_IDX;?>">
<input type="hidden" name="to_page" value="<?echo $to_page;?>"><!--current page-->

<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  nowrap>&nbsp;<img src="../<?echo $DIR_IMAGE.$MSNP_MSN?>">&nbsp;<span  title="<?echo $MSN_DATETIME?>"><B><?echo $MSN_DATETIME_SHOW?></B>: </span><?echo $row2[$DB_MSN_DATE]?> |
	  <span title="<?echo $MSN_USERID?>"><B><?echo $MSN_USERID_SHOW?>: </span><font color="red"><?echo $row2[$DB_MSN_OWNER]?></font></B>
	</td>
	<td align="right">
	  <span class="EveryPage"title="<?echo $MSN_PAGEVIEW;?>"><?echo $MSN_PAGEVIEW_SHOW;?> : </span>
	  <input type="text" size="1" name="sizepage" value="<?echo $sizepage?>" class="Text_P">
	  <input type="button" name="bntPageSize" value="<?echo $MSNB_OK_SHOW;?>" onClick="ChangePageSize();" class="Btn_C" title="<?echo $MSNB_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="11%" title="<?echo $MSN_DATETIME?>"><?echo $MSN_DATETIME_SHOW?></td>
	<td width="26%" title="<?echo $MSN_USERID?>"><?echo $MSN_USERID_SHOW?></td>
	<td title="<?echo $MSN_MSG_MESSAGE?>"><?echo $MSN_MSG_MESSAGE_SHOW?></td>
	<td width="15%" title="<?echo $MSN_MSG_FILENAME?>"><?echo $MSN_MSG_FILENAME_SHOW?></td>
	<td width="10%" title="<?echo $MSN_MSG_FILESIZE?>"><?echo $MSN_MSG_FILESIZE_SHOW?></td>
  </tr>
  </table>
</span>

<table width="100%" cellSpacing="0" cellPadding="0" border="0">
<tr id="Tr_F" ><td></td>
</table>

<table class="DataTb" >
  <tr class="Tr_Do">
	<td width="12%"></td>
	<td width="30%"></td>
	<td></td>
	<td width="15%"></td>
	<td width="6%"></td>
  </tr>
  <?echo $Listmsn_msg ;?>	
  <tr>
    <td colSpan="<?if ($ad_server == 1) echo "12"; else echo "11"; ?>">
  	  <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>