<%@ Control Language="C#" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="Kesion.Config" %>
<%@ Import Namespace="Kesion.Components" %>
<%@ Import Namespace="Kesion.HtmlTags" %>
<%@ Import Namespace="System.Data" %>
<script runat="server" type="text/C#">
    dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息，
    private static dynamic __info = new System.Dynamic.ExpandoObject();   //初始化当前页信息
    bool isLoadPage = true;  //定义页面是否加载

    private string action = string.Empty;
    private int Id = 0;

    int recordcount, pagecount;
    int CurrPage = new BasicField().GetCurrPage;
    int PageSize = 10;
    protected void Page_Load(object sender, EventArgs e)
    {
        action = KSCMS.S("action");
        if (string.IsNullOrEmpty(action))
        {
            action = BasicField.GetParam("do");
        }
        Id = Utils.StrToInt(BasicField.GetParam("id"));
        if (Id == 0)
        {
            Id = Utils.StrToInt(KSCMS.S("id"));
        }


        action = action.ToLower();
        switch (action)
        {
            case "dosave":
                DoSave();
                return;
            case "verify": //审核
                using (DataTable dt = DataFactory.GetDataTable("SELECT FLAG FROM KS_BlogComment WHERE UserID=" + __user.UserID + " and ID = " + Id))
                {
                    if (dt.Rows.Count > 0)
                    {
                        DataRow dr = dt.Rows[0];
                        int flag = Utils.StrToInt(dr["flag"].ToString());
                        Hashtable htt = new Hashtable();
                        if (flag==1)
                        {
                            htt.Add("Flag", 0);
                        }
                        else
                        {
                            htt.Add("Flag", 1);
                        }

                        if (CommonData.Update("KS_BlogComment", htt, "WHERE ID = " + Id + " And UserID=" + __user.UserID))
                        {
                            Msg.Alert("恭喜，操作成功!", KSCMS.GetComeUrl());
                        }
                        else
                        {
                            Msg.Alert("审核失败！", KSCMS.GetComeUrl());
                        }
                    }
                    else
                    {
                        Msg.Alert("审核失败！", KSCMS.GetComeUrl());

                    }
                }
                return;
            case "del":  //删除
                Hashtable ht = new Hashtable();
                ht.Add("ID", Id);
                ht.Add("UserID", __user.UserID);

                if (CommonData.Delete("KS_BlogComment", ht))
                {
                    Msg.Alert("删除成功!", KSCMS.GetComeUrl());
                }
                else
                {
                    Msg.Alert("删除失败!", KSCMS.GetComeUrl());
                }
                return;
            default:
                Initial();
                break;
        }

    }
    private void Initial()
    {
        if (Id > 0)
        {
            using (DataTable dt = DataFactory.GetDataTable("SELECT * FROM KS_BlogComment WHERE UserID = " + __user.UserID + " and ID = " + Id))
            {
                if (dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    __info.labSender = dr["AnounName"].ToString();
                    __info.labTitle = dr["Title"].ToString();
                    __info.labText = dr["Content"].ToString();
                    __info.ReplyContent = dr["Replay"].ToString();
                }
                else
                {
                    Msg.Alert("error", KSCMS.GetComeUrl());
                    isLoadPage = false;
                    return;
                }
            }


        }
        else
        {
            __info.labSender = "";
            __info.labTitle = "";
            __info.labText = "";
            __info.ReplyContent = "";
        }
    }

    /// <summary>
    /// 回复保存
    /// </summary>
    private void DoSave()
    {
        string replyText =Utils.RemoveXss(KSCMS.S("ReplyContent"));
        if (!string.IsNullOrEmpty(replyText.Trim()))
        {
            Hashtable ht = new Hashtable();
            ht.Add("Replay", replyText);
            ht.Add("ReplayDate", DateTime.Now);
            if (CommonData.Update("KS_BlogComment", ht, "Where ID = " + Id+" and userid="+__user.UserID))
            {
                Msg.Alert("回复成功!", BasicField.GetUserUrl("space/BlogComment"));
            }
            else
            {
                Msg.Alert("回复失败！");
                return;
            }

        }
        else
        {
            Msg.Alert("回复内容不能为空！");
            return;
        }

    }
</script>

<%
    if (!isLoadPage) return;
%>

<div class="r_tybox nomar">
<div class="r_title"><h4>博文评论管理</h4></div>
        <div class="tabs">
            <ul>
                <li><a href="<%=BasicField.GetUserUrl("space/message") %>">留言管理</a></li>
                <li class="puton"><a href="<%=BasicField.GetUserUrl("space/blogcomment") %>">博文评论管理</a></li>
                <li><a href="<%=BasicField.GetUserUrl("space/albumcomment") %>">相册评论管理</a></li>
            </ul>
       </div>

     <% if (string.IsNullOrEmpty(action))
           { %>
 <div class="r_padbox">
    <div class="tabs2">
        <ul>
        <li<%=Kesion.Publics.KSCMS.S("showType")==""?" class='puton'":string.Empty %>><a href="<%=BasicField.GetUserUrl("space/blogcomment") %>"><span>所有记录</span></a></li>
        <li<%=Kesion.Publics.KSCMS.S("showType")=="1"?" class='puton'":string.Empty %>><a href="<%=BasicField.GetUserUrl("space/blogcomment","showtype-1") %>"><span>未审核的记录</span></a></li>
        <li<%=Kesion.Publics.KSCMS.S("showType")=="2"?" class='puton'":string.Empty %>><a href="<%=BasicField.GetUserUrl("space/blogcomment","showtype-2") %>"><span>已审核的记录</span></a></li>
        </ul>
    </div>

    <table class="border" cellspacing="0" align="Center" border="0"  style="width:99%;border-collapse:collapse;">
			<tr class="title">
				<th scope="col" style="width:80px">ID号</th><th scope="col">标题</th><th scope="col">留言时间</th><th scope="col">状态</th><th scope="col">↓管理操作</th>
			</tr>
        <%

            string param = "where UserID =" + __user.UserID+" AND Ext='article'";
            switch (Utils.StrToInt(BasicField.GetParam("showtype")))
            {
                case 1:
                    param += " and flag=0";
                    break;
                case 2:
                    param += " and flag=1";
                    break;
            }
            
            using (DataTable dt = DataFactory.GetPage("*", "KS_BlogComment "+param, "ID", "order by ID desc", CurrPage, PageSize, out recordcount, out pagecount))
            {
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {

                        KSCMS.W(string.Format(@"<tr class=""tdbg""><td class=""splittd"" align=""center"">{0}</td>", dr["ID"].ToString()));
                        KSCMS.W(string.Format(@"<td class=""splittd"">{0}</td>",(bool)string.IsNullOrEmpty(dr["Title"].ToString())? "(无)": "<a href='"+Kesion.HtmlTags.BasicField.GetBlogArticleUrl(Kesion.Publics.Utils.StrToInt(dr["logid"].ToString()),dr["userid"].ToString())+"' target='_blank'>"+dr["Title"].ToString()+"</a>"));
                        KSCMS.W(string.Format(@"<td class=""splittd"" style=""text-align:center"">{0}</td>", dr["addTime"].ToString()));
                        KSCMS.W(string.Format(@"<td class=""splittd"" style=""text-align:center"">{0}</td>", dr["flag"].ToString() == "1" ? "已审核" : "<span style='color:red'>未审核</span>"));

                        KSCMS.W(@"<td class=""splittd"" style=""text-align:center"">");
                        KSCMS.W("<a href='" + BasicField.GetUserUrl("space/blogcomment", "do-view,id-" + dr["ID"].ToString()) + "'>查看/回复</a>");
                        KSCMS.W(" <a href='" + BasicField.GetUserUrl("space/blogcomment", "do-verify,id-" + dr["ID"].ToString()) + "'>审核</a>");
                        KSCMS.W(@" <a onclick=""return(confirm('确认删除吗？'))"" href='" + BasicField.GetUserUrl("space/blogcomment", "do-del,id-" + dr["ID"].ToString()) + "'>删除</a>");
                        KSCMS.W("</td>");
                        KSCMS.W("</tr>");
                    }
                }
                else
                {
                    KSCMS.W(@"<tr class=""emptycss"">
				<td colspan=""5"">没有留言!</td>
			</tr>");
                }


            }

        %>
        </table>
        <%
            #region 分页
            string PageStr = "[KS:PageStr2]";
            BasicField.ReplaceFilterPage(ref PageStr, CurrPage, PageSize, pagecount, recordcount);
            KSCMS.W(PageStr);
            #endregion
         %>

    	</div>    
    
    
    <%} else if (action == "view")  //查看回复
        {
      %>
    <iframe src="about:blank" style="display:none;width:0px;height:0px" name="hidiframe"></iframe>
        <form name="myform" action="{$GetCurrUrl}" method="post" id="myform" target="hidiframe">
           <input type="hidden" name="action" value="dosave"/>
     <table cellspacing="1" cellpadding="3" class="border" width="100%" align="center" border="0">
          <tr class="tdbg">
                <td width="100" style="text-align:right;">用户：</td>
                <td><label><%=__info.labSender %></label></td>
            </tr>
           <tr class="tdbg">
                <td width="100" style="text-align:right;">留言主题</td>
                <td><%=__info.labTitle %></td>
            </tr>
            <tr class="tdbg">
                <td width="100" style="text-align:right;">留言内容</td>
                <td><%=__info.labText %></td></tr>

          <tr class="tdbg">
              <td width="100" style="text-align:right;">回复留言</td>
                  <td>
                      <textarea name="ReplyContent" id="ReplyContent" class="textbox" cols="70" rows="4" style="height:100px;width:500px; color:#777;"><%=__info.ReplyContent %></textarea>
  
                 </td>
              </tr>
            <tr class="tdbg">
                 <td width="100" style="text-align:right;"></td>
                     <td class="splittd" style="height:50px; text-align:left;border-bottom:0px; font-size:12px">
            <input type="submit" name="btn1" value=" 回 复 " onclick="return CheckForm();" class="button" />　　 
            <input type="button" name="btn2" onclick="location.href='<%=BasicField.GetUserUrl("space/blogcomment")%>'" value=" 返 回 " class="button" />
                     
                     </td>
                 </tr>

          </table>
        <script>
            function CheckForm() {
                if ($('#ReplyContent').val() == "") {
                    alert("请输入你的回复内容！");
                    $('#ReplyContent').focus();
                    return false;
                } 
                return true;
            }
       </script>


     </form>
    <%} %>
     


 </div>   