<?
	session_start();
	$selelag = $HTTP_SESSION_VARS["SelLanguage"];
	if (empty($selelag)) header("location:../break.php");
	require("../config/".$selelag);
	require("../_ConnectString.php");
	require("../_function.php");
	include ("../userule/getpattern.inc");
	require ("../message_trans_set/forward_email.php");
	require("../_image.php");


	$DATAS_PATH ="/datas/";
	$SETUP_MAIL = "/opt/local/apache/htdocs/config_file/setup_mail";

	if (file_exists($SETUP_MAIL)){
		$line = file($SETUP_MAIL);
		$arr_setup_mail = explode("/",$line[0]);
		$setup_mail_position = $arr_setup_mail[0]; // Local mail server
		$mail_host_name = $arr_setup_mail[1];
		$_SENDER = $arr_setup_mail[2];
	}else{
		$setup_mail_position = '_local'; // Local mail server
		$_SENDER = "dc@decision.com.tw";
	}

	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){
			$TABLE = $HTTP_GET_VARS["TABLE"];
			$_AUTO = $HTTP_GET_VARS["_AUTO"];
			$language = $HTTP_GET_VARS["language"];
		}else{
			$RunAs = $HTTP_POST_VARS["RunAs"];
			$mailadd = $HTTP_POST_VARS["mailadd"];
			$language = $HTTP_POST_VARS["language"];
			$TABLE = $HTTP_POST_VARS["TABLE"];
			$_AUTO = $HTTP_POST_VARS["_AUTO"];
		}

        if ($RunAs == 'submit'){
			$_INFORM = $mailadd;
			if ($TABLE == 'HTTP_PAGE'){
				$strSQL = "Select _HTML,_DBTAG,_HOST From ".$TABLE." Where _AUTO =".$_AUTO;
				$intResult =  mysql_query($strSQL);
				While($row = mysql_fetch_array($intResult)){
					$_SUBJECT =  "Forward ED :".$row["_HOST"];
					$_SUBJECT = iconv("UTF-8",$language,$_SUBJECT);
					$_FILEPATH = "/datas/".$row["_DBTAG"];
					$_FILENAME = $row["_HTML"];
				}
			}else if ($TABLE == 'WEBMAIL'){
				$strSQL = "Select _UTF_SUBJECT,_SUBJECT,_DBTAG,_FILE_BODY From ".$TABLE." Where _AUTO =".$_AUTO;
				$intResult =  mysql_query($strSQL);
				While($row = mysql_fetch_array($intResult)){
					$_SUBJECT =  "Forward ED:".$row["_UTF_SUBJECT"];
					$_SUBJECT = iconv("UTF-8",$language,$_SUBJECT);
					$auto=$_AUTO;
						include("tarfile.php");
						$_FILEPATH = "/tmp/";
						$_FILENAME = $dt.".tgz";
						$_BODY = "";
				 }
			}else{
				$strSQL = "Select _SUBJECT,_DBTAG,_BODY_NAME From ".$TABLE." Where _AUTO =".$_AUTO;
				$intResult =  mysql_query($strSQL);
				While($row = mysql_fetch_array($intResult)){
					$_SUBJECT =  "Forward ED : ".$row["_SUBJECT"];
					$_SUBJECT = iconv("UTF-8",$language,$_SUBJECT);
					$_FILEPATH = "/datas/".$row["_DBTAG"];
					$_FILENAME = $row["_BODY_NAME"];
				}
			}

			if (file_exists($_FILEPATH."/".$_FILENAME)){						 
				if(Forward_Email_SMTP($mail_host_name,$_SENDER,$_INFORM,$_SUBJECT,$_BODY,$_FILENAME,$_FILEPATH)==0)
							  $ErrorMsg = $Forward_Success;
					else
						  $ErrorMsg = $Forward_Fail;
			}else{
					print "<html><title></title><head>";
					print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=unicode\">";
					print "<center><b><font size=\"10\" color=\"red\"><span title=\"".$NO_Mail."\">Mail is deleted!</span></font></b></center>";
					print "</head></html>";
			}
		
		}
	}else {
		print "<html><title></title><head>";
		print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=unicode\">";
		print "<center><b><font size=\"10\" color=\"red\"><span title=\"".$L_BREAK."\">You have not privilege to do it !</span></font></b></center>";
		print "</head></html>";
		exit();
    }
?>
<html>
<head>
<title>E-Mail Forward</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">
<?if ($ErrorMsg != ""){?>
	fn_ErrorMsg('<?echo $ErrorMsg?>')
<?}?>
	function fn_download(){
		  
		  if (!emailCheck(document.frm.mailadd)){
           
			alert("Please Enter E-Mail Address");
			return false;
		  }
        
			document.frm.RunAs.value = 'submit';
			document.frm.submit();
	}


		
</script>
</head>
<body onLoad="window_onload_language();">
<center>
<form name="frm" action="forward.php" method="post">
<input type="hidden" name="TABLE" value="<?echo $TABLE;?>">
<input type="hidden" name="_AUTO" value="<?echo $_AUTO;?>">
<input type="hidden" name="language" value="">
<input type="hidden" name="RunAs" value="">

<table width="430" border="0" cellSpacing="0" cellPadding="0" class="style1">
 <tr class="style2"><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr>
 <td width="30" height="25"><img src="../<?echo $DIR_IMAGE.$PIC_BLUE_TABLE1_1;?>"></td>
	<td align="center" background="../<?echo $DIR_IMAGE.$PIC_BLUE_TABLE1_2;?>"><img src="../<?echo $DIR_IMAGE.$PUBLICP_FW ;?>" border="0" align="absmiddle"><span class="Lab2_Sub" title="<?echo $FORWARD_FW_TITLE;?>"> <?echo $FORWARD_FW_TITLE_SHOW;?></span></td>
	<td width="30" height="25"><img src="../<?echo $DIR_IMAGE.$PIC_BLUE_TABLE1_3;?>"></td>
 </tr>
 <tr>
	<td width="30" background="../<?echo $DIR_IMAGE.$PIC_BLUE_TABLE2_1;?>"></td>
	<td background="../<?echo $DIR_IMAGE.$PIC_BLUE_TABLE2_2;?>">
		<table width="100%" border="0" align="center">
		  <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
		  <tr>
 			<td height="30" align="right" class="Lab2_Item"><span title="<?echo $FORWARD_Forward;?>"><?echo $FORWARD_Forward_SHOW;?>:</span>&nbsp;</td>
			<td><input type="text" name="mailadd" size="30" value=""></td></tr>
			<tr><tr height="30">
			 <td colspan="2" align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="button" value="OK" title="<?echo $FORWARD_Send;?>"  class="Btn_D_2" onmouseover="this.className='Btn_D_1'" onmouseout="this.className='Btn_D_2'" onmousedown="this.className='Btn_D_3'" onClick="fn_download();" >

			<input type="reset" value="Reset" title="<?echo $FORWARD_Cancel;?>"  class="Btn_D_2" onmouseover="this.className='Btn_D_1'" onmouseout="this.className='Btn_D_2'" onmousedown="this.className='Btn_D_3'">

                </td>
            </tr>
		</table>
	<td width="30" background="../<?echo $DIR_IMAGE.$PIC_BLUE_TABLE2_3;?>"></td>
  </tr>
  <tr>
	<td width="30" height="15"><img src="../<?echo $DIR_IMAGE.$PIC_BLUE_TABLE3_1;?>"></td>
	<td background="../<?echo $DIR_IMAGE.$PIC_BLUE_TABLE3_2;?>"></td>
	<td width="30" height="15"><img src="../<?echo $DIR_IMAGE.$PIC_BLUE_TABLE3_3;?>"></td>
  </tr>
</table>
</form>
</body>
</html>
