<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="True" Inherits="Kesion.NET.WebSite.Course.Admin.Course.KS_CosZjManage" Codebehind="KS.CosPeriod.Aspx.cs" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Kesion.Course" %>
<%@ Import Namespace="Kesion.BLL" %>
<asp:Content ID="Content1" ContentPlaceHolderID="KSContent" Runat="Server">

    <asp:Panel ID="ClassList" runat="server" Width="100%">
	
     <%if(istop==0){ %>
     <div class="listedit"> 
           <ul>
             <li id='p6' class="fl"><a href="javascript:;" onclick="location.href='KS.CosList.aspx';" class="button">返回课程列表</a></li> 
             <li id="p5" class="fl"><a onclick="GoPiLiang(<%=BookID.ToString()%>)" href="javascript:void(0);" class="button">批量设置</a></li>
           </ul>
     </div>
 	 <div class="footer_page"></div>  
	 <!--当前课程信息-->
     <asp:PlaceHolder ID="PlaceHolder1"  runat="server"></asp:PlaceHolder> 
     <div class="content-area pageBlank">
        <div class="myTitle">
            <div class="tabButton">
                <%if(Course.GetIsPeriod(CourseId)==1){ %>
                    <a class="on" href="KS.CosPeriod.Aspx?CourseId=<%=CourseId %>&teacherid=<%=teacherid%>">课时</a>
                <%} %>
                <a href="KS.CsTeacher.aspx?CourseId=<%=CourseId %>&teacherid=<%=teacherid%>&CosType=1">教师</a>
                <a href="KS.CsZLInfo.aspx?type=0&CourseId=<%=CourseId %>&teacherid=<%=teacherid%>">资料</a>
                <a href="KS.CosExamlist.aspx?CourseId=<%=CourseId %>&teacherid=<%=teacherid%>">试卷</a>
                <a href="KS.CosLearnRecord.aspx?courseid=<%=CourseId %>&teacherid=<%=teacherid%>&CosType=1">学员</a>
                <a href="KS.CosPJ.aspx?ShowPJ=ShowPJ&courseid=<%=CourseId %>&teacherid=<%=teacherid%>&CosType=1">评价</a>
             </div>
             <%} %>
          	 课时管理<span class="titleTips">该课程下共<span id="zhangnum"></span>章，<span id="jienum"></span>节，<span id="shinum"></span>课时</span>
		</div>
		<div class="quickSearch clearfix md20">
            <div class="fr headOperation ">
                 <a onclick="add(<%=BookID.ToString()%>,0,0)" href="javascript:void(0);" class="button ml15 button_on">添加章</a>
                 <a onclick="add(<%=BookID.ToString()%>,2,0)" href="javascript:void(0);" class="button ml15 button_on">添加节</a>
                 <a href="KS.CosPeriod.Aspx?action=add&Addtype=1&CourseID=<%=CourseId %>&Parentid=0&teacherid=<%=teacherid%>" class="button ml15 button_on">添加课时</a> 
            </div>
            <div class="SearchBox fl">
                <input type="text"  value="" id="key" style="margin-right:8px;" onkeypress="if(event.keyCode === 13){ event.preventDefault(); loaddata()}" />
                <select id="userselect" style="margin-right:8px;">
                    <option value="1">课时</option>
                    <%--<option value="0">章</option>
                    <option value="2">节</option>--%>
                </select>
                <input name="" value="搜索" type="button" class="button" onclick="loaddata()" />
            </div>
        </div>
	
        <div class="courseKeshi">
        	<div class="lineY"></div>
            <ul id="myloop">
            
        	</ul>
        </div>
	 </div>
           
     <script>
   	
	
		$(document).ready(function(){
			getmyPeriod();
		
		});
	
		function loaddata() {
			var key=$("#key").val();
			if(!key)
			{
				alert("请输入课时名称")
			}
			else
			{
				$.ajax({
					url: "?action=searchperiod&key=" + key + "&courseID=<%=CourseId%>&teacherid=<%=teacherid%>&userselect="+$("#userselect").val(),
					context: document.body,
					type: "GET",
					success: function (data) {
						//alert(data);
						$("#myloop").html(data);
					}
				});
			}
		}
	  
		function getmyPeriod()
		{
			$.ajax({
				type: 'Post',
				datatype: 'text',
				url: "?action=getperiod",
				data: { courseID: <%=CourseId%>},
				success: function (msg) {
					//alert(msg);
					msg=msg+"#&##&##&#";
					$("#myloop").html(msg.split("#&#")[0]);
					$("#zhangnum").html(msg.split("#&#")[1]);
					$("#jienum").html(msg.split("#&#")[2]);
					$("#shinum").html(msg.split("#&#")[3]);
				
					var num = $("#myloop li").length;
					if(num==0){
						$("#myloop").prev(".lineY").hide();
						$("#myloop").html('<div class="empty">您还未添加任何课时</div>')
					};
					
					$("#myloop li").hover(function(){
						$(this).find(".rButton").show();
					},function(){
						$(this).find(".rButton").hide();
					});
					
					$(".addButton").click(function(){
						$(this).toggleClass("addOn");
					});
					
					$(".rButton .icon").hover(function(){
						$(this).find("span").show();
					},function(){
						$(this).find("span").hide();
					});
					
					$(".rButton").click(function(){
						doNone(click());
					});
					
					//展开收缩
					click();
					function click(){
						$(".chapter,.section").click(function(){
							$(this).find(".menubtn").toggleClass("menubtn2");
							$(this).next(".box").stop().slideToggle(300);
						});
					};
					//是否添加按钮
					$(".menubtn").each(function() {
						var num = $(this).parent().next(".box").length;
						if(num==0){
							$(this).hide();
						};
					});
					$(".chapterBox").each(function() {
						var i = $(this).index()+1;
						if(i>10){
							$(this).find(".chapter .menubtn").addClass("menubtn2");
							$(this).find(".chapter").siblings(".box").hide();
						};
					});				
	
					
				}
			});
		}
	
		function showToggle(id) {
			if (jQuery('#xt' + id).html() == '') {
				jQuery('#xt' + id).append('<tr class="tdbg"><td height="30" align="center" colspan="4">该章节下还没有绑定课时!</td></tr>');
			}
			var t = jQuery("#t" + id).html();
			if (t.indexOf('打开') != -1) {
				jQuery('#xt' + id).slideDown('fast');
				jQuery("#t" + id).html('<span class="tree_Open"/>关闭</span>')
			} else {
				jQuery('#xt' + id).slideUp('fast');
				jQuery("#t" + id).html('<span class="tree_Close"/>打开</span>')
			}
		}
			jQuery(document).ready(function() {
				<%if (KSCMS.S("action") == "modifyth") {%>
				jQuery(".toggleArea").html('<span class="tree_Open"/>关闭</span>');
				jQuery('.showArea').each(function(){
					if (jQuery(this).html()==''){
						jQuery(this).append('<tr class="tdbg"><td height="30" align="center" colspan="4">该章节下还没有绑定课时!</td></tr>');
					}
				});
				<%}else{ %>
				jQuery(".toggleArea").html('<span class="tree_Close"/>打开</span>');
				jQuery(".showArea").attr("style","display:none");
				<%} %>
			});
			var currStatue=1;
			function openAll(){
				if (currStatue==1){ //展开
					currStatue=0
					jQuery(".toggleArea").html('<span class="tree_Open"/>关闭</span>');
					jQuery('.showArea').each(function(){
						if (jQuery(this).html()==''){
							jQuery(this).append('<tr class="tdbg"><td height="30" align="center" colspan="4">该课程下还没有绑定试卷!</td></tr>');
						}
					});
					jQuery('.showArea').show();
					jQuery("#allstate").html('全部隐藏');
				}else{
					currStatue=1;
					jQuery(".toggleArea").html('<span class="tree_Close"/>打开</span>');
					jQuery(".showArea").attr("style","display:none");
					jQuery("#allstate").html('全部展开');
				}
			}
			function IsDel(type)
			{
				if(type=="1")
				{
					if(confirm("是否删除该课时？"))
					{
						return true;
					}
				}
				if(type=="0")
				{
					if(confirm("是否删除该章以及章下所有内容？"))
					{
						return true;
					}
				}
				if(type=="2")
				{
					if(confirm("是否删除该节以及节下所有内容？"))
					{
						return true;
					}
				}
				return false;
			}
	</script>      
        </asp:Panel> 
    <script>
    	function CheckForm() {
    	    // alert("ddd");
    		if (jQuery('#<%=this.ClassName.ClientID %>').val() == '' && jQuery("#AddType")[0].checked == false) {
        		KesionJS.Alert('请输入名称！', "jQuery('#<%=this.ClassName.ClientID %>').focus()");
            	return false;
            }
			var checkrad = jQuery("#<%=this.RadioButtonList2.ClientID %> :radio[checked]").val();
        	var idArr = new Array();
        	var dest = document.getElementById('ctl00_KSContent_LstB1');
        	for (var i = 0; i < dest.options.length; i++) {
        		dest.options[i].selected = "true";
        		idArr.push(dest.options[i].value);
        	}
        	if (checkrad == "2") {
        		if (idArr.length <= 0) {
        			alert("你没有选择试卷ID!");
        			return false;
        		}
        	}
        	return true;
        }
    </script>
<script type="text/javascript">
    function GetMyIds() {  //获取选中的课时id 信息
        var sid = null;
        for (var i = 0; i < document.getElementsByName("perioids").length; i++) {
            var KS = document.getElementsByName("perioids")[i];
            if (KS.checked == true) {
                if (sid == null)
                    sid = KS.value;
                else
                    sid += "," + KS.value;
            }
        }
        return sid;
    } 
    function GoPiLiang(id)
    {
        var sid = GetMyIds();//首先获取课时id
        if (sid!=null){ parent.openWin('批量设置', 'course/KS.CosAddZj.aspx?action=piliang&ids='+sid+'&Courseid='+id, true,600,400);}
        else{
            KesionJS.Alert('对不起,请先选择需要设置的课时!');
        } 
    }

	function add(id,type,parentid) {
		parent.openWin('添加章节', 'course/KS.CosAddZj.aspx?action=add&type='+type+'&parentid='+parentid+'&Courseid='+id, true,600,400);
	}
	function edit(id,Periodid,type,parentid) {
		parent.openWin('修改章节', 'course/KS.CosAddZj.aspx?action=edit&type='+type+'&Courseid='+id+'&parentid='+parentid+'&Periodid='+Periodid, true,600,400);
	}
	function pro(id,parentid) {
		location.href='KS.CosPeriod.Aspx?action=pro&CourseId='+<%=CourseId %>+'&Periodid='+id+"&parentid="+parentid;
    }
    function next(id,parentid) {

    	location.href='KS.CosPeriod.Aspx?action=next&CourseId='+<%=CourseId %>+'&Periodid='+id+"&parentid="+parentid;
     }
	
</script>
<script>
	$(document).ready(function(){
        judgejifen();
     
      });  
	function judgejifen()
	{
		var a = jQuery("#<%=this.RadioButtonList1.ClientID %> :radio[checked]").val();
	
		if(a=="0")
		{
		    jQuery("#tbody110").show();
		    jQuery("#tbody3").hide();
		    
		}
		else
		{
		    jQuery("#tbody3").show();
			jQuery("#tbody110").hide();
		}
		if("<%=periodbuy%>"=="none")
		{
		    jQuery("#tbody3").hide();
		    jQuery("#tbody110").hide();
		}

	}
</script>
        <asp:Panel ID="ClassAdd" runat="server" Width="100%">

		<asp:TextBox CssClass="textbox" style="display:none" ID="child" runat="server"  Width="350px"></asp:TextBox>
        <!--<KS:TopNav ID="TopNav1" runat="server" Text="添加视频" />   	-->	
		<div class="content-area mt20">
        	<div class="myTitle">添加课时</div>
        	 <input name="CourseId" type="hidden" value="<%=CourseId %>" />  
			 <input name="parentid" type="hidden" value="<%=Parentid %>" />  
             <table width="100%" border="0" cellpadding="0" cellspacing="0" class="CTable no-borderTable">
                   <tr style="display:none">
                       <td>
                 <asp:label ID="TxtOrderID" runat="server"  Width="20px" Text="" /></td>
                
                  </tr>
                   <tr>
                    <td class="lefttd" height="30" align="right" style="width: 155px">
                        <strong> <font color="red">*</font>标题：</strong></td>
                    <td class="righttd" width="751">
                       <span id="AddOne">
                        <asp:TextBox CssClass="textbox" ID="ClassName" runat="server"  Width="350px"></asp:TextBox>
                     
                       </span>                     
                         </td>
                  </tr>
                    <tr>
                       <td align="right" class="lefttd" style="width: 155px; height: 37px;"><strong>
                           所属章节：</strong><br>
                         </td>
                         <td class="righttd" style="height: 37px;">
                             <asp:DropDownList ID="MyItem" runat="server" Width="250">
                             <asp:ListItem Value="0">请选择章节</asp:ListItem>
                             </asp:DropDownList>
                       </td>
                    </tr>  
                  
                  <tbody id="Tbody5"  runat="server">
                     <tr>
                        <td align="right" class="lefttd" height="30" style="width: 102px">
                            <strong>是否有模拟试卷：</strong></td>
                        <td class="righttd">
                            
                            <asp:RadioButtonList ID="RadioButtonList2" onclick="showwatermarkarea()" runat="server"
                                RepeatDirection="Horizontal" Height="24px">
                                <asp:ListItem Value="0" Selected="True">无</asp:ListItem>
                            <%--    <asp:ListItem Value="1">指定试卷栏目</asp:ListItem>--%>
                                <asp:ListItem Value="2">指定试卷ID</asp:ListItem>
                            </asp:RadioButtonList>
                        </td>
                    </tr>
                    <tbody id="watermark0" runat="server" style="display: none">
                        <tr>
                            <td align="right" class="lefttd">
                                <strong>试卷栏目：</strong></td>
                            <td class="righttd">
                                <asp:ListBox ID="ListSjClass" runat="server" Width="150px" SelectionMode="Multiple" Height="150px"></asp:ListBox>
                                <a class="textarea_min" href="javascript:zoomtextarea(-5,'<%=this.ListSjClass.ClientID %>');"></a>
                                <a class="textarea_max" href="javascript:zoomtextarea(5,'<%=this.ListSjClass.ClientID %>');"></a>
                            </td>
                        </tr>
                    </tbody>
                    <tbody id="watermark2" style="display: none" runat="server">
                        <tr>
                            <td align="right" class="lefttd" height="30">
                                <strong>试卷ID：</strong></td>
                            <td class="righttd" valign="top">&nbsp;
         
            <table border="0" width='100%'>
                <tr>
                    <td style="width: 200px">搜索试卷：<asp:TextBox ID="TxtSJKey" runat="server" Width="160px" CssClass="textbox" />
                        <input type="button" value="搜索" class="button" onclick="searchSJ();" cssclass="button" />
                        <br />

                        <asp:ListBox ID="LstB2" runat="server" Width="300px" Height="200px" SelectionMode="Multiple"></asp:ListBox>
                    </td>
                    <td>
                        <p>
                            <input type="button" value=" > " onclick="addUser()" class="button" />
                        </p>
                        <br />
                        <p>
                            <input type="button" value=" < " onclick="delUser()" class="button" />
                        </p>
                    </td>
                    <td>指定试卷如下：
                 <br />
                        <asp:ListBox ID="LstB1" runat="server" Width="300px" Height="200px" SelectionMode="Multiple"></asp:ListBox>
                    </td>
                </tr>
            </table>
                 </td>
                        </tr>
                        <tr style="display:none">
                            <td align="right" class="lefttd" height="30"><strong>考试状态规定：</strong></td>
                            <td class="righttd">
                                <asp:TextBox ID="regulations" CssClass="textbox"
                                    runat="server" Width="40px" Height="23px"></asp:TextBox>%
               <font color="red">学习达到总课时的多少比例时才能考试，留空或0为不限制</font>
                            </td>
                        </tr>

                    </tbody>
                 </tbody>
                   <asp:PlaceHolder ID="PeriodPlace"  runat="server"></asp:PlaceHolder> 


    <tr >
            <td align="right" class="lefttd" height="30" >收费状态：</td>
            <td class="righttd">
            	<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal" onclick="judgejifen()"  >
                    <asp:ListItem Value="1" Selected="True">付费</asp:ListItem> 
                    <asp:ListItem Value="0" >免费</asp:ListItem>
                </asp:RadioButtonList>
                </td>
        </tr>  

       

<tbody id="tbody110">
 <tr>
            <td align="right" class="lefttd" height="30" >是否重复扣积分：</td>
            <td class="righttd">
            	<asp:RadioButtonList ID="RadioButtonList3" runat="server" RepeatDirection="Horizontal" onclick="judgejifen()"  >
                    <asp:ListItem Value="0" Selected="True">否</asp:ListItem> 
                    <asp:ListItem Value="1" >是</asp:ListItem>
                </asp:RadioButtonList>
                </td>
        </tr>  
	   <tr>
	   <td align="right" class="lefttd" height="30">
                <strong><font color="red">*</font>积分价格：</strong></td>
            <td class="righttd">
                &nbsp;<asp:TextBox ID="jifen" CssClass="textbox" runat="server"  Width="50px" Text="0"></asp:TextBox>积分</td>
				  <span class="tips">说明：如果用户已购课程，这里不再重复扣积分。</span>
       </tr>

	  </tbody>
   <tbody id="tbody3">
          <tr>
	   <td align="right" class="lefttd" height="30">
                <strong><font color="red">*</font>单个课时价格：</strong></td>
            <td class="righttd">
                &nbsp;<asp:TextBox ID="TextMoney" CssClass="textbox" runat="server"  Width="50px" Text="0"></asp:TextBox>元<span style="margin-left:10px" class="tips">设置为“0”表示不按课时收费</span></td>
				
				 </tr>
  </tbody>
   </table>



   
          <div align="center"><KS:Foot ID="Foot1" runat="server" OnSubmit="SaveButton_Click" /></div>
          
     </div>

     <script>

     	jQuery(document).ready(function () {
     		showwatermarkarea();
     	});
     	function showwatermarkarea() {
     	    var checkrad =  $("input[name='ctl00$KSContent$RadioButtonList2']:checked").val(); //jQuery("#<%=this.RadioButtonList2.ClientID %> :radio[checked]").val();
     	   
     	    if (checkrad == "2") {
               
         		jQuery("#<%=this.watermark0.ClientID %>").css("display", "none");
             	jQuery("#<%=this.watermark2.ClientID %>").css("display", "");
             }else  if(checkrad=="1"){
             	jQuery("#<%=this.watermark0.ClientID %>").css("display", "");  
             	jQuery("#<%=this.watermark2.ClientID %>").css("display", "none");
             }
             else 
             {
             	jQuery("#<%=this.watermark0.ClientID %>").css("display", "none");
             	jQuery("#<%=this.watermark2.ClientID %>").css("display", "none");

             }
	 }
	 function searchSJ() {
	 	var key = jQuery("#<%=this.TxtSJKey.ClientID %>").val();
    	if (key == '') {
    		KesionJS.Alert("请输入试卷关键字！", "jQuery('#<%=this.TxtSJKey.ClientID %>').focus()");
        	return false;
        } else {
        	jQuery.ajax({ url: "KS.CosPeriod.Aspx?action=GetSJ&CourseId=<%=CourseId%>&Key=" + escape(key), success: function (d) {
        	    jQuery("#<%=this.LstB2.ClientID %>").empty();
        	    jQuery("#<%=this.LstB2.ClientID %>").append(d);
            }
            });
		}
	}
  
	function addUser() {
		var src = document.getElementById('<%=this.LstB2.ClientID %>');
          	var dest = document.getElementById('<%=this.LstB1.ClientID %>');

          	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() {
          	var dest = document.getElementById('<%=this.LstB1.ClientID %>');

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


</asp:Content>