<%@ Control Language="C#" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.HtmlTags" %>
<%@ Import Namespace="Kesion.APPCode" %>
<%@ Import Namespace="Kesion.Weixin" %>
<%@ Import Namespace="Kesion.XML" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Xml" %>

<script runat="server" type="text/C#">
	dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息，
	private static dynamic __info = new System.Dynamic.ExpandoObject();   //初始化当前页信息
	bool isLoadPage = true;  //定义页面是否加载
	DataRow dr = null;

	public int keyId = 0;
	private string action = string.Empty;
	public DataRow TuDr = null;
	public DataRow ShopDr = null;
	private string AttentionStatus = "1";
	public int keytype = 0;
	public string Content = string.Empty;

	protected void Page_Load(object sender, EventArgs e)
	{
		string DoMethod = BasicField.GetParam("do");
		if (string.IsNullOrEmpty(DoMethod))
		{
			DoMethod = KSCMS.S("action");
		}
		Initial();
		switch (DoMethod)
		{
			case "save":
				Save_Click();
				break;
			case "save2":
				Save_Click2();
				break;
		}
	}
	private void Initial()
	{
		//ks_weixin.IsVerify(0);
		keyId = Utils.StrToInt(DataFactory.GetOnlyValue("select top 1 id from KS_WeixinKeyWord where iskeyword=1 and userid="+new TemporaryVar().UserID+" and TypeFlag="+new TemporaryVar().GroupID+""));
		AttentionStatus = DataFactory.GetOnlyValue("select top 1 AttentionStatus from KS_WeixinEpConfig where userid=" + new TemporaryVar().UserID + "");
		__info.RdbStatus = AttentionStatus;
		__info.TxtContent = "";
		if (keyId == 0)
		{
		}
		else
		{
			#region 修改

			using (DataTable dt = DataFactory.GetDataTable("select top 1 * from  KS_WeixinKeyWord where iskeyword=1 and  userid="+new TemporaryVar().UserID+" and TypeFlag=" + new TemporaryVar().GroupID + ""))
			{
				if (dt.Rows.Count > 0)
				{
					DataRow dr = dt.Rows[0];
					string[] typename = string.Concat(dr["typename"].ToString(), "§").Split('§');
					keyId = Utils.StrToInt(dr["id"].ToString());
					__info.TxtContent = dr["content"].ToString();

					if (!string.IsNullOrEmpty(dr["TuWenID"].ToString()))
					{
						keytype = 0;
					}
					else if (!string.IsNullOrEmpty(dr["content"].ToString()))
					{
						keytype = 1;
					}
					else if (!string.IsNullOrEmpty(dr["ShopID"].ToString()))
					{
						keytype = 2;
					}
					else if (!string.IsNullOrEmpty(dr["sucaiid"].ToString()))
					{
						keytype = 3;
					}
					else if (!string.IsNullOrEmpty(dr["courseid"].ToString()))
					{
						keytype = 4;
					}
				}
			}
			#endregion
		}
		using (DataTable dt = DataFactory.GetDataTable("select top 1 * from ks_weixinuser where userId='" + new TemporaryVar().UserID + "' and TypeFlag=" + new TemporaryVar().GroupID + ""))
		{
			if (dt.Rows.Count > 0)
			{
				dr = dt.Rows[0];
			}
		}
	}

	protected void Save_Click()
	{
		#region 保存
		Hashtable ht = new Hashtable();

		ht.Add("KeyWord", "关注自动回复");
		ht.Add("Type", 0);
		ht.Add("Content", KSCMS.S("TxtContent"));
		ht.Add("Title", "自动回复");
		string site = KSCMS.S("TxtTuWenID");

		if (!string.IsNullOrEmpty(site))
		{
			ht.Add("TuWenID", site);
		}
		if (!string.IsNullOrEmpty(KSCMS.S("TxtCourseID")))
		{
			ht.Add("CourseID", KSCMS.S("TxtCourseID"));
			ht.Add("Costype", Utils.StrToInt(KSCMS.S("costype")));
		}
		if (!string.IsNullOrEmpty(KSCMS.S("TxtSuCaiID")))
		{
			ht.Add("sucaiid", KSCMS.S("TxtSuCaiID"));
		}
		if (keyId != 0)
		{
			CommonData.Update("KS_WeixinKeyWord", ht, "where id=" + keyId);
		}
		else
		{
			ht.Add("userid", new TemporaryVar().UserID);
			ht.Add("AddPeople",new TemporaryVar().UserName);
			ht.Add("AddTime", DateTime.Now);
			ht.Add("IsKeyWord", 1);
			ht.Add("TypeFlag", new TemporaryVar().GroupID);
			CommonData.Insert("KS_WeixinKeyWord", ht);
		}
		DataFactory.ExecuteNonQuery("update KS_WeixinEpConfig set AttentionStatus=1 where userid="+new TemporaryVar().UserID+"");
		Kesion.Weixin.ks_weixin.ClearKeyWordCache();
		Msg.Alert("恭喜，保存成功！", KSCMS.GetComeUrl());
		#endregion
	}
	protected void Save_Click2()
	{
		#region 保存

		string content = "keyword";
		string picmsg = "picid";
		System.Web.Caching.Cache keywordCache = System.Web.HttpRuntime.Cache;
		keywordCache.Remove(picmsg);
		keywordCache.Remove(content);
		DataFactory.ExecuteNonQuery("update KS_WeixinEpConfig set AttentionStatus=0 where userid=" + new TemporaryVar().UserID + "");
		Msg.Alert("恭喜，保存成功！", BasicField.GetUserUrl("wx/wx_ReplyMsg"));

		#endregion
	}

	
</script>
<%
	if (!isLoadPage) return;
%>
<link href="/SysImg/teacher/css/newswx.css" rel="stylesheet" />
<div class="t_tybox">
    <div class="tytitle"><h4>微信关注回复</h4></div>
	<div class="tabs">
		<ul class="clearfix">
			<li class="puton">
				<a href="<%=BasicField.GetUserUrl("wx/wx_ReplyMsg") %>">关注回复  </a>
			</li>
			<li>
				<a href="<%=BasicField.GetUserUrl("wx/wx_AutomaticReplyMsg") %>">消息自动回复  </a>
			</li>
			<li>
				<a href="<%=BasicField.GetUserUrl("wx/wx_KeyWord") %>">关键词自动回复  </a>
			</li>
		</ul>

	</div>
	<div class="clear"></div>

	<script>
		jQuery(document).ready(function () {
			showStatus();
		});

		function showStatus() {
			var checkrad = jQuery("#RdbStatus :radio[checked]").val();
			if (checkrad == "1") {
				jQuery("#detail").show();
				jQuery("#visiblebutton").hide();

			} else {
				jQuery("#detail").hide();
				jQuery("#visiblebutton").show();
			}
		}
		$(function () {
			jump(<%=keytype%>);
     		$(".menu1box ul li").click(function () {
     			var k = $(this).index();
     			jump(k);
     		});
     	});
		function jump(k) {
			$(".menu1box ul li").each(function (index, domEle) {
				$(this).attr("class", "");
			});
			$(".menu1box ul li").each(function (index, domEle) {
				if (k == index) {
					$("#typekey").val(k);
					if (k == 0) {
						$('#iframemain0').attr('src', '<%=BasicField.GetUserUrl("wx/wx_TuWenList","frame-no,action-attention,keyId-"+keyId+"") %>');
					} else if (k == 1) {
						$('#mybox2').show();
						$('#mybox1').hide();

					} else if (k == 2) {
						$('#iframemain0').attr('src', '<%=BasicField.GetUserUrl("wx/wx_ShopList","frame-no,action-attention,keyId-"+keyId+"") %>');

					}
					else if (k == 3) {
						$('#iframemain0').attr('src', '<%=BasicField.GetUserUrl("wx/wx_SuCaiList","frame-no,action-attention,keyId-"+keyId+"") %>');
					}
					$(this).attr("class", "hit");
				}
			});
		}
          var box = null;
          var isreload = false;
        function openWin(title, url, reload, width, height) {
          	if (width == null) width = 760;
          	if (height == null) height = 450;
          	isreload = reload;
          	box = $.dialog.open(url, {
          		id: 'topbox', lock: true, title: title, width: width, height: height, close: function () {
          			if (isreload) {
          				top.frames['main'].location.reload();
          			}
          		}
          	});
          }
	</script>
    <div class="console_body">
      <form name="myForm" method="post" action="<%=BasicField.GetUserUrl("wx/wx_ReplyMsg") %>" id="myForm">
          <input name="action" value="save" type="hidden" id="action" />
          <div class="openKey" style="margin-bottom: 0;">
              <span class="txt" style="float: left;">开启关注时回复:</span>
              <input type="hidden" name="keyid" id="keyid" value="<%=keyId%>">
              <table id="RdbStatus" onclick="showStatus()" border="0" style="margin-right: 5px;">
                  <tr>
                      <td><span style="margin-right: 10px;">
                          <input id="RdbStatus_0" type="radio" name="RdbStatus" <%=__info.RdbStatus=="1"?"checked":"" %> value="1" /><label for="RdbStatus_0">开启</label></span></td>
                      <td>
                          <input id="RdbStatus_1" type="radio" name="RdbStatus" value="0" <%=__info.RdbStatus=="0"?"checked":"" %> /><label for="RdbStatus_1"> 关闭</label></td>
                  </tr>
              </table>
              <div class="clear"></div>
          </div>
          <div id="detail" style="display: none">
              <input id="keytype" type="hidden" value="<%=keytype%>" />
              <input id="TxtTuWenID" type="hidden" name="TxtTuWenID" />
              <input id="TxtCourseID" type="hidden" name="TxtCourseID" />
              <input id="CosType" type="hidden" value="0" name="CosType" />
              <textarea id="ShowTxtTuWen0" style="width: 300px; height: 200px; display: none"></textarea>
              <textarea id="ShowTxtShop0" style="width: 300px; height: 200px; display: none"></textarea>
              <input id="TxtSuCaiID" type="hidden" name="TxtSuCaiID" />
              <textarea id="ShowTxtSuCai0" style="width: 300px; height: 200px; display: none"></textarea>
              <div class="phone_right">
                  <div class="cz_list">
                      <div class="tabs1">
                          <div class="menu1box clearfix">
                              <ul class="menu1">
                                  <li class="hit">
                                      <a href="<%=BasicField.GetUserUrl("wx/wx_TuWenList","frame-no,action-attention,keyId-"+keyId+"") %> " onclick="$('#mybox1').show();$('#mybox2').hide();" target="iframemain0">
                                          <i class="sm_tab tw2"></i>图文
                                      </a>
                                  </li>
                                  <li>
                                      <a href="javascript:;" onclick="$('#mybox2').show();$('#mybox1').hide();">
                                          <i class="sm_tab wz"></i>文字
                                      </a>
                                  </li>
                                  <%if (BaseFun.CheckModulePower("mall")) { %>
                                  <li>
                                      <a href="<%=BasicField.GetUserUrl("wx/wx_CourseList","frame-no,action-attention,keyId-"+keyId+"") %>" onclick="$('#mybox2').hide();$('#mybox1').show();" target="iframemain0">
                                          <i class="sm_tab sp"></i>课程
                                      </a>
                                  </li>
                                  <%} %>
                                  <li>
                                      <a href="<%=BasicField.GetUserUrl("wx/wx_SuCaiList","frame-no,action-attention,keyId-"+keyId+"") %>" onclick="$('#mybox1').show();$('#mybox2').hide();" target="iframemain0">
                                          <i class="sm_tab tw2"></i>素材
                                      </a>
                                  </li>
                              </ul>
                          </div>
                          <div class="main1box">
                              <div class="main">
                                  <dt class="mbimg" style="display: block;" id="mybox1">
                                      <iframe class="editArea-ifrm" frameborder="no" border="0" src="<%=BasicField.GetUserUrl("wx/wx_TuWenList","action-attention,keyId-"+keyId+"") %>" style="width: 100%;" name="iframemain0" id="iframemain0"></iframe>
                                  </dt>
                                  <dt id="mybox2" class="com_form msgBox" style="display: none; margin-bottom: 10px;">
                                      <div><textarea name="TxtContent" rows="2" cols="20" id="TxtContent" style="height: 200px; width: 98%; background: #fff; background-color: #fff; border: 1px solid #ddd;"><%=__info.TxtContent %></textarea></div>
                                  </dt>
                              </div>
                          </div>
                      </div>
                  </div>
              </div>
              <div class="opr1">
                  <br />
                  <br />
                  <input type="submit" name="ButtonAdd" value="保存" id="ButtonAdd" class="ct-btn blue" />
              </div>
          </div>
          <br />
          <br />
          <div id="visiblebutton" class="clearfix" style="display: none">
              <input type="submit" name="Button1" value="保存" id="Button1" onclick="$('#action').val('save2')" class="ct-btn blue" style="float: left" />
          </div>
      </form>
    </div>
</div>




