<?
session_start();
$selelag = $HTTP_SESSION_VARS["SelLanguage"];
if (empty($selelag)) header("location:../break.php");
require("../config/".$selelag);
require("../_ConnectString.php");
require("../_read_source/_yahoo.php");
require("../_read_source/_yahoo_msg.php");
require("../_image.php");
require("../_function.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['_IDX'];
	}else{
	    $_IDX     = $HTTP_POST_VARS['_IDX'];
	}

	$to_page                     = $HTTP_POST_VARS["to_page"];        //--記住目前的頁
	$sizepage					 = $HTTP_POST_VARS["sizepage"];       //--每頁筆數
	$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_YAHOO_MSG." Where ".$DB_YAHOO_MSG_IDX."='".$_IDX."'";

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

	//為了畫面排序的sql語法
	$strSQL = "Select *, DATE_FORMAT(".$DB_YAHOO_MSG_TIMESTAMP.",'%Y-%m-%d %T') AS ".$DB_YAHOO_MSG_TIMESTAMP.", DATE_FORMAT(".$DB_YAHOO_MSG_S_TIMESTAMP.",'%Y-%m-%d %T') AS ".$DB_YAHOO_MSG_S_TIMESTAMP.", DATE_FORMAT(".$DB_YAHOO_MSG_E_TIMESTAMP.",'%Y-%m-%d %T') AS ".$DB_YAHOO_MSG_E_TIMESTAMP;
	$strSQL = $strSQL." From ".$DB_YAHOO_MSG." A";
	$strSQL = $strSQL." Where ".$DB_YAHOO_MSG_IDX."='".$_IDX."'";
	$strSQL = $strSQL."Order by ".$DB_YAHOO_MSG_TIMESTAMP." ASC, ".$DB_YAHOO_MSG_AUTO." limit ".$m.", ".$n;
	$intResult = mysql_query($strSQL);

	$strSQL2 = "Select ".$DB_YAHOO_OWNER.", ".$DB_YAHOO_TIMESTAMP.",DATE_FORMAT(".$DB_YAHOO_TIMESTAMP.",'%Y-%m-%d %T') as ".$DB_YAHOO_TIMESTAMP." from ".$DB_YAHOO." where ".$DB_YAHOO_AUTO."='".$_IDX."'";					//SHOW DATETIME
	$intResult2 = mysql_query($strSQL2);
	$row2 = mysql_fetch_array($intResult2);

	//Accuont color
	$strAccount="Select  distinct _SENDER From ".$DB_YAHOO_MSG." Where ".$DB_YAHOO_MSG_IDX."='".$_IDX."'";
	$Result=mysql_query($strAccount);
	$arrcolor=array("#0000FF","#00FF00","#9900CC","#FF33CC","#FF9900","#663333","#009999","#FF6666","#00CCFF","#6600FF","#999900","#330066","#CC0099");
	$i=0;
	while ($row3= mysql_fetch_array($Result)){
		$key=$row3[$DB_YAHOO_MSG_SENDER];

		if($row3[$DB_YAHOO_MSG_SENDER]==$row2[$DB_YAHOO_OWNER]){
			$color[$key]="#FF0000";
		}
		else{
			$color[$key]=$arrcolor[$i];
			$i++;
		}
	}
		
	//<--組show畫面字串
	$ListYAHOO_Msg = "";  
	$flag = 0; 
	$chkCount = 1;
	while ($row=mysql_fetch_array($intResult)){
		//--0:純訊息 1:傳檔 2:聲音 3:影像
		switch ($row[$DB_YAHOO_MSG_TYPE]){
			case 4:
				$_TYPE = "JOIN";
				$_CONTEXT = $row[$DB_YAHOO_MSG_CONTEXT];
				$_STARTTIME = "";
				$_ENDTIME = "";
				break;
			case 5:
				$_TYPE = "LEFT";
				$_CONTEXT = $row[$DB_YAHOO_MSG_CONTEXT];
				$_STARTTIME = "";
				$_ENDTIME = "";
				break;
			case 0:
				$_TYPE = $YAHOOM_MSG_MSG;
				$_CONTEXT = $row[$DB_YAHOO_MSG_CONTEXT];
				$_STARTTIME = "";
				$_ENDTIME = "";
				break;
			case 1:
				$_TYPE = $YAHOOM_MSG_FILE;
		
				//--檢查DATAS是否有檔，有檔才有連結
				if (file_exists($DATAS_PATH_YAHOO.$row[$DB_YAHOO_MSG_DBTAG]."/".$row[$DB_YAHOO_MSG_DB_NAME])){
					$txtFile = $row[$DB_YAHOO_MSG_DB_NAME];
					$_CONTEXT = "<a href=\"../download.php?file=".$DATAS_PATH_YAHOO.$row[$DB_YAHOO_MSG_DBTAG]."/".$row[$DB_YAHOO_MSG_DB_NAME]."\" target=\"_blank\">";
					//--是圖ㄉ秀小圖
					switch(substr($txtFile,-3,3)){
						case "jpg":
						case "png":
						case "gif":
							$_CONTEXT = $_CONTEXT."<img src=\"".$DATAS_PATH_YAHOO.$row[$DB_YAHOO_MSG_DBTAG]."/".$row[$DB_YAHOO_MSG_DB_NAME]."\" border=\"0\" alt=\"".$row[$DB_YAHOO_MSG_CONTEXT]."\" width=\"70\">";
							break;
						default:
							$_CONTEXT = $_CONTEXT.$row[$DB_YAHOO_MSG_CONTEXT];
							break;
					}

					$_CONTEXT = $_CONTEXT."</a>";
				}
				else{
					$_CONTEXT = $row[$DB_YAHOO_MSG_CONTEXT]."";
				}
				$_STARTTIME = "";
				$_ENDTIME = "";
				break;
			case 2:
				$_TYPE = $YAHOOM_MSG_AUDIO;
				//$_CONTEXT = "<img src=\"../".$DIR_IMAGE.$YAHOO_MSGP_VIDEO."\">";
				if (file_exists($DATAS_PATH_YAHOO.$row[$DB_YAHOO_MSG_DBTAG]."/".$row[$DB_YAHOO_MSG_DB_NAME])){
					$_CONTEXT = "<a href=\"".$DATAS_PATH_YAHOO.$row[$DB_YAHOO_MSG_DBTAG]."/".$row[$DB_YAHOO_MSG_DB_NAME]."\"><img src=\"".$DIR_IMAGE.$YAHOO_MSGP_AUDIO."\" border=\"0\"></a>";
				}else{
					$_CONTEXT = $row[$DB_YAHOO_MSG_CONTEXT]."";
				}
				$_STARTTIME = $row[$DB_YAHOO_MSG_S_TIMESTAMP];
				$_ENDTIME = $row[$DB_YAHOO_MSG_E_TIMESTAMP];
				break;
			case 3:
				//--轉換 DBTAG 的格式
				$_DBTAG ='';
				$_DBTAG =str_replace("-","_",$row[$DB_YAHOO_MSG_DBTAG]);
				$_DBTAG =str_replace(":","_",$_DBTAG);

				$_TYPE = $YAHOOM_MSG_VIDEO;
			
				$_CONTEXT = "<a href=\"#\" onClick=\"MM_openBrWindow('".$CD_DIR."','".$_DBTAG."','".$row[$DB_YAHOO_MSG_CONTEXT]."','','left=200,top=80,scrollbars=no,resizable=yes,width=640,height=550')\"><img src=\"../".$DIR_IMAGE.$YAHOO_MSGP_VIDEO."\" border=\"0\"></a>";


				$_STARTTIME = $row[$DB_YAHOO_MSG_S_TIMESTAMP];
				$_ENDTIME = $row[$DB_YAHOO_MSG_E_TIMESTAMP];
			break;
		}
		
		//--列的顏色
		if ($chkCount%2 == 1){
			$ListYAHOO_Msg = $ListYAHOO_Msg."<tr class=\"Tr_Do\" onmouseover=\"this.className='Tr_Do_Out'\" onmouseout=\"this.className='Tr_Do_Over'\">";
		}else{
			$ListYAHOO_Msg = $ListYAHOO_Msg."<tr class=\"Tr_De\" onmouseover=\"this.className='Tr_De_Out'\" onmouseout=\"this.className='Tr_De_Over'\">";
		}

		$ListYAHOO_Msg = $ListYAHOO_Msg."<td align=\"center\">".$row[$DB_YAHOO_MSG_TIMESTAMP]."</td>\n";
		$ListYAHOO_Msg = $ListYAHOO_Msg."<td align=\"center\"><font  color=\"".$color[$row[$DB_YAHOO_MSG_SENDER]]."\"><B>".$row[$DB_YAHOO_MSG_SENDER]."</B></td>";
		$ListYAHOO_Msg = $ListYAHOO_Msg."<td align=\"center\">".$_TYPE."</td>";       //TYPE
		$ListYAHOO_Msg = $ListYAHOO_Msg."<td align=\"left\">".$_CONTEXT."</td>";    //CONTEXT
		$ListYAHOO_Msg = $ListYAHOO_Msg."<td align=\"center\">".$_STARTTIME."</td>";  //STARTTIME
		$ListYAHOO_Msg = $ListYAHOO_Msg."<td align=\"center\">".$_ENDTIME."</td>";	  //ENDTIME
		$ListYAHOO_Msg = $ListYAHOO_Msg."</tr>";

		$chkCount++;
	}//組show畫面字串-->
}
else{
	include("../no_privilege.php");
}
?>
<html>
<head>
<title></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">

function MM_openBrWindow(theURL1,theURL2,winName,features) { //v2.0
  //alert(theURL1);
  //alert(theURL2);
  theURL = '/yahoo/play.php?_VIDEO=/datas/'+theURL1+ '/'+ theURL2;
  window.open(theURL,winName,features);
}

//--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="yahoo_msg.php" method="post">
<input type="hidden" name="_IDX" value="<?echo $_IDX;?>">
<input type="hidden" name="_Owner" value="<?echo $_Owner;?>">
<input type="hidden" name="_Whom" value="<?echo $_Whom;?>">
<input type="hidden" name="_DateTime" value="<?echo $_DateTime;?>">
<input type="hidden" name="to_page" value="<?echo $to_page;?>"><!--current page-->
<input type="hidden" name="_IP" value="<?echo $_IP;?>">
<input type="hidden" name="RunAs" value="">

<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;<img src="../<?echo $DIR_IMAGE.$YAHOOP_YAHOO?>">&nbsp;<span  title="<?echo $YAHOO_DATETIME?>"><B><?echo $YAHOO_DATETIME_SHOW?></B> : </span><?echo $row2[$DB_YAHOO_TIMESTAMP]?> |
	<span  title="<?echo $YAHOO_USERID?>"><B><?echo $YAHOO_USERID_SHOW?> : </span><font color="red"><?echo $row2[$DB_YAHOO_OWNER]?></font></B>
	</td>
	<td align="right">
	<span class="EveryPage" title="<?echo $YAHOO_PAGEVIEW;?>"><?echo $YAHOO_PAGEVIEW_SHOW;?> : </span>
	<input type="text" size="1" name="sizepage" value="<?echo $sizepage?>" class="Text_P"> 
	<input type="button" name="bntPageSize" value="Confirm" onClick="ChangePageSize();" class="Btn_C" title="<?echo $YAHOOB_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="10%" title="<?echo $YAHOO_DATETIME?>">Date-Time</td>
	    <td width="15%" title="<?echo $YAHOO_USERID?>">User Handle</td>
	    <td width="8%" title="<?echo $YAHOO_MSG_TYPE?>">Type</td>
	    <td title="<?echo $YAHOO_MSG_MESSAGE?>">Message</td>
	    <td width="10%" title="<?echo $YAHOO_MSG_STARTTIME?>">StartTime</td>
		<td width="10%" title="<?echo $YAHOO_MSG_ENDTIME?>">EndTime</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="10%"></td>
	    <td width="15%"></td>
	    <td width="8%"></td>
	    <td></td>
	    <td width="10%"></td>
		<td width="10%"></td>
	</tr>
    <?echo $ListYAHOO_Msg;?>
	<tr>
		<td colSpan="<?if ($ad_server == 1) echo "12"; else echo "11"; ?>" 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>
