<?php
if( !defined('ISDVBBS') ){
	header('HTTP/1.0 404 Not Found');
	exit;
}

global $pagecharset;


if ($t==1 or $t==2){print <<<EOT

<script>
	if (parent.document.Dvform.Submit) parent.document.Dvform.Submit.disabled=false;
	if (parent.document.Dvform.Submit2) parent.document.Dvform.Submit2.disabled=false;
</script>
EOT;
}
# 提交上传图片文件
if( $t == 1 ){ print <<<EOT
<script language="javascript">
	(parent)||(parent=window.parent);
	(objtthisiframe=parent.Dvbbs_Composition)||(objtthisiframe=parent.document.getElementById('Dvbbs_Composition'));
	contentBody=false;
	(objtthisiframe)&&(objthisdocument=objtthisiframe.document||objtthisiframe.contentWindow.document)&&(contentBody=objthisdocument.body);
</script>
<table width="100%" height="100%" border=0 cellspacing=0 cellpadding=0>
  <tr>
	<td valign=top height=40>
EOT;
	if (!empty($UploadedFiles)) { // 部分或全部文件已成功移动到临时目录
		$__upfileinfo = base64_encode(serialize($UploadedFiles));
		foreach ( $UploadedFiles as $index => $currFile )if ($currFile['error'])unset($_FILES[$index]);
		foreach ($UploadedFiles AS $index => $currFile) {
			if ($currFile['ftype'] == 1 OR $currFile['ftype'] == 2) {
				$ShwoFileName = $currFile['destfile'];
				if (!empty($currFile['LocalUrl']))
				print "<script>contentBody.innerHTML += '<img src=\'file:///".htmlspecialchars($currFile['LocalUrl'], ENT_QUOTES)."\'><br />'</script>";
			} else {
				print "<script>contentBody.innerHTML += '[upload={$currFile['ext']}]viewfile.php?id=ViewFileID_{$currFile['name']}[/upload]<br />'</script>";
			}
		}
		//Start 上传成功后的其它处理，包括数据库的更新
		$upload_subdir = basename($updirsettings[1]);
		$tmp1 = str_replace($updirsettings['uptopdir'].'/', '', $updirsettings['uptmpdir']);
		$tmp2= str_replace($updirsettings['uptopdir'].'/', '', $updirsettings['updestdir']);
print <<<EOT
<script>
	with(parent.document.forms['Dvform']) {
		if (__upfileinfo.value != '') {
			__upfileinfo.value += '||';
		}
		__upfileinfo.value += '{$__upfileinfo}';
	}
	if(parent.document.all.preview)
	{
		with (parent.document.forms['preview'])
		{
			upload_tmp_dir.value = '{$tmp1}';
			uploadrepl.value = '{$tmp2}';
		}
	}
	parent.document.getElementById("showAjaxPic").style.display = "none";
</script>
EOT;
		$today_from = strtotime(gmdate('Y-m-d 00:00:00'));
		$today_to = strtotime(gmdate('Y-m-d 23:59:59'));
		if ($userinfo['userupfiledate'] < $today_from or $userinfo['userupfiledate'] > $today_to){
			$db->query("UPDATE {$dv}user SET userupfiledate = '".TIME_NOW."' WHERE userid='{$userid}'");
			$userinfo['userupfiledate'] = TIME_NOW;
		}

		if ($userinfo['userupfiledate'] >= $today_from && $userinfo['userupfiledate'] <= $today_to)
		{
			$arrUserToday[2] = $arrUserToday[2] + $uploadedcount;
			$TodayUploaded = get_cookie('upNum') + $uploadedcount;
		}
		else
		{
			$arrUserToday[2] = 1;
			$TodayUploaded = 1;
		}

		set_cookie('upNum', $TodayUploaded, 24*3600);
		$iUserInfo = $db->escape_string(implode('|',$arrUserToday));

		if ($OnceUPCount <= $groupsetting[40] && $arrUserToday[2] < $groupsetting[50]) {
			$num1 = intval($_POST['upcount']);
			$num2 = intval($arrUserToday[2]);
			eval('$strTmp="'.addslashes($lang['template.strings8']).'";');
			$strTmp=str_replace('{$t}', 2, $strTmp);
			
			print $strTmp;
		} else {
			$num1 = intval($_POST['upcount']);
			eval('$strTmp="'.addslashes($lang['template.strings9']).'";');
			print $strTmp;
		}

		$db->query("UPDATE {$dv}user SET usertoday = '{$iUserInfo}' WHERE userid='{$userid}'");
		set_cookie('usertoday', $iUserInfo, 24*3600);
		//End 上传成功后的其它处理，包括数据库的更新
	}
	print <<<EOT
	</td>
  </tr>
</table>
</body>
</html>
EOT;
#图片上传界面
} else if( $t == 2 ) {
	$upset = intval($groupsetting[66]);
	$dateupnum = $arrUserToday[2];
	$lang['tpl.str1']=str_replace('{$upset}',$upset,$lang['tpl.str1']);
	$isnewbuy=(!empty($board_settings[57])) ? intval($board_settings[57]) :0;
	print <<<EOT
<SCRIPT LANGUAGE="JavaScript">
<!--
function uploadframe(num)
{
	if (document.getElementById("setload").value=="{$lang['template.strings1']}" ){
		document.getElementById("Setupload").style.display="";
		document.getElementById("setload").value="{$lang['template.strings10']}";
		setid();
	}else{
		document.getElementById("Setupload").style.display="none";
		document.getElementById("setload").value="{$lang['template.strings1']}";	
		window.form.upcount.value=1;
		setid();
	}
}
var ifnumd=0;
function setid()
{
	str='';
	if(!window.form.upcount.value) window.form.upcount.value=1;
	if(window.form.upcount.value>{$upset})
	{
		alert("{$lang['tpl.str1']}");
		window.form.upcount.value = {$upset};
		setid();
	}else{
		for(i=1;i<=window.form.upcount.value;i++){
			str+='<tr><td width="80">'+i+'：</td>'
			str+='<td width="*" ><INPUT TYPE="hidden" NAME="hiddenname[]" id="hidname'+i+'" ><input type="file" name="file'+i+'" id="file'+i+'" width="200" value="" size="40" class="button" {$disableupload} onchange="getUpLoadUrl(\'file'+i+'\',\'hidname'+i+'\')"></td></tr><BR>';
			var num=i*40
			var obj=parent.document.getElementById("addif");
			if (parseInt(obj.height)+num>=100) obj.height = 100 + num;

		}
		if (str != '' )window.upid.innerHTML=str;
	}
	
}
function getUpLoadUrl(filename,hidname) {
	var hid =hidname; 
	if (document.getElementById(filename).value)
	{
		document.getElementById(hid).value=document.getElementById(filename).value
	}
}

//-->
</SCRIPT>
<table width="100%" border=0 cellspacing=0 cellpadding=0  style=" background:#fff;padding:6px">
<form name="form" method="post" action="post_upload.php?t=1&boardid={$boardid}" enctype="multipart/form-data">
EOT;
	if ($groupsetting[7] == 1) {
		mt_rand();
		$PostRanNum = intval(900*rand())+1000;
		$inttmp = $groupsetting[50]-$dateupnum;
		$disableupload = '';
		($inttmp <= 0) AND ($disableupload = ' disabled ') AND ($inttmp = 0);
print <<<EOT
  <tr>
	<td width="*" colspan="2">
EOT;
		$num1 = $groupsetting[40];
		$num2 = $groupsetting[50];
		$num3 = $groupsetting[44];
		$tmpStr = str_replace('{$num}', $inttmp, $lang['template.strings4']);//今天还可上传{$num}个
		$tmpStr2 = str_replace(array('{$num1}', '{$num2}', '{$num3}'), array($num1, $num2, $num3), $lang['template.strings5']);
print <<<EOT
	<span style="margin-left:8px;display:block;height:24px;vertical-align:middle;line-height:22px;"><font color="{$lang['Dvbbs.mainsetting1']}">{$tmpStr}</font>{$lang['tpl.str3']}
	<a style="CURSOR: help" title="{$tmpStr2}">{$lang['template.strings6']}</a></span>

	</td>
  </tr>
EOT;
	}
	if ($groupsetting[7] == 0) {
print <<<EOT
  <tr>
	<td width="*" colspan="2">{$lang['Error.strings0']}</td>
  </tr>
EOT;
	} else {
print <<<EOT
<INPUT TYPE="hidden" NAME="UploadCode" value="{$PostRanNum}">
  <tr>
	<td width="80">{$lang["tpl.str2"]}</td>
	<td width="*" id="upid"><input type="hidden" NAME="hiddenname[]" id="hidname1" /><input type="file" name="file1" id="file1" width="200" value="" size="40" class="button" {$disableupload} onchange="getUpLoadUrl('file1','hidname1')"></td>
  </tr>
  <tr>
	<td></td>
	<td>
	<button onmousemove="button_move(this)" onmouseout="button_out(this)" onclick="parent.document.Dvform.Submit.disabled=true;parent.document.Dvform.Submit2.disabled=true;" name="Submit" type="submit" {$disableupload}> {$lang['template.strings0']} </button>

EOT;
		#显示批量上传按钮
		if( $upset > 1 ){ print <<<EOT
	<button onmousemove="button_move(this)" onmouseout="button_out(this)" onClick="uploadframe(20);" name="setload" type="button" id="setload"> {$lang['template.strings1']} </button>
EOT;
		}
print <<<EOT
	</td>
  </tr>
  <tr>
	<td colspan="2"  id="Setupload" style="display:none;margin:0;padding:0 0 10px 10px;height:18px;">
EOT;
		#每次可以设置同时上传
		if ($upset > 1) {
		$tmpStr = str_replace('{$upset}',$upset,$lang['template.strings3']);
print <<<EOT
		{$lang['template.strings7']}
		<input type="text" value="1" name="upcount" style="width:40px" class="button">
		<button onmousemove="button_move(this)" onmouseout="button_out(this)" onClick="setid();" name="Button" type="button" id="setload"> {$lang['template.strings2']} </button>{$tmpStr}
EOT;
		} else {
print <<<EOT
		<input type="text" value="1" name="upcount" style="width:40" class="button">
EOT;
		}
print <<<EOT
	</td>
  </tr>
EOT;
}
print <<<EOT
	</form>
</table>
</body>
</html>
EOT;
#附件上传界面
} else if( $t == 3 ) {print <<<EOT
<script language="javascript">
	(parent)||(parent=window.parent);
	(objtthisiframe=parent.parent.Dvbbs_Composition)||(objtthisiframe=parent.parent.document.getElementById('Dvbbs_Composition'));
	 contentBody=false;
	(objtthisiframe)&&(objthisdocument=objtthisiframe.document||objtthisiframe.contentWindow.document)&&(contentBody=objthisdocument.body);
</script>
<table width="100%" height="100%" border=0 cellspacing=0 cellpadding=0>
  <tr>
	<td valign=top height=40>
EOT;
	if (!empty($UploadedFiles)) { // 部分或全部文件已成功移动到临时目录
		$__upfileinfo = base64_encode(serialize($UploadedFiles));
		foreach ($UploadedFiles AS $index => $currFile) {
			if ($currFile['ftype'] == 1 OR $currFile['ftype'] == 2) {
				$ShwoFileName = $currFile['destfile'];
				print "<script>contentBody.innerHTML += '[upload={$currFile['ext']}]{$ShwoFileName}[/upload]<br />'</script>";
			} else {
				print "<script>contentBody.innerHTML += '[upload={$currFile['ext']}]viewfile.php?id=ViewFileID_{$currFile['name']}[/upload]<br />'</script>";
			}
		}
		//Start 上传成功后的其它处理，包括数据库的更新
		$upload_subdir = basename($updirsettings[1]);
		$tmp1 = str_replace($updirsettings['uptopdir'].'/', '', $updirsettings['uptmpdir']);
		$tmp2= str_replace($updirsettings['uptopdir'].'/', '', $updirsettings['updestdir']);
		print <<<EOT
				
				<script>
					with(parent.parent.document.forms['Dvform']) {
						if (__upfileinfo.value != '') {
							__upfileinfo.value += '||';
						}
						__upfileinfo.value += '{$__upfileinfo}';
					}
					if(parent.parent.document.all.preview)
					{
						with (parent.parent.document.forms['preview'])
						{
							upload_tmp_dir.value = '{$tmp1}';
							uploadrepl.value = '{$tmp2}';
						}
					}
				</script>
EOT;

		$today_from = strtotime(gmdate('Y-m-d 00:00:00'));
		$today_to = strtotime(gmdate('Y-m-d 23:59:59'));
 		if ($userinfo['userupfiledate'] < $today_from or $userinfo['userupfiledate'] > $today_to){
			$db->query("UPDATE {$dv}user SET userupfiledate = '".TIME_NOW."' WHERE userid='{$userid}'");
			$userinfo['userupfiledate'] = TIME_NOW;
		}

		if ($userinfo['userupfiledate'] >= $today_from && $userinfo['userupfiledate'] <= $today_to)
		{
			$arrUserToday[2] = $arrUserToday[2] + $uploadedcount;
			$TodayUploaded = get_cookie('upNum') + $uploadedcount;
		}
		else
		{
			$arrUserToday[2] = 1;
			$TodayUploaded = 1;
		}

		set_cookie('upNum', $TodayUploaded, 24*3600);
		$iUserInfo = $db->escape_string(implode('|',$arrUserToday));

		if ($OnceUPCount <= $groupsetting[40] && $arrUserToday[2] < $groupsetting[50]) {
			$num1 = intval($upcount);
			$num2 = intval($arrUserToday[2]);
			eval('$strTmp="'.addslashes($lang['template.strings13']).'";');
			echo "<SCRIPT LANGUAGE=\"JavaScript\">alert('".$strTmp."');</SCRIPT>";			
		} else {
			$num1 = intval($upcount);
			eval('$strTmp="'.addslashes($lang['template.strings9']).'";');
			//print $strTmp;
			echo "<SCRIPT LANGUAGE=\"JavaScript\">alert('".$strTmp."');</SCRIPT>";			
		}

		$db->query("UPDATE {$dv}user SET usertoday = '{$iUserInfo}' WHERE userid='{$userid}'");

		set_cookie('usertoday', $iUserInfo, 24*3600);

		//End 上传成功后的其它处理，包括数据库的更新
	}
	print <<<EOT
	</td></tr>
	</table>
</body>
</html>
EOT;
EXIT;

} else if( $t == 4 ) { // 附件上传界面

	$upset = intval($groupsetting[66]);
	$dateupnum = $arrUserToday[2];
	$lang['tpl.str1']=str_replace('{$upset}',$upset,$lang['tpl.str1']);
	$isnewbuy=(!empty($board_settings[57])) ? intval($board_settings[57]) :0;
	if ($groupsetting[7] == 1) {
		mt_rand();
		$PostRanNum = intval(900*rand())+1000;
		$inttmp = $groupsetting[50]-$dateupnum;
		$disableupload = '';
	}
	($inttmp <= 0) AND ($inttmp = 0);


print <<<EOT



<SCRIPT LANGUAGE="JavaScript">
var snum=null;

function setannex(s)
{
	if (snum==null)snum=30;

	var obj=parent.document.getElementById("Annex");
	if(s==1){
		snum=snum+20
		if (parseInt(obj.height)>=20) obj.height = snum;
	}else{
		snum=snum-20
		if (parseInt(obj.height)>=40) obj.height = snum;
	}
}

function UpAnnex( list_target, max ){
    this.list_target = list_target;
    this.count = 0;
    this.id = 0;
    if( max ){
        this.max = max;
    } else {
        this.max = -1;
    };
    
    this.addElement = function( par_e ){


        if( par_e.tagName == 'INPUT' && par_e.type == 'file' ){
			 
			 eval("this.id++");
			 eval("par_e.name= 'file_' + this.id");
			 eval("par_e.AnnexSel = this");
            //选择文件触发

			par_e.onchange = function(){
                var new_par_e = document.createElement( 'input' );
                new_par_e.type = 'file';
                new_par_e.size = 1;
				new_par_e.className = "addfile";

                par_e.parentNode.insertBefore( new_par_e, par_e );
				AnnexSel.addElement( new_par_e );
                AnnexSel.addListRow( new_par_e, par_e);
				setannex(1);
                this.style.position = 'absolute';
                this.style.left = '-1000px';

            };
            if( this.max != -1 && this.count >= this.max ){
                par_e.disabled = true;//显示上传个数
            };

            this.count++;
            this.current_element = par_e;
        } else {
            alert( 'Error: not a file input element' );
        };

    };
    
    this.addListRow = function( new_par_e ,par_e){
        
		var new_row = document.createElement( 'div' );//创建div放内容地址
        
		var new_row_button = document.createElement( 'input' );//删除按钮
        new_row_button.type = 'button';
        new_row_button.value = '删除';
        new_row_button.className = 'files_input2';
        new_row.element = par_e;
        new_row.cssText = 'width:200px;';
		
        new_row_button.onclick= function(){ //点击删除按钮

            this.parentNode.element.parentNode.removeChild( this.parentNode.element );
            this.parentNode.parentNode.removeChild( this.parentNode );
            this.parentNode.element.AnnexSel.count--;
            this.parentNode.element.AnnexSel.current_element.disabled = false;
			setannex(0);
            return false;
        };
		//添加按钮
		
        new_row.innerHTML = this.getFileNmae(par_e.value);//在创建的div中插入附件地址
        new_row.appendChild( new_row_button );//删除按钮设置成创建div的子层
        this.list_target.appendChild( new_row );//创建div做file_list子层
    };
	this.getFileNmae = function ( fileurl ){
		
		var spos = fileurl.lastIndexOf('\\\');
		return (spos==-1?fileurl:fileurl.substr(spos+1));

	};
    this.sub = function( element ){
        //提交按钮
		var form_sub = document.createElement("form");
			this.list_target.appendChild(form_sub);
            form_sub.appendChild(element);
	 
			var hiddenIframe=document.createElement("iframe");
			 hiddenIframe.src="about:blank";
			 hiddenIframe.name="hiddenFrame";
			 hiddenIframe.id="hiddenFrame";
			 hiddenIframe.width="0";
			 hiddenIframe.height="0";
			 hiddenIframe.frameborder="0";
			 form_sub.appendChild(hiddenIframe);
    
			 form_sub.action = "post_upload.php?t=1&boardid=3";
			 form_sub.target = "hiddenFrame";
			 form_sub.method = "post";
			 form_sub.enctype="multipart/form-data";
			 form_sub.submit(); 

	}
};    
	
</SCRIPT>
<TABLE cellspacing="0" border=0 cellpadding="0" style="background: #fff;width:100%;height:100%">
<TR>
	<TD>
<iframe name="ifrAnnex" id="ifrAnnex" frameborder="0" width="0" height="0"  scrolling="no" src="post_upload.php?t=3&boardid={$boardid}" ></iframe>
<form style="margin:0px;padding:0px" enctype="multipart/form-data" target="ifrAnnex" action="post_upload.php?t=3&boardid={$boardid}" method = "post">
<a href="#?" class="addfile">
<input id="file_element" class="addfile" type="file" name="file_1" size="1" >
</a>
<input type="submit" value="附件上传" class="files_input1">
</form>
<div id="files_list" style="border:none;margin:0;padding:3px 0 0 0;" ></div>
<script LANGUAGE="JavaScript">
var AnnexSel = new UpAnnex( document.getElementById( 'files_list' ), {$inttmp} );
AnnexSel.addElement( document.getElementById( 'file_element' ) );
</script>
</TD>
</TR>
</TABLE>
</body>
</html>


EOT;


}
?>