<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title><!--{$UUDEV_PAGE_TITLE}--></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--{include file=elements/header.css.html}-->
<!--{include file=elements/header.js.html type=common}-->
<!--{include file=elements/header.js.html type=popbox}-->
<!--{include file=elements/header.js.html type=upload}-->
<!--{include file=elements/header.js.html type=valid}-->
<style type="text/css">
div.button {
	font-size:12px;
	color:#00f;
	line-height:22px;
	text-align:center;
	float:left;
	margin-left:5px;
}
div.button.hover{
	color:#f00;
}
.anchorbutton{
	font-size:12px;
	color:#00f;
	text-align:center;
	float:left;
	margin-left:5px;
	cursor:pointer;
}
.typesizeinput{
	width:30px;
}
.anchorinput{
	width:80px;
}
.serialbuttondiv{
	line-height:25px;
	height:25px;
	border-left:#ccc 1px dashed;
	border-right:#ccc 1px dashed;
	border-bottom:#ccc 1px dashed;
}
.anchorbuttonon{
	color:#f00;
}
</style>
</head>
<body>
<div id="outside">
	<!--{include file=frame/top.html}-->
	<div id="mainareaContent">
		<!--{include file=frame/left.html}-->
		<div id="rightContent">
			<div id="topContent">
				<div class="sitmap">
					<span class="r"><!--{include file="elements/uuadvad.html"}--></span>模块管理&nbsp;&gt;&nbsp;音乐模块&nbsp;&gt;&nbsp;内容管理
				</div>
			</div>
			<div class="tabcontent">
				<a href="index.php?r=Music.musiclist" class="nolink">内管管理</a>
				<a href="index.php?r=SiteSet.musicset" class="link">属性设置</a>
				<a href="index.php?r=Music.musicListLayout" class="link">列表页布局</a>
					<a href="index.php?r=Music.musicPageLayout" class="link">内容页布局</a>
				<a href="index.php?r=Music.categorylist" class="link">风格</a>
				<a href="index.php?r=Music.languagelist" class="link">语种</a>
				<a href="index.php?r=Music.singerarealist" class="link">地区</a>
				<a href="index.php?r=Music.singerlist" class="link">歌手</a>
				<a href="index.php?r=Music.albumlist" class="link">专辑</a>
			</div>
			<div id="secrightContent">
				<div class="tableContent2">
					<div class="operation">
						<button type="button" class="but4font" id="li_uploadfile">新增歌曲</button>
						<button type="button" class="but4font" id="li_addurl">新增链接</button>
						<button type="button" class="but4font" id="li_download" onclick="crawlgame('serial')">在线抓取</button>
					</div>
					<input type="hidden" id="input_music_id" value="<!--{$music.id}-->"/>
					<form name="addForm" action="index.php?r=Music.addmusicfile&music_id=<!--{$music_id}-->" method="post">
					<input type="hidden" name="action" value="do"/>
					<input type="hidden" name="returnParams" value="<!--{$returnParams}-->"/>
					<table class="tbl_list" id="tbl_uploadfile" cellpadding="0" cellspacing="0" width="100%" border="0">
						<tr class="thead">
							<td width="20%">说明</td>
							<td width="30%">歌曲下载地址</td>
							<td width="20%">歌词下载地址</td>
							<td width="20%">类型/大小(K)</td>
							<td width="10%">操作</td>
						</tr>
						<!--{foreach from=$datalist item=item name=list}-->
						<tr onMouseOver="chgTrColor(this)" onMouseOut="chgTrColor(this)">
							<td><!--{$item.introduction}--></td>
							<td style="word-break:break-all"><!--{$item.download_url}--></td>
							<td style="word-break:break-all"><!--{$item.lyric_down_url}--></td>
							<td><!--{$item.file_type}-->/<!--{$item.file_size}--></td>
							<td id="td_deletefile<!--{$item.id}-->"><a href="javascript:editMusicFile('<!--{$item.id}-->', '<!--{$filelistReturnParams}-->')">修改</a>
								<a href="javascript:deleteMusicFile('<!--{$item.id}-->')">删除</a></td>
						</tr>
						<!--{/foreach}-->
					</table>
					<div class="submitdiv">
					<button type="button" class="butsubmit" onClick="submitFile()">提交</button>
					<!--{if $backFlag eq 1}-->&nbsp;&nbsp;<button type="button" class="but2font" onClick="window.location.href='index.php?<!--{$returnParams}-->'">返回</button><!--{/if}--></div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<script>
var count = 0;
//新增歌曲
$("#li_uploadfile").click(function(){
	count = count + 1;
	var index = count;
	var str = "<tr>";
	str += "<td><input class=\"anchorinput\" name=\"introduction[]\"/></td>";
	str += "<td class=\"left\"><div style=\"float:left;padding:2px 0 2px 4px;\"><span class=\"red\">*</span><input class=\"anchorinput required\" id=\"download_url"+index+"\" name=\"download_url[]\" readonly/></div><div class=\"button\" id=\"uploadclick"+index+"\" style=\"padding:2px 0 2px 0px;\">上传</div></td>";
	str += "<td class=\"left\"><div style=\"float:left;padding:2px 0 2px 4px;\"><input class=\"anchorinput\" id=\"lyric_down_url"+index+"\" name=\"lyric_down_url[]\" readonly/></div><div class=\"button\" id=\"uploadlyricclick"+index+"\" style=\"padding:2px 0 2px 0px;\">上传</div></td>";
	str += "<td><input class=\"typesizeinput\" id=\"file_type"+index+"\" name=\"file_type[]\" readonly/>&nbsp;";
	str += "<input class=\"typesizeinput\" id=\"file_size"+index+"\" name=\"file_size[]\" readonly/></td>";
	str += "<td><a href=\"#\" id=\"deleteFile"+index+"\">删除</a><input type=\"hidden\" name=\"download_type[]\" value=\"1\"/></td>";
	str += "</tr>";
	$("#tbl_uploadfile").append(str);
	initial();
	//删除事件
	$("#deleteFile"+count).click(function(){
		var tdObj = $(this).parent();
		$(tdObj).html("<img src=\"images/ajax.gif\"/>");
		$(tdObj).parent().remove();
	});
	//歌曲上传事件
	var musicbutton = $("#uploadclick"+index);
	new AjaxUpload($("#uploadclick"+index), {
		action: "index.php?r=Music.uploadmusicfile&music_id="+$("#input_music_id").val(),
		name: "musicfile",
		onSubmit: function(file, ext){
			musicbutton.html('<img src="images/ajax.gif"/>');
			this.disable();
		},
		onComplete: function(file, response){
			musicbutton.html('上传');
			this.enable();
			var data = eval("("+response+")");
			if (data.flag == 1) {
				$("#download_url"+index).val(data.name);
				$("#file_type"+index).val(data.fileext);
				$("#file_size"+index).val(data.size);
			} else if (data.flag == -2) {
				alert("不能上传" + data.fileext + "文件!");
			} else if (data.flag == -3) {
				alert("文件大小超出指定范围!");
			}
		}
	});
	
	//歌词上传事件
	var lyricbutton = $("#uploadlyricclick"+index);
	new AjaxUpload($("#uploadlyricclick"+index), {
		action: "index.php?r=Music.uploadmusicfile&music_id="+$("#input_music_id").val(),
		name: "musicfile",
		onSubmit: function(file, ext){
			lyricbutton.html('<img src="images/ajax.gif"/>');
			this.disable();
		},
		onComplete: function(file, response){
			lyricbutton.html('上传');
			this.enable();
			var data = eval("("+response+")");
			if (data.flag == 1) {
				$("#lyric_down_url"+index).val(data.name);
			} else if (data.flag == -2) {
				alert("不能上传" + data.fileext + "文件!");
			} else if (data.flag == -3) {
				alert("文件大小超出指定范围!");
			}
		}
	});
});

//新增链接
$("#li_addurl").click(function(){
	count = count + 1;
	var index = count;
	var str = "<tr>";
	str += "<td><input class=\"anchorinput\" name=\"introduction[]\"/></td>";
	str += "<td class=\"left\">&nbsp;<span class=\"red\">*</span><input class=\"anchorinput required\" id=\"download_url"+index+"\" name=\"download_url[]\"/></td>";
	str += "<td class=\"left\">&nbsp;<input class=\"anchorinput\" id=\"lyric_down_url"+index+"\" name=\"lyric_down_url[]\"/></td>";
	str += "<td><input class=\"typesizeinput\" id=\"file_type"+index+"\" name=\"file_type[]\"/>&nbsp;";
	str += "<input class=\"typesizeinput\" id=\"file_size"+index+"\" name=\"file_size[]\"/></td>";
	str += "<td><a href=\"#\" id=\"deleteFile"+index+"\">删除</a><input type=\"hidden\" name=\"download_type[]\" value=\"2\"/></td>";
	str += "</tr>";
	$("#tbl_uploadfile").append(str);
	initial();
	//删除事件
	$("#deleteFile"+count).click(function(){
		var tdObj = $(this).parent();
		$(tdObj).html("<img src=\"images/ajax.gif\"/>");
		$(tdObj).parent().remove();
	});
});

//删除
function deleteMusicFile(id){
	if (confirm('删除之后，信息无法恢复，是否确定删除？')) {
		var tdObj = $("#td_deletefile"+id);
		$(tdObj).html("<img src=\"images/ajax.gif\"/>");
		$.get("index.php?r=Music.deletemusicfile&id="+id, function(data){
			if (data == 1) {
				$(tdObj).parent().remove();
			} else {
				alert("删除失败");
			}
		});
	}
}

//修改
function editMusicFile(id, filelistReturnParams){
	$.popbox({title:"修改歌曲文件", content:popstr_search});
	$.ajax({
		type: "get",
		url: "index.php?r=Music.editmusicfile",
		data: {
			id: id,
			filelistReturnParams: filelistReturnParams
		},
		cache: false,
		success: function(data){
			$.popbox.setcontent({title:"修改歌曲文件", content:data, height:260});
		}
	});
}

//提交
function submitFile(){
	var flag = 1;
	$(".required").each(function(){
		if (!$(this).val()) {
			flag = 0;
		}
	});
	
	if (flag == 1) {
		document.forms['addForm'].submit();
	} else {
		alert("输入有误，红色*处为必填内容！");
	}
}


//在线抓取
function crawlgame(type){
	var str = "<table class=\"tbl_edit\" width=\"100%\"><tr><td>输入MP3地址</td></tr></table>";
	str += "<table id=\"tbl_crawlurl\" class=\"tbl_edit\" width=\"100%\"><tr><td><input type=\"text\" class=\"text\" name=\"url[]\"/></td></tr></table>";
	str += "<table class=\"tbl_edit\" width=\"100%\"><tr>";
	str += "<td class=\"noborder\"><button type=\"button\" class=\"but4font\" id=\"addcrawlbtn\">增加地址</button>&nbsp;&nbsp;<button type=\"button\" class=\"but2font\" id=\"crawlbtn\">抓取</button></td>";
	str += "</tr></table>";
	$.popbox({title:"在线抓取", content:str, height:300});
	$("#addcrawlbtn").click(function(){
		//if ($("input:text[name=url[]]").size() < 5) {
			$("#tbl_crawlurl").append("<tr><td><input type=\"text\" class=\"text\" name=\"url[]\"/></td></tr>");
		//} else {
		//	alert("一次最多只能抓取5个游戏包！");
		//}
	});
	$("#crawlbtn").click(function(){
		if ($(this).text() == "重新抓取") {
			$(this).attr("class", "but2font").text("抓取");
			$("#tbl_crawlurl").html("<tr><td><input type=\"text\" class=\"text\" name=\"url[]\"/></td></tr>");
			$("#addcrawlbtn").attr("disabled", false);
		} else {
			$("input:text[name=url[]]").each(function(){
				var remoteurl = $(this).val();
				var tdobj = $(this).parent();
				if (remoteurl != "") {
					tdobj.html("抓取"+remoteurl+"<img src=\"images/spinner.gif\"/>正在抓取...");
					$.ajax({
						type: "get",
						url: "index.php?r=Music.crawl",
						cache: false,
						data: {
							url: remoteurl,
							music_id: function(){
								return $("#input_music_id").val();
							}
						},
						dataType: "json",
						success: function(data){
							//alert(data.status );
							if (data.status == 1) {
								count++;
										var index = count;
										var str = "<tr>";
	str += "<td><input class=\"anchorinput\" name=\"introduction[]\"/></td>";
	str += "<td class=\"left\">&nbsp;<span class=\"red\">*</span><input class=\"anchorinput required\" style=\"width:80%;\" id=\"download_url"+index+"\" name=\"download_url[]\" value=\""+data.file.download_url+"\"/></td>";
	str += "<td class=\"left\">&nbsp;<input class=\"anchorinput\" id=\"lyric_down_url"+index+"\" name=\"lyric_down_url[]\"/></td>";
	str += "<td><input class=\"typesizeinput\" id=\"file_type"+index+"\" name=\"file_type[]\" value=\""+data.file.file_type+"\"/>&nbsp;";
	str += "<input class=\"typesizeinput\" id=\"file_size"+index+"\" name=\"file_size[]\" value=\""+data.file.file_size+"\"/></td>";
	str += "<td><a href=\"#\" id=\"deleteFile"+index+"\">删除</a><input type=\"hidden\" name=\"download_type[]\" value=\"1\"/></td>";
	str += "</tr>";
	$("#tbl_uploadfile").append(str);
										$("#deleteFile" + index).click(function(){
											$(this).parent().parent().remove();
										});
								
								tdobj.html("抓取"+remoteurl+"成功！");
							} else {
								tdobj.html("抓取"+remoteurl+"失败！");
							}
						}
					});
				} else {
					tdobj.html("没有输入地址...");
				}
			});
			$("#addcrawlbtn").attr("disabled", true);
			$(this).attr("class", "but4font").text("重新抓取");
		}
	});
}

</script>
</html>