<%@ 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="System.Data" %>
<%@ Import Namespace="Kesion.Course" %>
<script runat="server" type="text/C#">
    dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息，
    private static dynamic __info = new System.Dynamic.ExpandoObject();   //初始化当前页信息
    bool isLoadPage = true;  //定义页面是否加载
    public string channelid = "0";
    public string tablename = "KS_CosTeacher";
    public string selectparam = "b.tcid,photo,tname";
    public string field1 = "tname";
    public string field2 = "photo";
    public string key = "tcid";
    public string url = "teacherview";
    public string optype = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        string DoMethod = BasicField.GetParam("do");
        if (string.IsNullOrEmpty(DoMethod))
        {
            DoMethod = KSCMS.S("action");
        }
        if (!BaseFun.CheckModulePower("edu") && string.IsNullOrEmpty(KSCMS.S("optype")))
        {
            if (BaseFun.CheckModulePower("exam"))
            {
                Response.Redirect(Kesion.HtmlTags.BasicField.GetUserUrl("exam/myexamfavorite"));
            }
            else if (BaseFun.CheckModulePower("mall"))
            {
                Response.Redirect(Kesion.HtmlTags.BasicField.GetUserUrl("other/mycollect","optype-mall"));
            }else
            {
                Response.Redirect(Kesion.HtmlTags.BasicField.GetUserUrl("other/mycollect","optype-article"));
            }
        }

        optype = KSCMS.S("optype").ToString();
        switch (optype)
        {
            case "teacher": break;
            //case "cosall":
            //    channelid = "-10,-12";
            //    tablename = "KS_Course";
            //    selectparam = "name,photourl";
            //    field1 = "name";
            //    field2 = "photourl";
            //    key = "courseid";
            //    break;
            case "cos":
                channelid = "-10";
                tablename = "KS_Course";
                selectparam = "courseid,name,photourl";
                field1 = "name";
                field2 = "photourl";
                key = "courseid";
                url = "courseview";
                break;
            case "coslive":
                channelid = "-12";
                tablename = "KS_Course";
                selectparam = "courseid,name,photourl";
                field1 = "name";
                field2 = "photourl";
                key = "courseid";
                url = "liveview";
                break;
            case "cosface":
                channelid = "-11";
                tablename = "KS_CourseFace";
                selectparam = "courseid,name,photourl";
                field1 = "name";
                field2 = "photourl";
                key = "courseid";
                url = "faceview";
                break;
            case "stu":
                channelid = "-15";
                tablename = "KS_User";
                selectparam = "b.userid,b.username,userface";
                field1 = "username";
                field2 = "userface";
                key = "userid";
                url = "space";
                break;
            case "group":
                channelid = "-16";
                tablename = "KS_BBSBoard";
                selectparam = "boardid,boardname,ico";
                field1 = "boardname";
                field2 = "ico";
                key = "boardid";
                url = "clubforum";
                break;
            case "sj"://收藏试卷信息
                channelid = "50";//试卷信息   50
                tablename = "KS_SJ";
                selectparam = "title ";
                field1 = "title";
                field2 = "id";
                key = "id";
                url = "examview";
                break;
            case "article":
                channelid = "1";
                tablename = "KS_U_Article";
                selectparam = "title,classid,filename ";
                field1 = "title";
                field2 = "infoid";
                key = "infoid";
                url = "contentview";
                break;
            case "photo":
                channelid = "2";
                tablename = "KS_U_Photo";
                selectparam = "title,classid,filename ";
                field1 = "title";
                field2 = "infoid";
                key = "infoid";
                url = "contentview";
                break;
            case "imall":
            case "mall":
                channelid = "4";
                tablename = "KS_U_Product";
                selectparam = "title,classid,filename ";
                field1 = "title";
                field2 = "infoid";
                key = "infoid";
                url = "shopview4";
                break;
            case "download":
                channelid = "3";
                tablename = "KS_U_Download";
                selectparam = "title,classid,filename ";
                field1 = "title";
                field2 = "infoid";
                key = "infoid";
                url = "contentview";
                break;
        }

        switch (DoMethod)
        {
            case "cancel":
                RemoveFromFavorite();
                break;
        }
    }
    public void RemoveFromFavorite()
    {
        string ids = BasicField.GetParam("ids").Replace(" ", "");
        if (string.IsNullOrEmpty(ids))
        {
            ids = KSCMS.S("ids");
        }
        if (ids != "")
        {
            string[] id_arr = ids.Split(',');
            Hashtable ht = new Hashtable();
            foreach (string id in id_arr)
            {
                ht.Add("id", id);
                CommonData.Delete("[KS_Favorite]", ht);
                ht.Clear();

            }
            string optype = string.Empty;
            switch (KSCMS.S("costype"))
            {
                case "cos":
                case "coslive":
                case "cosface":
                    optype = KSCMS.S("costype") + "c";
                    break;
                case "stu":
                    optype = "ucenterc";
                    break;
                case "group":
                    optype = "topicc";
                    break;
                default:
                    optype = "teachercollect";
                    break;
            }
            Kesion.APPCode.Public.CountInfo(Utils.StrToInt(KSCMS.S("courseid")), optype); //更新收藏数量
            Kesion.APPCode.GiveThumbUpCache.DelFavJsonCache(new TemporaryVar().UserID);
        }
        Msg.Alert("删除成功！", KSCMS.GetComeUrl());
        isLoadPage = false;
        return;
    }
</script>
<%
    if (!isLoadPage) return;
%>
	<div class="r_tybox nomar">
 <div class="r_title "><h4>我的收藏</h4>
       <div class="tabs">
             <ul>
              <%if (BaseFun.CheckModulePower("edu"))
             { %>
               <li <%=(KSCMS.S("optype") == "cos" || KSCMS.S("optype") == "coslive" || KSCMS.S("optype") == "cosface") ? "class='puton'" : "" %>><a href='<%=BasicField.GetUserUrl("other/mycollect", "optype-cos") %>'>课程收藏</a> </li>
              <li <%=KSCMS.S("optype") == "" ? "class='puton'" : "" %>><a href='<%=BasicField.GetUserUrl("other/mycollect") %>'>教师收藏</a></li>
              <%}
                  if (BaseFun.CheckModulePower("plus.group"))
                  {%>
              <li <%=KSCMS.S("optype") == "group" ? "class='puton'" : "" %>><a href='<%=BasicField.GetUserUrl("other/mycollect", "optype-group") %>'>小组收藏</a></li>
                  <%
               }
                      if (BaseFun.CheckModulePower("exam"))
                      { %>
              <li <%=KSCMS.S("optype") == "sj" ? "class='puton'" : "" %>><a href='<%=BasicField.GetUserUrl("other/mycollect", "optype-sj") %>'>试卷收藏</a></li>
                 <%} %>
              <li <%=(KSCMS.S("optype")=="article" || KSCMS.S("optype")=="photo" || KSCMS.S("optype")=="download")?"class='puton'":"" %>><a href="<%=BasicField.GetUserUrl("other/mycollect","optype-article") %>">内容收藏</a></li>
                 <%if (BaseFun.CheckModulePower("plus.ask"))
                  { %>
              <li <%=KSCMS.S("optype")=="favorite"?"class='puton'":"" %>><a href='<%=BasicField.GetUserUrl("other/favorite","flag-1") %>'>问题收藏</a></li>
                 <%} %>
            </ul>
       </div>
       
    </div>
    <%if (KSCMS.S("optype")=="cos" || KSCMS.S("optype")=="coslive" || KSCMS.S("optype")=="cosface"){ %>
        <div class="top-sort clearfix">
            <div class="top-sort-tab">
                <ul>
                    <li <%=KSCMS.S("optype")=="cos"?"class='puton'":"" %>><a href='<%=BasicField.GetUserUrl("other/mycollect","optype-cos") %>'>点播收藏</a> </li>
                    <li <%=KSCMS.S("optype")=="coslive"?"class='puton'":"" %>><a href='<%=BasicField.GetUserUrl("other/mycollect","optype-coslive") %>'>直播收藏</a></li>
                    <li <%=KSCMS.S("optype")=="cosface"?"class='puton'":"" %>><a href='<%=BasicField.GetUserUrl("other/mycollect","optype-cosface") %>'>面授收藏</a></li>    
                </ul>
            </div>
        </div>
    
    <%} %>
     <%if (KSCMS.S("optype")=="sj"){ %>
        <div class="top-sort clearfix">
            <div class="top-sort-tab">
                <ul>
                    <li class="puton"><a href='<%=BasicField.GetUserUrl("other/mycollect","optype-sj") %>'>试卷收藏</a> </li>
                    <li ><a href='<%=BasicField.GetUserUrl("exam/Myexamfavorite") %>'>试题收藏</a></li>
                     
                </ul>
            </div>
        </div>
    
    <%} %>

     <%if (KSCMS.S("optype")=="article" || KSCMS.S("optype")=="photo" || KSCMS.S("optype")=="download"|| KSCMS.S("optype")=="imall"){ %>
        <div class="top-sort clearfix">
            <div class="top-sort-tab">
                <ul>
                    <li <%=KSCMS.S("optype")=="article"?"class='puton'":"" %>><a href="<%=BasicField.GetUserUrl("other/mycollect","optype-article") %>">文章收藏</a></li>
                    <li <%=KSCMS.S("optype")=="photo"?"class='puton'":"" %>><a href="<%=BasicField.GetUserUrl("other/mycollect","optype-photo") %>">作品收藏</a></li>
                    <li <%=KSCMS.S("optype")=="download"?"class='puton'":"" %>><a href="<%=BasicField.GetUserUrl("other/mycollect","optype-download") %>">资料收藏</a></li>
                    <%if (BaseFun.CheckModulePower("mall")){ %>
                    <li <%=KSCMS.S("optype")=="imall"?"class='puton'":"" %>><a href="<%=BasicField.GetUserUrl("other/mycollect","optype-imall") %>">商品收藏</a></li>
                    <%} %>
                </ul>
            </div>
        </div>
    
    <%} %>

	<form name="myform" action="<%=BasicField.GetUserUrl("other/mycollect") %>" method="post" id="myform" >

		  <table id="tablist" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
				 <tr class="title">
				 <td width="5%" align="center" nowrap="nowrap">选择</td>
				 <td width="15%">图片</td>
				 <td align="left">名称</td>
				 <td width="25%" align="center">收藏时间 </td>
				 <td align="center" width="10%">操作</td>
				 </tr>
				 <%
                     KSCMS.W(" <input type=\"hidden\" name=\"action\" value=\"cancel\"/>");
                     int recordcount, pagecount;
                     int CurrPage = new BasicField().GetCurrPage;
                     int PageSize = 10;
                     using (DataTable dt = DataFactory.GetPage("a.adddate,a.id,a.infoid," + selectparam + "", "[KS_Favorite] a inner join " + tablename + " b on a.infoid=b." + key + "  where a.channelid in (" + channelid + ") and a.UserName='" + Utils.ChkSQL((new TemporaryVar()).UserName) + "'", "a.id", "order by a.AddDate Desc", CurrPage, PageSize, out recordcount, out pagecount))
                     {
                         if (dt.Rows.Count > 0)
                         {
                             if(optype=="sj")
                             {
                                 key = "infoid";
                             }
                             foreach (DataRow dr in dt.Rows)
                             {
                                
                                 if (optype == "article")
                                 {
                                     url = Kesion.HtmlTags.BasicField.GetItemUrl(1,Utils.StrToInt(dr["ClassID"].ToString()), Utils.StrToInt(dr["infoID"].ToString()), dr["fileName"].ToString(),"");
                                 }
                                 else
                                 {
                                     url = BaseFun.GetRewriteUrl(url, Utils.StrToInt(dr[key].ToString()));
                                 }
                                 KSCMS.W("<tr class=\"tdbg\"><td class=\"splittd\" align=\"center\"><input class=\"cleckbtn\" type=\"checkbox\" name=\"ids\" value=\"" + dr["id"].ToString() + "\" /></td>");
                                 KSCMS.W("<td class=\"splittd\" align=\"left\" style=\"padding:15px\"><img src=\"" + dr[field2].ToString() + "\" style=\"width:60px;height:60px;\" onerror=\"this.src='/sysimg/nopic.gif'\"  type=\"exam\"/></td>");
                                 KSCMS.W("<td class=\"splittd tdTitle\" align=\"left\"> <a href='" + url + "' title=\"前台页\" target=\"_blank\">" + dr[field1].ToString() + "</a> </td>");
                                 // KSCMS.W("<td class=\"splittd\" align=\"center\"><img src=\"/user/images/10/star" + dr["grade"].ToString() + ".png\" height=\"16\"></td>");
                                 KSCMS.W("<td class=\"splittd\" align=\"center\">" + Utils.FormatHumanizedTime(Convert.ToDateTime(dr["AddDate"].ToString())) + "  </td> ");
                                 string str = ",courseid-" + dr[key].ToString() + ",costype-" + KSCMS.S("optype");
                                 KSCMS.W("<td class=\"splittd\" align=\"center\"> <a onclick=\"return(confirm('确定删除吗？'));\" href=\"" + BasicField.GetUserUrl("other/mycollect", "do-cancel,ids-" + dr["id"].ToString() + str ) + "\"><i class=\"userfont uf-delete\"></i></a></div></td></tr>");
                             }
                         }
                         else
                         {
                             KSCMS.W("<tr class=\"tr-nobor\"><td class=\"splittd\" style=\"text-align:center\" colspan=\"10\" ><div class=\"empty\">还没有任何收藏</div></td> </tr><style>.cz_btn{display:none;}</style>");
                         }
                     }
		  %>
	 </table>
	 <div class="cz_btn">
        <div class="f-left">
            <%
            #region 分页
            string PageStr = "[KS:PageStr2]";
            BasicField.ReplaceFilterPage(ref PageStr, CurrPage, PageSize, pagecount, recordcount);
            KSCMS.W(PageStr);
            #endregion
            %>
        </div>
        <div class="f-right">
            <span><input type="checkbox" name="chkall" id="chkall" onclick="CheckAll(this.form);"/>全选</span>
            <span><input type="submit" class="grey-bt" value="批量删除" onclick="return (CheckIds('del'));"></span>
        </div>
        <div class="clear"></div>
     </div>
	    
	</form>
</div>