<%@ Page Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="True" Inherits="Kesion.NET.WebSite.Admin.Course.KS_CosGroupPeriod" Codebehind="KS.CosGroupPeriod.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'><a href="javascript:;" onclick="location.href='KS.CosList.aspx?costype=2';" 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(<%=CourseId.ToString()%>,0,0)" href="javascript:void(0);" class="button ml15 button_on">添加章</a>
                    <a onclick="add(<%=CourseId.ToString()%>,2,0)" href="javascript:void(0);" class="button ml15 button_on">添加节</a>
                    <a href="KS.CosGroupPeriod.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;"/>
                    <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="courseTips">
            </div>
            <div class="clear blank10"></div>

            <div class="courseKeshi">

                <div class="lineY"></div>
                <ul id="myloop">
                </ul>
            </div>
        </div>


    </asp:Panel>

    <script type="text/javascript">
        $(document).ready(function () {
            getmyPeriod();

        });
        function add(id, type, parentid) {
            parent.openWin('添加章节', 'course/KS.CosAddZj.aspx?action=add&type=' + type + '&parentid=' + parentid + '&costype=2&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 + '&costype=2&Periodid=' + Periodid, true, 600, 400);
        }

        function pro(id, parentid) {
            location.href = 'KS.CosGroupPeriod.Aspx?action=pro&CourseId=' +<%=CourseId %>+'&costype=2&Periodid=' + id + "&parentid=" + parentid;
        }
        function next(id, parentid) {
            location.href = 'KS.CosGroupPeriod.Aspx?action=next&CourseId=' +<%=CourseId %>+'&costype=2&Periodid=' + id + "&parentid=" + parentid;
        }
        function getmyPeriod() {
            $.ajax({
                type: 'Post',
                datatype: 'text',
                url: "?action=getperiod",
                data: { courseID: <%=CourseId%>},
                success: function (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();
                        };
                    });
                }
            });
        }

    </script>
    <!--章节相关脚本-->
    <script>


        function changePeriod() {
            var checked = jQuery("#<%=this.RdbTeachWay.ClientID %> :radio[checked]").val();
        if (checked == "1") {
            location.href ="?action=add&addtype=1&courseid=<%=CourseId%>&parentid=<%=Parentid%>&teacherid=<%=teacherid%>&periodtype=0";

        }
        else if (checked == "5") {
            location.href ="?action=add&addtype=1&courseid=<%=CourseId%>&parentid=<%=Parentid%>&teacherid=<%=teacherid%>&periodtype=1";
        }
        else {
            location.href ="?action=add&addtype=1&courseid=<%=CourseId%>&parentid=<%=Parentid%>&teacherid=<%=teacherid%>&periodtype=2";
            }
        }

    </script>
    <script>
        $(document).ready(function () {
            judgecosjifen();
            free();
        });
        function judgecosjifen() {
            var total = jQuery("#<%=this.RdbTeachWay.ClientID %> :radio[checked]").val();    //1点播 5直播
             if (total == "1") {
                 $("#coscharge").show();
                 var a = jQuery("#<%=this.RdbVodIsFree.ClientID %> :radio[checked]").val();
                if (a == "0") {    //免费
                    jQuery("#tbody110").show();     //积分显示
                }
                else {            //收费
                    jQuery("#tbody110").hide();
                 }
                 if ("<%=(courseIsFree==0||courseIsChargePeriod==1).ToString().ToLower()%>"=="true" || a == 0) {   //主程课免费或是不允许按课时购买时，不能显示价格录入框
                        jQuery("#tbody4").hide();
                    } else {
                        jQuery("#tbody4").show();
                    }
            }
            else {
                jQuery("#tbody110").hide();
                jQuery("#tbody4").hide();
                $("#coscharge").hide();
            }
        }

        function free() {   //面授
            var isFree = jQuery("#<%=this.RdbFaceIsFree.ClientID %> :radio[checked]").val();
            if ("<%=(courseIsFree==0||courseIsChargePeriod==1).ToString().ToLower()%>"=="true" || isFree == 0) {   //主程课免费或是不允许按课时购买时，不能显示价格录入框
                        jQuery("#SetPrice").hide();
              } else {
                        jQuery("#SetPrice").show();
             }

        }

    </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>
                    <td align="right" class="lefttd" style="width: 155px; height: 37px;"><strong>选择课时类型：</strong><br>
                    </td>
                    <td class="righttd" style="height: 37px;">
                        <asp:RadioButtonList ID="RdbTeachWay" runat="server" RepeatDirection="Horizontal">
                            <asp:ListItem Value="1" Selected="True">点播课时</asp:ListItem>
                            <asp:ListItem Value="5">直播课时</asp:ListItem>
                            <asp:ListItem Value="0">面授课时</asp:ListItem>
                        </asp:RadioButtonList>
                    </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>
                <%if (Utils.StrToInt(KSCMS.S("periodtype")) == 0 || Utils.StrToInt(KSCMS.S("periodtype")) == 1)
                    { %>
                <tbody id="Tbody5">
                    <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>
                <%} %>
                <% if (Utils.StrToInt(KSCMS.S("periodtype")) == 0)
                    { %>

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


                <tr id="coscharge">
                    <td align="right" class="lefttd" height="30">收费状态：</td>
                    <td class="righttd">
                        <asp:RadioButtonList ID="RdbVodIsFree" runat="server" RepeatDirection="Horizontal" onclick="judgecosjifen()">
                            <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="judgecosjifen()">
                                <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>积分
                            <span class="tips">说明：如果用户已购课程，这里不再重复扣积分。</span>
                        </td>
                    </tr>
                </tbody>

                <tbody id="tbody4"<%=((courseIsFree == 0||courseIsChargePeriod==1)?" style='display:none'":"") %>>
                    <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>
                <%} %>
                <% if (KSCMS.S("periodtype") == "1")
                    { %>

                <asp:PlaceHolder ID="LivePeriodPlace" runat="server"></asp:PlaceHolder>

                <%} %>
                <% if (KSCMS.S("periodtype") == "2" || this.RdbTeachWay.SelectedValue == "0")
                    { %>
                <tbody id="showface">
                    <tr>
                        <td align="right" class="lefttd" height="30">收费状态：</td>
                        <td class="righttd">
                            <asp:RadioButtonList ID="RdbFaceIsFree" runat="server" RepeatDirection="Horizontal" onclick="free()">
                                <asp:ListItem Value="1">付费</asp:ListItem>
                                <asp:ListItem Value="0" Selected="True">免费</asp:ListItem>
                            </asp:RadioButtonList>
                        </td>
                    </tr>
                    <tr id="SetPrice" <%=((courseIsFree == 0||courseIsChargePeriod==1)?" style='display:none'":"") %>>
                        <td align="right" class="lefttd" height="30">
                            <strong><font color="red">*</font>单个课时价格：</strong>
                        </td>
                        <td class="righttd">&nbsp;<asp:TextBox ID="TxtMoney" CssClass="textbox" runat="server" Width="50px" Text="0"></asp:TextBox>元<span style="margin-left: 10px" class="tips">设置为“0”表示不按课时收费</span></td>
                    </tr>
                    <tr>
                        <td align="right" class="lefttd" height="30">
                            <strong><font color="red">*</font>开始时间：</strong></td>
                        <td class="righttd">&nbsp;<asp:TextBox ID="BeginDate" CssClass="textbox Wdate" runat="server" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'%y-%M-%d'});" Width="180px" Text=""></asp:TextBox>2015-09-24 10:08:36 </td>
                    </tr>
                    <tr>
                        <td align="right" class="lefttd" height="30">
                            <strong><font color="red">*</font>结束时间：</strong></td>
                        <td class="righttd">&nbsp;<asp:TextBox ID="EndDate" CssClass="textbox Wdate" runat="server" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'%y-%M-%d'});" Width="180px" Text=""></asp:TextBox>2015-09-24 10:08:36 </td>
                    </tr>
                    <tr>
                        <td align="right" class="lefttd" height="30"><strong>课程介绍：</strong></td>
                        <td class="righttd">
                            <asp:TextBox ID="TxtIntro" TextMode="MultiLine" Width="100%" Height="300px" runat="server"></asp:TextBox>
                            <% Kesion.APPCode.EditorAPI.EchoEditor("editor", this.TxtIntro.ClientID, "Common");%>
                        </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 = 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;
                            opt.selected = true;
                            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>
