<%@ 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.XML" %>
<script runat="server" type="text/C#">
    dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息，
    private static dynamic __info = new System.Dynamic.ExpandoObject();   //初始化当前页信息
    bool isLoadPage = true;  //定义页面是否加载
    public static int classId;
    public static int CourseId;
    public static int TcID;
    protected static string UserName;
    public static int Provinceid = 0;
    public static int CityId = 0;
    public static int CountyId = 0;
    protected DataRow dr;
    public bool isteacher = false;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (KSCMS.S("action").Equals("save"))
        {
            SaveChange();
        }
        UserName = new TemporaryVar().UserName;
        initialEdit();
        
    }

    private string GetVal(string fieldName)
    {
        if (dr != null)
        {
            return dr[fieldName].ToString();
        }
        else
        {
            return string.Empty;
        }
    }
    
    protected void SaveChange()
    {
        Hashtable ht = new Hashtable();
        Utils.TipsDisabled();  //检查是否演示状态
        ht.Add("Tlxdh", Utils.ChkSQL(KSCMS.S("Txtlxdh")));  // 联系电话
        ht.Add("email", Utils.ChkSQL(KSCMS.S("Txtemail"))); //邮箱
        ht.Add("czdh", Utils.ChkSQL(KSCMS.S("Txtczdh")));   //传真号码
        ht.Add("pxzc", Utils.ChkSQL(KSCMS.S("Txtpxzc")));   //培训专长
        ht.Add("fwkh", Utils.ChkSQL(KSCMS.S("txtfwkh")));    // 服务客户
        ht.Add("Tadd", Utils.ChkSQL(KSCMS.S("TxtADD")));    //联系地址   
        ht.Add("Tename", Utils.ChkSQL(KSCMS.S("TxtTename")));  //英文姓名
        ht.Add("TIntro", Utils.ChkSQL(KSCMS.S("TxtIntro")));  //教师简介
        ht.Add("Tlevel", Utils.ChkSQL(KSCMS.S("Txtlevel")));   //教师职称    
        ht.Add("sex", Utils.StrToInt(KSCMS.S("RadioButtonList1")));//  1男 0 女     
        ht.Add("photo", "/UploadFiles/avatar/"+new TemporaryVar().UserID+".jpg");//图片
        ht.Add("system", 2);

        if (DataFactory.Exists("KS_CosTeacher", "Field='" + UserName + "'"))
        {
            CommonData.Update("KS_CosTeacher", ht, " where   Field='" + new TemporaryVar().UserName + "'");
            Msg.Alert("恭喜，添加成功！", BasicField.GetUserUrl("teacher/teacher"));
            isLoadPage = false;
            return;
        }
        else
        {
            int classId = Utils.StrToInt(KSCMS.S("DrpClassID1").ToString());
            ht.Add("Grade", 3);
            ht.Add("cityid", Utils.StrToInt(KSCMS.S("cityid")));
            ht.Add("Provinceid", Utils.StrToInt(KSCMS.S("Provinceid")));
            ht.Add("Tname", Utils.ChkSQL(KSCMS.S("TxtName")));  //中文名称
            ht.Add("ClassID", classId);
            string Verify = XmlObject.ReadXmlReturnNode(Utils.GetMapPath(MyCache.GetCacheConfig(0) + "config/divide.config"), "//Divide/Verify");
            ht.Add("verify", Utils.StrToInt(Verify) == 1 ? 1 : 0);//教师状态
            ht.Add("Field", UserName);
            ht.Add("adddate", DateTime.Now);
            ht.Add("username", UserName);
            ht.Add("userid", new TemporaryVar().UserID);
            CommonData.Insert("KS_CosTeacher", ht);
            Msg.Alert("恭喜，添加成功！", BasicField.GetUserUrl("teacher/teacher"));
            isLoadPage = false;
            return;
        }
    }
    private void initialEdit()
    {
        string sql = "select top 1 * from KS_CosTeacher where   Field='" + UserName + "'";
        using (DataTable dt = DataFactory.GetDataTable(sql))
        { 
            if (dt.Rows.Count > 0)
            {
                dr = dt.Rows[0];
                if (dr["verify"].ToString() != "1")
                {
                    isteacher = false; 
                    Msg.Alert("您的资料正在审核中，请耐心等待!");
                }
                else
                {
                    isteacher = true;
                }
            }
            else
            {
                isteacher = false; 
                //Msg.Alert("您的资料正在审核中，请耐心等待!");
                return;
            }
             
        }
    }
    public string GetParam(string Fields)
    {
        string result = string.Empty;
        if (dr != null)
        {
            result = dr[Fields].ToString();
        }
        return result;
    }
</script>



<%
    if (!isLoadPage) return;
%>
<div class="t_tybox">
    	<div class="tytitle"><h4>教师资料</h4></div>

<div class="tabs">	
			<ul class="clearfix">
                    <li class='puton'><a href="<%=BasicField.GetUserUrl("teacher/teacher") %>">我的资料</a></li>
                    <li><a href="<%=BasicField.GetUserUrl("basic/userface") %>">上传头像</a></li>
                    <li><a href="<%=BasicField.GetUserUrl("basic/editpass") %>">修改密码</a></li>
                    <li><a href="<%=BasicField.GetUserUrl("basic/editquestion") %>">修改安全问题</a></li>
                    <li><a href="<%=BasicField.GetUserUrl("basic/mobilebind") %>">第三方绑定</a></li>
                    <li><a href="<%=BasicField.GetUserUrl("Shop/MyAddress") %>">收货人地址</a></li>
                   
			</ul>
        </div>
 <%
	if(DataFactory.Exists("KS_CosTeacher", "Field='" +  __user.UserName + "'")&&!KSCMS.S("action").Equals("add") ){
%>
      
        <div class="teacherinfo">
        	<div class="t_left">
            	<img id="blogLogo" src="<%=GetParam("photo") %>" style="height:180px;width:180px;" />    
            </div>
            <div class="t_right">
            	<ul class="clearfix">
                	<li>
                    	<div class="libox">
                            <span>账号状态：</span>
                            <%=GetVal("verify").ToString()=="0"?"<font color=#e83851>未审核</font>":"<font color=#51a744>已审核</font>" %>
                        </div>
                    </li>
                	<li>
                    	<div class="libox">
                            <span>教师类别：</span>
                            <%=MyCache.GetCosClass(Utils.StrToInt(GetParam("classid").ToString()), "ClassName", 0) %>
                        </div>
                    </li>
                    <li>
                    	<div class="libox">
                            <span>中文姓名：</span>
                            <%=GetVal("TName").ToString() %>
                        </div>
                    </li>
                    <li>
                    	<div class="libox">
                            <span>英文姓名：</span>
                            <%= GetVal("Tename").ToString() %>
                        </div>
                    </li>
                    <li>
                    	<div class="libox">
                            <span>教师性别：</span>
                           <%=GetVal("sex").ToString()=="0"?"女":"男" %>
                       </div>
                    </li>
                    <li>
                    	<div class="libox">
                            <span>教师职称：</span>
                           <%=GetVal("Tlevel").ToString() %>
                       </div>
                    </li>
                    <li>
                    	<div class="libox">
                            <span>邮箱地址：</span>
                           <%=GetVal("email").ToString() %>
                       </div>
                    </li>
                    <li>
                    	<div class="libox">
                           <span>传真号码：</span>
                           <%=GetVal("czdh").ToString() %>
                        </div>
                    </li>
                    <li>
                    	<div class="libox">
                           <span>联系电话：</span>
                           <%=GetVal("Tlxdh").ToString() %>
                        </div>
                    </li>
                    <li>
                    	<div class="libox">
                           <span>联系地址：</span>
                           <%= GetVal("Tadd").ToString() %>
                        </div>
                    </li>
                    <li>
                    	<div class="libox">
                           <span>所在地：</span>
                           <%= MyCache.GetAreaName( Utils.StrToInt(GetVal("ProvinceID").ToString()),"City") %> <%=  MyCache.GetAreaName( Utils.StrToInt(GetVal("cityid").ToString()),"City") %>
                        </div>
                    </li>
                    <li>
                    	<div class="libox">
                           <span>推荐星级：</span>
                           <font color="#ff6600"><%= GetVal("Grade").ToString() %>星</font>
                        </div>  
                    </li>
                    <li>
                    	<div class="libox">
                           <span>教师介绍：</span>
                           <%=GetVal("TIntro").ToString() %>
                        </div>
                    </li>
                    <li>
                    	<div class="libox">
                           <span>服务客户：</span>
                           <%=GetVal("fwkh").ToString() %>
                       </div>
                    </li>
                    <li>
                    	<div class="libox">
                           <span>培训专长：</span>
                           <%=GetVal("pxzc").ToString() %>
                         </div>
                    </li>
                  
                </ul>
            </div>
              <%if (GetVal("verify").ToString() == "0" || Teacher.getTeacherConfig(8)=="1" )
                { %>
                    	 <div class="cz_btn" style="padding-left:200px">
                          <input type="button" class="button" value=" 修 改 " onclick="location.href = '<%=BasicField.GetUserUrl("teacher/teacher","action-add")%>	';" />
                         </div>
                    <%} %>
			<div class="clear"></div>
        </div>      
		</div>
		<%}
            if ((Teacher.getTeacherConfig(8) == "1" && KSCMS.S("action").Equals("add")) || ( !KSCMS.S("action").Equals("add") && !isteacher))
    {
		Kesion.APPCode.EditorAPI.EchoHead();
		 %>
		   <form name="myform" action="<%=BasicField.GetUserUrl("teacher/teacher") %>" method="post" id="myform" >
		   <input type="hidden" value="save" name="action" />
		<div class="t_tybox">     
      		<div class="tytitle"><h4>完善教师资料</h4></div>   
            <div class="tips" style="padding:20px 0px 20px 20px">带有"<font color="red">*</font>"添加资料后将不能修改！</div>
      <table width="100%" align="center" border="0" cellpadding="1" cellspacing="1" class="border"> 

          <tbody id="tbody1" style="display:<%=DataFactory.Exists("KS_CosTeacher", "Field='" + __user.UserName + "'")==true?"none":""%>">
             <tr>
             <td class="lefttd" align="right"><font color="red">*</font>教师类型：</td>
              <td class="tag_left">
			  <select name="DrpClassID1" id="DrpClassID1">
			  <%
				  StringBuilder sb = new StringBuilder();
				  using (DataTable dt = MyCache.GetCosClass(0))
				  {
					  if (dt.Rows.Count > 0)
					  {
						  foreach (DataRow dr in dt.Rows)
						  {
							  string selcected = string.Empty;
							  if (GetParam("classid").Equals(""))//Convert.ToInt16(GetVal("depth").ToString())
								  sb.AppendFormat("<option value=\"{0}\" {2} >{1}</option>", dr[0].ToString(), KSCMS.getClassTree(dr["classname"].ToString(), Convert.ToInt16(Utils.StrToInt(dr["depth"].ToString())), 1).ToString(), selcected);
						  }
					  }
					  KSCMS.W(sb.ToString());
				  }
		 %>
			  </select>
		   
             </td>          
             </tr>  
             <tr>
                <td align="right" class="lefttd" height="30" >教师省市：</td>
                 <td class="tag_left">
                     <script src="../../plus/area.aspx?pid=<%=Provinceid %>&cityid=<%=CityId %>&county=<%=CountyId %>"></script>
                <span class="msgtips"> 选择教师所在的省份和城市,方便检索。</span>
                 </td>
             </tr>  
              <tr>
                <td align="right" class="auto-style1 lefttd" ><font color="red">*</font>教师姓名：</td>
                 <td class="tag_left"><input name="TxtName" type="text" id="TxtName" class="textbox" value="<%=GetParam("TName") %>"/> </td>
             </tr>             
          </tbody>

         <tbody id="tbody2" style="display:<%=Teacher.getTeacherConfig(8)=="1"?"":"none"%>">
             <tr>
             <td class="lefttd" align="right">教师类型：</td>
              <td class="tag_left">
                  <span id="Label1"><%=MyCache.GetCosClass(Utils.StrToInt(GetParam("classid").ToString()), "ClassName", 0) %></span>
             </td>          
             </tr>
             <tr>
                <td align="right" class="lefttd" height="30" >教师省市：</td>
                 <td class="tag_left">
                      <span id="Label2"><%=MyCache.GetAreaName(Utils.StrToInt(GetParam("Provinceid").ToString()), "City") + " " + MyCache.GetAreaName(Utils.StrToInt(GetParam("cityid").ToString()), "City") %></span>
                 </td>
             </tr>  
             <tr>
                <td align="right" class="lefttd" >教师姓名：</td>
                 <td class="tag_left">
                      <span id="Label3"><%=GetParam("TName") %></span>
                 </td>
             </tr>
             <tr>
                <td align="right" class="auto-style1" >推荐等级：</td>
                 <td class="tag_left">
                      <span id="Label4"><%=GetParam("Grade") %></span>星&nbsp;&nbsp;(推荐等级由管理员设置)
                 </td>
             </tr>

          </tbody>
     <tr>
        <td align="right" class="lefttd" height="30" >英文名称：</td>
         <td class="tag_left"><input name="TxtTename" type="text" id="TxtTename" value="<%=GetParam("Tename") %>" class="textbox" /></td>
     </tr>
      <tr>
        <td align="right" class="lefttd" height="30" >教师职称：</td>
         <td class="tag_left"><input name="Txtlevel" type="text" id="Txtlevel" value="<%=GetParam("Tlevel") %>" class="textbox" /></td>
     </tr>
      
      <tr>
            <td align="right" class="lefttd" height="30" style="width: 102px">性别：</td>
            <td class="tag_left">
             <table id="RadioButtonList1" border="0" style="height:24px;width:137px;">
		<tr> 
			<td><input id="RadioButtonList1_0" type="radio" class="radiobtn" name="RadioButtonList1" value="1" <%=(GetParam("sex").Equals("1")||GetParam("sex").Equals(""))?"checked":"" %> /><label for="RadioButtonList1_0">男</label></td>
			<td><input id="RadioButtonList1_1" type="radio" class="radiobtn" name="RadioButtonList1" value="0" <%=GetParam("sex").Equals("0")?"checked":"" %> /><label for="RadioButtonList1_1">女</label></td>
		</tr>
	</table>
             </td>
        </tr>
      <tr>
        <td align="right" class="lefttd" height="30" >电话号码：</td>
         <td class="tag_left"><input name="Txtlxdh" type="text" value="<%=GetParam("Tlxdh") %>" id="Txtlxdh" class="textbox" /></td>
     </tr>
       <tr>
        <td align="right" class="lefttd" height="30" >传真号码：</td>
         <td class="tag_left"><input name="Txtczdh" type="text" value="<%=GetParam("czdh") %>" id="Txtczdh" class="textbox" /></td>
     </tr>
     <tr>
        <td align="right" class="lefttd" height="30" >联系地址：</td>
         <td class="tag_left"><input name="TxtADD" type="text" value="<%=GetParam("Tadd") %>" id="TxtADD" class="textbox" style="width:355px;" /></td>
     </tr>

      <tr>
        <td align="right" class="lefttd" height="30" >邮箱地址：</td>
         <td class="tag_left"><input name="Txtemail" type="text" value="<%=GetParam("email") %>" id="Txtemail" class="textbox" style="width:197px;" /><span class="tips">如edu@kesion.com</span></td>
     </tr>
     
    
     <tr>
        <td align="right" class="lefttd" height="30" >教师介绍：</td>
         <td class="tag_left">
		 <textarea name="TxtIntro" rows="2" cols="20" id="TxtIntro" style="height:200px;width:90%;"><%=GetParam("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 name="Txtpxzc" rows="2" cols="20" id="Txtpxzc" style="height:200px;width:90%;"><%=GetParam("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 name="txtfwkh" rows="2" cols="20" id="txtfwkh" style="height:200px;width:90%;"><%=GetParam("fwkh") %></textarea>             
      <% Kesion.APPCode.EditorAPI.EchoEditor("editor", "txtfwkh", "Basic",0,false,true,true,false);%> </td>
     </tr>

  </table>
 
 		
        <div class="cz_btn nofloat" style="padding-left:142px">
      		<span><input type="submit" name="Button2" value="确定修改(O)" onclick="return (CheckForm());" id="Button2" class="button" /></span>
            <span><input type="button" class="button" onclick="window.history.go(-1);"value=" 返 回 "></span>
       </div>	   
      <div class="clear blank20"></div>
    
    </div>  
	</form>
		<%} %>

		 <script>
		 	function CheckForm() {
		 		if (jQuery('#DrpClassID1').val() == '0') {
		 			KesionJS.Alert('请选择所授课的类型!', "jQuery('#DrpClassID1').focus()");
		 			return false;
		 		}
		 		if (jQuery('#TxtName').val() == '') {
		 			KesionJS.Alert('请输入教师名字!', "jQuery('#TxtName').focus()");
		 			return false;
		 		}
		 		return true;
		 	}
     </script> 
