<?php
include_once('../init.php');
if(!isLogin()){
	exit('请先登录');
}
if(getPopedom(14)==0){
	exit('<div style="font-size:14px; padding:10px; text-align:center;">您所在的用户组没有权限上传附件。</div>');
}
$file_size_limit = getPopedom(15);
$file_num_limit = getPopedom(16);
$file_types=getPopedom(17);

$row=$db->row_select_one("users","id={$lg['userid']}","todayuploaded");
$today_uploaded=$row['todayuploaded'];

$types=explode(",",$file_types);
$file_types="";
foreach($types as $ext){
	if(!empty($ext)){
		$file_types.="*.{$ext};";
	}
}

?><!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" >
<head>
<title>SWF</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/swfupload.js"></script>
<script type="text/javascript" src="js/swfupload.queue.js"></script>
<script type="text/javascript" src="js/fileprogress.js"></script>
<script type="text/javascript" src="js/handlers.js"></script>
<script type="text/javascript" src="../../getfiles.php?t=js&v=<?php echo $_SYS['VERSION'];?>&f=util|ajax"></script>
<script type="text/javascript">
		var swfu;
		var oldindex=-10000;
		
		var daily_allow_num= <?php echo $file_num_limit;?>;
		var today_uploaded= <?php echo $today_uploaded;?>;
		var today_allow_num=daily_allow_num-today_uploaded;
		today_allow_num=today_allow_num<1?0.5:today_allow_num;


		window.onload = function() {
			var settings = {
				flash_url : getPath()+"/js/swfupload.swf",
				upload_url: getPath()+"/upload.php",	// Relative to the SWF file
				post_params: {"PHPSESSID" : "<?php echo session_id(); ?>"},
				file_size_limit : "<?php echo $file_size_limit;?> KB",
				file_types : "<?php echo $file_types;?>",//上传类型控制"*.zip;*.doc;*.ppt;"
				file_types_description : "All Files",
				file_upload_limit : today_allow_num,   //上传容量大小
				file_queue_limit : 0,     //上传数量
				custom_settings : {
					progressTarget : "fsUploadProgress",
					cancelButtonId : "btnCancel"
				},
				debug: false,

				// Button settings
				button_image_url: "images/btn.gif",	// Relative to the Flash file
				button_width: "100",
				button_height: "28",
				button_placeholder_id: "spanButtonPlaceHolder",
				button_text: "",
				button_text_style: "",
				button_text_left_padding: 12,
				button_text_top_padding: 3,
				
				// The event handler functions are defined in handlers.js
				file_queued_handler : fileQueued,
				file_queue_error_handler : fileQueueError,
				file_dialog_complete_handler : fileDialogComplete,
				upload_start_handler : uploadStart,
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_success_handler : uploadSuccess,
				upload_complete_handler : uploadComplete,
				queue_complete_handler : queueComplete	// Queue plugin event
			};

			swfu = new SWFUpload(settings);
			
			var file;
			
			<?php
				$rows=$db->row_select("attachments","tid=0 and postid=0 and userid={$lg['userid']}",0,"*","id");
				foreach($rows as $row){
					$md5str=md5($row['filepath'].$row['uploadtime']);
echo <<<EOT
			file = {};
			file.id = oldindex++;
			file.name = "{$row['filename']}";
			file.size = {$row['filesize']};
			swfu.uploadSuccess(file,"{fileid:'{$row[id]}',filepath:'{$row[filepath]}', md5:'{$md5str}'}");			
EOT;
				}
			?>
			

	     };

		 //获取当前路径
		function getPath(){
			var locHref = location.href;
			var locArray = locHref.split("/");
			delete locArray[locArray.length-1];
			var dirTxt = locArray.join("/");
			return dirTxt;
		}

		//删除文件
		function delFile(divid, fileid, md5str){
			var filediv = document.getElementById(divid);
			 if (filediv != null){
				filediv.parentNode.removeChild(filediv);
			 }
			 ajaxGet("../../ajaxmember.php?action=deleteAttachment&id="+fileid+"&md5="+md5str, delFile_callback);
		}

		function delFile_callback(data){
			
		}

		//使用文件
		function useFile(fileid,filename){
			window.parent.insertAttachment(fileid,filename);
		}
	</script>
</head>
<body>
	<div>
		<span id="spanButtonPlaceHolder"></span>
		<input id="btnCancel" type="button" value="取消上传" onclick="swfu.cancelQueue();" disabled="disabled" style="display:none;" class="button_css" /> <img src="images/btn_close.gif" id="btnClose" onclick="window.parent.popwin.close()" border="0" style="cursor:pointer;" /> 今日最多上传 <b id="span_file_num_limit"><?=$file_num_limit?></b> 个, 已上传 <b id="span_today_uploaded"><?=$today_uploaded?></b> 个, 文件大小不能超过 <b id="span_size_limit"><?php echo $file_size_limit;?></b> KB
	</div>
	
	<div class="progressWrapper"></div>
	<div style="clear:both; height:5px;"></div>
	<div class="progressWrapper progressTitle">
		<div class="progressContainer">
			<div class="progressCancel"></div><div class="progressName">文件名(点击插入到帖子中)</div><div class="progressSize">文件大小</div><div class="progressBarStatus">上传进度</div><div class="progressX">删除</div>
		</div>
	</div>
	<div id="fsUploadProgress" class="fieldset flash"></div>
	<input type="hidden" value="GO" onclick="javascript:swfu.setFileUploadLimit(1);" />
</html>
