<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh" xml:lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset={$_SET['def_charset']}">
<title>上传程序</title>
<link href="{AW_P}images/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="{WW_P}images/js/qmecms.js"></script>
<script type="text/javascript" src="{AW_P}images/js/upload/swfupload.js"></script>
<script type="text/javascript" src="{AW_P}images/js/upload/handlers.js"></script>
<script type="text/javascript">
	var swfu;
	var linkurl = "{$action_url}";
	var file_type = '{$file_type}';
	var keepName = {$keepName};
	var thumb = {$thumb};
	var bts = {$bts};
	var allowUploadFileType = {$allowUploadFileType};
	var uploadType = {$type};
	var reloadSwf = function(){
		if($('forKeepName').checked == true) keepName = 1;
		else keepName = 0;
		if($('forThumb').checked == true) thumb = 1;
		else thumb = 0;
		if($('forThumb').checked == true){
			$('set-wh').style.display = '';
		}else{
			$('set-wh').style.display = 'none';
		}
		var w = parseInt($('f-width').value.trim());
		var h = parseInt($('f-height').value.trim());
		if(isNaN(w) || isNaN(h) || w < 1 || h < 1){
			w = h = 0;
		}
		var url = linkurl + '&keepName='+keepName.toString()+'&thumb='+thumb.toString()+"&width="+w+"&height="+h;
		swfu.setUploadURL(url);
	}
	var loadSwf = function() {
		var url = linkurl + '&keepName='+keepName+'&thumb='+thumb;
		$('forKeepName').checked = keepName ? true : false;
		$('forThumb').checked = thumb ? true : false;
		if($('forThumb').checked == true){
			$('set-wh').style.display = '';
		}else{
			$('set-wh').style.display = 'none';
		}
		if($('forKeepName').checked== true){
			$('for-pic').parentNode.style.display = '';
		}
		if(file_type.toLowerCase() != 'image') $('for-pic').style.display = 'none';
		if(allowUploadFileType == 0) return document.body.innerHTML = "<p>当前频道下不能上传媒体文件</p><p>你可以更改当前频道里的上传文件设置</p>";
		if(uploadType) $('tips').innerHTML = '可以使用Ctrl或者Shift键一次选中多个文件批量上传';
		var settings = {
			flash_url : "images/js/upload/swfupload.swf",
			upload_url: url,
			post_params: {"channelid": "{$channelid}", "targetDir":"{$dir}","adminSession":"<!--{eval echo urlencode($_COOKIE['admin_auth']);}-->"},
			file_size_limit : "{$max_file_size} KB",
			file_types : "<!--{eval echo implode(';', $allowUploadExtFlash);}-->",
			file_types_description : "选择文件",
			file_upload_limit : "0",
			button_action: uploadType ? SWFUpload.BUTTON_ACTION.SELECT_FILES : SWFUpload.BUTTON_ACTION.SELECT_FILE,

			file_queue_limit : 0,
			debug: false,

			// Button settings
			button_image_url: "{AW_P}images/TestImageNoText_65x29.png",
			button_width: "55",
			button_height: "27",
			button_placeholder_id: "form",
			button_text: "<span class=\"theFont\"> 添加</span>",
			button_text_style: ".theFont { font-size: 14; }",
			button_text_left_padding: 12,
			button_text_top_padding: 3,

			upload_progress_handler:function(file, bytesLoaded, bytesTotal){
				var obj = $(file.id);
				if(obj == null){
					obj = createUpload(file);
				}
				var len = bytesLoaded/bytesTotal;
				$(file.id+'_loading').style.width = len * 100 + '%';
				obj.cells[2].innerHTML = parseInt(len * 100) + '%';
				if(len >= 1) obj.cells[3].innerHTML = '处理中';
			},
			file_dialog_complete_handler : fileDialogComplete,
			file_queue_error_handler : fileQueueError,
			upload_success_handler : function(file, serverData){
				var obj = $(file.id);
				var json = evaljson(serverData);
				if(typeof json == 'undefined' || typeof json['status'] == 'undefined'){
					obj.cells[1].innerHTML = '系统出现了点问题，或者文件太大了';
					obj.cells[2].innerHTML = '<span class="error"></span>';
					obj.cells[3].innerHTML = '';
					if(serverData.indexOf('Fatal error') > -1 && serverData.indexOf('Allowed memory size') > -1){
						alert("php.ini 限制使用的内存太小，不够使用");
					}
					alert(serverData);
					return false;
				}
				if(json.status == 200){
					if(file_type.toLowerCase() == 'image'){
						var img = json.msg[1] || json.msg[0];
						obj.cells[0].innerHTML = "<img src='"+parent.config.url+img+"' class='preview-img' />";
					}
					obj.cells[2].innerHTML = '<span class="succ"></span>';
					obj.cells[3].innerHTML = '完成';
					if(fck){
						var o = parent.document.getElementsByTagName('iframe');
						for(var i=0;i<o.length;i++){
							if(o[i].src.indexOf('fckdialog.html') > -1){
								var obb = o[i].contentWindow.document.getElementById('frmMain').contentWindow.document.getElementById(id);
								if(obb != null){
									obb.value =  json.msg[0];
									if(typeof obb.onchange == 'function') obb.onchange();
								}
								break;
							}
						}
					}else{
						if(javascript){
							var call;
							if(javascript != null){
								eval("call=parent."+javascript);
							}
							if(typeof call == 'function'){
								call(json.msg, id);
							}else{
								parent.document.getElementById(id).value = json.msg[0];
							}
						}else{
							parent.document.getElementById(id).value = json.msg[0];
						}
					}
					if(!uploadType) parent.qmeCms.dialogView.close(1000);
				}else{
					obj.cells[1].innerHTML = (typeof parent.swfuploadLanguage == 'undefined' || typeof parent.swfuploadLanguage[json.msg] == 'undefined') ? json.msg : parent.swfuploadLanguage[json.msg];
					obj.cells[2].innerHTML = '<span class="error"></span>';
					obj.cells[3].innerHTML = '';
				}
			},
			upload_complete_handler : uploadComplete,
			queue_complete_handler : queueComplete
		};
		swfu = new SWFUpload(settings);
		setTimeout(function(){parent.qmeCms.dialogView.reHeight();}, 500);
	 };
	 window.onload = function(){
		 parent.qmeCms.dialogView.iframeOnload();
		 loadSwf();
	 }
</script>
<script language=javascript>
var id         = "{$file_id}";
var channelid  = "{$channelid}";
var javascript = "{$javascript}";
var type       = "{$type}";
var fck       = {$fck};
</script>
<style type="text/css">
	html{overflow:hidden}
	body {font-size: 12px;background:#F5F5F5 }
	input {FONT-SIZE: 12px;}
	table {border-collapse:collapse;border-spacing:0;text-align:left;}
	th,td {border-collapse:collapse;}
	.upload{border-top:1px solid #dedede;color:#666666}
	.upload td{padding:5px;height:29px;border-bottom:1px solid #dedede}
	.upload td.icon{width:52px;}
	.upload td.loading{width:310px;}
	.upload td.loading-num{width:31px;}
	.upload td.status{width:42px;}
	.upload div.loading, .upload div.name-box, .upload div.name{height:29px;line-height:29px;}
	.upload div.loading{width:0px;background:red;position:absolute;left:0;top:0}
	.upload div.box{height:29px}
	.upload div.name{position:absolute;left:0;top:0}
	.upload div.name-box{position:relative;text-align:left;width:100%;background:#dedede;overflow:hidden}
	.upload div.name-box span{padding-left:10px;}
	.upload div.preview{background-color:#EBEBEB;border:1px solid #FFFFFF;height:27px;width:45px;}
	.preview-img{width:41px;height:23px;padding:2px;background-color:#EBEBEB;}
	span.error{width:20px;height:17px;display:block;background:url({AW_P}images/icons-upload.png) no-repeat 0 0}
	span.succ{width:20px;height:17px;display:block;background:url({AW_P}images/icons-upload.png) no-repeat 0 -17px}
	.item{float:left;line-height:28px;width:100%;height:28px;}
	.item *{float:left;}
	.item input{margin-top:8px;*margin-top:3px;}
	.item input.f-text-input{margin-top:5px;margin-right:10px;}
	#tips{color:green}
</style>
</head>
<body>
<div style="background:url({AW_P}images/upload_list_bg.png) repeat-y 0 0;" id="upload"></div>
<div style="width:100%;padding:10px 0 10px 0;">
	<div class="item" id="form_parent"><span id="form">程序初始化...</span></div>
	<div class="item nw" <!--{if $close_thumb}-->style="display:none"<!--{/if}-->>
		<div id="for-pic">
			<input onclick="reloadSwf();" type="checkbox" id="forThumb" />
			<label for="forThumb" style="margin-right:10px;">按频道设置缩放</label>
			<div id="set-wh" style="display:none;">
				<label>宽：</label><input id="f-width" onchange="reloadSwf()" class="f-text-input" type="text" value="{$pic_width}" size="5" />
				<label>高：</label><input id="f-height" onchange="reloadSwf()" class="f-text-input" type="text" value="{$pic_height}" size="5" />
			</div>
		</div>
		<input onclick="reloadSwf();" type="checkbox" id="forKeepName" />
		<label for="forKeepName">保持文件名不变</label>
	</div>
	<div style="clear:both;color:#999">缩放的意思是把上传的图片缩小或放大，并非是再生成一张图</div>
	<div style="color:blue">允许的文件类型：<!--{echo str_replace('*.', ' ', implode('，', $allowUploadExtFlash))}--></div>
	<div id="tips" style="clear:both;"></div>
</div>
</body>
</html>