<?php die;?><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-cn" />
<title><!--{$smarty.const.MICE_TITLE}--></title>
<base href="<!--{$smarty.const.MICE_URL}--><!--{$smarty.const.MICE_TPL}-->/admin/" />
<link href="css/Default.css" rel="stylesheet" type="text/css" />
<script language="JavaScript">
var baseurl = '<!--{$smarty.const.MICE_URL}--><!--{$smarty.const.MICE_TPL}-->/admin/';
//alert(<!--{$filecategoryid}-->);
</script>
<script type="text/javascript" src="js/Main.js"></script>
<script language="javascript"> 
  function copyToClipboard(txt) {
      if(window.clipboardData) {
              window.clipboardData.clearData();   
              window.clipboardData.setData("Text", txt);   
			  alert(txt+"\n文件地址复制成功");
      } else if(navigator.userAgent.indexOf("Opera") != -1) {
           alert("您所用的浏览器暂不支持JS复制功能\n请直接复制文本框中的内容");   
      } else if (window.netscape) {   
           try {   
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");   
           } catch (e) {   
                alert("被浏览器拒绝！\n请直接复制文本框内的内容\n或\n在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");   
           }   
           var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);   
           if (!clip)   
                return;   
           var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);   
           if (!trans)   
                return;   
           trans.addDataFlavor('text/unicode');   
           var str = new Object();   
           var len = new Object();   
           var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);   
           var copytext = txt;   
           str.data = copytext;   
           trans.setTransferData("text/unicode",str,copytext.length*2);   
           var clipid = Components.interfaces.nsIClipboard;   
           if (!clip)   
                return false;   
           clip.setData(trans,null,clipid.kGlobalClipboard);   
           alert("复制成功\n"+txt);
      }
 }
</script>
<style>
.fu_list {
	width:420px;
	background:#fff;
	font-size:12px;
}
.fu_list td {
	padding:5px;
	line-height:20px;
	background-color:#fff;
}
.fu_list table {
	width:100%;
	border:1px solid #ebebeb;
}
.fu_list thead td {
	background-color:#f4f4f4;
}
.fu_list b {
	font-size:14px;
}
/*file容器样式*/
a.files {
	width:120px;
	height:30px;
	overflow:hidden;
	display:block;
	border:1px solid #BEBEBE;
	background:url(imgs/fu_btn.gif) left top no-repeat;
	text-decoration:none;
}
a.files:hover {
	background-color:#FFFFEE;
	background-position:0 -30px;
}
/*file设为透明，并覆盖整个触发面*/
a.files input {
	margin-left:-350px;
	font-size:30px;
	cursor:pointer;
	filter:alpha(opacity=0);
	opacity:0;
}
/*取消点击时的虚线框*/
a.files, a.files input {
	outline:none;/*ff*/
	hide-focus:expression(this.hideFocus=true);/*ie*/
}
</style>
</head>
<body>
  <table border="0" cellspacing="1" class="fu_list" align="center">
    <tbody>
	<script>document.write(unescape('%3Ciframe id="form1post" name="form1post" width="0" height="0" src="" %3E%3C/iframe%3E'))</script>
	<form id="uploadForm" action="<!--{$formaction}-->" target="form1post">
		<input name="inputsize" type="hidden" value="35">
      <tr>
        <td align="center"><a href="javascript:void(0);" class="files" id="idFile"></a> <img id="idProcess" style="display:none;" src="imgs/loading.gif"  /></td>
      </tr>
      <tr>
        <td>
		  <table border="0" cellspacing="0">
            <tbody id="idFileList">
            </tbody>
          </table>
		</td>
      </tr>
      <tr>
        <td colspan="2"  style="word-wrap:break-word;word-break:break-all;color:gray;">1、一次可同时上传10个文件;<br>2、单个文件最大<!--{$filesize}-->K;<br>3、文件类型<!--{$fileexts}--></td>
      </tr>
      <tr>
        <td colspan="2" align="center" id="idMsg"><input type="button" value="上传" id="idBtnupload" disabled="disabled" />&nbsp;<input type="button" value="取消" id="idBtndel" disabled="disabled" />
        </td>
      </tr>
	  <tr>
        <td colspan="2" style="color:gray"><a href="<!--{$smarty.const.MICE_URL}-->admin.php/mimgs/updatelist">查看以前上传的文件</a><br>上传成功的文件:<br><span id="idFileSuccess"></span></td>
      </tr>
	  </form>
    </tbody>
  </table>
<script type="text/javascript">

var isIE = (document.all) ? true : false;

var $ = function (id) {
    return "string" == typeof id ? document.getElementById(id) : id;
};

var Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}

var Extend = function(destination, source) {
	for (var property in source) {
		destination[property] = source[property];
	}
}

var Bind = function(object, fun) {
	return function() {
		return fun.apply(object, arguments);
	}
}

var Each = function(list, fun){
	for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
};

//文件上传类
var FileUpload = Class.create();
FileUpload.prototype = {
  //表单对象，文件控件存放空间
  initialize: function(form, folder, options) {
	
	this.Form = $(form);//表单
	this.Folder = $(folder);//文件控件存放空间
	this.Files = [];//文件集合
	
	this.SetOptions(options);
	
	this.FileName = this.options.FileName;
	this._FrameName = this.options.FrameName;
	this.Limit = this.options.Limit;
	this.Distinct = !!this.options.Distinct;
	this.ExtIn = this.options.ExtIn;
	this.ExtOut = this.options.ExtOut;
	
	this.onIniFile = this.options.onIniFile;
	this.onEmpty = this.options.onEmpty;
	this.onNotExtIn = this.options.onNotExtIn;
	this.onExtOut = this.options.onExtOut;
	this.onLimite = this.options.onLimite;
	this.onFail = this.options.onFail;
	this.onIni = this.options.onIni;
	
	if(!this._FrameName){
		//为每个实例创建不同的iframe
		this._FrameName = "uploadFrame_" + Math.floor(Math.random() * 1000);
		//ie不能修改iframe的name
		var oFrame = isIE ? document.createElement("<iframe name=\"" + this._FrameName + "\">") : document.createElement("iframe");
		//为ff设置name
		oFrame.name = this._FrameName;
		oFrame.style.display = "none";
		//在ie文档未加载完用appendChild会报错
		document.body.insertBefore(oFrame, document.body.childNodes[0]);
	}
	
	//设置form属性，关键是target要指向iframe
	this.Form.target = this._FrameName;
	this.Form.method = "post";
	//注意ie的form没有enctype属性，要用encoding
	this.Form.encoding = "multipart/form-data";

	//整理一次
	this.Ini();
  },
  //设置默认属性
  SetOptions: function(options) {
    this.options = {//默认值
		FileName:	"Files[]",//文件上传控件的name，配合后台使用
		FrameName:	"",//iframe的name，要自定义iframe的话这里设置name
		onIniFile:	function(){},//整理文件时执行(其中参数是file对象)
		onEmpty:	function(){},//文件空值时执行
		Limit:		10,//文件数限制，0为不限制
		onLimite:	function(){},//超过文件数限制时执行
		Distinct:	true,//是否不允许相同文件
		ExtIn:		[<!--{$ufn}-->],//允许后缀名
		onNotExtIn:	function(){},//不是允许后缀名时执行
		ExtOut:		[],//禁止后缀名，当设置了ExtIn则ExtOut无效
		onExtOut:	function(){},//是禁止后缀名时执行
		onFail:		function(){},//文件不通过检测时执行(其中参数是file对象)
		onIni:		function(){}//重置时执行
    };
    Extend(this.options, options || {});
  },
  //整理空间
  Ini: function() {
	//整理文件集合
	this.Files = [];
	//整理文件空间，把有值的file放入文件集合
	Each(this.Folder.getElementsByTagName("input"), Bind(this, function(o){
		if(o.type == "file"){ o.value && this.Files.push(o); this.onIniFile(o); }
	}))
	//插入一个新的file
	var file = document.createElement("input");
	file.name = this.FileName; file.type = "file"; file.onchange = Bind(this, function(){ this.Check(file); this.Ini(); });
	this.Folder.appendChild(file);
	//执行附加程序
	this.onIni();
  },
  //检测file对象
  Check: function(file) {
	//检测变量
	var bCheck = true;
	//空值、文件数限制、后缀名、相同文件检测
	if(!file.value){
		bCheck = false; this.onEmpty();
	} else if(this.Limit && this.Files.length >= this.Limit){
		bCheck = false; this.onLimite();
	} else if(!!this.ExtIn.length && !RegExp("\.(" + this.ExtIn.join("|") + ")$", "i").test(file.value)){
		//检测是否允许后缀名
		bCheck = false; this.onNotExtIn();
	} else if(!!this.ExtOut.length && RegExp("\.(" + this.ExtOut.join("|") + ")$", "i").test(file.value)) {
		//检测是否禁止后缀名
		bCheck = false; this.onExtOut();
	}
	//没有通过检测
	!bCheck && this.onFail(file);
  },
  //删除指定file
  Delete: function(file) {
	//移除指定file
	this.Folder.removeChild(file); this.Ini();
  },
  //删除全部file
  Clear: function() {
	//清空文件空间
	Each(this.Files, Bind(this, function(o){ this.Folder.removeChild(o); })); this.Ini();
  }
}

var fu = new FileUpload("uploadForm", "idFile", { ExtIn: [<!--{$ufn}-->],
	onIniFile: function(file){ file.value ? file.style.display = "none" : this.Folder.removeChild(file); },
	onEmpty: function(){ alert("请选择一个文件"); },
	onLimite: function(){ alert("最多可同时上传10个文件"); },
	onNotExtIn:	function(){ alert("只允许上传" + this.ExtIn.join("，") + "文件"); },
	onFail: function(file){ this.Folder.removeChild(file); },
	onIni: function(){
		//显示文件列表
		var arrRows = [];
		if(this.Files.length){
			var oThis = this;
			Each(this.Files, function(o){
				var filename = "<input size='55' type='text' value='" + o.value + "' readonly>";
				var a = document.createElement("a"); a.innerHTML = "删除"; a.href = "javascript:void(0);";
				a.onclick = function(){ oThis.Delete(o); return false; };
				arrRows.push([filename, a]);
			});
		} else { arrRows.push(["<font color='gray'>无上传文件</font>", "&nbsp;"]); }
		AddList(arrRows);
		//设置按钮
		$("idBtnupload").disabled = $("idBtndel").disabled = this.Files.length <= 0;
	}
});

$("idBtnupload").onclick = function(){
	//显示文件列表
	var arrRows = [];
	Each(fu.Files, function(o){var filename = "<input size='55' type='text' value='" + o.value + "' readonly>";arrRows.push([filename, "&nbsp;"]); });
	AddList(arrRows);
	
	fu.Folder.style.display = "none";
	$("idProcess").style.display = "";
	$("idMsg").innerHTML = "上传中…<br /><a href='<!--{$miniupload}-->'><font color='red'>取消</font></a>";
	alert('ssf');
	fu.Form.submit();
}

//用来添加文件列表的函数
function AddList(rows){
	//根据数组来添加列表
	var FileList = $("idFileList"), oFragment = document.createDocumentFragment();
	//用文档碎片保存列表
	Each(rows, function(cells){
		var row = document.createElement("tr");
		Each(cells, function(o){
			var cell = document.createElement("td");
			if(typeof o == "string"){ cell.innerHTML = o; }else{ cell.appendChild(o); }
			row.appendChild(cell);
		});
		oFragment.appendChild(row);
	})
	//ie的table不支持innerHTML所以这样清空table
	while(FileList.hasChildNodes()){ FileList.removeChild(FileList.firstChild); }
	FileList.appendChild(oFragment);
}

$("idBtndel").onclick = function(){ fu.Clear(); }

$("idFileSuccess").innerHTML ="<!--{$filenames}-->";

//在后台通过window.parent来访问主页面的函数
function Finish(msg1,msg2){
	var msg='';
	if((msg1!="" && msg1!=null))	msg="上传成功:\n"+msg1;
	if((msg2!="" && msg2!=null))	msg=msg+"\n上传失败:\n"+msg2;
	if((msg1=="" || msg1==null) && (msg2=="" || msg2==null)){msg="上传失败";}
	alert(msg);
	location.href = location.href; 
}

</script>
</body>
</html>
