<%@ Page Language="C#" AutoEventWireup="true" Inherits="Kesion.NET.WebSite.Admin.Course.KS_CosVideoAdvertiseAdd" Codebehind="KS.CosVideoAdvertiseAdd.aspx.cs" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="/admin/images/style.css" rel="stylesheet" type="text/css" />
    <script src="../../admin/images/pannel/tabpane.js" type="text/javascript"></script>
    <link href="/admin/images/pannel/tabpane.CSS" rel="stylesheet" type="text/css" />
    <script src="/KS_Inc/jQuery.js"></script>
    <script src="/KS_Inc/Kesion.Common.js"></script>
    <script src="/KS_Inc/DatePicker/WdatePicker.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            clickadvertisetype();
        });
        function clickadvertisetype() {
            var location = document.getElementById('AdvertiseType').value;//广告类型
            if (location != '2') {
                $("#displaysize").show();
            } else {
                $("#displaysize").hide();
            }
        }
        function postVideo() {
             var advertseId='<%=id%>';
            var title = $('#TxtTitle').val();
            var note =  $('#TxtNote').val();
            var startDate = $('#startdate').val();
            var endDate = $('#enddate').val();
            var ptime = '<%=ptime%>';
            var cataid = document.getElementById('myCataid').value;//类型
            var location = document.getElementById('AdvertiseType').value;//广告类型:1片头，2暂停，3片尾
             var size = $('#TxtSize').val();
             var status =document.getElementById('status').value;
             var fileObj = document.getElementById("Filedata").files[0] || {name:''};
             var videotype =document.getElementById('VideoType').value;

            if (cataid == '0') {
                cataid = '1';
            }
            if (title == '') {
                KesionJS.Alert("请输入广告名称！", "jQuery('#TxtTitle').focus()");
                return false;
            }
          if (fileObj.name == '') {
                KesionJS.Alert("请上传广告素材！", "jQuery('#Filedata').focus()");
                return false;
            }
            if (size == '' && location!='2') {
                KesionJS.Alert("请输入广告时长！", "jQuery('#TxtSize').focus()");
                return false;
            }
              if (parseInt(size)<=0&& location!='2') {
                KesionJS.Alert("请输入合法的广告时长！", "jQuery('#TxtSize').focus()");
                return false;
            }
          

            $.ajax({
                url: "KS.CosVideoAdvertiseAdd.aspx?action=getsign&id=<%=id%>&ptime=" + ptime + "&title=" + title + "&size=" + size+"&cataid="+cataid+"&status="+status+"&location="+location+"&startdate="+startDate+"&enddate="+endDate+"&rnd=" + Math.random(),
                context: document.body,
                type: "get",
                success: function (data) {
                    //cataids=1&endDate=2018-12-05&location=1&ptime=1543913032245&size=33&startDate=2018-12-04&status=10&title=vvbbbhH7nNwNQ5N
                    var form = new FormData();
                  
                     var url='http://api.polyv.net/v2/advertising/<%=userId%>/create';
                      if(advertseId!='0')
                      {
                       form.append("adid", '<%=adid %>');
                       url='http://api.polyv.net/v2/advertising/<%=userId%>/edit';
                      }
                    form.append("cataids", cataid);
                    form.append("endDate", endDate);
                    form.append("file", fileObj);
                    form.append("location", parseInt(location));
                    form.append("ptime", ptime);
                    if (location != '2') {
                        form.append("size", size);
                    }
                    form.append("startDate", startDate);
                    form.append("status", parseInt(status));
                    form.append("sign", data);
                    form.append("title", title);
                    var xhr = new XMLHttpRequest();
                     $("#Loading").show();
                    xhr.open("post", url, true);
                    xhr.onload = function () {

                        var jsonObject = JSON.parse(xhr.response);
                       //alert(jsonObject.code);
                        if (jsonObject.code == 200) {
                            $("#Loading").hide();
                            $.ajax({
                                url: "KS.CosVideoAdvertiseAdd.aspx?action=getadd&data="+jsonObject.data+"&id="+advertseId+"&videotype=" + videotype + "&title=" + title + "&cataid=" + cataid + "&size=" + size + "&status=" + status + "&advertisetype=" + location + "&startdate=" + startDate+ "&enddate=" + endDate + "&file="+fileObj.name+"&rnd=" + Math.random(),
                                  context: document.body,
                                  type: "get",
                                 success: function (data) {
                                    //alert(data);
                                      if (data == 'ok') { 
                                           KesionJS.Alert("恭喜，<%=id==0?"添加":"修改"%>视频广告成功", "location.href='Course/KS.CosVideoAdvertiseManage.aspx';");
                                         
                                      }else{
                                        KesionJS.Alert("对不起，<%=id==0?"添加":"修改"%>视频广告失败:"+data, "location.href='Course/KS.CosVideoAdvertiseAdd.aspx';");
                                         
                                     }
                                  }
                              });
                        }
                        else {
                            $("#Loading").hide();
                            alert(jsonObject.message);
                        }

                    };
                    xhr.send(form);
                }
            });
        }
    </script>
</head>
<body>
    <div class="content-area mt20">
        <div class="myTitle">添加视频广告</div>
        <form id="Formvideo" enctype="multipart/form-data" method="post">

            <div class="prompt_bg" style="display: none" id="Loading">
                <div class="prompt_box">
                    <p>
                        <img src="/admin/images/loading.gif" />正在上传，因为文件有点大，可能有点卡，请勿刷新，请耐心等待...
                    </p>
                </div>
            </div>
            <table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" class="CTable no-borderTable">

                <tr>
                    <td align="right" class="lefttd" height="30">播放器类型</td>
                    <td class="righttd">
                        <%=GetPlayType(playVideoType) %>
                      
                    </td>
                </tr>
                <tr>
                    <td align="right" class="lefttd" height="30"><font color="red">*</font>广告名称</td>
                    <td class="righttd">
                        <input id="TxtTitle" name="TxtTitle" type="text" placeholder="请输入广告名称" value="<%=title %>" />
                    </td>
                </tr>

                <tr>
                    <td align="right" class="lefttd" height="30"><font color="red">*</font>广告素材</td>
                    <td class="righttd">文件:<input type="file" name="Filedata" id="Filedata"  value="<%=advertiseMaterial%>"/><br>
                        <span class="tips">片头、片尾广告素材支持：JPEG,GIF,PNG,FLV,MP4;暂停广告支持：SWF,PNG,JPEG,GIF;</span>
                    </td>
                </tr>

                <tr>
                    <td align="right" class="lefttd" height="30">类型</td>
                    <td class="righttd">
                        <%=GetAdvertiseType(advertiseType) %>
                      
                    </td>
                </tr>
                <tr style="display: none">
                    <td align="right" class="lefttd" height="30">内容分类</td>
                    <td class="righttd">
                        <select id="myCataid" name="myCataid">
                            <option value="0">--选择视频分类--</option>

                        </select>

                    </td>
                </tr>
                <tr style="display: none" id="displaysize">
                    <td align="right" class="lefttd" height="30"><font color="red">*</font>广告时长(s)</td>
                    <td class="righttd">
                        <input id="TxtSize" name="TxtSize" type="text" placeholder="请输入广告时长(s)" value="<%=size%>" />
                        <span class="tips">以秒为单位</span>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="lefttd" height="30"><font color="red">*</font>投放起止日期</td>
                    <td class="righttd">
                        <input type="text" value="<%=startDate %>" class="textbox Wdate" id="startdate" name="startdate" onclick="WdatePicker({dateFmt:&#39;yyyy-MM-dd&#39;});" />
                        ~
                       <input type="text" value="<%=endDate %>" class="textbox Wdate" id="enddate" name="enddate" onclick="WdatePicker({dateFmt:&#39;yyyy-MM-dd&#39;});" />
                    </td>
                </tr>

                <tr>
                    <td align="right" class="lefttd" height="30">状态</td>
                    <td class="righttd">
                        <%=GetStatus(status) %>
                    </td>
                </tr>
            </table>
        </form>
        <div class="main-button">
            <input type="button" onclick="postVideo();" class="button" value="确定上传">
        </div>
        <script type="text/javascript">
            showtips('<span class="state"><strong>说明：本接口只支持保利威视基础版本以上的套餐，其他接口请等待开发，如果出现ptime is too old这个问题，是当前时间与北京时间的时间差超过3分钟。</strong><br /></span>');
		</script>
    </div>
      
</body>
</html>

