<%@ 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;  //定义页面是否加载
    bool ispower = false;     //判断用户权限
    public static int RoomID = 0;
    public static int NoticeID;
    public static string ClassRoomTitle = string.Empty;
    public DataRow drp = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        RoomID = Utils.StrToInt(KSCMS.S("RoomID"));
        NoticeID = Utils.StrToInt(KSCMS.S("id"));
        int tcid = Utils.StrToInt(DataFactory.GetOnlyValue("select TcID from KS_CosTeacher where UserID =" + __user.UserID));
         /*
        if (__user.GroupID == 3 || Utils.StrToInt(DataFactory.GetOnlyValue("select count(*) from KS_CosClassroom where BanzhuRenID =" + new TemporaryVar().UserID + " and RoomID =" + RoomID)) > 0)
        {
            ispower = true;
        }
        //独立教师
        else if (__user.GroupID == 4 && new TemporaryVar().SchoolID == 0)
        {
            ispower = true;
        }
        else if (Kesion.APPCode.Public.IsClassRoomPower(Utils.StrToInt(RoomID), tcid, "notice") || __user.GroupID == 3)
        {
            ispower = true;
        }
        if(!ispower)
        {
            Msg.Alert("您没有公告管理的权限，请联系网站管理员！",BasicField.GetUserUrl("teacher/tcclassroom"));
            isLoadPage = false;
            return;
        }*/
        ispower = true;
        string sql1 = "";
        if (RoomID != 0)
        {
            sql1 = "select top 1 Title from KS_CosClassRoom where RoomID=" + RoomID;
            using (DataTable dt = DataFactory.GetDataTable(sql1))
            {
                if (dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    ClassRoomTitle = dr["Title"].ToString();
                }
            }
        }

        string DoMethod = KSCMS.S("do");

        switch (DoMethod)
        {
            case "del":
                deleteSj(KSCMS.S("id"));
                break;
            case "verify":
                string id = KSCMS.S("id");

                if (!string.IsNullOrEmpty(id))
                {
                    string[] ids = id.Split(',');

                    for (int i = 0; i < ids.Length; i++)
                    {

                        CommonData.UpdateFieldStatus("KS_CosClassNotice", "verify", "id", Utils.StrToInt(ids[i].ToString()));
                    }
                }
                KSCMS.Redirect(BasicField.GetUserUrl("teacher/TcClassRoomNotice", "roomid-" + RoomID));
                isLoadPage = false;
                return;
                break;
            case "modify":

                DataTable dt = DataFactory.GetDataTable("select top 1 * from KS_CosClassNotice where id=" + NoticeID + " ");
                if (dt.Rows.Count > 0)
                    drp = dt.Rows[0];
                break;
        }
        if (KSCMS.S("action").Equals("save"))
        {
            SaveChange();
        }
    }
    protected void SaveChange()
    {
        if (string.IsNullOrEmpty(KSCMS.S("title")))
        {
            Msg.Alert("标题不能为空！");
            isLoadPage = false;
            return;
        }
        Hashtable ht = new Hashtable();
        ht.Add("RoomID", RoomID);
        ht.Add("Userid", new TemporaryVar().UserID);

        ht.Add("contents", Utils.RemoveXss((KSCMS.S("contents"))));
        ht.Add("title", Utils.RemoveXss(Utils.RemoveHtml(KSCMS.S("title"))));
        ht.Add("verify", Utils.StrToInt(KSCMS.S("RBIsOff")));
        if (Utils.IsDateTime(KSCMS.S("adddates")))
        {
            ht.Add("AddDate", KSCMS.S("adddates"));
        }
        else
        {
            ht.Add("AddDate", DateTime.Now);
        }
        if (KSCMS.S("do").Equals("add"))
        {
            CommonData.Insert("KS_CosClassNotice", ht);
            Kesion.Course.Course.CheckCount("KS_CosClassNotice", "roomid=" + RoomID + "", "id", 1, "KS_CosClassRoom", "Noticenum", "roomid=" + RoomID + "");
            Msg.Alert("恭喜,添加公告成功!", BasicField.GetUserUrl("teacher/TcClassRoomNotice", "roomid-" + RoomID));
        }
        else
        {
            CommonData.Update("KS_CosClassNotice", ht,"where ID="+NoticeID);
            Msg.Alert("恭喜,修改公告成功!", BasicField.GetUserUrl("teacher/TcClassRoomNotice", "roomid-" + RoomID));
        }

        isLoadPage = false;
        return;
    }
    private void deleteSj(string WorkID)
    {
        if (WorkID == null || WorkID == "0") return;

        WorkID = Utils.FilterIDs(WorkID);
        DataFactory.ExecuteNonQuery("delete from KS_CosClassNotice where id in (" + WorkID + ")");

        Kesion.Course.Course.CheckCount("KS_CosClassNotice", "roomid=" + RoomID + "", "id", 1, "KS_CosClassRoom", "Noticenum", "roomid=" + RoomID + "");
        Msg.Alert("删除成功!", BasicField.GetUserUrl("teacher/TcClassRoomNotice", "roomid-" + RoomID));
    }

    public string GetParam(string Fields)
    {
        string result = string.Empty;
        if (drp != null)
        {
            result = drp[Fields].ToString();
        }
        return result;
    }

</script>
<%
    if (!isLoadPage) return;
	if (!KSCMS.S("do").Equals("modify") && !KSCMS.S("do").Equals("add")){
%>
 <form name="myform" action="<%=BasicField.GetUserUrl("teacher/TcClassRoomNotice") %>" method="post" id="Form1" >
	  <div class="t_tybox">
            <div class="tytitle"><h4>班级公告管理</h4>
           	<a onclick="" href="<%=BasicField.GetUserUrl("teacher/TcClassRoom") %>" class="addbtn">返回</a>
            <%if(ispower){ %>
			 <a href="<%=BasicField.GetUserUrl("teacher/TcClassRoomNotice","do-add,roomid-"+RoomID) %>" class="addbtn">发布公告</a>
            <%} %>
            </div>
            <div class="clear blank10"></div>
			<div class="part_now">当前班级：<%=ClassRoomTitle %></div>
			<div class="clear blank10"></div>
      
         <table id="Table1" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
      <tr align="center" class="title">
        	<td width="6%" align="center">选择</td>
			<td width="6%"" align="center">状态</td>
        	<td width="18%" align="left">标题</td>
        	<td width="50%" align="left">内容</td>
            <td width="10%" align="center">发布时间</td>
            <td align="center">操作</td>
        </tr>
		<%
	 	    int recordcount, pagecount;
			int CurrPage = new BasicField().GetCurrPage;
			int PageSize = 10;
			using (DataTable dt = DataFactory.GetPage("*", "KS_CosClassNotice where  roomid=" + RoomID + "", "ID", "order by  AddDate 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\" align=\"center\"><input class=\"cleckbtn\" type=\"checkbox\" name=\"id\" value=\"" + dr["id"].ToString() + "\" /></td>");
						KSCMS.W("<td class=\"Ctd\" align=\"center\"><a href=\"" + BasicField.GetUserUrl("teacher/TcClassRoomNotice", "do-verify,roomid-" + RoomID + ",id-" + dr["id"].ToString()) + "\">" + (Utils.StrToInt(dr["verify"].ToString()) == 0 ? "<font color=red>未发布</font>" : "<font color=green>发布<font>") + "</a> </td>");
						KSCMS.W("  <td class=\"tag_left\" style=\"text-align:left;padding: 20px;\"> "+dr["title"].ToString()+"</td>");
						KSCMS.W(" <td class=\"tag_left\">" + Utils.CutStr(dr["contents"].ToString(),150) + "</td>");
						KSCMS.W("<td class=\"splittd\" align=\"center\">" + Utils.FormatHumanizedTime(Convert.ToDateTime(dr["AddDate"])) + "</td>");
                        if (ispower)
                        {
                            KSCMS.W("<td><div class=\"gl_btn\"> " +
                            "<span class=\"span5\" style=\"width:50%\"><a href='" + BasicField.GetUserUrl("teacher/TcClassRoomNotice", "do-del,roomid-" + RoomID + ",id-" + dr["id"].ToString()) + "' Class=\"delete\" OnClick=\"return(confirm('确定删除该公告将会影响的您的班级的公告数吗?'));\" ><i class=\"icon iconfont icon-lajitong-copy\"></i>删除</a></span>" +
                            "<span class=\"span4\" style=\"width:50%\"><a href='" + BasicField.GetUserUrl("teacher/TcClassRoomNotice", "do-modify,roomid-" + RoomID + ",id-" + dr["id"].ToString()) + "' ><i class=\"icon iconfont icon-xiazai48\"></i>编辑</a></span>" +
                            " </div> </td>   ");
                        }
                        else
                        {
                            KSCMS.W("<td class=\"splittd\" align=\"center\">无操作权限</td>");
                        }
                        KSCMS.W("</tr>");
					}
				}
				else
				{
					KSCMS.W(" <tr>	<td colspan=\"5\" style=\"border-bottom:0px;\"><div class=\"clear blank10\"></div> <div class=\"empty\">没有找到问题！</div> </td></tr>");
				}
			}
	   %>
      </table>
    
     	<div class="fy_box ">
		  <%
            #region 分页
            string PageStr = "[KS:PageStr1]";
            BasicField.ReplaceFilterPage(ref PageStr, CurrPage, PageSize, pagecount, recordcount);
            KSCMS.W(PageStr);
            #endregion
         %>
     	</div>
        <%if(ispower){ %>  
       <div class="cz_btn">
		  <input type="hidden" value="<%=RoomID %>" name="RoomID" />
		 <input type="hidden" value="del" name="do" />
        <span ><input type="checkbox" class="checkbtn" name="chkall" id="chkall" onclick="CheckAll(this.form);"/>全选</span>
        <span><input type="submit" class="button" value="批量删除" onclick="return (CheckIds('del'));"></span>       
     </div>
          <%} %>
      <div class="clear"></div>
     </div>
	
	 </form>
	 <%}
	else
	{
		Kesion.APPCode.EditorAPI.EchoHead();%>
		    	<script src="/ks_inc/DatePicker/WdatePicker.js"></script>
  <form name="myform" action="<%=BasicField.GetUserUrl("teacher/TcClassRoomNotice") %>" method="post" id="myform" >
 <div class="t_tybox">
         <div class="ty_title">发布公告</div>
         <div class="tips" style="padding:10px; font-size:14px">
        <span id="Label2">班级名称：<%=ClassRoomTitle %></span></div>
       <table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" class="border"> 
	    <tr>
		<td class="lefttd" height="30" ><font color=red >*</font>标题：</td>
		 <td class="tag_left">
	       <input type="text" value="<%=GetParam("title") %>" class="textbox" id="TxtName" name="Title" style="width:350px;">
		 </td>
	  </tr> 
			    <tr>
		                       <td class="lefttd" height="30">公告内容：</td>
		                       <td class="tag_left">
			                       <textarea name="Contents" rows="2" cols="20" id="TxtNotice" style="height:200px;width:80%;"><%=GetParam("contents") %></textarea>
			                        <% Kesion.APPCode.EditorAPI.EchoEditor("editor", "TxtNotice", "Basic", 0, false, true, true, false);     %>
			                      </td>
		                </tr>

						   <tr>
                                <td class="lefttd" height="30"><font color="red"></font>发布时间：</td>
                                <td class="tag_left">
                                
              <input name="adddates" type="text" id="adddates" value="<%=string.IsNullOrEmpty( GetParam("adddate"))?Utils.GetDateTime(): GetParam("adddate") %>" class="textbox  Wdate" onclick="WdatePicker({dateFmt:&#39;yyyy-MM-dd HH:mm:ss&#39;,minDate:&#39;%y-%M-%d&#39;});" /> 
         
                                </td>
                            </tr>
						 <tr>
            <td class="lefttd" height="30" style="width: 102px">
              是否发布：</td>
            <td class="tag_left">
             <table id="RBIsOff" class="radio" border="0" >
		<tr>
			<td class="bo-min"><input id="RBIsOff_0" type="radio" name="RBIsOff" value="1" <%=GetParam("verify")=="1"?"checked":"" %> /><label for="RBIsOff_0">发布</label></td>
			<td  class="bo-min"><input id="RBIsOff_1" type="radio" name="RBIsOff" value="0" <%= Utils.StrToInt(GetParam("verify"))==0?"checked":"" %> /><label for="RBIsOff_1">未发布</label></td>
		</tr>
	</table>
             </td>
        </tr>
    </table>
	<input name="action" value="save" type="hidden" />
		<input name="do" value="<%=KSCMS.S("do") %>" type="hidden" />
	<input name="roomid" value="<%=RoomID %>" type="hidden" />
	<input name="id" value="<%=NoticeID %>" type="hidden" />
    <div class="clear blank10"></div>
       <div class="cz_btn nofloat" style="padding-left:162px;">
           <span><input type="submit" name="Button2" value="确定保存"  class="button" /></span>
           <span><input type="button" class="button" onclick="window.history.go(-1);"value=" 返 回 "></span>
       </div>

       <div class="clear blank20"></div>
     </div>
	 </form>
<%} %>