<%@ Page Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="True" Inherits="Kesion.NET.WebSite.Course.Admin_Course_KS_AddNew" Codebehind="KS.AddNew.aspx.cs" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.Publics" %>
<asp:Content ID="Content1" ContentPlaceHolderID="KSContent" runat="Server">
    <script>
        function searchUser() {
           
            jQuery('#ajaxmsg', window.parent.document).fadeIn("slow");

            var url = '../../plus/ajaxs.ashx';
            jQuery.get(url, { a: "SearchUser", key: jQuery("#key").val() }, function (s) {
                jQuery('#ajaxmsg', window.parent.document).fadeOut("slow");
                showResponse(s);
            });
            
            
        }
        function showResponse(s) {
        
                var result = s;
                if (result != '') {
                    var obj = jQuery('#user_search')[0];
                    obj.length = 0;
                    var rarr = result.split('|');
                    for (var i = 0; i < rarr.length; i++) {
                        if (rarr[i] != '') {
                            var opt = document.createElement('OPTION');
                            opt.value = rarr[i];
                            opt.text = rarr[i];
                            obj.options.add(opt);
                        }
                    }
                }
         
        }
        function addUser() {
           
           
                var src = document.getElementById('user_search');
                var dest = document.getElementById('user');

                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('user');
                 for (var i = dest.options.length - 1; i >= 0 ; i--) {
                     if (dest.options[i].selected) {
                         dest.options[i] = null;
                     }
                 }
           
        }
    
       
        function CheckForm() {
            <%if(string.IsNullOrEmpty(username)){ %>
                var idArr = new Array();
                var dest = document.getElementById('user');
                for (var i = 0; i < dest.options.length; i++) {
                    dest.options[i].selected = "true";
                    idArr.push(dest.options[i].value);
                }
                if (idArr.length <= 0) {
                    alert("你没有选择要开通课程的用户!");
                    return false;
                }
            <%}%>
                var idArr1 = new Array();
                var dest1 = document.getElementById('<%=this.LstB1.ClientID %>');
                 for (var i = 0; i < dest1.options.length; i++) {
                     dest1.options[i].selected = "true";
                     idArr1.push(dest1.options[i].value);
                 }


                 if (idArr1.length <= 0) {
                     alert("你没有选择要开通课程!");
                     return false;
                 }
                //alert(idArr1.length);

               
              return true;

            }
        function searchCos() {
            var key = jQuery("#<%=this.TxtSJKey.ClientID %>").val();
            var checkrad = jQuery("#<%=this.RdbOpenType.ClientID %> :radio[checked]").val();
          
              jQuery.ajax({
               url: "KS.AddNew.aspx?action=GetCos&Key=" + escape(key) + "&costype=" + checkrad, success: function (d) {
                    jQuery("#<%=this.LstB2.ClientID %>").empty();
                   jQuery("#<%=this.LstB2.ClientID %>").append(d);
               
                }
            });
           
                
        }
        //选择套餐，触套餐下的课程
        function selectBind() {
            var checkrad = jQuery("#<%=this.RdbOpenType.ClientID %> :radio[checked]").val();
            if (checkrad = '4') {
                var str = '';
                jQuery("#<%=this.LstB1.ClientID %> option:selected").each(function () {
                    if (str == '')
                        str += $(this).val();
                    else
                        str += "," + $(this).val();
                });
               // alert(str);
                if (str != '') {
                       jQuery.ajax({
                           url: "KS.AddNew.aspx?action=GetbindCos&courseids=" + str, success: function (d) {
                             //  console.log(d);
                             var d1 = d.split("&&&")[0];
                             var d2 = d.split("&&&")[1];//选修课程
                              //$("#showMustChooseCourse").html(d1);
                              jQuery("#<%=this.LstBindCouurse.ClientID %>").empty();
                              jQuery("#<%=this.LstBindCouurse.ClientID %>").append(d2);
                     }
                });
                }
            }

        }
        function searchBindCos() {
             var str = '';
             jQuery("#<%=this.LstB2.ClientID %> option:selected").each(function () {
		    if (str == '')
		        str += jQuery(this).val() + "|" + jQuery(this).text();
		    else
		        str += "," + jQuery(this).val() + "|" + jQuery(this).text();
        });
            alert(str);
               jQuery.ajax({
                url: "KS.AddNew.aspx?action=GetbindCos&courseids=" + str, success: function (d) {

                
               
                }
                });
                
          }




            function addCos() {
                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 delCos() {
                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;
                    }
                }
            }
        function showstatus() {
            var checkrad = jQuery("#<%=this.RdbOpenType.ClientID %> :radio[checked]").val();
            if (checkrad == 4) {
                $("#spanCourseName").html('套餐');
                $("#showBind").show();
                $("#divide").hide();
            } else {
                 $("#spanCourseName").html('课程');
                $("#showBind").hide();
                $("#divide").show();
            }
            jQuery("#<%=this.TxtSJKey.ClientID %>").val('');
            jQuery("#<%=this.LstB2.ClientID %>").empty('');
            jQuery("#<%=this.LstB1.ClientID %>").empty('');
        }

           
    </script>
    
    <asp:Panel ID="AddPanel" runat="server" Width="100%">
        <div id="manage_top" class="menu_top_fixed">
            <ul class="titleTab">
                <li class="curr"><a href="KS.AddNew.aspx">开通课程</a></li>
                <li><a href="KS.CsStatisticalCourseOrder.aspx">按课程查看订单记录</a></li>
                <li><a href="KS.CsStatisticalUserOrder.aspx">按学生查看订单记录</a></li>
            </ul>
        </div>  
        <div class="menu_top_fixed_height"></div>
        <div class="content-area">
            <div class="clearfix">
                <%if (string.IsNullOrEmpty(username)) { %>
                <table align="center" border="0" cellpadding="0" cellspacing="0" width="40%" class="fl cosOrderTable no-borderTable mt20 md20">
                    <tr>
                        <td colspan="3"><div class="f16 mb" style="height:26px"><font class="greenFont">1.</font>选择用户：</div></td>
                    </tr>
                    <tr>
                        <td style="width:250px" nowrap="nowrap">
                            <input type="text" class="textbox" name="key" id="key" size="15" style="width: 160px" />
                            <input type="button" value="搜索" class="button button_on" onclick="searchUser();" />
                            <br /><br />
                            <select name="user_search" id="user_search" size="10" style="width:250px;height:328px; border-radius:5px;" ondblclick="addUser()" multiple="true"></select>
                        </td>
                        <td style="width:70px">
                            <p style="text-align:center">
                                <input type="button" value=" > " onclick="addUser()" class="button" />
                            </p>
                            <br />
                            <p style="text-align:center">
                                <input type="button" value=" < " onclick="delUser()" class="button" />
                            </p>
                        </td>
                        <td>
                            <div class="Lheight36">指给下列用户：</div>
                            <br />
                            <select id="user" multiple="true" name="user" ondblclick="delUser()" size="10" style="width: 250px;height:328px;border-radius: 5px;">
                            </select>
                        </td>
                    </tr>
               </table>
               <%} else {%>
               <table align="center" border="0" cellpadding="0" cellspacing="0" width="50%" class="fl cosOrderTable no-borderTable mt20 md20">
                    <tr>
                       <td align="right" class="lefttd" height="30">用户名：</td>
                        <td class="righttd"><%=username %>
                            <input name="user" hidden value="<%=username %>" />
                        </td>
                    </tr>
               </table>
               <%} %>
               
               <table align="center" border="0" cellpadding="0" cellspacing="0" width="60%" class="fl cosOrderTable no-borderTable mt20 md20">
                    <tr>
                        <td colspan="3">
                            <div class="f16 mb" style="height:26px">
                                <font class="greenFont">2.</font>要开通的课程名称：
                                <asp:RadioButtonList ID="RdbOpenType" runat="server" RepeatDirection="Horizontal" onclick="showstatus()" CssClass="md20" style="display: inline;vertical-align: middle;">
                                    <asp:ListItem Value="1" Selected="True">点播</asp:ListItem>
                                    <asp:ListItem Value="2">面授</asp:ListItem>
                                    <asp:ListItem Value="3">直播</asp:ListItem>
                                     <asp:ListItem Value="4">套餐</asp:ListItem>
                                </asp:RadioButtonList>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td style="width:312px" nowrap="nowrap">
                            <asp:TextBox ID="TxtSJKey" runat="server" Width="200" CssClass="textbox"/>
                            <input type="button" value="搜索" class="button button_on" onclick="searchCos();"/>
                            <br /><br />
                            <asp:ListBox ID="LstB2" runat="server" SelectionMode="Multiple" style="width:300px;height:328px; border-radius:5px;"></asp:ListBox>
                        </td>
                        <td style="width:100px">
                            <p style="text-align:center">
                                <input type="button" value=" > " onclick="addCos()" class="button" />
                            </p>
                            <br />
                            <p style="text-align:center">
                                <input type="button" value=" < " onclick="delCos()" class="button" />
                            </p>
                        </td>
                        <td>
                            <div class="Lheight36">指定<span id='spanCourseName'>课程</span>如下：</div>
                            <br />
                            <asp:ListBox ID="LstB1" runat="server" Width="280" Height="328" style=" border-radius:5px;" SelectionMode="Multiple"  onclick="selectBind()" ></asp:ListBox>
                        </td>
                        
                         <td id="showBind" style="display:none">
                            <div class="Lheight36">套餐课程如下：</div>
                             <div id="showMustChooseCourse"></div>
                            <br />
                            <asp:ListBox ID="LstBindCouurse" runat="server" Width="280" Height="328" style=" border-radius:5px;" SelectionMode="Multiple"></asp:ListBox>
                        </td>
                    </tr>
                    <tr style="display: none">
                        <td align="right" class="lefttd" height="30">输入课程观看次数
                        </td>
                        <td class="righttd">
                            <asp:TextBox ID="TextBox3" runat="server" Width="64" CssClass="textbox">10</asp:TextBox>
                            次  如10      
                        </td>
                    </tr>
                </table>
                <%if (BaseFun.CheckModulePower("school") || Utils.GetSysInfo("//sysinfo/businessver").Trim().ToLower() != "edu0")
                                                            {%>
                 <table align="center" border="0" cellpadding="0" cellspacing="0" width="100%" class="fl cosOrderTable no-borderTable mt20 md20" id="divide" >
                    <tr>
                        <td colspan="3">
                            <div class="f16 mb" style="height:26px">
                                <font class="greenFont">3.</font>
                                如果是<%if (BaseFun.CheckModulePower("school"))
                                                            { %>机构或<%}%>
                                <%if (Utils.GetSysInfo("//sysinfo/businessver").Trim().ToLower() != "edu0")
                                                            { %>教师
                                <%} %>的课程是否要计算分成：
                                <asp:RadioButtonList ID="RdbIsDivide" runat="server" RepeatDirection="Horizontal"  CssClass="md20" style="display: inline;vertical-align: middle;">
                                    <asp:ListItem Value="1" >是</asp:ListItem>
                                    <asp:ListItem Value="0" Selected="True">否</asp:ListItem>
                                   
                                </asp:RadioButtonList>
                                <span class="tips">如果选择是的话，该<%if (BaseFun.CheckModulePower("school"))
                                                            { %>机构或<%}%>
                                <%if (Utils.GetSysInfo("//sysinfo/businessver").Trim().ToLower() != "edu0")
                                                            { %>教师
                                <%} %>的课程是计算分成。</span>
                            </div>
                        </td>
                    </tr>
                  </table>
                <%} %>
            </div>
            <script type="text/javascript">
                    showtips('<span class="state"><strong>操作说明：</strong><br /></span>只适用于整个订单的开通，例如订单有2个课程，那么开通的话，就会把整个订单都开通的（包括这个订单的所有课程的）， 在此开通的课程根据您所选择的开关如果是属于<%if (Kesion.BLL.BaseFun.CheckModulePower("school")) {%>机构或<%}%> 教师的课程，都是有相应分成,套餐课程是不计算相应分成的，所以请慎重用这个功能的。');
            </script>
            <KS:Foot ID="buttonnext" CancelButtonVisible="false" OnSubmit="buttonnext_Click" runat="server" SubmitButtonText="确定开通" />
        </div>
    </asp:Panel>
    
    <asp:Panel ID="WaitPanel" runat="server" Width="100%" Visible="false">
        <div id="manage_top" class="menu_top_fixed">
            <ul class="titleTab">
                <li class="curr"><a href="KS.AddNew.aspx">开通课程</a></li>
                <li><a href="KS.CsStatisticalCourseOrder.aspx">按课程查看订单记录</a></li>
                <li><a href="KS.CsStatisticalUserOrder.aspx">按学生查看订单记录</a></li>
            </ul>
        </div>
        <div class="menu_top_fixed_height"></div>
        <div class="content-area">
            <div class="myTitle">待开通学员：<%=KSCMS.S("user") %></div>
            <table width="100%" align="center" border="0" cellpadding="1" cellspacing="1" class="CTable">
                <tr class="CTitle"><th style="width:400px;">待开通课程名称</th><th style="text-align: left;">价格(免费开通课程,价格请输入0)</th></tr>
                <%=GetOpenCourse()%>
            </table>
            <input type="hidden" id="cosType" runat="server"  />
            <input type="hidden" id="userNames" name="userNames" value="<%=KSCMS.S("user")%>"/>
            <input type="hidden" id="courseIds" runat="server" />
            <KS:Foot ID="Foot1" runat="server" OnSubmit="Foot1_Submit" />
        </div>
    </asp:Panel>
</asp:Content>
