<%@ 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="Kesion.UCenter" %>
<%@ Import Namespace="Kesion.XML" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Xml" %>
<script runat="server" type="text/C#">

    dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息
    bool isLoadPage = true;  //定义页面是否加载

    public static int flag = 0;

    int recordcount, pagecount;
    int CurrPage = new BasicField().GetCurrPage;
    int PageSize = 10;
    int cmtType = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        flag = Utils.StrToInt(KSCMS.S("flag"));
        cmtType = Utils.StrToInt(KSCMS.S("cmttype"));

        if (KSCMS.S("action") == "delete")
        {
            isLoadPage = false;
            switch (cmtType)
            {
                case 1:
                    DeleteTeacherComment();  //删除教师评价
                    break;
                default:
                    DeleteComment();
                    break;
            }
            return;
        }

    }

    /// <summary>
    /// 删除教师评价
    /// </summary>
    public void DeleteTeacherComment()
    {
        string ids = BasicField.GetParam("ids").Replace(" ", "");
        if (string.IsNullOrEmpty(ids))
        {
            ids = KSCMS.S("ids");
        }
        if (ids != "")
        {
            ids = Utils.FilterIDs(ids);
            using (DataTable dt = DataFactory.GetDataTable("select id from KS_CosTeacherPJ Where id in(" + ids + ") and userName='" + UserManage.GetUserInfo().UserName + "'"))
            {
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        int id = Utils.StrToInt(dr["id"].ToString());
                        int tcid = Utils.StrToInt(DataFactory.GetOnlyValue("select tcid from KS_CosTeacherPJ where id=" + id + ""));
                        Hashtable ht = new Hashtable();
                        ht.Add("id", id.ToString());
                        CommonData.Delete("[KS_CosTeacherPJ]", ht);

                        float PJ = Utils.StrToFloat(DataFactory.GetOnlyValue("select avg(PJstar) from KS_CosTeacherPJ where status=1 and tcid=" + tcid));
                        float PJstate = Utils.StrToFloat(DataFactory.GetOnlyValue("select count(*) from KS_CosTeacherPJ where status=1 and PJstar>3 and tcid=" + tcid));
                        float totalPJ = Utils.StrToFloat(DataFactory.GetOnlyValue("select count(*) from KS_CosTeacherPJ where status=1 and tcid=" + tcid));
                        float i = PJstate / totalPJ;
                        Hashtable ht2 = new Hashtable();
                        if (PJ > 0)
                        {
                            ht2.Add("totalPJ", PJ);
                            ht2.Add("PJCount", totalPJ);
                            ht2.Add("PJRate", i);
                        }
                        else
                        {
                            ht2.Add("totalPJ", 0);
                            ht2.Add("PJCount", 0);
                            ht2.Add("PJRate", 0);
                        }
                        CommonData.Update("KS_CosTeacher", ht2, "where TcID=" + tcid);
                    }
                }
            }
        }
        Msg.Alert("删除成功！", KSCMS.GetComeUrl());
        isLoadPage = false;
        return;
    }


    private static string ReplaceFace(string c)
    {
        string str = "惊讶|撇嘴|色|发呆|得意|流泪|害羞|闭嘴|睡|大哭|尴尬|发怒|调皮|呲牙|微笑|难过|酷|非典|抓狂|吐|";
        string[] strArr = str.Split('|');
        for (int k = 0; k <= 19; k++)
        {
            c = c.Replace(@"[e" + k + "]", string.Format(@"<img title=""{0}"" src=""/sysimg/emot/{1}.gif"">", strArr[k].ToString(), k.ToString()));
        }
        return c;
    }


    public static string GetPhoto(string photourl)
    {
        if (string.IsNullOrEmpty(photourl))    photourl = "/sysimg/nopic.gif";
        return photourl;
    }
    public static string GetSubject(int ChannelID, int ClassID, int InfoID, string FileName, string TurnUrl, string Subject)
    {
        string TitleStr;
        TitleStr = string.Format("<a href='{1}' target='_blank'>{0}</a>", Subject, Kesion.HtmlTags.BasicField.GetItemUrl(ChannelID, ClassID, InfoID, FileName, TurnUrl));
        return TitleStr;
    }


    public static string GetCommentContent(string content)
    {
        return ReplaceFace(content);
    }

    private void DeleteComment()
    {
        if (KSCMS.S("ids") != "")
        {
            string ids = KSCMS.S("ids").Replace(" ", "");
            string[] id_arr = ids.Split(',');
            Hashtable ht = new Hashtable();
            foreach (string id in id_arr)
            {
                ht.Add("id", Utils.StrToInt(id));
                ht.Add("username", __user.UserName);
                CommonData.Delete("[KS_Comment]", ht);
                ht.Clear();
            }
        }
        Msg.Alert("恭喜，删除成功！", BasicField.GetUserUrl("other/comment", "flag-" + flag));
    }
</script>
<%
    if (!isLoadPage) return;
%>



    <div class="r_tybox  t_tybox nomar disting ">
        <div class="r_title tytitle">
            <h4 class="disting-title">我的评价</h4>
             <div class="tabs">  
              <ul>
                  <%
                  Response.Write(@"<li><a href=""" + BasicField.GetUserUrl("message/Receivedmessage") + @""">站内消息</a></li>");
                  Response.Write(@"<li><a href=""" + BasicField.GetUserUrl("other/mychatinfo") + @""">我的咨询</a></li>");
                  Response.Write(@"<li class=""puton""><a href=""" + BasicField.GetUserUrl("other/comment") + @""">我的评价</a></li>");
                  if (CommonJsonCache.CheckYunAPPHasAllow("plus.ask"))
                  {
                      Response.Write(@"<li><a href=""" + BasicField.GetUserUrl("other/MyAsk") + @""">问题互动</a></li>");
                  }
                  if (BaseFun.CheckModulePower("edu"))
                  {
                      Response.Write(@"<li><a href=""" + BasicField.GetUserUrl("Course/MyCosZan", "optype") + @""">我的点赞</a></li>");
                      Response.Write(@" <li><a href=""" + BasicField.GetUserUrl("Course/MyInteractRecord") + @""">互动礼物</a></li>");
                  }
                 %>
                </ul>
       		 </div>
        </div>

           <div class="top-sort clearfix">
              <div class="top-sort-tab">
                    <ul>
                        <%
                            Response.Write("<li"+ (cmtType==0 && flag==0?" class='puton'":"")+@"><a href=""" + BasicField.GetUserUrl("other/comment","cmttype-0") + @""">我发表的评论</a></li>");
                            Response.Write("<li"+ (cmtType==0 && flag==2?" class='puton'":"")+@"><a href=""" + BasicField.GetUserUrl("other/comment","cmttype-0,flag-2") + @""">我收到的评论</a></li>");
                            if (BaseFun.CheckModulePower("edu"))
                            {
                                Response.Write(@"<li"+ (cmtType==1?" class='puton'":"")+@"><a href=""" + BasicField.GetUserUrl("other/comment","cmttype-1") + @""">我评价的教师</a></li>");
                                Response.Write(@"<li"+ (cmtType==2?" class='puton'":"")+@"><a href=""" + BasicField.GetUserUrl("course/mycommentcourse","cmttype-2") + @""">我评价的课程</a></li>");
                                 Response.Write(@"<li"+ (cmtType==6?" class='puton'":"")+@"><a href=""" + BasicField.GetUserUrl("course/mycommentcourse","cmttype-6") + @""">我评价的班级</a></li>");
                            }
                            if (BaseFun.CheckModulePower("mall"))
                            {
                                Response.Write(@"<li><a href=""" + BasicField.GetUserUrl("shop/mycomment", "cmttype-3") + @""">我评价的商品</a></li>");
                            }
                       %>
                    </ul>
                </div>    
         </div>
    <form name="myform" action="{$GetCurrUrl}" method="post" id="myform">
    <%
     if (cmtType == 1)                  //评价教师
     {
         %>
				<table id="tablist" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
				 <tr class="title">
				<td width="40" align="center">选择</td>
									<td width="50" align="center">状态</td>
									<td width="80" align="center" nowrap="nowrap">评价等级 </td>
									<td align="center" width="80">教师姓名</td>
									<td align="center" width="200">评价内容</td>
									<td align="center" width="80">评价时间</td>
									<td align="center" width="70">操作</td>
				 </tr>
				 <%
					
					 int recordcount, pagecount;
					 int CurrPage = new BasicField().GetCurrPage;
					 int PageSize = 10;
					 KSCMS.W(" <input type=\"hidden\" name=\"action\" value=\"cancel\"/>");
					 using (DataTable dt = DataFactory.GetPage("*", "[KS_CosTeacherPJ] where UserName='" + Utils.ChkSQL((new TemporaryVar()).UserName) + "'", "id", "order by PJdate Desc", CurrPage, PageSize, out recordcount, out pagecount))
					 {
						 if (dt.Rows.Count > 0)
						 {
							 foreach (DataRow dr in dt.Rows)
							 {
								KSCMS.W("<tr class=\"tdbg\"><td class=\"splittd\" style=\"text-align:center\"><input class=\"cleckbtn\" type=\"checkbox\" name=\"ids\" value=\""+dr["id"].ToString()+"\" /></td><td class=\"splittd\" style=\"text-align:center\">"+  (Convert.ToString(dr["status"].ToString()) == "1" ? "已审核" : "<font class=red>未审核</font>")+"</td>");
								KSCMS.W(" <td class=\"splittd\" style=\"text-align:center\">	<img src=\"/SysImg/user/10/star"+dr["PJstar"].ToString()+".png\" height=\"14\"></td>");
								KSCMS.W("<td class=\"splittd tdTitle\" style=\"text-align:center\"> <a href=\""+BaseFun.GetRewriteUrl("teacherview",Utils.StrToInt(dr["TcID"].ToString()))+"\" title=\"前台页\" target=\"_blank\">"+dr["tcname"].ToString()+"</a></td>");
								KSCMS.W("<td class=\"splittd tdTitle\">"+dr["PJcontent"].ToString()+"</td>");
								KSCMS.W("<td class=\"splittd\" nowrap=\"nowrap\" style=\"text-align:center\">"+dr["PJdate"].ToString()+"</td>");
								KSCMS.W("<td class=\"splittd\" style=\"text-align:center\"><a class=\"deletebtn\" onclick=\"return(confirm('确定删除吗？'));\" href=\"" + BasicField.GetUserUrl("other/comment", "cmttype-1,action-delete,ids-" + dr["id"].ToString() + "") + "\"><i class=\"userfont uf-delete\"></i></a></div></td></tr>");
							 }
						 }
						 else
						 {
							 KSCMS.W("<tr class=\"tr-nobor\"><td class=\"splittd\" style=\"text-align:center;border:0px;\" colspan=\"10\" ><div class=\"empty\">还没有任何评价</div></td> </tr> <style>.cz_btn{display:none;}</style>");
						 }
					 }
					
		  %>
	 </table>
        <%
     }else if (cmtType == 2)           //评价课程 
     {

     }else if (cmtType == 3){          //评价商品

     }
     else                               //文章评论
     {
         %>
   
       <input type="hidden" name="action" value="delete"/>
     <table id="tablist" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
         <tr class="title">
          	<td width="50">选择</td>
          	<td>内容</td>
          	<td>评论人</td>
         	<td>时间</td>
          	<td>操作</td>
         </tr>
         <%
             string param;
             if (flag ==2)
             {
                 param = "Where c.username='" + Utils.ChkSQL(__user.UserName) + "'";
             }
             else
             {
                 param = "Where I.Inputer='" + Utils.ChkSQL(__user.UserName) + "'";
             }

             using (DataTable dt = DataFactory.GetPage("I.InfoID,I.ClassID,I.ChannelID,I.FileName,I.TurnUrl,I.Title,I.FileName,I.DefaultPic,C.ID,C.Content,C.AddDate,C.UserName", "[KS_InfoList] I Inner Join [KS_Comment] C On I.InfoID=C.InfoID " + param, "I.infoid", "order by C.AddDate desc", CurrPage, PageSize, out recordcount, out pagecount))
             {
                 if (dt.Rows.Count > 0)
                 {
                     foreach(DataRow dr in dt.Rows)
                     {
                         KSCMS.W(@"<tr class=""tdbg"">");
                         if (flag == 2) {
                             KSCMS.W(@"  <td class=""splittd"" align=""center""><input class=""cleckbtn"" type=""checkbox"" name=""ids"" value='" + dr["id"].ToString() + "' /></td>");
                         }
                         KSCMS.W(@" <td class=""tag_left"">评论内容：" + GetCommentContent(Convert.ToString(dr["Content"].ToString())) + @"
                        <div style=""margin-top:10px;color:#999999;"">
          分类:" + MyCache.GetCacheClass(Convert.ToInt32(dr["ClassID"].ToString()), 1) + @"&nbsp;&nbsp;标题: " + GetSubject(Convert.ToInt16(dr["ChannelID"].ToString()), Convert.ToInt32(dr["ClassID"].ToString()), Convert.ToInt32(dr["InfoID"].ToString()), Convert.ToString(dr["FileName"].ToString()), Convert.ToString(dr["TurnUrl"].ToString()), Convert.ToString(dr["Title"].ToString())) + @"
          </div>
          </td>
          <td class=""splittd"" align=""center"">" + dr["UserName"].ToString() + @"
          </td>
          <td class=""splittd"">" + Utils.FormatHumanizedTime(Convert.ToDateTime(dr["AddDate"].ToString())) + "</td>");
                         if (flag == 2) {
                             KSCMS.W(@"<td class=""splittd"" align=""center""><a class=""bt"" onclick='return(confirm(""确认删除吗？""))'  href="""+BasicField.GetUserUrl("other/comment","action-delete,flag-"+flag+",ids-" + dr["ID"].ToString()) + @"""'><i class=""userfont uf-delete""></i></a>
          </td>");
                         }
                         KSCMS.W("</tr>");

                     }

                 }else
                 {
                     KSCMS.W(@" <tr class=""tdbg"">
                        <td class=""splittd"" style=""text-align:center;border:0px;"" colspan=""10"">
                          <div class=""empty"">没有评论记录！</div>
                        </td>
                        <style>.cz_btn{display:none;}</style>
                   </tr> ");
                 }
             }
          %>
    </table>
        <%
     }

     %>
      

    
    <div class="cz_btn">
        <%if (flag!=2)
          { %>
            <div class="f-right">
                <span class="check-all"><label><input type="checkbox" name="chkall" id="chkall" onclick="CheckAll(this.form);"/>全选</label></span>
                <span><input ID="btnDelete" type="submit" onmousedown="return(GetIDS());" class="grey-bt bt-w-auto" value="删除选中" /></span>
            </div>
            <div class="f-left">
        <%} %>

        <%
            #region 分页
            {
                string PageStr=__user.GroupID==3||__user.GroupID==4?"[KS:PageStr1]": "[KS:PageStr2]";
                BasicField.ReplaceFilterPage(ref PageStr, CurrPage, PageSize, pagecount, recordcount);
                KSCMS.W(PageStr);
            }
            #endregion
         %>

        <%if (flag==2)
          { %>
            </div>

        <%} %>  


    </div>

    </form>

</div>