<%@ 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#">
	bool isLoadPage = true;  //定义页面是否加载
	public StringBuilder fs = new StringBuilder();
	public StringBuilder cs = new StringBuilder();
	public StringBuilder es = new StringBuilder();
	public StringBuilder ssb = new StringBuilder();
	public static int Epid = 0;
	public int groupID = 3;
	protected void Page_Load(object sender, EventArgs e)
	{
		if (CheckUserLogin.Check() != "success")
        {

			Msg.Alert("对不起，您未登录，请先登录！", Utils.GetRootPath());
			isLoadPage = false;
			return;
		}
		groupID =new TemporaryVar().GroupID;
        string sql = "select top 1 verify,FaceClass,CourseClass,ExamClass from KS_CosTeacher where userid=" + new TemporaryVar().UserID;
		if (groupID == 3)
		{
			sql = "select top 1 verify,FaceClass,CourseClass,ExamClass from KS_EnterPrise where   userid=" + new TemporaryVar().UserID;
		}
        using (DataTable dt = DataFactory.GetDataTable(sql))
		{
			if (dt.Rows.Count > 0)
			{
				DataRow dr = dt.Rows[0];
				cs.Append(GetBusiness(dr["courseClass"].ToString() == "" ? "0" : dr["courseClass"].ToString(), 0, 0));
				fs.Append(GetBusiness(dr["FaceClass"].ToString() == "" ? "0" : dr["FaceClass"].ToString(), 1, 0));
				es.Append(GetBusiness(dr["examClass"].ToString() == "" ? "0" : dr["examClass"].ToString(), 2, 0));
			}
		}
		string DoMethod = KSCMS.S("do");
		switch (DoMethod)
		{
			case "save":
				SaveChange();
				break;
		}
	}
	public string GetBusiness(string nametype, int num, int status)
	{
		#region 经营范围
		DataTable dt = MyCache.GetCosClass(0);  //0网授课程分类
		if (num == 1)
		{
			dt = MyCache.GetCosClass(1);//1面授课程分类
		}
		else if (num == 2)
		{
			dt = MyCache.GetCacheSJCategoryTable();       //考试分类         
		}
		StringBuilder sb = new StringBuilder();
		if (!string.IsNullOrEmpty(nametype))
		{
			DataView dv = dt.DefaultView;
			dv.RowFilter = " classid in(" + nametype + ")";
			//  dv.Sort = "root,orderid";
			dt = dv.ToTable();
		}
		int depth = 1;
		if (dt.Rows.Count > 0)
		{
			foreach (DataRow dr in dt.Rows)
			{
				string str = string.Empty;
				depth = Utils.StrToInt(dr["depth"].ToString());
				if (depth == 2)
				{
					str = "　├ ";
				}
				if (depth == 3)
				{
					str = "　   　├ ";
				}
				nametype = "," + nametype + ",";
				if (nametype.IndexOf("," + dr["classid"].ToString() + ",") != -1)
				{
					sb.AppendFormat(@"<option value ={0} selected = 'selected' >{1}</option>", dr["classid"].ToString(), str + dr["classname"].ToString());
				
				}
				else
				{
					sb.AppendFormat(@"<option value ='{0}' >{1}</option>", dr["classid"].ToString(), str + dr["classname"].ToString());
				}
			}

		}
		dt.Dispose();
		return sb.ToString();
		#endregion
	}
	protected void SaveChange()
	{
        Utils.TipsDisabled();  //检查是否演示状态
        
		Hashtable ht = new Hashtable();

		#region 面授分类
		string[] faceclass = KSCMS.S("faceclass").Split(',');
		string str = string.Empty;
		for (int i = 0; i < faceclass.Length; i++)
		{
			str += MyCache.GetCosClass(Utils.StrToInt(faceclass[i]), "ParentIDPath", 1);
		}
		str += "," + KSCMS.S("faceclass");
		str = Utils.FilterRepeatInArray(Utils.FilterIDs(str), ",");
		ht.Add("FaceClass", str);
		#endregion

		#region 网授分类
		str = string.Empty;
		string[] courseclass = KSCMS.S("courseclass").Split(',');
		for (int i = 0; i < courseclass.Length; i++)
		{
			str += MyCache.GetCosClass(Utils.StrToInt(courseclass[i]), "ParentIDPath", 0);
		}
		str += "," + KSCMS.S("courseclass");
		str = Utils.FilterRepeatInArray(Utils.FilterIDs(str), ",");
		ht.Add("courseClass", str);
		#endregion

		#region 考试分类
		str = string.Empty;
		string[] examclass = KSCMS.S("examclass").Split(',');
		for (int i = 0; i < examclass.Length; i++)
		{
			str += MyCache.GetCacheSJCategory(Utils.StrToInt(examclass[i]), "ParentIDPath");
		}
		str += "," + KSCMS.S("examclass");
		str = Utils.FilterRepeatInArray(Utils.FilterIDs(str), ",");
		ht.Add("examclass", str);
		#endregion
		if (groupID == 3)
		{
			CommonData.Update("KS_EnterPrise", ht, " where userid =" + new TemporaryVar().UserID);
		}
		else
		{
            CommonData.Update("KS_CosTeacher", ht, " where userid =" + new TemporaryVar().UserID);
		}
		Msg.Alert("恭喜,分类设置成功!",BasicField.GetUserUrl("teacher/CsMemberClass") );
		isLoadPage = false;
		return;
	}
	
</script>

  <script>
  	function addUser(v) {
  		var src = document.getElementById('prolist' + v);
  		var dest = document.getElementById('faceclass' + v);

  		for (var i = 0; i < src.options.length; i++) {
  			if (src.options[i].selected) {
  				var exist = false;
  				for (var j = 0; j < dest.options.length; j++) {
  					if (dest.options[j].value == src.options[i].value) {
  						exist = true;
  						break;
  					}
  				}
  				if (!exist) {
  					var opt = document.createElement('OPTION');
  					opt.value = src.options[i].value;
  					opt.text = src.options[i].text;
  					dest.options.add(opt);
  				}
  			}
  		}
  	}
  	function delUser(v) {
  		var dest = document.getElementById('faceclass' + v);

  		for (var i = dest.options.length - 1; i >= 0 ; i--) {
  			if (dest.options[i].selected) {
  				dest.options[i] = null;
  			}
  		}
  	}

  	function addAllUser(v) {
  		var src = document.getElementById('prolist' + v);
  		var dest = document.getElementById('faceclass' + v);

  		for (var i = 0; i < src.options.length; i++) {
  		//	if (src.options[i].selected) {
  				var exist = false;
  				for (var j = 0; j < dest.options.length; j++) {
  					if (dest.options[j].value == src.options[i].value) {
  						exist = true;
  						break;
  					}
  				}
  				if (!exist) {
  					var opt = document.createElement('OPTION');
  					opt.value = src.options[i].value;
  					opt.text = src.options[i].text;
  					dest.options.add(opt);
  				}
  		//	}
  		}
  	}
  	function delAllUser(v) {
  		var dest = document.getElementById('faceclass' + v);

  		for (var i = dest.options.length - 1; i >= 0 ; i--) {
  			//if (dest.options[i].selected) {
  				dest.options[i] = null;
  		//	}
  		}
  	}

  	function check() {
  	  
  		var idArr = new Array();
  		var idArr1 = new Array();
  		var idArr2 = new Array();
  	
  		var dest = document.getElementById('faceclass1');
  		for (var i = 0; i < dest.options.length; i++) {
  		 
  			dest.options[i].selected = "true";
  			idArr.push(dest.options[i].value);
  		}
  		//if (t == 0) {
  		//	if (idArr.length <= 0) {
  		//		alert("你没有选择面授分类!");
  		//		return false;
  		//	}
  		//}
  		var dest1 = document.getElementById('faceclass2');
  		for (var i = 0; i < dest1.options.length; i++) {
  		 
  			dest1.options[i].selected = "true";
  			idArr1.push(dest1.options[i].value);
  		}

  		 dest1 = document.getElementById('faceclass3');
  		for (var i = 0; i < dest1.options.length; i++) {
  		    dest1.options[i].selected = "true";
  		    idArr2.push(dest1.options[i].value);
  		}


  		//if (t == 1) {
  		//	if (idArr1.length <= 0) {
  		//		alert("你没有选择网授分类!");
  		//		return false;
  		//	}
  		//}
  		return true;
  	}
		 
</script>
 

<%
    if (!isLoadPage) return;
%>
<style>
#prolist1{width:320px !important; background:#fff; padding:0px !important;height:360px !important;}
#prolist1 option{ padding:5px 20px;}
#faceclass1{width:320px !important; background:#fff; padding:0px !important;height:360px !important;}
#faceclass1 option{ padding:5px 20px;}
#prolist2{width:320px !important; background:#fff; padding:0px !important;height:360px !important;}
#prolist2 option{ padding:5px 20px;}
#faceclass2{width:320px !important; background:#fff; padding:0px !important;height:360px !important;}
#faceclass2 option{ padding:5px 20px;}
#prolist3{width:320px !important; background:#fff; padding:0px !important;height:360px !important;}
#prolist3 option{ padding:5px 20px;}
</style>
	<form  method="post" action="<%=BasicField.GetUserUrl("teacher/CsMemberClass","do-save") %>">

	<div class="t_tybox">
	   <div class="blank10"></div>
	<div class="tytitle"><h4 >课程分类</h4></div>
	      <div class="tabs">	
                <ul class="clearfix">
                    <li class='puton'><a>面授课程分类</a></li>
                    <li><a>在线课程分类</a></li>   
                      <li><a>考试分类</a></li>             
                </ul>
			</div> 
			
			 <div class="clear"></div>
			 <div class="content-box">
	 <div id="faclasslist" class="content-item">
       
       <table  cellspacing="0" cellpadding="0" border="0" class="border"  >
           <tr class="tdbg" >
             <td class="clefttitle tdclass"  style="width:200px;text-align:center">招生课程分类：</td>
            <td>
                   	<div><%
						  ssb.AppendFormat(@"<select name=""prolist1"" id=""prolist1"" multiple=""true"" ondblclick=""addUser(1)"" >{0}</select>", GetBusiness("", 1, 0)); //  0面授，0状态
						 KSCMS.W(ssb.ToString());
						  %></div>
	                </td>
       		<td class='righttd tdclass' style="text-align:center">
			            <input type="button" value=" >>" onclick="addAllUser(1)" class="ty_button ty-box mb15" />
						<input type="button" value=" > " onclick="addUser(1)" class="ty_button ty-box mb15" />
						<div class="clear blank20"></div>
						<input type="button" value=" < " onclick="delUser(1)" class="ty_button ty-box mb15" />
						<input type="button" value=" << " onclick="delAllUser(1)" class="ty_button ty-box mb15" />
			</td>
            
            <td  class='righttd tdclass ' style="text-align:center">
						<select name="faceclass" id="faceclass1" multiple="true" size="18" ondblclick="delUser(1)">
						<%=fs.ToString() %>
                          </select>
                          
                         
			</td>	
            
          </tr>          
        </table>
        <div class="clear blank10"></div>
      	
    </div>
     <div id="clclasslist" style="display:none" class="content-item"> 
       <table  cellspacing="0" cellpadding="0"   border="0" align="left" class="border">
           <tr class="tdbg">
             <td class="clefttitle tdclass"  style="width:200px;text-align:center">在线课程分类：</td>
                  <td>
               	<div class="GroupPanelbox" ID="GroupPanel2">
				<%
					ssb.Clear();
					ssb.AppendFormat(@"<select  name=""prolist2"" size=""18"" style=""width:260px"" id=""prolist2"" multiple=""true""  ondblclick=""addUser(2)"" >{0}</select>", GetBusiness("", 0, 0));
					KSCMS.W(ssb.ToString());
					 %>
               	</div>
                         
	       </td>
           <td  class='righttd tdclass' style="text-align:center;">
					 <input type="button" value=" >>" onclick="addAllUser(2)" class="ty_button ty-box mb15" />
						<input type="button" value=" > " onclick="addUser(2)" class="ty_button ty-box mb15" />
						<div class="clear blank20"></div>
						<input type="button" value=" < " onclick="delUser(2)" class="ty_button ty-box mb15" />
						<input type="button" value=" << " onclick="delAllUser(2)" class="ty_button ty-box mb15" />
			</td>
            	<td  class='righttd tdclass' style="text-align:center; ">
						<select name="courseclass" id="faceclass2" multiple="true" size="18" style="width:260px" ondblclick="delUser(2)">
						<%=cs.ToString() %>
                              </select>
			</td>	
          </tr>      
          
        </table>
         <div class="clear blank10"></div>
     	
    </div>
     <div id="examclasslist" style="display:none" class="content-item">
       <table  cellspacing="0" cellpadding="0"  width="60%" border="0" class="border">
           <tr class="tdbg">
             <td class="clefttitle tdclass"  style="width:200px;text-align:center">考试分类：</td>
                  <td>
               	<div class="GroupPanelbox" ID="GroupPanel3">
				<%   ssb.Clear();
		 ssb.AppendFormat(@"<select  name=""prolist3"" size=""18"" style=""width:260px"" id=""prolist3"" multiple=""true""  ondblclick=""addUser(3)"" > {0}</select>", GetBusiness("", 2, 0));  //2考试分类
		 KSCMS.W(ssb.ToString());
		 %>
               	</div>
                         
	       </td>
       <td  class='righttd tdclass' style="text-align:center;">
					 <input type="button" value=" >>" onclick="addAllUser(3)" class="ty_button ty-box mb15" />
						<input type="button" value=" > " onclick="addUser(3)" class="ty_button ty-box mb15" />
						<div class="clear blank20"></div>
						<input type="button" value=" < " onclick="delUser(3)" class="ty_button ty-box mb15" />
						<input type="button" value=" << " onclick="delAllUser(3)" class="ty_button ty-box mb15" />
			</td>
            
            	<td class='righttd tdclass' style="text-align:center;">
						<select name="examclass" id="faceclass3" multiple="true" size="18" style="width:260px" ondblclick="delUser(3)">
						<%=es.ToString() %>
                   </select>
			</td>	
          </tr>          
          
        </table>
        <div class="clear blank10"></div>
      	 
    </div>  
    </div>
    	 <div style="padding-left:220px; display:block;margin-top:20px">
		  <input type="submit" class="ty_button" value="保存分类设置" onclick="return (check())" >
		  <div class="clearfix"></div>

      	  </div>
	</div>

	</form>
	<script>
	    $(".tabs ul li").click(function() {
	     
	        var index = $(this).index();
	        $(this).addClass("puton").siblings().removeClass("puton");
	        $(".content-item").eq(index).show().siblings().hide();
	    });
</script>