<include file="__THEME__/admin_header" />
<!-- upload video by dengjb 2014/4/14 -->
<?php 
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
include '__APP__/spark_config.php';?>
<style type="text/css">
.fla_btn {
	position: relative;
}
.fla_btn embed {
	position: absolute;
	z-index: 1;
}
#swfDiv{*position:absolute; z-index:2;}
</style>
<script type="text/javascript" src="__APP__/js/swfobject.js"></script>
<body>
<h1>创建视频同步至CC</h1>
<hr />
<form id="addvform" name="addvform" action="" method="get" onsubmit="alert('提交视频');">
<div class="fla_btn">
<span style="float:left;">
选择视频：<input id="videofile" name="videofile" type="text" />
</span> 
<div style="float:left; position:relative; width:80px; height:25px;">
	<div id="swfDiv" style="width:80px;height:25px;position:absolute;z-index:2;"></div>
	<input type="button" value="upload"	id="btn_width" style="width:80px;height:25px;position:absolute;z-index:1;" />
</div>
<div style="clear:both;">视频标题：<input id="title" name="title" type="text" /></div> 
<div>视频标签：<input id="tag" name="tag" type="text" /></div> 
<div>视频简介：<textarea id="description" name="description" rows="5" cols="30"></textarea></div> 
<input id="videoid" name="videoid" type="hidden" value="" /> 
<div><input type="button" value="提交" onclick="submitvideo();"></div> 
<br />
<hr />
<div><span id="up" style="color:red;"></span></div>
</form>
<br />
<div style="color: red;" id="delete_result"></div>
<div class="so_main">
    <div class="Toolbar_inbox"></div>
    <div class="list">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <th class="line_l">ID</th>
            <th class="line_l">视频ID</th>    
            <th class="line_l">视频截图</th>
            <th class="line_l">视频状态</th>
			<th class="line_l">创建时间</th>
            <th class="line_l">操作</th>
        </tr>
        {eqxue{if(empty($list['data'])) {?}
        <tr>
            <td>{:L('PUBLIC_NO_MORE')}{$value['name']}</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        {eqxue{}else{?}
        <volist id="vo" name="list['data']">
        <tr overstyle='on' id="{$vo['name']}">
            <td>{$vo['id']}</td>
            <td>{$vo['videoid']}</td>
			<td><img src="{$vo['imgurl']}" width="80px" height="60px"/></td>
            <td>{eqxue{if($vo['vstatus']==0){?}未审核{eqxue{}else if($vo['vstatus']==1){?}已通过{eqxue{}else if($vo['vstatus']==2){?}已驳回{eqxue{}?}</td>
            <td>{$vo['utime']|date="Y-m-d H:i:s",###}</td>
			<td><a href="api/cc/video_edit.php?userid=C27F610DD5DEF22B&videoid={$vo['videoid']}"">编辑</a> | <a href="#" onclick="deletevideo('{$vo['videoid']}');">删除</a> | <a href="api/cc/play.php?userid=C27F610DD5DEF22B&videoid={$vo['videoid']}">播放</a></td>
        </tr>
        </volist>
		{eqxue{}?}
    </table>
    </div>
	<div class="page">{$list.html}</div>
    <div class="Toolbar_inbox"></div>
</div>

<script type="text/javascript">

// 加载上传flash ------------- start
var swfobj=new SWFObject('http://union.bokecc.com/flash/api/uploader.swf', 'uploadswf', '80', '25', '8');
swfobj.addVariable( "progress_interval" , 1);	//	上传进度通知间隔时长（单位：s）
var notify_url = "<?php echo 'http://'.$_SERVER['HTTP_HOST'].'/api/cc/notify.php';?>";
swfobj.addVariable( "notify_url" , notify_url);	//	上传视频后回调接口
swfobj.addParam('allowFullscreen','true');
swfobj.addParam('allowScriptAccess','always');
swfobj.addParam('wmode','transparent');
swfobj.write('swfDiv');
var notify = "<?php echo U('admin/Video/doAdd')?>";
// 加载上传flash ------------- end

//-------------------
//调用者：flash
//功能：选中上传文件，获取文件名函数
//时间：2014-4-14
//说明：用户可以加入相应逻辑
//-------------------
function on_spark_selected_file(filename) {
	document.getElementById("videofile").value = filename;
}

//-------------------
//调用者：flash
//功能：验证上传是否正常进行函数
//时间：2014-4-14
//说明：用户可以加入相应逻辑
//-------------------
function on_spark_upload_validated(status, videoid) {
	if (status == "OK") {
		//alert("上传正常,videoid:" + videoid);
		document.getElementById("videoid").value = videoid;
		document.getElementById("videoidshow").innerHTML = videoid;
	} else if (status == "NETWORK_ERROR") {
		alert("网络错误");
	} else {
		alert("api错误码：" + status);
	}
}

//-------------------
//调用者：flash
//功能：通知上传进度函数
//时间：2014-4-14
//说明：用户可以加入相应逻辑
//-------------------
function on_spark_upload_progress(progress) {
	var uploadProgress = document.getElementById("up");
	if (progress == -1) {
		uploadProgress.innerHTML = "上传出错：" + progress;
	} else if (progress == 100) {
		uploadProgress.innerHTML = "进度：100% 上传完成";
	} else {
		uploadProgress.innerHTML = "进度：" + progress + "%";
	}
}

function positionUploadSWF() {
	document.getElementById("swfDiv").style.width = document
			.getElementById("btn_width").style.width;
	document.getElementById("swfDiv").style.height = document
			.getElementById("btn_width").style.height;
}
//提交创建视频 - dengjb - 20140416
function submitvideo() {
	var videofile = document.getElementById("videofile").value;
	var title = encodeURIComponent(document.getElementById("title").value, "utf-8");
	var tag = encodeURIComponent(document.getElementById("tag").value, "utf-8");
	var description = encodeURIComponent(document.getElementById("description").value, "utf-8");
	if(videofile == ''){
		alert('还没选择上传视频文件!');
		return false;
	}
	if(title == ''){
		alert('视频标题不为空!');
		return false;
	}
	if(tag == ''){
		alert('视频标签不为空!');
		return false;
	}
	if(description == ''){
		alert('视频描述不为空!');
		return false;
	}
	var url = "api/cc/getuploadurl.php?title=" + title + "&tag=" + tag
			+ "&description=" + description;
	var req = getAjax();
	 
	req.open("GET", url, true);
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			if (req.status == 200) {
				var re = req.responseText;//获取返回的内容
				document.getElementById("uploadswf").start_upload(re); //	调用flash上传函数
				document.getElementById("request_params").innerHTML = re;
			}
		}
	};
	req.send(null);
}

//视频播放 - dengjb - 21040418
function play(videoid){
	var userid = 'C27F610DD5DEF22B';
	alert(videoid);
	var url = "api/cc/play.php?userid=" + userid + "&videoid=" + videoid;
	var req = getAjax();
	 
	req.open("GET", url, true);
}
//删除视频 - dengjb - 20140418
function deletevideo(videoId) {
			var url = "api/cc/video_del.php?videoid=" + videoId;
			var req = getAjax();
			req.open("GET", url, true);
			req.onreadystatechange = function(videoId) {
				if (req.readyState == 4) {
					if (req.status == 200) {
						var re = req.responseText;//获取返回的内容
						document.getElementById("delete_result").innerHTML = re;
					}
				}
			};
			req.send(null);
}
//异步请求 - dengjb - 20140416
function getAjax() {
	var oHttpReq = null;

	if (window.XMLHttpRequest) {
		oHttpReq = new XMLHttpRequest;
		if (oHttpReq.overrideMimeType) {
			oHttpReq.overrideMimeType("text/xml");
		}
	} else if (window.ActiveXObject) {
		try {
			oHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			oHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
	} else if (window.createRequest) {
		oHttpReq = window.createRequest();
	} else {
		oHttpReq = new XMLHttpRequest();
	}

	return oHttpReq;
}
</script>
</body>
</html>

<include file="__THEME__/admin_footer" />