<%@ 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.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.RadioButtonList2.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 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() {

            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="50%" 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:312px" nowrap="nowrap">
                            <input type="text" class="textbox" name="key" id="key" size="15" style="width: 200px" />
                            <input type="button" value="选择用户" class="button button_on" onclick="searchUser();" />
                            <br /><br />
                            <select name="user_search" id="user_search" size="10" style="width:312px;height:328px; border-radius:5px;" ondblclick="addUser()" multiple="true"></select>
                        </td>
                        <td style="width:100px">
                            <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: 312px;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="50%" 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="RadioButtonList2" 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:312px;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">指定课程如下：</div>
                            <br />
                            <asp:ListBox ID="LstB1" runat="server" Width="312" 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>
            </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>
