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

$_AUTO = $HTTP_GET_VARS["_AUTO"];
$_TYPE = $HTTP_GET_VARS["_TYPE"];

$strSQL = "Select * from ".$DB_WEBMAIL." where ".$DB_WEBMAIL_AUTO." ='$_AUTO'";
$intResult=mysql_query($strSQL);

if (mysql_num_rows($intResult)>0){
	$row = mysql_fetch_array($intResult);
	$Charset = $row[$DB_WEBMAIL_CHARSET];
	//--轉換 DBTAG 的格式
	$_DBTAG ='';
	$_DBTAG =str_replace("-","_",$row[$DB_WEBMAIL_DBTAG]);
	$_DBTAG =str_replace(":","_",$_DBTAG);

	//--檢查subject是否有檔，有檔才有連結
	if (file_exists($CD_DIR.":\\".$_DBTAG."\\".$row[$DB_WEBMAIL_FILE_BODY])){
		$readFile =$CD_DIR."://".$_DBTAG."/".$row[$DB_WEBMAIL_FILE_BODY];
    }
	$_From		= $row[$DB_WEBMAIL_SENDER];
	$_Date		= $row[$DB_WEBMAIL_DATETIME];
	$_To			= convert($row[$DB_WEBMAIL_TO]);
	$_CC			= convert($row[$DB_WEBMAIL_CC]);
	$_BCC		= convert($row[$DB_WEBMAIL_BCC]);
	$_Subject  =convert($row[$DB_WEBMAIL_UTF_SUBJECT]);
}

$strATT= "select * from ATTACHMENT where _NEWIDX='$_AUTO' and _TYPE='$_TYPE'";
$Result=mysql_query($strATT);
$numATT=mysql_num_rows($Result);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=''">
<title>Webmail (Sender)</title>
<link href="../Display/display.css" type="text/css" rel="stylesheet">
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.style3 {font-family: Arial, Helvetica, sans-serif; font-size: x-small; }
.style5 {font-family: Arial, Helvetica, sans-serif; font-size: x-small; font-weight: bold; }
-->
</style>
</head>
<body>
<table width="100%" border="0" height="100%" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
  <tr>
    <td width="15%" class="style5" align="right">FROM :&nbsp;&nbsp;</td>
    <td height="25" class="style3"> <?echo $_From;?> </td>
  </tr>
  <tr nowrap>
    <td width="15%" class="style5" nowrap align="right">DATE / TIME :&nbsp;&nbsp;</td>
    <td height="25" class="style3"> <?echo $_Date;?> </td>
  </tr>
  <tr>
    <td width="15%" class="style5" align="right">TO :&nbsp;&nbsp</td>
    <td height="25" class="style3"> <?echo $_To;?> </td>
  </tr>
  <?if (strlen($_CC) > 2){?>
  <tr>
    <td width="15%" class="style5" align="right">CC :&nbsp;&nbsp</td>
    <td height="25" class="style3"> <?echo $_CC;?> </td>
  </tr>
  <?}?>
  <?if (strlen($_BCC) > 2){?>
  <tr>
    <td width="15%" class="style5" align="right">BCC :&nbsp;&nbsp</td>
    <td height="25" class="style3"> <?echo $_BCC;?> </td>
  </tr>
  <?}?>
  <tr>
    <td width="15%" class="style5" align="right">SUBJECT :&nbsp;&nbsp</td>
    <td height="25" class="style3"> <?echo $_Subject;?> </td>
  </tr>
  <?if($numATT>0){?>
	  <tr>
		<td width="15%" class="style5" align="right">ATTACHMENT :&nbsp;&nbsp</td>
		<td height="25" class="style3"> 
		<?if ($numATT < 2){?>
		  <iframe name="Winattach" width="99%" height="33" src="attach.php?_AUTO=<?echo $_AUTO;?>&_TYPE=<?echo $_TYPE;?>&_CHARSET=<? echo $Charset?>"></iframe>

		<?}else{?>
		  <iframe name="Winattach" width="99%" height="63" src="attach.php?_AUTO=<?echo $_AUTO;?>&_TYPE=<?echo $_TYPE;?>&_CHARSET=<? echo $Charset?>"></iframe>
		<?}?>
		</td>
	  </tr>
 <?}?>
  <tr height="3"><td></td></tr>
  <tr>
    <td colspan="2">
	  <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
	    <tr>
		  <td width="8"></td>
		  <td><iframe name="WinFile" width="99%" height="100%" src="readfile.php?_file= <?echo $readFile?>"></iframe></td>
		</tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>
