<?php
if( !defined('ISDVBBS') ){
	header('HTTP/1.0 404 Not Found');
	exit;
}
$skinpath = $GLOBALS['spaceConfig_System']['s_path'];
$_strMode = strtolower($_GET['mode']);
if( $_strMode === 'uploadform' ){
	$_tpl_upset = 5;
	$_tpl_spaceName = $GLOBALS['spaceName'];
	print <<<EOT
<body topmargin="0" leftmargin="0" oncontextmenu1="return false;" onselectstart1="return false;">
<style>
body { font-size:9pt; }
input { font-size:9pt; }
</style>
<script>
var upset = {$_tpl_upset};
if (top.location==self.location){
	//top.location="space.php"
}
function uploadframe(num)
{
	var obj=parent.document.getElementById("UPLOADFRAME");
	if (obj){
	if (parseInt(obj.height)+num>=24) {
		obj.height = parseInt(obj.height) + num;
		document.getElementById("Setupload").style.display="";
		document.getElementById("allupload").style.display="none";
	}
	}
}
function setid()
{
	str='';
	if(!window.form.upcount.value)
	window.form.upcount.value=1;
	if(window.form.upcount.value>upset){
	alert("您最多只能同时上传"+upset+"个文件!");
	window.form.upcount.value = upset;
	setid();
	}
	else{
	for(i=1;i<=window.form.upcount.value;i++)
	str+='文件'+i+':<input type="file" name="file'+i+'" style="width:200px"/><br/>';
	window.upid.innerHTML=str+'<br/>';
	var num=i*16
	var obj=parent.document.getElementById("UPLOADFRAME");
	if (parseInt(obj.height)+num>=24) {
		obj.height = 24 + num;	
	}
	}
}
</script>
<form name="form" method="post" action="spaceupload.php?user={$_tpl_spaceName}&mode=saveupload" enctype="multipart/form-data">
<table border="0" cellspacing="0" cellpadding="0" style="width:100%;height:100%">
<tr>
<Input type="hidden" name="act" value="upload"/>
<TD id="upid" valign="top" align="left" class="reply_t3">
<input type="file" name="file1" width="120px" value="" size="25" class="button" /></TD>
<td valign="top" width="*" align="left" class="reply_t3">
<input type="submit" name="Submit" value="上传" onclick="parent.document.PostForm.submit.disabled=true" class="button"/>
</td>
<td id="allupload" valign="top" align="left" class="reply_t3">
</td>
<td valign="top" align="left" class="reply_t3">
<div id="Setupload" style="display:none" align="left"></div>
</td>
</tr>
</table>
</form>
<script language="JavaScript">
<!--
if (upset > 1){
var tempstr1='<input type="button" name="setload" onClick="uploadframe(0);" value="批量上传" class="button" />';
var tempstr2='设置个数<input type="text" value="1" name="upcount" size="1" maxlength="1"/><input type="button" name="Button" onClick="setid();" value="设定"/>';
document.getElementById("allupload").innerHTML=tempstr1;
document.getElementById("Setupload").innerHTML=tempstr2;
}
//-->
</script>
</body>
</html>
EOT;
} elseif ('saveupload' === $_strMode) {
	print <<<EOT
<script>parent.document.PostForm.submit.disabled=false;</script>
EOT;
	$_intUpCountSize = 0;
	$_intUpCount = 0;
	$_strAllFileName = '';
	$_strScriptNameUrl = getScriptUrl();
	if( !empty($UploadedFiles) && is_array($UploadedFiles) ){
		$_intUpCount = count($UploadedFiles);
		$__upfileinfo = base64_encode(serialize($UploadedFiles));
		foreach ($UploadedFiles AS  $index => $currFile) {
			if( $currFile['ftype'] == 1 || $currFile['ftype'] == 2 ){
				$_tpl_ShwoFileName = $currFile['destfile'];
				$_intUpCountSize += $currFile['size'];
				$_strAllFileName .= "<br />{$_strScriptNameUrl}{$spaceSystemUpSetting[9]}{$initedupparams['dest_dir']}{$currFile['fullname']}";
				print <<<EOT
<script>parent.put_html('postcontent','[upload={$currFile['ext']}]{$_tpl_ShwoFileName}[/upload]<br/>')</script>
EOT;
			} else{
				print <<<EOT
<script>parent.put_html('postcontent','[upload={$currFile['ext']}]viewfile.php?src=space&id=ViewFileID_{$currFile['name']}[/upload]<br/>');</script>
EOT;
			}
		}
			$upload_subdir = $subuploaddir;
			print <<<EOT
				<script>
					with(parent.document.forms['PostForm']) {
						if (__upfileinfo.value != '') {
							__upfileinfo.value += '||';
						}
						__upfileinfo.value += '{$__upfileinfo}';
					}
				</script>
EOT;
		$_intUpCountSize = number_format(((float)$_intUpCountSize/1024)/1024,5);
		if( $spaceUserInfo['spacesize'] > 0 ){
			$_intRemainSize = $spaceUserInfo['spacesize'] - $_intUpCountSize;
			if( $_intRemainSize < 0 ){
				$_intRemainSize = 0;
			}
		} else{
			$_intRemainSize = -1;
		}
		$_strSucMsg = "{$_intUpCount}个附件上传成功,共{$_intUpCountSize}MB;";
		if( $_intRemainSize == 0 ){
			$_strSucMsg .='[ 当前我的空间已满,请与管理员联系。]';
		} else{
			$_strSucMsg .= '[ <a href="?mode=UploadForm">继续上传</a> ]';
		}
		$db->query("UPDATE {$dv}space_user SET spacesize='{$_intRemainSize}' WHERE userid='{$spaceUserID}'");
		if( $_strMode === '1' ){
			$_strSucMsg .= "<br>文件地址：{$_strAllFileName}";
		}
		print <<<EOT
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<td class="reply_t3" valign="top" height="40" align="left">
{$_strSucMsg}
</td>
</tr>
</table>
</body>
</html>
EOT;
	} else {
		print <<<EOT
请正确选择要上传的文件。[ <a href="?mode=UploadForm">重新上传</a> ]
EOT;
	}
}
?>