<?php
session_start();
require_once "../init.php";
require_once "../authority.inc.php";


if($_GET['ID'])
{
	$ID = $_GET['ID'];
}
else
{
	$ID = $_POST['ID'];
}
//$key = $_GET['key'];
if($_GET['key'])
{
	$key = $_GET['key'];
}
else
{
	$key = $_POST['key'];
}

$mailto = $_POST['mailto'];
$subject = $_POST['subject'];
$body = $_POST['body'];
$Reply = $_POST['Reply'];
$backUrl = $_POST['backUrl'];
$IsReply = $_GET['IsReply'];

if(!CheckHashKey('ques'.$ID,$key)){
   $DB->close();
   die("非法入侵");
}
$backUrl=$backUrl?$backUrl:$_SERVER["HTTP_REFERER"];
if(!$Reply){
	/****** 客户问题信息 ******/
	$sql="select question.* from question where question.ID='$ID'";
	$result=$DB->query($sql);
	$qes=$DB->fetch_array($result);
	//当前登录员工的信息
	$sql="select * from admins where UserID='$_SESSION[AdmUserID_S]'";
	$result=$DB->query($sql);
	$adm=$DB->fetch_array($result);
	
	$Content=implode("",file("reply_template.txt"));
    $Content=str_replace("@CONTACT",$qes[Contact],$Content);
	$Content=str_replace("@REPLY_NAME",$adm[RealName],$Content);
	$Content=str_replace("@REPLY_TIME",date("Y-m-d",time()),$Content);
	$Content=str_replace("@MSG_ORG",$qes[Content],$Content);
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="../lib/html5.js"></script>
<script type="text/javascript" src="../lib/respond.min.js"></script>
<script type="text/javascript" src="../lib/PIE_IE678.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.7/iconfont.css" />
<link rel="stylesheet" type="text/css" href="../lib/icheck/icheck.css" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="../static/h-ui.admin/js/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>修改客户问题</title>

<script src='../share/global.js'></script>
<script>
function check(form){
   if(form.mailto.value==""){
       alert("请输入收件人地址");
	   form.mailto.focus();
	   return false;
   }
   
   /*if(form.mailfrom.value==""){
       alert("请输入发件人地址");
	   form.mailfrom.focus();
	   return false;
   }*/
   
   if(form.subject.value==""){
       alert("请输入邮件地址");
	   form.subject.focus();
	   return false;
   }
   
   if(form.body.value==""){
       alert("请输入邮件内容");
	   form.body.focus();
	   return false;
   }
}
</script>
</head>
<body>


<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 评论管理 <span class="c-gray en">&gt;</span> 意见反馈 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
<div class="cl pd-5 bg-1 bk-gray mt-10"> <span class="l"><a href="ques_list.php"  <?if(!isset($hot)){?>id="hot"<?}?> class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 问题列表</a> <a   <?if(($hot=="add")){?>id="hot"<?}?>  onclick="Hui_admin_tab(this)"  class="btn btn-primary radius" data-title="已回复" href="ques_list.php?IsReply=1"  href="ques_list.php?IsReply=1"><i class="Hui-iconfont">&#xe600;</i> 已回复</a> <a   <?if(($hot=="add")){?>id="hot"<?}?> class="btn btn-primary radius" data-title="需要回复的" href="ques_list.php?IsReply=0"  onclick="Hui_admin_tab(this)"href="ques_list.php?IsReply=0"><i class="Hui-iconfont">&#xe600;</i> 需回复</a></span> <span class="r"><?
	$pageStr="共 $totalRecord 条记录,共 <strong>1</strong> 页,当前第 </strong>1</strong> 页";
	echo $pageStr;
?></span></div><br>
<!--结束-->
	  <?
	  if($Reply==1){
		  $sql="update question set IsReply=1,RContent='$body',ReplyName='$_SESSION[AdmUserID_S]' where ID=$ID";
		  $DB->query($sql);
		  $email=new MailTemplate($body);
		  $email->setReplyTo($mailfrom);
		  $AgentInfo = GetAgentInfo();
		  $oEmail = new MailTemplate($body);
		  $oEmail->SmtpServer = $AgentInfo[SmtpServer] ; 
		  $oEmail->SmtpUser = $AgentInfo[SmtpUser] ;
		  $oEmail->SmtpPW = $AgentInfo[SmtpPW] ;
		  $oEmail->SmtpSender = $AgentInfo['SmtpSender'];
		  $result=$oEmail->sendmail($mailto,$subject,$AgentInfo[Company]."<".$AgentInfo[SmtpUser].">");
		  if($result){
			 echo "<center><br><br><br>邮件已经成功发送到 $mailto ";
		  }else{
			 echo "<center>邮件发送失败";
		  }
		  echo "<br><br><br><a href='ques_reply.php?ID=".$ID."&key=".$key."&backUrl=".urlencode($backUrl)."'>返回客户问题详细信息</a>  <a href='".$backUrl."'>[ 返 回 ]</a></center><br><br>";
	  }else{ 
	  ?>


	<table width="100%" border="0" cellpadding="0" cellspacing="0" id="table" class="table table-border table-bordered table-hover table-bg table-sort">
  <tr align="center" bgcolor="#EEEEEE" id="tr">
	<td colspan="4">客户问题详细内容 </td>
  </tr>
		<tr>
		  <td width="12%" align="right">问题类型:</td>
		  <td width="37%" class="inputline"><?=$qes[QuesType]?></td>
		  <td width="12%" align="right">会员号:</td>
		  <td width="39%" class="inputline">
		  <a href="../users/user_edit.php?UserName=<?=$qes[UserName]?>&key=<?=GetHashKey('users'.$qes[UserName])?>&backUrl=<?=$backUrl?>">
		  <?=$qes[UserName]?></a>
		  <?=!$qes[UserName]?"&nbsp;":""?>
		  </td>
		</tr>
		<tr>
		  <td align="right">联系人:</td>
		  <td class="inputline"><?=$qes[Contact]?></td>
		  <td align="right">E-Mail:</td>
		  <td class="inputline"><?=$qes[Email]?></td>
		</tr>
		<tr>
		  <td align="right">提交时间:</td>
		  <td class="inputline"><?=substr($qes[dtCreate],0,10)?></td>
		  <td align="right">是否回复:</td>
		  <td class="inputline"><?
			  if($qes[IsReply]==1)echo "<font color='#009900'>已回复</font>";
			  elseif($qes[IsReply]==0)echo "<font color='red'>未回复</font>";
			  ?>
		  </td>
		</tr>
		<tr>
		  <td align="right">标题:</td>
		  <td class="inputline"><?=$qes[Subject]?></td>
		  <td align="right">回复人:</td>
		  <td class="inputline"><?=$qes[ReplyName]?>&nbsp;</td>
		</tr>
		<tr>
		  <td align="right">内容:</td>
		  <td colspan="3" class="inputline"><?=trans($qes[Content])?></td>
		</tr>
		<tr>
		  <td align="right" valign="top">回复内容:</td>
		  <td colspan="3" class="inputline"><?=trans($qes[RContent])?></td>
		</tr>
	  </table>
		<br>
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table table-border table-bordered table-hover table-bg table-sort">
		  <form action="ques_reply.php" method="post" onSubmit="return check(this)">
			<tr>
			  <td width="12%" align="right">收件人:</td>
			  <td><input name="mailto" type="text" class="inputline" value="<?=$qes[Email]?>" size="30"></td>
			</tr>
			<tr>
			  <td align="right">主题:</td>
			  <td><input name="subject" type="text" class="inputline" value="Re:<?=$qes[Subject]?>" size="50"></td>
			</tr>
			<tr>
			  <td align="right" valign="top">内容:</td>
			  <td><textarea name="body" cols="100" rows="15" style="width:100%" class="textarea"><?=$Content?></textarea></td>
			</tr>
			<tr>
			  <td colspan="2" align="center" style="text-align:center;">
			  <br>
				<input name="submit" type="submit" class="bt2" value="提 交"> &nbsp;
				<input name="reset" type="button" class="bt2" value="返 回" onclick="location='<?=$backUrl?>'">
				<input name="Reply" type="hidden" value="1">
				<input name="backUrl" type="hidden" value="<?=$backUrl?>">
				<input name="key" type="hidden" value="<?=$key?>">
				<input name="ID" type="hidden" value="<?=$ID?>">
			  </td>
			</tr>
		  </form>
	  </table>
</div>

<?}?>

<? 
$DB->close();
include "../share/bottom.php"?>
</body>
</html>
