<%
dim UC_SYSTEM_MSG
class UC_SYSTEM_MSG_CLASS
	
	private oRs,sSQL,sString
	
	private sub class_initialize()
	end sub
	
	public sub init()
		select case ACT
		case "do"
		case "detail"
			call getMsgDetail()
			if V("msg_exist") then
				call msgDetail()
			else
				UC.errorLink = array(UC.lang(2101) &">"& UCENTER_HURL &"ctl=system_msg",OS.lang(75) &">javascript:OW.goBack();")
				call UC.errorSetting(UC.lang(2108))
			end if
		case "delete"
			
		case else
			call main()
		end select
	end sub
	
	private sub class_terminate()
	end sub
	
	private function getMsgDetail()
		dim arr,fieldsCount
		V("msgid") = OW.int(OW.getForm("get","id"))
		set oRs = OW.DB.getRecordBySQL("SELECT * FROM "& DB_PRE &"system_msg WHERE id="& V("msgid") &" AND uid="& UID &" AND "& OW.DB.auxSQL &"")
		fieldsCount = oRs.fields.count-1
		if oRs.eof then
			V("msg_exist") = false
		else
			V("msg_exist") = true
			for i=1 to fieldsCount
				V(oRs.fields(i).name) = OW.rs(oRs(oRs.fields(i).name))
			next
			call OW.DB.execute("UPDATE "& DB_PRE &"system_msg SET is_user_read=1 WHERE id="& V("msgid") &"")
		end if
		OW.DB.closeRs oRs
	end function
	
	private function msgDetail()
		call UC.echoHeader()
		call OW.DB.execute("UPDATE "& DB_PRE &"system_msg SET user_unread_num=0 WHERE id="& OW.int(V("msgid")) &"")
%>
	<%=UC.htmlHeaderMobile("<a href="""& UCENTER_URL &"?ctl="& CTL &""" class=""goback""></a>",UC.lang(2101))%>
    <section id="mbody">
      <div class="section-system-msg-detail">
          <dl class="msg-time"><dt><%=UC.lang(2102)%></dt><dd><%=V("msg_time")%></dd></dl>
          <dl class="msg-title"><dt><%=UC.lang(2103)%></dt><dd><%=V("msg_title")%></dd></dl>
          <dl class="msg-content"><dt><%=UC.lang(2106)%></dt><dd><%=OW.dbDataDecode(V("msg_content"))%></dd></dl>
      </div>
      <% if OS.isVersionSenior then %>
      <div class="system-msg-reply-list" id="system_msg_reply_list"></div>
      <div class="system-msg-reply">
          <div class="hd">回复</div>
          <div class="bd">
              <div class="textarea-box"><textarea id="reply_content" maxlength="250"></textarea></div>
              <div class="image-box"><%=UC.createMsgReplyImagesUploadHtml(V("msgid"),"imgfile","+ 上传图片")%></div>
          </div>
          <div class="ft">
              <button type="submit" class="owui-btn owui-btn-primary" id="submit">发送</button>
          </div>
      </div>
    </section>
    <script type="text/javascript">
    $(window).ready(function(){
		var getReplyList = function(){
			var msgid = "<%=V("msgid")%>";
			OW.ajax({
				url:OW.sitePath +"ow-includes/ow.ajax.main.asp?ctl=system_msg&act=get_reply_list&msgid="+msgid+"",data:"",
				success:function(){
					var html = unescape(OW.ajaxData.html);
					$("#system_msg_reply_list").html(html).show(200);
				},
				failed:function(msg){
					$("#system_msg_reply_list").html('亲，很抱歉，数据加载失败，请刷新页面再试试！<br>'+msg);
				}
			});
		};
		getReplyList();
		UC.imageUploadCallback = function(){getReplyList();};
		$("#submit").click(function(){
			var replyContent = $("#reply_content").val();
			if(OW.isNull(replyContent)){
				alert("请先填写回复内容！");
			}else{
				var msgid = "<%=V("msgid")%>",
				url       = OW.siteUrl +"ow-includes/ow.ajax.main.asp?ctl=system_msg&act=reply&save=true",
				$dialog   = UC.dialogPosting();
				OW.ajax({
					me:"",url:url,data:"msgid="+ msgid +"&reply_content="+escape(replyContent),
					success:function(){
						$dialog.success("已发送").position().timeout(1);
						$("#reply_content").val("");
						OW.delay(1000,function(){
							getReplyList();
						});
					},
					failed:function(msg){
						$dialog.error('发送失败',msg).position().timeout(4);
						OW.setDisabled($("#submit"),false);
					}
				});
			};
		});
	});
    </script>
    <% end if%>
	<%=UC.htmlFooter()%>
    <style type="text/css">
    .ow-nav{ display:none!important;}
    </style>
<%
	call UC.echoFooter()
	end function
	
	private function main()
		call UC.echoHeader()
%>
	<%=UC.htmlHeaderMobile("<a href="""& UCENTER_URL &""" class=""ucenter""></a>",UC.lang(2100))%>
    <section id="mbody">
        <div class="section-system-msg" id="system_msg">
			<div class="section">
				<%
                OW.Pager.sql      = "select id,msg_title,msg_time,is_user_read,user_unread_num from "& DB_PRE &"system_msg where uid="& UID &" AND is_user_delete=0 ORDER BY id DESC"
                OW.Pager.pageSize = 20
                OW.Pager.pageUrl  = "index.asp?ctl="& CTL &"&page={$page}"
                OW.Pager.pageTpl  = "{prev}{current}{next}"
                OW.Pager.loopHtml = "<dl is_user_read=""{$is_user_read}"" user_unread_num=""{$user_unread_num}""><dt><a href="""& UCENTER_HURL &"ctl="& CTL &"&act=detail&id={$id}"">{$msg_title}</a></dt></dl>"
                OW.Pager.run()
                %>
                <%=OW.Pager.loopHtmls%>
            </div>
            <div class="footer"><div class="pager"><%=OW.Pager.pageHtmls%></div></div>
        </div>
    </section>
    <script type="text/javascript">
    $(window).ready(function(){
		//**已读
		$("#system_msg dl").each(function(){
			var html,read = $(this).attr("is_user_read"),
			userUnreadNum = $(this).attr("user_unread_num");
			$a = $(this).find("a");
			if(read==0){
				$a.addClass("read-0");
			}else{
				$a.addClass("read-1");
			};
			if(userUnreadNum>0){
				$a.append('<em class="msg-unread-num">'+userUnreadNum+'<em>');
			};
		});
	});
    </script>
	<%=UC.htmlFooter()%>
<%
	call UC.echoFooter()
	end function
	
	
	
end class
%>

