<%@ 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" %>
<%@ Import Namespace="Kesion.Components" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.IO" %>
<script runat="server" type="text/C#">
    int classId;
    int CourseId;
    int TcID;
    string username;
    int Provinceid = 0;
    int CityId = 0;
    int CountyId = 0;
    string DefaultPic = string.Empty;
    EpConfig ep = null;
    int t_count = 0;
    int t_free = 0;
    int verify = 0;

    string button = string.Empty;
    string label1 = string.Empty;
    int recordcount, pagecount;
    int PageIndex = new BasicField().GetCurrPage;
    int pagesize = 10;
    DataRow drr = null;//编辑初始化
    string tcpower = string.Empty;
    public string tcusername = string.Empty;

    private string GetVal(string fieldName)
    {
        if (drr != null)
        {
            return drr[fieldName].ToString();
        }
        else
        {
            return string.Empty;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        label1 = "添加讲师信息"; button = "确定保存";
        username = UserManage.GetUserInfo().UserName;
        ep = new EpConfig();
        if (KSCMS.S("deleteall").Equals("deleteall"))
        {
            deleteTeacher(KSCMS.S("ids"));//批量删除
        }
        TcID = Utils.StrToInt(KSCMS.S("tcid"));
        classId = Utils.StrToInt(KSCMS.S("classid"));

        if (KSCMS.S("action").Equals("addorupdate"))
        {
            if(TcID != 0)
            {
                label1 = "修改讲师信息"; button = "确定修改(0)";
                initialEdit(TcID); //編輯初始化修改
            }
            if(KSCMS.S("addinfo")=="addinfo")
            {
                addinfo();  // 修改或者新增操作
            }
        }
        else if (KSCMS.S("action") == "delete")
        {
            deleteTeacher(TcID.ToString()); //删除单个
        }
    }
    //新增或者修改
    private void addinfo()
    {
        #region 创建账号判断账号是否存在
        if (Utils.StrToInt(KSCMS.S("SelfAccount")) == 1)
        {
            if (TcID == 0)//新教师
            {
                if (string.IsNullOrEmpty(KSCMS.S("tcusername")))
                {
                    Msg.Alert("请输入用户名！");
                    return;
                }
                if (string.IsNullOrEmpty(KSCMS.S("tcpassword")))
                {
                    Msg.Alert("请输入密码！");
                    return;
                }
                if (DataFactory.Exists("KS_User", "username='" + KSCMS.S("tcusername") + "'"))
                {
                    Msg.Alert("对不起，用户名已存在！");
                    return;
                }
            }
        }
        #endregion
        Utils.TipsDisabled();  //检查是否演示状态
        int classId = Utils.StrToInt(KSCMS.S("DrpClassID1"));
        Hashtable ht = new Hashtable();
        ht.Add("ClassID", classId);
        ht.Add("cityid", Utils.StrToInt(KSCMS.S("cityid")));
        ht.Add("Provinceid", Utils.StrToInt(KSCMS.S("Provinceid")));
        ht.Add("CountyId", Utils.StrToInt(KSCMS.S("CountyId")));
        ht.Add("Tlxdh", Utils.RemoveXss(KSCMS.S("Txtlxdh")));  // 联系电话
        ht.Add("email", Utils.RemoveXss(KSCMS.S("Txtemail"))); //邮箱
        ht.Add("czdh", Utils.RemoveXss(KSCMS.S("Txtczdh")));   //传真号码
        ht.Add("pxzc", KSCMS.S("Txtpxzc"));   //培训专长
        ht.Add("fwkh", KSCMS.S("txtfwkh"));    // 服务客户
        ht.Add("Tadd", Utils.RemoveXss(KSCMS.S("TxtADD")));    //联系地址
        ht.Add("Tname", Utils.RemoveXss(KSCMS.S("TxtName")));  //中文名称
        ht.Add("Tename", Utils.RemoveXss(KSCMS.S("TxtTename")));  //英文姓名
        ht.Add("TIntro",KSCMS.S("TxtIntro"));  //教师简介
        ht.Add("Tlevel", Utils.RemoveXss(KSCMS.S("Txtlevel")));   //教师职称

        //ht.Add("verify", this.RdbVerify.SelectedValue);

        ht.Add("sex", Utils.StrToInt(KSCMS.S("RadioButtonList1")));//  1男 0 女
        ht.Add("Grade", Utils.StrToInt(KSCMS.S("RadioButtonList2")));//  
        ht.Add("photo", Utils.RemoveXss(KSCMS.S("DefaultPic")));//图片

        ht.Add("tcpower", KSCMS.S("checkpower"));


        if (TcID==0)
        {
            ht.Add("system", 1);
            ht.Add("adddate", DateTime.Now);
            ht.Add("username", username);  //机构用户名
            ht.Add("PJRate", 0);
            ht.Add("PJCount", 0);
            ht.Add("totalPJ", 0);
            ht.Add("MessageCount", 0);
            if (ep.GetEpConfig("Setting", 8) == "0")  //发布bu需要审核
            {
                ht.Add("verify", 1);
            }
            else
            {
                ht.Add("verify", 0);
            }
            #region 判断是否超过限制数

            if (EnterPrise.GetTotal("teacher", 2))
            {
                #region 创建用户账号
                int userid=0;
                if (Utils.StrToInt(KSCMS.S("SelfAccount")) == 1)
                {
                    string tcusername = KSCMS.S("tcusername");
                    string tcpassword = KSCMS.S("tcpassword");
                    UserInfo __info = new UserInfo();
                    __info.SchoolID = new TemporaryVar().UserID;
                    __info.UserName = tcusername;
                    __info.Password = tcpassword;
                    __info.GroupID = 4;
                    __info.Email = Utils.RemoveXss(KSCMS.S("Txtemail"));
                    __info.Sex = (Utils.StrToInt(KSCMS.S("RadioButtonList1")) == 1 ? "男" : "女");
                    __info.RegDate = DateTime.Now;
                    __info.JoinDate = DateTime.Now;
                    __info.LastLoginTime = DateTime.Now;
                    __info.LastLoginIP = Utils.GetRealIP();
                    __info.LoginTimes = 0;
                    __info.ChargeType = 1;
                    __info.BeginDate = DateTime.Now;
                    __info.Mobile = KSCMS.S("Txtlxdh");
                    //机构用户自己添加 自己的教师信息
                    if (new TemporaryVar().GroupID == 3)
                    {
                        __info.SchoolID = new TemporaryVar().UserID;
                    }
                    if (UserManage.CreateUser(__info) == "success")
                    {
                        userid = CommonData.GetMaxId("KS_User", "userid");
                        ht.Add("field", tcusername);
                        ht.Add("UserID", userid);
                        //权限JSON缓存
                        string jsonKey = "teacher:tcpower:" + userid;
                        JsonCache.SaveCacheToFile(jsonKey, KSCMS.S("checkpower"));
                    }
                }
                Kesion.Controls.CustomFields.DoSchoolFieldSave(ref ht);
                #endregion


                CommonData.Insert("KS_CosTeacher", ht);


                if (ep.GetEpConfig("Setting", 8) == "0")  //发布bu需要审核
                {
                    EnterPrise.AddInorOutScore("course", "teacheradd", username,new TemporaryVar().UserID);
                }
                DataFactory.ExecuteNonQuery("UPDATE [KS_EnterPrise] SET [TeacherTotal] = [TeacherTotal] + 1 WHERE UserId = " + UserManage.GetUserInfo().UserID + "");//条数+1

                KSCache cache = KSCache.GetCacheService(); //更新缓存
                cache.RemoveObject("/CMS/TeacherTableList");
                Msg.Alert("恭喜,教师添加成功!", BasicField.GetUserUrl("teacher/CsTeacher"));
            }
            else
            {
                Msg.Alert("发布教师已达到上限!", BasicField.GetUserUrl("teacher/CsTeacher"));
            }
            #endregion
        }
        else
        {
            if (verify == 1)
            {
                if (ep.GetEpConfig("Setting", 9) == "0")  //修改bu需要审核
                {
                    ht.Add("verify", 1);
                }
                else
                {
                    ht.Add("verify", 0);
                }
            }
            string tcpassword = KSCMS.S("tcpassword");
            if (!string.IsNullOrEmpty(tcpassword))
            {
                string salt = Utils.RndKey(32);
                string password = Utils.MD5(tcpassword.ToString() + salt, 32);
                if (!string.IsNullOrEmpty(KSCMS.S("field")))
                {
                    DataFactory.ExecuteNonQuery("update KS_User set password='" + password + "',salt='" + salt + "' where username='" + Utils.ChkSQL(KSCMS.S("field")) + "'");
                }
            }
            int userid = Utils.StrToInt(DataFactory.GetOnlyValue("select top 1 userid from KS_User where username='" + Utils.ChkSQL(KSCMS.S("field")) + "'"));
            CommonData.Update("KS_CosTeacher", ht, "where TcID=" + TcID);

            string checkpower=KSCMS.S("checkpower");
            //权限JSON缓存
            if (userid > 0)
            {
                string jsonKey = "teacher:tcpower:" + userid;
                JsonCache.SaveCacheToFile(jsonKey, checkpower);
            }

            //if (checkpower.ToLower().IndexOf("courselist") != -1)
            //{
            //    checkpower += ",Teacher/CsZlList" + ",Teacher/tcsendinfo" + ",Teacher/CsZj";
            //}
            //if (checkpower.ToLower().IndexOf("livelist") != -1)
            //{
            //    checkpower += ",Teacher/CsLiveZj";
            //}
            //if (checkpower.ToLower().IndexOf("tcclassroom") != -1)
            //{
            //    checkpower += ",Teacher/TcHomeWork,Teacher/StuImport,Teacher/TcClassCourse,Teacher/TcClassRoomPj,Teacher/TcClassStudent,Teacher/TcClassRoomAskList,Teacher/TcClassRoomNotice";
            //}
            //if (checkpower.ToLower().IndexOf("tcsjlist") != -1)
            //{
            //    checkpower += ",SJ/TcSjAddST,SJ/TcSjAddST,SJ/TcSjAddTm";
            //}
            //if (checkpower.ToLower().IndexOf("tcsjtotal") != -1)
            //{
            //    checkpower += ",SJ/TcSjTotalitem,SJ/TcSJPaperAnalysis,SJ/tcSJShowReviews";
            //}
            //checkpower += ",basic/logmoney";



            KSCache cache = KSCache.GetCacheService();  //更新缓存
            cache.RemoveObject("/CMS/TeacherTableList");
            Msg.Alert("恭喜,教师修改成功!", BasicField.GetUserUrl("teacher/CsTeacher"));
        }
    }
    //删除
    private void deleteTeacher(string TcID)
    {
        if (TcID == null || TcID == "0") return;
        TcID = Utils.FilterIDs(TcID);
        using (DataTable dt = DataFactory.GetDataTable("select top 20 TcId,verify,userId from KS_CosTeacher Where TcId in(" + TcID + ") and username='" + UserManage.GetUserInfo().UserName + "'"))
        {
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    int userid = Utils.StrToInt(dr["userid"].ToString());
                    int TcId = Utils.StrToInt(dr["TcId"].ToString());
                    Hashtable ht = new Hashtable();
                    ht.Add("TcId", TcId);
                    CommonData.Delete("[KS_CosTeacher]", ht);

                    if (userid > 0)
                    {
                        string jsonKey = "teacher:tcpower:" + userid;
                        JsonCache.DeleteCacheFile(jsonKey);
                    }
                    if (dr["verify"].ToString() == "1")
                    {
                        EnterPrise.AddInorOutScore("course", "teacherdel", username, UserManage.GetUserInfo().UserID);
                    }
                    int TeacherTotal = Utils.StrToInt(DataFactory.GetOnlyValue("select count(TcId) from  KS_CosTeacher where username='" + UserManage.GetUserInfo().UserName + "'"));
                    DataFactory.ExecuteNonQuery("UPDATE [KS_EnterPrise] SET [TeacherTotal]=TeacherTotal-1  WHERE TeacherTotal>0 and  UserId = " + UserManage.GetUserInfo().UserID + "");//教师总数-1
                }
            }
        }
        Msg.Alert("恭喜,教师删除成功!", KSCMS.GetComeUrl());
    }
    //编辑初始化
    private void initialEdit(int TcId)
    {
        SqlParam[] param = new SqlParam[1];
        param[0] = new SqlParam("TcId", TcId);

        using (DataTable dt = CommonData.GetDataTable("[KS_CosTeacher]", "*", param))
        {
            if (dt.Rows.Count > 0)
            {
                drr = dt.Rows[0];

                CityId = Utils.StrToInt(drr["cityid"].ToString());
                Provinceid = Utils.StrToInt(drr["Provinceid"].ToString());
                CountyId = Utils.StrToInt(drr["CountyId"].ToString());
                verify = Utils.StrToInt(drr["verify"].ToString());
                DefaultPic = drr["photo"].ToString();//图片
                tcpower = drr["tcpower"].ToString();
            }
        }
    }
    //初始化教师等级
    private void initteacher()
    {
        string Grade1 = Teacher.getTeacherConfig(0);
        string Grade2 = Teacher.getTeacherConfig(1);
        string Grade3 = Teacher.getTeacherConfig(2);
        string Grade4 = Teacher.getTeacherConfig(3);
        string Grade5 = Teacher.getTeacherConfig(4);
        if (!string.IsNullOrEmpty(Grade1))
        {
            KSCMS.W(@"<input type=""radio"" name=""RadioButtonList2"" Value=""1"" " + (GetVal("Grade") == "1" ? "checked" : "" )+ " /> 1级");
        }
        if (!string.IsNullOrEmpty(Grade2))
        {
            KSCMS.W(@"<input type=""radio"" name=""RadioButtonList2"" Value=""2"" " + (GetVal("Grade") == "2" ? "checked" : "") + " />2级");
        }
        if (!string.IsNullOrEmpty(Grade3))
        {
            KSCMS.W(@"<input type=""radio"" name=""RadioButtonList2"" Value=""3"" " + ((GetVal("Grade") == "3" || string.IsNullOrEmpty(GetVal("Grade")))? "checked" : "") + " />3级");
        }
        if (!string.IsNullOrEmpty(Grade4))
        {
            KSCMS.W(@"<input type=""radio"" name=""RadioButtonList2"" Value=""4"" " + (GetVal("Grade") == "4" ? "checked" : "") + " />4级");
        }
        if (!string.IsNullOrEmpty(Grade5))
        {
            KSCMS.W(@"<input type=""radio"" name=""RadioButtonList2"" Value=""5"" " + (GetVal("Grade") == "5" ? "checked" : "") + " />5级");
        }
    }


</script>
  <script>
      function SetDate() {
          var today = new Date();
          if ($("#showdate").is(":hidden")) {
              $("#showdate").show();
              $('#TxtBeginDate').val(today.getFullYear() + '-' + (today.getMonth() + 1) + '-01');
                 $('#TxtEndDate').val(today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate());
             }
             else {
                 $("#showdate").hide();
                 $('#TxtBeginDate').val('');
             $('#TxtEndDate').val('');
             }
         }
         function keyWordFocus() {
             if (jQuery("#KeyWord").val() == '请输入关键字！') {
             jQuery("#KeyWord").val('');
         }
     }
     function keyWordBlur() {
         if (jQuery("#KeyWord").val() == '') {
             jQuery("#KeyWord").val('请输入关键字！');
         }
     }
   </script>

<%if(KSCMS.S("action")==""){ %>
     <div ID="ListPanel"  Width="100%">
    <div class="t_tybox">
     	<div class="tytitle clearfix"><h4 class="fl lf">讲师列表</h4>

             <%if (EnterPrise.GetTotal(t_free, t_count, "Teacher",2))
                { %>
             <a href="<%=BasicField.GetUserUrl("teacher/csteacher","action-addorupdate") %>" class="addbtn">+添加讲师</a>
             <%} %>
                <div class="top_c_sc mt10">
       		<%--<span>教师名称：</span>--%>
          <%-- <input type="text"  ID="TextBox1" class="textbox"  ></input>--%>

           <span> <strong>快速搜索：</strong></span>
             
            <form action="{$GetCurrUrl}" method="post" style="float:right">
              <select name="Condition" ID="Condition" >
                      <option Value="1">教师名称</option>
                      <option Value="2">职称</option>
                   </select>
                <input type="text" name="KeyWord" ID="KeyWord" class="textbox"  value="请输入关键字！" onfocus="keyWordFocus();" Width="200" onblur="keyWordBlur();" style="color:#ccc" ></input>
                <span id="showdate" <%if (KSCMS.S("TxtBeginDate") == "")
                                      { %> style="display: none" <%} %>>
                    <input type="text" name="TxtBeginDate" ID="TxtBeginDate" placeholder="格式：YYYY-MM-DD" Width="120px"  onclick="WdatePicker({dateFmt:&#39;yyyy-MM-dd&#39;});" class="textbox Wdate"></input><span style="margin-left:10px">至</span>
                   <input type="text" name="TxtEndDate" ID="TxtEndDate" placeholder="格式：YYYY-MM-DD" Width="120px"  onclick="WdatePicker({dateFmt:&#39;yyyy-MM-dd&#39;});" class="textbox Wdate"></input>
                </span>
                <input type="submit" ID="Button4"  value=" 搜索 " class="button" onclick="Button4_Click" style="margin-left:10px;border:1px solid #dce2e4;border-radius:3px;"/>
                <b onclick="SetDate()" style="cursor: pointer; margin-left:10px;float:right">日期范围？</b>
           </form>
           
        </div> 
     	</div>
     
		<div class="clear blank10"></div>
         <div class="tabs_header">
             <% if (ep.GetEpConfig("Setting", 8) == "1")  //bu需要审核
                { %>
              <ul class="tabs clearfix">
                
                <li <%=KSCMS.S("Type")==""?" class='active'":string.Empty %>><a href="<%=BasicField.GetUserUrl("teacher/CsTeacher") %>"><span>所有记录</span></a></li>
                <li <%=KSCMS.S("Type")=="1"?" class='active'":string.Empty %>><a href="<%=BasicField.GetUserUrl("teacher/CsTeacher","type-1") %>"><span><font color="red">待审核</font></span></a></li>
                <li <%=KSCMS.S("Type")=="2"?" class='active'":string.Empty %>><a href="<%=BasicField.GetUserUrl("teacher/CsTeacher","type-2") %>"><span>已审核</span></a></li>
                
            </ul>
             <%} %>
        </div>
		<form action="{$GetCurrUrl}" method="post">
            <input type="hidden" name="deleteall" value="deleteall" />
         <table id="tablist" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
             <tr align="center" class="title">
                 <td>选择</td>
                 <td width="6%">序号</td>
                 <td width="10%">状态</td>
                 <td width="20%">教师名称</td>          
                 <td width="9%">等级</td>
                 <td width="18%">职称</td>
                 <td width="13%">添加时间</td>
                 <td width="14%" >操作</td>
              </tr>
                <%
                    
                    string sqlParam = "KS_CosTeacher where  username='" + username + "'";
                    classId = Utils.StrToInt(KSCMS.S("classid"));
                    int Type = Utils.StrToInt(KSCMS.S("Type"));
            if (!string.IsNullOrEmpty(KSCMS.S("Type")))
            {
                switch (Type)
                {
                    case 1:
                        sqlParam += " and verify=0 ";
                        break;
                    case 2:
                        sqlParam += " and verify=1 ";
                        break;
                }
            }
                #region 关键字搜索
                if (!string.IsNullOrEmpty(KSCMS.S("KeyWord")))
                {
                    if (KSCMS.S("KeyWord") != "请输入关键字！")
                    {
                        switch (Convert.ToInt16(KSCMS.S("Condition")))
                        {
                            case 1:
                                sqlParam += " and Tname like'%" + Utils.ChkSQL(KSCMS.S("KeyWord").Trim().Replace("'", "''")) + "%'";
                                break;
                            case 2:
                                sqlParam += " and  Tlevel like'%" + Utils.ChkSQL(KSCMS.S("KeyWord").Trim().Replace("'", "''")) + "%'";
                                break;
                        }
                    }
                }
                #endregion

                #region 日期搜索
                string beginDate = KSCMS.S("TxtBeginDate");
                string endDate = KSCMS.S("TxtEndDate");
                if (!string.IsNullOrEmpty(beginDate) && !string.IsNullOrEmpty(endDate))
                {
                    if (Utils.IsDateTime(beginDate) && Utils.IsDateTime(endDate))
                    {
                        sqlParam += " AND adddate>='" + beginDate + "' and adddate<='" + Convert.ToDateTime(endDate).AddDays(1) + "'";
                    }
                }
                #endregion

                using (DataTable dt = DataFactory.GetPage("*", sqlParam, "Tcid", "order by  adddate desc", PageIndex, pagesize, out recordcount, out pagecount))
                {
                    if (dt.Rows.Count > 0)
                    {
                        int i=0;
                        foreach(DataRow dr in dt.Rows)
                        {
                            %>
                <TR class="tdbg sort bar num<%= ((i + 1)%2)==0?"2":"1"%>" height="25">
                 <td align="center"> 
                     <input type="checkbox"  name="ids" id="ids" value="<%=dr["TcID"] %>"/>

                 </td>
                  <td align="center">
                         <%= i + 1%>.
                 </td>
                 <td align="center">
                       
                     <%= Convert.ToString(dr["verify"])=="0"?"未审":"<font class='green_cor'>已审</font>" %>

                 </td>
                 <td class="tag_left lefticon">
                  <div onmouseover="jQuery('#a<%=dr["TcID"] %>').show();" onmouseout="jQuery('#a<%=dr["TcID"] %>').hide();">
                   
                  <a href="<%=Convert.ToString(dr["verify"])=="0"?"javascript:;":Kesion.HtmlTags.BasicField.GetRewriteUrl("teacherview", Utils.StrToInt(dr["TcID"].ToString()))%>" title="前台页" target="_blank" <%=Convert.ToString(dr["verify"])=="0"?"class=\"none_click\"":""%>><%=Convert.ToString(dr["verify"])=="0"?"<i class=\"iconfont\">&#xe637;</i>":"<i class=\"iconfont\">&#xe637;</i>"%></a>
                      
                     
              [<%= MyCache.GetCosClass( Utils.StrToInt( dr["classid"]),"ClassName",0)  %>]
                <font class="fonths"><%= Utils.CutStr(Convert.ToString(dr["Tname"]),30) %></font></a>
                 </div>
                 </td>
                 <td align="center">
                        <%=Teacher.GetGradeName(Utils.StrToInt(dr["Grade"])) %></span>
                 </td>
            
                 <td align="left">
                       <%= Utils.CutStr(Convert.ToString(dr["Tlevel"]), 255)%>       
                 </td>
                 <td nowrap align="left">
                     <%= dr["adddate"]%>
                 </td>
                 <td nowrap align="center">
                 	<div class="gl_btn">
                       <%=Convert.ToString(dr["verify"])=="1" ?"<span style=\"width:49%\"><a href=\""+BasicField.GetUserUrl("teacher/CsTeacher","action-addorupdate,tcid-"+dr["tcid"].ToString()) +"\" Class=\"edit\"><i class=\"iconfont\">&#xe61d;</i>编辑</a></span>":Convert.ToString(dr["verify"])=="0"?"<span style=\"width:49%\"><a href=\""+BasicField.GetUserUrl("teacher/CsTeacher","action-addorupdate,tcid-"+dr["tcid"].ToString())+"\" Class=\"edit\"><i class=\"iconfont\">&#xe61d;</i>编辑</a></span>":"<span style=\"width:49%\" class=\"hengxian\">-</span>"%>
                       <%=Convert.ToString(dr["verify"])=="1" ?"<span style=\"width:49%\"><a href=\""+BasicField.GetUserUrl("teacher/CsTeacher","action-delete,tcid-"+dr["tcid"].ToString())+"\" Class=\"delete\" onclick=\"return(confirm('您确定要删除该名师吗?删除后会影响到您的综合积分'));\"><i class=\"iconfont\">&#xe731;</i>删除</a></span>":Convert.ToString(dr["verify"])=="0"?"<span style=\"width:49%\"><a href=\""+BasicField.GetUserUrl("teacher/CsTeacher","action-delete,tcid-"+dr["tcid"].ToString())+"\" Class=\"delete\" onclick=\"return(confirm('您确定要删除该名师吗?'));\"><i class=\"iconfont\">&#xe731;</i>删除</a></span>":"<span style=\"width:49%\" class=\"hengxian\">-</span>"%>
                      </div>
                 </td>
             </TR>               
                <%
                            i++;
                        }
                    }
                    else {
                        KSCMS.W(@"<tr class=""tdbg"" >
                                    <td class=""Ctd"" colspan=""8"">
                                     <div class=""empty"">您还没有添加教师</div>
                                    </td>
                                   </tr> ");
                    }
                    }
                  
                    
                     %>
             

           </table>
        
         <div ID="Panel2"   Width="100%">
        <div class="cz_btn">        
         	<span><input type="checkbox" class="checkbtn" name="chkall" id="chkall" onclick="CheckAll(this.form);" /><label for="chkall">全部选中</label></span>		   
            <span>
                <input type="submit" ID="BtnDel"  value="批量删除" class="button" OnClick="return(GetIDS());"  />
            </span>
        </div> 
             </div>
               <div class="fy_box" >
                      <%
                        #region 分页
                        string PageStr = "[KS:PageStr3]";
                        BasicField.ReplaceFilterPage(ref PageStr, PageIndex, pagesize, pagecount, recordcount);
                        KSCMS.W(PageStr);
                        #endregion
                     %>
        </div>
		<div class="clearfix"></div> 
         </form>              
      </div>
       <div ID="Panel1"  Width="100%">
		   <div style="padding:10px 0px 0px;">
			<script type="text/javascript">
			    showtips('<span class="state">操作说明：<br /></span><span class="tips_cor" style="display:block;margin-top:5px;">1.如果是待审核是不能预览的！<br>2.如果复选框是<font color="blue">浅灰色</font>，代表是不能点击<br>3.如果审核通过而且你有删除的功能，那么你确定要执行的将影响你的<font color="blue">综合积分</font></span>');
			</script>
			</div>			
		  </div>
       </div>
 
<%} if(KSCMS.S("action")=="addorupdate"){ %>


 <div ID="AddPanel"  Width="100%">
      <%Kesion.APPCode.EditorAPI.EchoHead(); %>
      <div class="clear"></div>
     <form action="{$GetCurrUrl}" method="post">
            <input type="hidden" name="addinfo" value="addinfo" />
      <div class="t_tybox">
      		<div class="ty_title"><span ID="Label1"  ><%=label1 %></span></div>
      <div class="clear"></div>

          <div class="tabs">
                <ul>
                    <li class='puton'><a>教师基本信息</a></li>
					 <li <%=(string.IsNullOrEmpty(GetVal("field"))&&Utils.StrToInt(KSCMS.S("tcid"))!=0)?"style='display:none'":"" %>><a>高级设置</a></li>
                </ul>
            </div>
          <script>
              //$(document).ready(function(){
              //    $('#basicinfo').find('.border').eq(1).show().siblings().hide();
              //})
             
              $(".tabs").on('click','li',function(){
                  $(this).addClass('puton').siblings().removeClass('puton');
                  $('#basicinfo').find('.border').eq($(this).index()).show().siblings().hide();
               
              });

          </script>
        <div id="basicinfo">
         <table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" class="border"> 
             <tr>
             <td class="lefttd" width="120"> <font color=red >*</font>教师类型：</td>
              <td class="tag_left">
      	        <select name="DrpClassID1" ID="DrpClassID1" >
                   <option Value="0">--选择教师分类--</option>
                    <%
      string tccalssid = GetVal("classid");
      string select=string.Empty;
              using (DataTable dt = EnterPrise.getEpriseBusiness(UserManage.GetUserInfo().UserName, 0, 0))
              {
                  if (dt != null)
                  {
                      foreach (DataRow dr in dt.Rows)
                      {

                          int depth = Utils.StrToInt(dr[2].ToString());
                          if (depth <= 3)
                          {
                              int id = Utils.StrToInt(dr[0].ToString());
                              string CatetoryName = dr[1].ToString();
                              if (depth == 2)
                              {
                                  CatetoryName = "　├ " + CatetoryName;
                              }
                              if (depth == 3)
                              {
                                  CatetoryName = "　   　├ " + CatetoryName;
                              }
                              if (id.ToString() == tccalssid)
                              {
                                  select = "selected";
                              }
                              else
                              {
                                  select = "";
                              }
                              KSCMS.W("<option " + select + " value='" + id + "'>" + CatetoryName + "</option>");
                              //  initial(id, drp);
                          }
                          else
                          {
                              break;
                          }
                      }
                  }
              } %>
                 </select>
                   <span class="tips">根据课程分类<font color=red >网授分类</font>那边设置的。</span>
             </td>          
             </tr>
 
                <tr>
                <td align="right" class="lefttd" height="30" >教师省市：</td>
                 <td class="tag_left">
                       <script src="/plus/area.aspx?pid=<%=Provinceid %>&cityid=<%=CityId %>&countyid=<%=CountyId %>"></script>
            
                <span class="tips">选择教师所在的省份和城市,方便检索。</span>
                 </td>
             </tr> 
             <tr>
              <%--  <td align="right" class="auto-style1" ><font color=red >*</font>教师姓名：</td>--%>
	           <td class="lefttd" width="120"> <font color=red >*</font>教师姓名：</td>
                 <td class="tag_left"><input type="text" name="TxtName" value="<%=GetVal("tname") %>" ID="TxtName" class="textbox" ></input>
             
                 </td>
             </tr>
               <tr>
                <td align="right" class="lefttd" height="30" >英文名称：</td>
                 <td class="tag_left"><input type="text" name="TxtTename" ID="TxtTename" value="<%=GetVal("Tename") %>" class="textbox" ></input>
                 </td>
             </tr>
              <tr>
                <td align="right" class="lefttd" height="30" >教师职称：</td>
                 <td class="tag_left"><input type="text"  name="Txtlevel" ID="Txtlevel" value="<%=GetVal("Tlevel") %>" class="textbox" ></input>
                 </td>
             </tr>
              <tr>
                    <td align="right" class="lefttd" height="30">
                     推荐等级：</td>
                    <td class="tag_left"> 
                        <%initteacher(); %>
                     </td>
                </tr>
              <tr>
                    <td align="right" class="lefttd" height="30">
                      性别：</td>
                    <td class="tag_left">
                      <input type="radio" name="RadioButtonList1" Value="1"   <%=(string.IsNullOrEmpty(GetVal("sex"))|| GetVal("sex")=="1")?"checked":"" %>>男</input>
                      <input type="radio" name="RadioButtonList1" Value="0" <%=GetVal("sex")=="0"?"checked":"" %>>女</input>
                     </td>
                </tr>
              <tr>
                <td align="right" class="lefttd" height="30" >电话号码：</td>
                 <td class="tag_left"><input type="text"  name="Txtlxdh" value="<%=GetVal("Tlxdh") %>" ID="Txtlxdh" class="textbox" /></td>
             </tr>
               <tr>
                <td align="right" class="lefttd" height="30" >传真号码：</td>
                 <td class="tag_left"><input type="text" name="Txtczdh"  ID="Txtczdh" value="<%=GetVal("czdh") %>" class="textbox" ></input></td>
             </tr>
             <tr>
                <td align="right" class="lefttd" height="30" >联系地址：</td>
                 <td class="tag_left"><input type="text" name="TxtADD"  ID="TxtADD" value="<%=GetVal("Tadd") %>" class="textbox"  Width="355px"></input></td>
             </tr>

              <tr>
                <td align="right" class="lefttd" height="30" >邮箱地址：</td>
                 <td class="tag_left"><input type="text"  name="Txtemail" ID="Txtemail" value="<%=GetVal("email") %>" class="textbox"  Width="197px"></input>如edu@kesion.com</td>
             </tr>
       
              <tr>
                    <td align="right" class="lefttd">
                     教师照片：</td>
                    <td class="tag_left"> 
                      <input id="DefaultPic" name="DefaultPic" Class="textbox fl" type="text" value="<%=DefaultPic%>" >
                        &nbsp;  &nbsp;<input type="button" class="ty_button ep-inline" onclick="SelectUserFiles('DefaultPic', 0);" value="选择图片" />
                        <div class="clear blank10"></div>	
            	        <%=Kesion.APPCode.UploadAPI.EchoUpload("courseUserPic","DefaultPic") %>
                     </td>
              </tr>
    
             <tr>
                <td align="right" class="lefttd" height="30" >教师介绍：</td>
                 <td class="tag_left"><textarea type="text"  ID="TxtIntro" name="TxtIntro"   TextMode="MultiLine" style="width:600px;height:140px" ><%=GetVal("TIntro")%></textarea> 
                    <% Kesion.APPCode.EditorAPI.EchoEditor("editor", "TxtIntro", "Basic", 0, false, true, true, false);%>

                </td>
             </tr>

              <tr>
                <td align="right" class="lefttd" height="30" >培训专长：</td>
                 <td class="tag_left"><textarea type="text"  name="Txtpxzc" ID="Txtpxzc"  TextMode="MultiLine" style="width:600px;height:140px" ><%=GetVal("pxzc")%></textarea>
                    <% Kesion.APPCode.EditorAPI.EchoEditor("editor", "Txtpxzc", "Basic", 0, false, true, true, false);%>
                </td>
             </tr>
              <tr>
                <td align="right" class="lefttd" height="30" >服务客户：</td>
                 <td class="tag_left"><textarea type="text" name="txtfwkh"  ID="txtfwkh"  TextMode="MultiLine" style="width:600px;height:140px" ><%=GetVal("fwkh")%></textarea>
                  <% Kesion.APPCode.EditorAPI.EchoEditor("editor", "txtfwkh", "Basic", 0, false, true, true, false);%>
                </td>
             </tr>
           
                <%--<tr>
                    <td align="right" class="lefttd" height="30" style="width: 102px">
                    教师状态：</td>
                    <td class="tag_left">
                     <asp:RadioButtonList ID="RdbVerify"   RepeatDirection="Horizontal" Height="24px">
                      <asp:ListItem Value="1" Selected="True">审核</asp:ListItem>
                      <asp:ListItem Value="0">未审核</asp:ListItem>
                     </asp:RadioButtonList>
                     </td>
                </tr>--%>
         
          </table>
            <table class="border" style="display:none;">
               <tr>
            <td align="right" class="lefttd" height="30">
              是否为管理团队：</td>
            <td class="tag_left" id="SelfAccount" onclick="showconfig()">
              <input type="radio" name="SelfAccount" Value="0"   <%=string.IsNullOrEmpty(GetVal("field"))?"checked":"" %>>否
              <input type="radio" name="SelfAccount" Value="1" <%=string.IsNullOrEmpty(GetVal("field"))?"":"checked readonly" %>>是
             </td>
        </tr>
              <tbody id="Tbody1">
                    <tr>
        <td align="right" class="lefttd" height="30" >账号：</td>
                        <input type="hidden"  name="field" value="<%=GetVal("field").ToString() %>" class="textbox" <%=GetVal("field").ToString()==""?"":"disaneble" %> />
         <td class="tag_left"><input type="text" <%= string.IsNullOrEmpty(GetVal("field"))?"":"readonly" %>  name="tcusername" value="<%=GetVal("field") %>" class="textbox" /></td>
     </tr>
      <tr>
        <td align="right" class="lefttd" height="30" >密码：</td>
         <td class="tag_left"><input type="text"  name="tcpassword" value="" class="textbox" /></td>
     </tr>
                  <%
                      XmlDocument doc = new XmlDocument();
                      doc.Load(Server.MapPath("~/config/menu/TcMenu.xml"));
                      XmlNode nodes = doc.SelectSingleNode("usermenu");
                      string ischeckeds = string.Empty;
                      StringBuilder sb = new StringBuilder();
                      int i = 0;
                      int allcount =0;
                      string partname = "";//模块名称
                      foreach (XmlNode first in nodes.ChildNodes)
                      {

                          EpConfig EnterPrise = new EpConfig();
                          if (first.SelectSingleNode("@role").InnerText=="weixin" &&Utils.StrToInt(EnterPrise.GetEpConfig(29))!= 1)
                          {
                              continue;
                          }
                          partname = first.SelectSingleNode("@role").InnerText;
                          int isselectall = 0;//判断子模块有没有全选
                          string check = string.Empty;//外模块全选

                          foreach (XmlNode sub in first.SelectNodes("leftitem/itemlist/item[@en='true']"))
                          {
                              allcount++;
                              string url = sub.SelectSingleNode("url").InnerText;
                              string name = sub.SelectSingleNode("name").InnerText + "</span>";
                              string ischecked = string.Empty;

                              if (Utils.InArray("" + url + "","" + tcpower + "",",") ==true)
                              {
                                  ischecked = "checked";
                                  isselectall++;
                                  i++;
                              }
                              //  url = url.Replace(",", "#");
                              sb.Append("<span style='margin-left:10px'><input " + ischecked + " onclick='docheck(\"" + partname + "\")' opgroup=\"" + partname + "\"  name='checkpower' type=\"checkbox\" value=\"" + url + "\">" + name);

                          }

                          KSCMS.W("<tr><td>" + first.SelectSingleNode("@name").InnerText + "" );

                          //  if (isselectall == first.SelectNodes("leftitem/itemlist/item[@en='true']").Count)
                          if (isselectall >= 1)
                          {
                              check = "checked";
                          }

                          KSCMS.W("<span style='margin-left:10px'><input " + check + " id=" + partname + " onclick='selectpart(\"" + partname + "\")' name='checkpower' type=\"checkbox\" value=\"" + partname + "\">");
                          KSCMS.W("</td>");

                          KSCMS.W("<td class=\"tag_left\">");
                          KSCMS.W(sb.ToString());

                          KSCMS.W("</td>");
                          KSCMS.W("</tr>");
                          sb.Clear();
                      }
                      // KSCMS.W(allcount.ToString() + "||" + k.ToString() + "||"+i.ToString());
                      if (allcount == i)
                      {
                          ischeckeds = "checked";
                      }

                      KSCMS.W(" <tr><td><input " + ischeckeds + " onclick=\"selectall(this)\" id='checkall' type=\"checkbox\" />全选</td></tr>");
                       %>

              </tbody>

          </table>

          </div>
       
        <div class="cz_btn nofloat" style="padding:20px 0px 0px 192px">
            <span><input type="submit" ID="Button2" OnClick="return(CheckForm())" class="button"  value="<%=button %>"   /></span>
            <span><input type="button" class="button" onclick="window.history.go(-1);"value=" 返 回 "></span>
        </div>
    </div>
    </form>
  </div>
<%} %>

  <script>
      $(document).ready(function(){
          showconfig()
      })
      function CheckForm() {
          if (jQuery('#DrpClassID1').val() == '0') {
              KesionJS.Alert('请选择教师类型!', "jQuery('#ctl00_KSContent_DrpClassID1').focus()");
              return false;
          }
          if (jQuery("#TxtName").val() == '') {
              KesionJS.Alert("教师姓名不能为空！", "jQuery('#TxtName').focus()");
              return false;
          }

      }
      function selectpart(partname)
      {
          //控制模块选中
          if($("#"+partname).attr("checked")=="checked")
          {
              $("input[opgroup="+partname+"]").each(function(){
                  $(this).attr("checked",true);
              })
          }
          else
          {
              $("input[opgroup="+partname+"]").each(function(){
                  $(this).attr("checked",false);
              })
          }
          docheck("");
      
      }
      function selectall(s)
      {
         //控制全选
          if($(s).attr("checked")=="checked")
          {
              $("input[name=checkpower]").each(function(){
                  $(this).attr("checked",true)
              }) 
          }
          else
          {
              $("input[name=checkpower]").each(function(){
                  $(this).attr("checked",false);
              }) 
          }
      }
      function docheck(partname)
      {
          //小模块取消全选或勾选全选
          if(partname!=""){
              var k=0;
              var j=0;
              $("input[opgroup="+partname+"]").each(function(){
                  if(!$(this).attr("checked"))
                  {
                   //   k=1;
                      $("#checkall").attr("checked",false);
                      j++;
                    //  $("#"+partname).attr("checked",false);
                  }
                  k++;
              });
              if(k!=j)
              {
                  $("#"+partname).attr("checked",true);
              }else
              {
                  $("#"+partname).attr("checked",false);
              }
          }

       //全选状态控制
              var i=0;
              $("input[name=checkpower]").each(function(){
                  if(!$(this).attr("checked"))
                  {
                      i=1;
                      $("#checkall").attr("checked",false);
                  }
              }) 
              if(i==0)
              {
                  $("#checkall").attr("checked",true);
              }
          
        

      }
      function showconfig()
      {
          //开启注册后，显示全选配置
          var s= $("input[name=SelfAccount]:checked").val();
          if(s=="0")
          {
              $("#Tbody1").hide();
          }
          else
          {
              $("#Tbody1").show();
          }
      }
  </script>



