<%@ 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="System.Data" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Net" %>
<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 id;
	public string Openid = string.Empty;
	public string epOpenID = string.Empty;
	protected void Page_Load(object sender, EventArgs e)
	{
		string DoMethod = KSCMS.S("do");
		if (string.IsNullOrEmpty(DoMethod))
		{
			DoMethod = KSCMS.S("action");
		}
		Openid = KSCMS.S("openid");
		epOpenID = ks_weixin.WeiXinOpenID(1);
		switch (DoMethod)
		{
			case "del":
				BtnDelete_Click();
				break;
		}
		if (!IsPostBack)
		{		
			__info.Panel1 = true;

			if (KSCMS.S("action") == "look")
			{
				__info.Panel1 = false;
				DataFactory.ExecuteNonQuery("update KS_WeixinMsg set IsRead=1 where FromUserName='" + Openid + "'");
			}
		}
	}
	protected void BtnDelete_Click()
	{
		if (KSCMS.S("ids") != "") deleteMsg(KSCMS.S("ids"));
	}
	public void deleteMsg(string id)
	{
		#region 批量删除
		
		if (id != "")
		{
			string ids = id.Replace(" ", "");
			string[] id_arr = ids.Split(',');
			Hashtable ht = new Hashtable();
			foreach (string id2 in id_arr)
			{
				using (DataTable dt = DataFactory.GetDataTable("select * from KS_WeixinMsg where id=" + id2))
				{
					if (dt.Rows.Count > 0)
					{
						DataRow dr = dt.Rows[0];
						ht.Add("FromUserName", dr["FromUserName"].ToString());
						CommonData.Delete("ks_weixinmsg", ht);
					}
				}
				ht.Clear();
			}
			Msg.Alert("删除成功！", BasicField.GetUserUrl("wx/wx_SendMsg"));
		}

		#endregion
	}
	 public string Count(string openid)
        {
            #region 总计条数
            string count = string.Empty;
            count = DataFactory.GetOnlyValue("select count(id) from KS_WeixinMsg where FromUserName='" + openid + "' and  MsgType='text' and ToUserName='" + epOpenID + "'");
            return count;
            #endregion
        }
		 public string NoReadCount(string openid)
        {
            #region 未读条数
            string count = string.Empty;
			count = DataFactory.GetOnlyValue("select count(id) from KS_WeixinMsg where FromUserName='" + openid + "' and MsgType='text' and IsRead=0 and ToUserName='" + epOpenID + "'");
            return count;
            #endregion
        }
        public string GetReply(DateTime createTime)
        {
            #region 发送的权限
            string str = string.Empty;
            DateTime curretTime = DateTime.Now;

            TimeSpan ts = curretTime - DateTime.Parse(createTime.ToString());
           if (ts.Hours <= 48)
           {
               str="<div class=\"operating_right\"> <span class=\"quick_reply\"><a><img src=\"/admin/weixin/images/kjhuifu.png\" /></a></span></div>";
           }
           else
           {
               str = "用户已经发送的信息超过48个小时所以不能对该用户进行发送";
           }
           return str;
           #endregion
        }
		public string GetSendUserMessage(string MsgType, string Content, string PicUrl, string MediaId)
		{
			string str = string.Empty;

			if (MsgType == "text")
			{
				str = ks_weixin.ReplaceEmot(Content);
			}
			else if (MsgType == "image")
			{

				string file = GetMultimedia(ks_weixin.IsExistAccess_Token(1), MediaId, MsgType);
				str += string.Format(@"<a class=""title_wrp"" href=""{0}""  target=""_blank"">
                      <img class=""icon"" src=""{0}"">
                      <span class=""title"">[图片]</span>
			    </a>", file);

			}
			else if (MsgType == "voice")
			{
				string file = GetMultimedia(ks_weixin.IsExistAccess_Token(1), MediaId, MsgType);
				str += string.Format(@" <div class=""show_player"" style="" display:none;"">
				   <a class=""show_player_click""><img src=""show_click.png"" />收起</a>
				   <div class=""video"">
				   </div>
				</div>
				<div class=""hit_player_img"">
				   <img src=""{0}""  class=""wxImg""/>
				   <span class=""iconVideo"" title=""点击播放视频""></span>
				</div>", file);

			}
			else if (MsgType == "shortvideo")
			{
				string file = GetMultimedia(ks_weixin.IsExistAccess_Token(1), MediaId, MsgType);
				str += string.Format(@" <div class=""show_player"" style="" display:none;"">
				   <a class=""show_player_click""><img src=""show_click.png"" />收起</a>
				   <div class=""video"">
				   </div>
				</div>
				<div class=""hit_player_img"">
				   <img src=""{0}""  class=""wxImg""/>
				   <span class=""iconVideo"" title=""点击播放视频""></span>
				</div>", file);
			}
			else if (MsgType == "video")
			{
				string file = GetMultimedia(ks_weixin.IsExistAccess_Token(1), MediaId, MsgType);
				str += string.Format(@" <div class=""show_player"" style="" display:none;"">
				   <a class=""show_player_click""><img src=""show_click.png"" />收起</a>
				   <div class=""video"">
				      aaa
				   </div>
				</div>
				<div class=""hit_player_img"">
				   <img src=""{0}""  class=""wxImg""/>
				   <span class=""iconVideo"" title=""点击播放视频""></span>
				</div>", file);
			}


			return str;
		}
		/// <summary>  
		/// 下载保存多媒体文件,返回多媒体保存路径  
		/// </summary>  
		/// <param name="ACCESS_TOKEN"></param>  
		/// <param name="MEDIA_ID"></param>  
		/// <param name="MsgType"></param>
		/// <returns></returns>  
		public string GetMultimedia(string ACCESS_TOKEN, string MEDIA_ID, string MsgType)
		{
			string file = string.Empty;
			string content = string.Empty;
			string strpath = string.Empty;
			string savepath = string.Empty;
			string stUrl = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" + ACCESS_TOKEN + "&media_id=" + MEDIA_ID;
			HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(stUrl);
			req.Method = "GET";
			using (WebResponse wr = req.GetResponse())
			{
				HttpWebResponse myResponse = (HttpWebResponse)req.GetResponse();
				strpath = myResponse.ResponseUri.ToString();
				WebClient mywebclient = new WebClient();
				if (MsgType == "image")
				{

					savepath = (@"\UploadFiles\temp") + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + (new Random()).Next().ToString().Substring(0, 4) + ".jpg";

				}
				else if (MsgType == "voice")
				{
					savepath = (@"\UploadFiles\temp") + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + (new Random()).Next().ToString().Substring(0, 4) + ".mp3";
				}
				try
				{
					mywebclient.DownloadFile(strpath, Server.MapPath(savepath));
					file = savepath;
				}
				catch (Exception ex)
				{
					savepath = ex.ToString();
				}
			}
			return file;
		}
		public string GetSendContent(string MsgType, string Content, string MediaId, string PicUrl)
		{
			string str = string.Empty;
			if (MsgType == "text")
			{
				str += ks_weixin.ReplaceEmot(Content);
			}
			else if (MsgType == "image")
			{
				string file = GetMultimedia(ks_weixin.IsExistAccess_Token(1), MediaId, MsgType);
				str += string.Format(@"<a class=""title_wrp"" href=""{0}""  target=""_blank"">
                      <img class=""icon"" src=""{0}"">
                      <span class=""title"">[图片]</span>
			    </a>", file);
			}
			else if (MsgType == "voice")
			{
				string file = GetMultimedia(ks_weixin.IsExistAccess_Token(1), MediaId, MsgType);
				str += string.Format(@" <div class=""show_player"" style="" display:none;"">
				   <a class=""show_player_click""><img src=""show_click.png"" />收起</a>
				   <div class=""video"">
				      aaa
				   </div>
				</div>
				<div class=""hit_player_img"">
				   <img src=""{0}""  class=""wxImg""/>
				   <span class=""iconVideo"" title=""点击播放视频""></span>
				</div>", file);
			}
			else if (MsgType == "shortvideo")
			{
				string file = GetMultimedia(ks_weixin.IsExistAccess_Token(1), MediaId, MsgType);
				str += string.Format(@" <div class=""show_player"" style="" display:none;"">
				   <a class=""show_player_click""><img src=""show_click.png"" />收起</a>
				   <div class=""video"">
				      aaa
				   </div>
				</div>
				<div class=""hit_player_img"">
				   <img src=""{0}""  class=""wxImg""/>
				   <span class=""iconVideo"" title=""点击播放视频""></span>
				</div>", file);
			}
			else if (MsgType == "video")
			{
				string file = GetMultimedia(ks_weixin.IsExistAccess_Token(1), MediaId, MsgType);
				str += string.Format(@" <div class=""show_player"" style="" display:none;"">
				   <a class=""show_player_click""><img src=""show_click.png"" />收起</a>
				   <div class=""video"">
				      aaa
				   </div>
				</div>
				<div class=""hit_player_img"">
				   <img src=""{0}""  class=""wxImg""/>
				   <span class=""iconVideo"" title=""点击播放视频""></span>
				</div>", file);
			}
			return str;
		}
		public string GetReplyContent(string ReplyStatus, string ReplyTime, string replyContent, string tuwenid, string Courseid, string sucaiId,int cosType)
		{
			#region 得到回复内容

			int tm_id = 0;
			int tinfoid = 0;
			int sm_id = 0, sinfoid = 0;
			string ss = string.Empty;
			if (ReplyStatus == "1")
			{
				ss = (string.Format(@" <li class=""inner_msg_list clearfix"">
	        <div class=""personal_replies"">
	       <div class=""service_list_left"">
	       <div class=""service_img""><img src=""/admin/weixin/images/logo.jpg"" />
         </div>
		    <div class=""service_info_left"">
		  <div class=""service_info"">
		     {0}
		     </div>
	     <div class=""service_list_right"">
	           <div class=""operating_left"">
		      <span class=""response_time"">{1}</span></div>
		       <div class=""clear""></div> </div>     
                 <div class=""clear""></div> 
		    <span class=""send_message"">
        ", DataFactory.GetOnlyValue("select top 1 OpenName from KS_WeixinUser where TypeFlag="+new TemporaryVar().GroupID+" and userid="+new TemporaryVar().UserID+""), ReplyTime));
				if (!string.IsNullOrEmpty(replyContent))
				{
					ss += @"<div class=""reply_tuwen_list"">" + replyContent + "</div>";
				}
				if (!string.IsNullOrEmpty(tuwenid))
				{
					string[] tuwen = string.Concat(tuwenid, "|").Split('|');
					tm_id = Utils.StrToInt(tuwen[1].ToString());
					tinfoid = Utils.StrToInt(tuwen[2].ToString());
					using (DataTable dt2 = DataFactory.GetDataTable("select Top 1 * from KS_EnterpriseNews where id=" + tinfoid + ""))
					{
						if (dt2.Rows.Count > 0)
						{
							DataRow dr2 = dt2.Rows[0];
							ss += string.Format(@"<div class=""reply_tuwen_list""><a class=""title_wrp"" href=""{0}"" target=""_blank""><span class=""tuwen_title"">{1}</span>
                              <img class=""icon"" src=""{2}"" />
                                 <span class=""title"">[图文]</span></a><div class=""tuwen_intro"">{3}</div><div class=""clear""></div></div>",
							 MyCache.GetCacheConfig(5)+BasicField.GetEplistContentUrl(Utils.StrToInt(dr2["SchoolID"]), "action-news,archive-archive,paramID-" + dr2["id"]), 
							 dr2["title"].ToString(), dr2["photo"].ToString() == string.Empty ? "/SysImg/nopic.gif" : dr2["photo"].ToString(), dr2["intro"].ToString() == string.Empty ? Utils.CutStr(Utils.ClearHtml(dr2["content"].ToString()), 10) : dr2["intro"].ToString());
						}
					}
				}
				if (!string.IsNullOrEmpty(Courseid))
				{
					string[] Course = string.Concat(Courseid, "§").Split('§');
					sm_id = Utils.StrToInt(Course[1].ToString());
					sinfoid = Utils.StrToInt(Course[2].ToString());
					string tableName = "KS_Course";
					if (cosType == 0)
					{
						tableName = "KS_CourseFace";
					}
					using (DataTable dt2 = DataFactory.GetDataTable("select Top 1 * from " + tableName + " where courseid=" + sinfoid + " "))
					{
						if (dt2.Rows.Count > 0)
						{
							DataRow dr2 = dt2.Rows[0];
							ss += string.Format(@"<div class=""reply_tuwen_list""><a class=""title_wrp"" href=""{0}"" target=""_blank""><span class=""tuwen_title"">{1}</span>
                              <img class=""icon"" src=""{2}"" />
                                 <span class=""title"">[课程]</span></a><div class=""tuwen_intro"">{3}</div><div class=""clear""></div></div>",
							GetUrl(sinfoid, cosType), dr2["name"].ToString(), dr2["photourl"].ToString() == string.Empty ? "/SysImg/nopic.gif" : dr2["photourl"].ToString(), dr2["intro"].ToString() == string.Empty ? Utils.CutStr(Utils.ClearHtml(dr2["target"].ToString()), 50) : dr2["intro"].ToString());
						}
					}
				}
				if (!string.IsNullOrEmpty(sucaiId))
				{
					using (DataTable dt2 = DataFactory.GetDataTable("select top 1 * from KS_WeixinPigmsg where id=" + sucaiId))
					{
						if (dt2.Rows.Count > 0)
						{
							DataRow dr2 = dt2.Rows[0];

							ss += string.Format(@"<div class=""reply_tuwen_list""><a class=""title_wrp"" href=""javascript:(0)"" ><span class=""tuwen_title"">{0}</span>
                              <img class=""icon"" src=""{1}"" />
                                 <span class=""title"">[素材]</span></a><div class=""tuwen_intro"">{2}</div><div class=""clear""></div></div>",
							 dr2["title"].ToString(), dr2["PicUrl"].ToString() == string.Empty ? "/SysImg/nopic.gif" : dr2["PicUrl"].ToString(), dr2["Info"].ToString() == string.Empty ? Utils.CutStr(Utils.ClearHtml(dr2["content"].ToString()), 10) : dr2["Info"].ToString());
						}
					}
				}
				ss += string.Format(@"  
         </span>
        </div> </div> </li>");
			}
			return ss;
			#endregion
		}
		public string GetUrl(int courseid,int costype)
		{
			string value = "courseview";
			if (costype == 0)
			{
				value = "faceview";
			}
			else if (costype == 5)
			{
				value = "liveview";
			}
			return BasicField.GetRewriteUrl(value, courseid);
		}
		
</script>
<%
	if (!isLoadPage) return;
%>
<link href="/SysImg/teacher/css/newswx.css" rel="stylesheet" />
<div class="t_tybox">
<div class="tytitle"><h4>微信消息管理</h4></div>
<form name="myForm" method="post" action="<%=BasicField.GetUserUrl("wx/wx_SendMsg") %>" id="myForm">
<input type="hidden" value="" name="action" id="action">
<input type="hidden" value="" name="do" id="domethod">
	<div class="content-area">
		<script>
			$(function () {
				var w = 250;
				var h = 50;
				$(".prompt_box").css("position", "fixed");
				$(".prompt_box").css("width", w).css("height", h);
				var x = ($(window).width() - w) / 2;
				var y = ($(window).height() - h) / 3;
				$(".prompt_box").css("top", y).css("left", x);
			});

			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();
						}
					}
				});
			}
			function DoSend(id) {
				var content = escape($("#txtcontent" + id).val());
				var openid = $("#openid" + id).val();
				var sendid = $("#sendid" + id).val();
				var tuwenid = $("#TxtTuWenID" + id).val().replace(/§/g, '|');
				var Courseid = $("#TxtCourseID" + id).val();
				var Costype = $("#CosType" + id).val();
				var sucaiid = $("#TxtSuCaiID" + id).val();
				$("#Loading").show();
				$.ajax({
					url: "/plus/course/wxajax.aspx?action=replymsg&sendopenid=" + openid + "&tuwenid=" + (tuwenid) + "&Courseid=" + Courseid + "&Costype=" + Costype + "&sucaiid=" + sucaiid + "&sendid=" + sendid + "&replycontent=" + content + "&rnd=" + Math.random(),
					context: document.body,
					type: "post",
					contentType: "text/html;charset=utf-8",
					success: function (data) {
						if (data == 'ok') {
							KesionJS.Alert("发送成功", "location.reload();");
						} else {
							KesionJS.Alert("发送失败", "location.reload();");
						}
						$("#Loading").hide();
					}
				});
				return false;
			}
			$(function () {
				$(".service_list_dg li .quick_reply").click(
					function () {
						$(this).parents("li").children(".reply_box").slideToggle("slow");
					}
			)
			});
		</script>
		<style>
			.emoji {
				background: transparent url(/admin/weixin/images/qqface/emoji218877.png) no-repeat 0 0;
				width: 20px;
				height: 20px;
				display: -moz-inline-stack;
				display: inline-block;
				vertical-align: middle;
				margin-top: -0.2em;
				zoom: 1;
			}
			.emoji1f604 {
				background-position: 0 -3260px;
			}
		</style>

		<%if(__info.Panel1){ %>
		<div ID="Panel1" >

			<div class="prompt_bg" style="display: none" id="Loading">
				<div class="prompt_box">
					<p>
						<img src="/admin/weixin/images/loading.gif" />正在发送，请耐心等待...</p>
				</div>
			</div>
			<div class="service">

				<a href="<%=BasicField.GetUserUrl("wx/wx_SendMsg","do-del") %>"></a>
				<input type="submit" value="删除记录" class="sendmsg_delete_btn" onclick="if (GetIDS('del')) { $('#domethod').val('del'); return true; } else { return false }" />

				<span class="quanxuan">
					<input type="checkbox" name="chkall" id="chkall" onclick="CheckAll(this.form);" />全选</span>
					<ul class="service_list_dg">
					<%
                        int recordcount, pagecount;
                        int CurrPage = new BasicField().GetCurrPage;
                        int PageSize = 10;
                        //
                          string sqlParam = " ks_weixinmsg a  inner join  ks_weixinopenuser b on a.FromUserName=b.openid where a.id = (select max(id) from ks_weixinmsg where FromUserName = a.FromUserName) and MsgType!='event'  and a.toUserName='" + epOpenID + "' and schoolID=" + new TemporaryVar().UserID + "";
                     //   string sqlParam = " ks_weixinmsg a  inner join  ks_weixinopenuser b on a.FromUserName=b.openid where a.id = (select top 1 id from ks_weixinmsg where FromUserName = a.FromUserName) and  MsgType!='event' and a.toUserName='" + epOpenID + "' and schoolID=" + new TemporaryVar().UserID + "";
                        int pagesize = 20;
                        #region 日期限制
                        if (!string.IsNullOrEmpty(KSCMS.S("adddate")))
                        {
                            if (Utils.IsDateTime(KSCMS.S("adddate")))
                            {
                                sqlParam += " and [AddTime]>='" + KSCMS.S("adddate") + "'";
                            }
                        }
                      //  Utils.WriteLog(sqlParam);
                        #endregion
                        using (DataTable dt = DataFactory.GetPage("FromUserName,a.id,a.content,a.MsgType,a.PicUrl,a.MediaId,a.ReplyStatus,a.CreateTime,b.NickName,b.HeadImgurl ", sqlParam, "a.id", "order by a.CreateTime desc", CurrPage, pagesize, out recordcount, out pagecount))
                        {
                            if (dt.Rows.Count > 0)
                            {
                                foreach (DataRow dr in dt.Rows)
                                {
                                    KSCMS.W("<li class=\"clearfix\">" +
                                        "<input id='TxtTuWenID" + dr["id"].ToString() + "' type=\"hidden\" name=\"TxtTuWenID" + dr["id"].ToString() + "\" />" +
                                            "<textarea id='ShowTxtTuWen" + dr["id"].ToString() + "' style=\"width: 300px; height: 200px; display: none\" name=\"ShowTxtTuWen" + dr["id"].ToString() + "\"></textarea>" +
                                            "<textarea id='ShowTxtCourse" + dr["id"].ToString() + "' style=\"width: 300px; height: 200px; display: none\" name=\"ShowTxtCourse" + dr["id"].ToString() + "\"></textarea>" +
                                            "<input id='TxtCourseID" + dr["id"].ToString() + "' type=\"hidden\" name=\"TxtCourseID" + dr["id"].ToString() + "\" />" +
                                                "<input id='CosType" + dr["id"].ToString() + "' type=\"hidden\" name=\"CosType" + dr["id"].ToString() + "\" />" +
                                            "<input id='TxtSuCaiID" + dr["id"].ToString() + "' type=\"hidden\" name=\"TxtSuCaiID" + dr["id"].ToString() + "\" />" +
                                            "<textarea id='ShowTxtSuCai" + dr["id"].ToString() + "' style=\"width: 300px; height: 200px; display: none\"></textarea>" +
                                            "<input id='sendid" + dr["id"].ToString() + "' name=\"sendid" + dr["id"].ToString() + "\" type=\"hidden\" value=\"" + dr["id"].ToString() + "\" />" +
                                            "<input id='openid" + dr["id"].ToString() + "' name=\"openid" + dr["id"].ToString() + "\" type=\"hidden\" value=\"" + dr["FromUserName"].ToString() + "\" />" +
                                            "<div class=\"personal_replies\"><input type=\"checkbox\" name=\"ids\" id=\"ids\" value='" + dr["id"].ToString() + "' style=\"height: 15px; width: 15px; margin-right: 10px; float: left;\" />" +
                                            "<div class=\"service_list_left1\"><div class=\"service_img\"><img src=\"" + dr["HeadImgurl"].ToString() + "\" /></div>" +
                                            "<div class=\"service_info_left\"><div class=\"service_info\">" +
                                            dr["NickName"].ToString() + "(<a href=\"" + BasicField.GetUserUrl("wx/wx_sendMsg", "action-look,openid-" + dr["FromUserName"].ToString() + ",sendid-" + dr["id"].ToString() + "") + "\" style=\"color: red\">" +
                                    "总共" + Count(dr["FromUserName"].ToString()) + "条|" + NoReadCount(dr["FromUserName"].ToString()) + "未读消息) </a></div>" +
                                                        "<div class=\"service_list_right1\"><div class=\"operating_left\"><span class=\"response_time\">" + dr["CreateTime"].ToString() + "</span>" +
                                                            "<span class=\"response_status\">" + (Convert.ToString(dr["ReplyStatus"].ToString()) == "0" ? "未回复" : "已回复") + "</span></div>" + GetReply(Utils.StrToDateTime(dr["CreateTime"].ToString())) + "</div>" +
                                                        "<div class=\"clear\"></div><span class=\"send_message\">" + GetSendUserMessage(dr["MsgType"].ToString(), dr["content"].ToString(), dr["PicUrl"].ToString(), dr["MediaId"].ToString()) + "</span></div></div></div>");

                                    KSCMS.W("<div class=\"reply_box\"><div class=\"reply_box_tab\"><ul class=\"reply_title_tab\">" +
                                                        "<li class=\"hit\"><a href=\"" + BasicField.GetUserUrl("wx/wx_TuWenList", "frame-no,action-sendmsg,sendid-" + dr["id"].ToString() + "") + "\" onclick=\"$('#mybox1" + dr["id"].ToString() + "').show();$('#mybox2" + dr["id"].ToString() + "').hide();\" target=\"iframemain" + dr["id"].ToString() + "\">图文</a></li><li>" +
                                                            "<a href=\"javascript:;\" onclick=\"$('#mybox2" + dr["id"].ToString() + "').show();$('#mybox1" + dr["id"].ToString() + "').hide();\">文字</a></li>");
                                    if (BaseFun.CheckModulePower("mall"))
                                    {
                                        KSCMS.W("<li><a href=\"" + BasicField.GetUserUrl("wx/wx_CourseList", "frame-no,action-sendmsg,sendid-" + dr["id"].ToString() + "") + "\" onclick=\"$('#mybox1" + dr["id"].ToString() + "').show();$('#mybox2" + dr["id"].ToString() + "').hide();\" target=\"iframemain" + dr["id"].ToString() + "\">课程 </a></li>");
                                    }
                                    KSCMS.W("<li><a href=\"" + BasicField.GetUserUrl("wx/wx_SuCaiList", "frame-no,action-sendmsg,sendid-" + dr["id"].ToString() + "") + "\" onclick=\"$('#mybox1" + dr["id"].ToString() + "').show();$('#mybox2" + dr["id"].ToString() + "').hide();\" target=\"iframemain" + dr["id"].ToString() + "\">素材" +
                                                            "</a></li><div class=\"clear\"></div></ul>" +
                                                    "<div class=\"clear\"></div><div class=\"reply_con_tab\"><div class=\"reply_con_info\" style=\"display: block;\" id='mybox1" + dr["id"].ToString() + "'>" +
                                                            "<iframe class=\"editArea-ifrm\" frameborder=\"no\" border=\"0\" src=\"" + BasicField.GetUserUrl("wx/wx_TuWenList", "frame-no,action-sendmsg,sendid-" + dr["id"].ToString() + "") + "\" style=\"width: 100%; height: 230px;\" name=\"iframemain" + dr["id"].ToString() + "\" id='iframemain" + dr["id"].ToString() + "' scrolling=\"no\"></iframe></div>" +
                                                        "<div class=\"reply_con_info\" id='mybox2" + dr["id"].ToString() + "' style=\"display: none\">" +
                                                            "<textarea id='txtcontent" + dr["id"].ToString() + "' name=\"txtcontent" + dr["id"].ToString() + "\" cols=\"20\" rows=\"2\" style=\"width: 100%; height: 220px;\"></textarea></div></div></div>" +
                                                "<button value=\"发送\" class=\"send\" onclick=\"return(DoSend(" + dr["id"].ToString() + "))\">发送</button></div></li>");
                                }
                            }
                            else
                            {
                                KSCMS.W("<div class=\"norecord\" style=\"text-align: center;\"><span style=\"text-align: center\">暂无信息！</span></div>");
                            }
                        }
		  %>
		  </ul>
				<div class="fy_box">
                  <%
            #region 分页
            string PageStr = "[KS:PageStr1]";
            BasicField.ReplaceFilterPage(ref PageStr, CurrPage, PageSize, pagecount, recordcount);
            KSCMS.W(PageStr);
            #endregion
         %>
         </div>
         <div class="clear"></div>
			</div>

		</div>

		<%}else{ %>
		<div ID="Panel2">
			<script>

				$(function () {
					$(".hit_player_img").click(function () {
						$(this).hide();
						$(this).prev().show()
					});
					$(".show_player_click").click(function () {
						$(this).parent(".show_player").hide();
						$(this).parent(".show_player").next().show();
					});
				});
			</script>
			<div class="openKey" style="margin-right: 40px; margin-left: 40px; margin-bottom: 0;">
				<span class="txt" style="float: left;">消息排序方式:</span>

				<table id="RdbOrderID" border="0">
		<tr>
			<td><input id="RdbOrderID_0" type="radio" name="RdbOrderID" value="0" <%=Utils.StrToInt(KSCMS.S("orderby"))==0?"checked":"" %> onclick="location.href='<%=BasicField.GetUserUrl("wx/wx_SendMsg","orderby-0,action-look,openid-"+KSCMS.GetParam("openid",false)+",sendid-"+KSCMS.S("sendid")+"")%>'" /><label for="RdbOrderID_0">升序</label></td>
			<td><input id="RdbOrderID_1" type="radio" name="RdbOrderID" value="1" <%=KSCMS.S("orderby")=="1"?"checked":"" %> onclick="location.href='<%=BasicField.GetUserUrl("wx/wx_SendMsg","orderby-1,action-look,openid-"+KSCMS.GetParam("openid",false)+",sendid-"+KSCMS.S("sendid")+"")%>'" /><label for="RdbOrderID_1"> 降序</label></td>
		</tr>
	</table>
				<div class="clear"></div>
			</div>

			<div class="service">
			<ul class="service_list_dg">
			<%
		int PageSize = 20;
		int CurrPage = new BasicField().GetCurrPage;
		string HtmlLabel = string.Empty;
		int recordcount = 0, pagecount = 0;
		string orderby = "order by a.CreateTime desc";
		if (Utils.StrToInt( KSCMS.S("orderby")) == 0)
		{
			orderby = "order by a.CreateTime asc";
		}
		else
		{
			orderby = "order by a.CreateTime desc";
		}
		using (DataTable dt = DataFactory.GetPage("FromUserName,a.id,a.content,a.ReplyStatus,a.CreateTime,a.ReplyTime,a.MsgType,a.MediaId,a.PicUrl,a.ReplyContent,a.tuwenid,a.Courseid,a.costype,a.sucaiid,b.NickName,b.HeadImgurl,b.Province,b.City,b.Country,b.sex", " ks_weixinmsg a  inner join  ks_weixinopenuser b on a.FromUserName=b.openid where a.FromUserName='" + KSCMS.S("openid") + "' and MsgType!='event' and b.schoolID="+new TemporaryVar().UserID+"", "a.id", orderby, CurrPage, PageSize, out recordcount, out pagecount))
		{
			if (dt.Rows.Count > 0)
			{
				foreach (DataRow dr in dt.Rows)
				{
					KSCMS.W("<li class=\"inner_msg_list clearfix\"><div class=\"personal_replies\"><div class=\"service_list_left\"><div class=\"service_img\"><img src=\""+dr["HeadImgurl"].ToString()+"\" />"+
										"<div class=\"fans_message\"><div class=\"xx_fans_message\"><i class=\"fans_message_jiantou\"></i><div class=\"fans_message_title\">详细信息</div>"+
												"<div class=\"fans_message_list\">"+
													"<div class=\"message_no1\"><span style=\"display: block;\">"+dr["NickName"].ToString()+"</span></div>"+
													"<div class=\"message_no2\"><span class=\"message_no1_name\">地区</span><span class=\"message_no1_address\">"+dr["Province"].ToString()+"&nbsp;"+dr["City"].ToString()+"&nbsp;"+dr["Country"].ToString()+"</span></div>"+
													"<div class=\"message_no3\"><span class=\"message_no1_name\">性别</span><span class=\"message_no1_write\">"+ (dr["sex"].ToString()=="1"?"男":"女")+"</span></div>"+
												"</div></div></div></div><div class=\"service_info_left\">"+
										"<div class=\"service_info\">"+dr["NickName"].ToString()+"</div><div class=\"service_list_right\">"+
											"<div class=\"operating_left\"><span class=\"response_time\">"+dr["CreateTime"].ToString()+"</span><span class=\"response_status\">"+(Convert.ToString(dr["ReplyStatus"].ToString())=="1"?"已回复":"") +"</span></div>"+
											"<div class=\"clear\"></div></div><div class=\"clear\"></div><span class=\"send_message\">"+GetSendContent(dr["MsgType"].ToString(),dr["Content"].ToString(),dr["MediaId"].ToString(),dr["PicUrl"].ToString())+""+
										"</span></div></div></div></li>");
					KSCMS.W(Convert.ToString(dr["ReplyStatus"].ToString()) == "1" ? GetReplyContent(dr["ReplyStatus"].ToString(), dr["ReplyTime"].ToString(), dr["ReplyContent"].ToString(), dr["tuwenid"].ToString(), dr["Courseid"].ToString(), dr["sucaiid"].ToString(),Utils.StrToInt(dr["costype"].ToString())) : "");
				}
			}
			else
			{
				KSCMS.W(" <div class=\"norecord\"><span style=\"text-align: center\">暂无信息！</span></div>");
			}
		}
	   
	    %>
		</ul> 
				
			</div>
            <div class="fy_box">
			 <%
            #region 分页
            string PageStr = "[KS:PageStr1]";
            BasicField.ReplaceFilterPage(ref PageStr, CurrPage, PageSize, pagecount, recordcount);
            KSCMS.W(PageStr);
            #endregion
         %>
         </div>
         <div class="clear"></div>
		</div>

		<%} %>

	</div>



</form>
</div>