<?php
//新用戶投稿驗證
function qCheckNewMemberAddInfo($registertime){
	global $public_r;
	if(empty($public_r['newaddinfotime']))
	{
		return '';
	}
	$registertime=eReturnMemberIntRegtime($registertime);
	if(time()-$registertime<=$public_r['newaddinfotime']*60)
	{
		printerror('NewMemberAddInfoError','',1);
	}
}

//驗證同一IP發信息數
function eCheckIpAddInfoNum($ip,$tbname,$mid,$checked=1){
	global $empire,$dbtbpre,$public_r,$emod_r;
	if(!$public_r['ipaddinfonum']||!$public_r['ipaddinfotime'])
	{
		return '';
	}
	//是否有IP字段
	$qenterf=$emod_r[$mid]['qenter'];
	if(!strstr($qenterf,',infoip,'))
	{
		return '';
	}
	$infotb=ReturnInfoMainTbname($tbname,$checked);
	//時間
	$cktime=time()-$public_r['ipaddinfotime']*3600;
	$num=$empire->gettotal("select count(*) as total from ".$infotb." where newstime>$cktime and infoip='$ip'");
	if($num+1>$public_r['ipaddinfonum'])
	{
		printerror('IpMaxAddInfo','history.go(-1)',1);
	}
}

//一個會員單信息
function qCheckMemberOneInfo($tbname,$mid,$classid,$userid){
	global $empire,$dbtbpre,$class_r;
	$classid=(int)$classid;
	$userid=(int)$userid;
	if(empty($class_r[$classid]['oneinfo']))
	{
		return '';
	}
	$GLOBALS['classqoneinfo']=$class_r[$classid]['oneinfo'];
	//表
	$num=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$tbname." where userid='$userid' and ismember=1 and classid='$classid'");
	if($num>=$class_r[$classid]['oneinfo'])
	{
		printerror('OneInfoAddInfo','history.go(-1)',1);
	}
	//審核表
	$cknum=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$tbname."_check where userid='$userid' and ismember=1 and classid='$classid'");
	$allnum=$num+$cknum;
	if($allnum>=$class_r[$classid]['oneinfo'])
	{
		printerror('OneInfoAddInfo','history.go(-1)',1);
	}
}

//屏蔽字符
function qCheckInfoCloseWord($mid,$add,$closewordsf,$closewords){
	if(empty($closewordsf)||$closewordsf=='|'||empty($closewords)||$closewords=='|')
	{
		return '';
	}
	$fr=explode('|',$closewordsf);
	$count=count($fr);
	$r=explode('|',$closewords);
	$countr=count($r);
	for($i=0;$i<$count;$i++)
	{
		if(empty($fr[$i]))
		{
			continue;
		}
		for($j=0;$j<$countr;$j++)
		{
			if($r[$j])
			{
				if(stristr($r[$j],'##'))//多字
				{
					$morer=explode('##',$r[$j]);
					if(stristr($add[$fr[$i]],$morer[0])&&stristr($add[$fr[$i]],$morer[1]))
					{
						printerror("HaveCloseWords","history.go(-1)",1);
					}
				}
				else
				{
					if(stristr($add[$fr[$i]],$r[$j]))
					{
						printerror("HaveCloseWords","history.go(-1)",1);
					}
				}
			}
		}
	}
}

//提交字段值的處理
function DoqValue($mid,$f,$val){
	global $public_r,$emod_r;
	$val=RepPhpAspJspcodeText($val);
	if(strstr($emod_r[$mid]['editorf'],','.$f.','))//編輯器
	{
		$val=ClearNewsBadCode($val);
	}
	else
	{
		$val=doehtmlstr($val);//替換html
		if(!strstr($emod_r[$mid]['tobrf'],','.$f.',')&&strstr($emod_r[$mid]['dohtmlf'],','.$f.','))//加回車
		{
			$val=doebrstr($val);
		}
	}
	return $val;
}

//返回字段值的處理
function DoReqValue($mid,$f,$val){
	global $public_r,$emod_r;
	if($emod_r[$mid]['savetxtf']&&$emod_r[$mid]['savetxtf']==$f)//存文本
	{
		$val=stripSlashes(GetTxtFieldText($val));
	}
	if(strstr($emod_r[$mid]['editorf'],','.$f.','))//編輯器
	{
		return $val;
	}
	$val=dorehtmlstr($val);//替換html
	if(!strstr($emod_r[$mid]['tobrf'],','.$f.',')&&strstr($emod_r[$mid]['dohtmlf'],','.$f.','))//加回車
	{
		$val=dorebrstr($val);
	}
	return $val;
}

//替換html代碼
function doehtmlstr($str){
	$str=ehtmlspecialchars($str,ENT_QUOTES);
	return $str;
}

//還原html代碼
function dorehtmlstr($str){
	return $str;
}

//替換回車
function doebrstr($str){
	$str=str_replace("\n","<br />",$str);
	return $str;
}

//還原回車
function dorebrstr($str){
	$str=str_replace("<br />","\n",$str);
	$str=str_replace("<br>","\n",$str);
	return $str;
}

//投稿生成內容頁面
function qAddGetHtml($classid,$id){
	$titleurl=DoGetHtml($classid,$id);
	return $titleurl;
}

//投稿生成頁面
function qAddListHtml($classid,$mid,$qaddlist,$listdt){
	global $class_r;
	if($qaddlist==0)//不生成
	{
		return "";
	}
	elseif($qaddlist==1)//生成當前欄目
	{
		if(!$listdt)
		{
			$sonclass="|".$classid."|";
			QReClassHtml($sonclass);
		}
	}
	elseif($qaddlist==2)//生成首頁
	{
		QReIndex();
	}
	elseif($qaddlist==3)//生成父欄目
	{
		$featherclass=$class_r[$classid]['featherclass'];
		if($featherclass&&$featherclass!="|")
		{
			QReClassHtml($featherclass);
		}
	}
	elseif($qaddlist==4)//生成當前欄目與父欄目
	{
		$featherclass=$class_r[$classid]['featherclass'];
		if(empty($featherclass))
		{
			$featherclass="|";
		}
		if(!$listdt)
		{
			$featherclass.=$classid."|";
		}
		QReClassHtml($featherclass);
	}
	elseif($qaddlist==5)//生成父欄目與首頁
	{
		QReIndex();
		$featherclass=$class_r[$classid]['featherclass'];
		if($featherclass&&$featherclass!="|")
		{
			QReClassHtml($featherclass);
		}
	}
	elseif($qaddlist==6)//生成當前欄目、父欄目與首頁
	{
		QReIndex();
		$featherclass=$class_r[$classid]['featherclass'];
		if(empty($featherclass))
		{
			$featherclass="|";
		}
		if(!$listdt)
		{
			$featherclass.=$classid."|";
		}
		QReClassHtml($featherclass);
	}
}

//投稿生成欄目
function QReClassHtml($sonclass){
	global $empire,$dbtbpre,$class_r;
	$r=explode("|",$sonclass);
	$count=count($r);
	for($i=1;$i<$count-1;$i++)
	{
		//終極欄目
		if($class_r[$r[$i]]['islast'])
		{
			if(!$class_r[$r[$i]]['listdt'])
			{
				ListHtml($r[$i],'',0,$userlistr);
			}
		}
		elseif($class_r[$r[$i]]['islist']==1)//列表式父欄目
		{
			if(!$class_r[$r[$i]]['listdt'])
			{
				ListHtml($r[$i],'',3);
			}
		}
		elseif($class_r[$r[$i]]['islist']==3)//欄目綁定信息式
		{
			ReClassBdInfo($r[$i]);
		}
		else//父欄目
		{
			$cr=$empire->fetch1("select classtempid from {$dbtbpre}enewsclass where classid='$r[$i]'");
			$classtemp=$class_r[$r[$i]]['islist']==2?GetClassText($r[$i]):GetClassTemp($cr['classtempid']);
			NewsBq($r[$i],$classtemp,0,0);
		}
	}
}

//投稿生成首頁
function QReIndex(){
	$indextemp=GetIndextemp();
	NewsBq($classid,$indextemp,1,0);
}

//驗證權限
function CheckQdoinfo($classid,$id,$userid,$tbname,$adminqinfo,$ecms=0){
	global $empire,$dbtbpre,$emod_r,$class_r;
	//索引表
	$index_r=$empire->fetch1("select id,classid,checked from {$dbtbpre}ecms_".$tbname."_index where id='$id' limit 1");
	if(!$index_r['id']||$index_r['classid']!=$classid)
	{
		printerror("HaveNotLevelQInfo","history.go(-1)",1);
	}
	//返回表
	$infotb=ReturnInfoMainTbname($tbname,$index_r['checked']);
	$r=$empire->fetch1("select * from ".$infotb." where id='$id' and classid='$classid' and ismember=1 and userid='$userid' limit 1");
	if(!$r['id'])
	{
		printerror("HaveNotLevelQInfo","history.go(-1)",1);
	}
	$r['checked']=$index_r['checked'];
	if($adminqinfo==1)//管理未審核信息
	{
		if($index_r['checked'])
		{
			printerror("ClassSetNotAdminQCInfo","history.go(-1)",1);
		}
	}
	elseif($adminqinfo==2)//只可編輯未審核信息
	{
		if($index_r['checked']||$ecms!=1)
		{
			printerror("ClassSetNotEditQCInfo","history.go(-1)",1);
		}
	}
	elseif($adminqinfo==3)//只可刪除未審核信息
	{
		if($index_r['checked']||$ecms!=2)
		{
			printerror("ClassSetNotDelQCInfo","history.go(-1)",1);
		}
	}
	elseif($adminqinfo==4)//管理所有信息
	{}
	elseif($adminqinfo==5)//只可編輯所有信息
	{
		if($ecms!=1)
		{
			printerror("ClassSetNotEditQInfo","history.go(-1)",1);
		}
	}
	elseif($adminqinfo==6)//只可刪除所有信息
	{
		if($ecms!=2)
		{
			printerror("ClassSetNotDelQInfo","history.go(-1)",1);
		}
	}
	else//不能管理投稿
	{
		printerror("ClassSetNotAdminQInfo","history.go(-1)",1);
	}
	//返回表信息
	$infotbr=ReturnInfoTbname($tbname,$index_r['checked'],$r['stb']);
	//副表
	$mid=$class_r[$classid]['modid'];
	$finfor=$empire->fetch1("select ".ReturnSqlFtextF($mid)." from ".$infotbr['datatbname']." where id='$r[id]' limit 1");
	$r=array_merge($r,$finfor);
	return $r;
}

//組合下載/影視
function DoqReturnDownPath($path,$ecms=0){
	global $fun_r;
	$downqz="";
	$fen=0;
	$fuser=0;
	$f_exp="::::::";
	$r_exp="\r\n";
	$returnstr="";
	$path=str_replace($f_exp,"",$path);
	$path=str_replace($r_exp,"",$path);
	if($ecms==0)
	{
		$name=$fun_r['DownPath']."1";
	}
	else
	{
		$name="1";
	}
	if($path)
	{
		$returnstr=$name.$f_exp.$path.$f_exp.$fuser.$f_exp.$fen.$f_exp.$downqz.$r_exp;
	}
	//去掉最後的字符
	$returnstr=substr($returnstr,0,strlen($returnstr)-2);
	return $returnstr;
}

//返回下載/影視地址
function DoReqDownPath($downpath){
	if(empty($downpath))
	{
		return "";
	}
	$f_exp="::::::";
	$r_exp="\r\n";
	$r=explode($r_exp,$downpath);
	$r1=explode($f_exp,$r[0]);
	$r1[1]=addslashes(RepPostStr($r1[1]));
	return $r1[1];
}

//特殊字段處理
function DoqSpecialValue($mid,$f,$value,$add,$infor,$ecms=0){
	global $public_r,$loginin,$emod_r;
	if($f=="morepic")//圖片集
	{
		$add['msavepic']=0;
		$value=ReturnMorepicpath($add['msmallpic'],$add['mbigpic'],$add['mpicname'],$add['mdelpicid'],$add['mpicid'],$add,$add['mpicurl_qz'],$ecms,0,($ecms==1?$infor['fstb']:$public_r['filedeftb']));
		$value=doehtmlstr($value);
	}
	elseif($f=="downpath")//下載地址
	{
		$value=DoqReturnDownPath($value,0);
		$value=doehtmlstr($value);
	}
	elseif($f=="onlinepath")//在線地址
	{
		$value=DoqReturnDownPath($value,1);
		$value=doehtmlstr($value);
	}
	elseif($f=="newstext")//內容
	{
		//遠程保存
		//$value=addslashes(CopyImg(stripSlashes($value),$add[copyimg],$add[copyflash],$add[classid],$add[qz_url],$loginin,$add['id'],$add['filepass'],$add['mark'],($ecms==1?$infor['fstb']:$public_r['filedeftb'])));
	}
	//存文本
	if($emod_r[$mid]['savetxtf']&&$f==$emod_r[$mid]['savetxtf'])
	{
		if($ecms==1)
		{
			//建立目錄
			$newstexttxt_r=explode("/",$infor[$f]);
			$thetxtfile=$newstexttxt_r[2];
			$truevalue=MkDirTxtFile($newstexttxt_r[0]."/".$newstexttxt_r[1],$thetxtfile);
		}
		else
		{
			//建立目錄
			$thetxtfile=GetFileMd5();
			$truevalue=MkDirTxtFile(date("Y/md"),$thetxtfile);
		}
		//寫放文件
		EditTxtFieldText($truevalue,$value);
		$value=$truevalue;
	}
	return $value;
}

//檢測點數是否足夠
function MCheckEnoughFen($userfen,$userdate,$fen){
	if(!($userdate-time()>0))
	{
		if($userfen+$fen<0)
		{
			printerror("HaveNotFenAQinfo","history.go(-1)",1);
		}
	}
}

//返回字段
function ReturnQAddinfoF($mid,$add,$infor,$classid,$filepass,$userid,$username,$ecms=0){
	global $empire,$dbtbpre,$public_r,$emod_r,$ecms_config;
	$ret_r=array();
	$pr=$empire->fetch1("select qaddtran,qaddtransize,qaddtranimgtype,qaddtranfile,qaddtranfilesize,qaddtranfiletype,closewords,closewordsf from {$dbtbpre}enewspublic limit 1");
	$isadd=$ecms==0?1:0;
	qCheckInfoCloseWord($mid,$add,$pr['closewordsf'],$pr['closewords']);//屏蔽字符驗證
	//檢測必填字段
	$pagef=$emod_r[$mid]['pagef'];
	$mustr=explode(",",$emod_r[$mid]['mustqenterf']);
	$mustcount=count($mustr)-1;
	for($i=1;$i<$mustcount;$i++)
	{
		$mf=$mustr[$i];
		if(strstr($emod_r[$mid]['filef'],','.$mf.',')||strstr($emod_r[$mid]['imgf'],','.$mf.',')||strstr($emod_r[$mid]['flashf'],','.$mf.',')||$mf=='downpath'||$mf=='onlinepath')//附件
		{
			$mfilef=$mf."file";
			//上傳文件
			if($_FILES[$mfilef]['name'])
			{
				if(strstr($emod_r[$mid]['imgf'],','.$mf.','))//圖片
				{
					if(!$pr['qaddtran'])
					{
						printerror("CloseQTranPic","",1);
					}
				}
				else//附件
				{
					if(!$pr['qaddtranfile'])
					{
						printerror("CloseQTranFile","",1);
					}
				}
			}
			elseif(!trim($add[$mf])&&!$infor[$mf])
			{
				printerror("EmptyQMustF","",1);
			}
		}
		else
		{
			$chmustval=ReturnCheckboxAddF($add[$mf],$mid,$mf);//復選框
			$chmustval=ReturnMoreValueAddF($add,$chmustval,$mid,$mf,$ecms);//多值
			if(!trim($chmustval))
			{
				printerror("EmptyQMustF","",1);
			}
		}
	}
	//字段處理
	$dh="";
	$tranf="";
	$fr=explode(',',$emod_r[$mid]['qenter']);
	$count=count($fr)-1;
	for($i=1;$i<$count;$i++)
	{
		$f=$fr[$i];
		if($f=='special.field'||($ecms==0&&!strstr($emod_r[$mid]['canaddf'],','.$f.','))||($ecms==1&&!strstr($emod_r[$mid]['caneditf'],','.$f.',')))
		{continue;}
		//附件
		$add[$f]=str_replace('[!#@-','ecms',$add[$f]);
		if(strstr($emod_r[$mid]['filef'],','.$f.',')||strstr($emod_r[$mid]['imgf'],','.$f.',')||strstr($emod_r[$mid]['flashf'],','.$f.',')||$f=='downpath'||$f=='onlinepath')
		{
			//上傳附件
			$filetf=$f."file";
			if($_FILES[$filetf]['name'])
			{
				$filetype=GetFiletype($_FILES[$filetf]['name']);//取得文件類型
				if(CheckSaveTranFiletype($filetype))
				{
					printerror("NotQTranFiletype","",1);
				}
				if(strstr($emod_r[$mid]['imgf'],','.$f.','))//圖片
				{
					if(!$pr['qaddtran'])
					{
						printerror("CloseQTranPic","",1);
					}
					if(!strstr($pr['qaddtranimgtype'],"|".$filetype."|"))
					{
						printerror("NotQTranFiletype","",1);
					}
					if($_FILES[$filetf]['size']>$pr['qaddtransize']*1024)
					{
						printerror("TooBigQTranFile","",1);
					}
					if(!strstr($ecms_config['sets']['tranpicturetype'],','.$filetype.','))
					{
						printerror("NotQTranFiletype","",1);
					}
				}
				else//附件
				{
					if(!$pr['qaddtranfile'])
					{
						printerror("CloseQTranFile","",1);
					}
					if(!strstr($pr['qaddtranfiletype'],"|".$filetype."|"))
					{
						printerror("NotQTranFiletype","",1);
					}
					if($_FILES[$filetf]['size']>$pr['qaddtranfilesize']*1024)
					{
						printerror("TooBigQTranFile","",1);
					}
					if(strstr($emod_r[$mid]['flashf'],','.$f.','))//flash
					{
						if(!strstr($ecms_config['sets']['tranflashtype'],",".$filetype.","))
						{printerror("NotQTranFiletype","",1);}
					}
					if($f=="onlinepath")//視頻
					{
						if(strstr($wmv_type,",".$filetype.","))
						{}
					}
				}
				$tranf.=$dh.$f;
				$dh=",";
				$fval="[!#@-".$f."-@!]";
			}
			else
			{
				if($public_r['modinfoedittran']==1)
				{
					$fval=$add[$f];
					if($ecms==1&&$infor[$f]&&!trim($fval))
					{
						$fval=$infor[$f];
						//特殊字段
						if($f=="downpath"||$f=="onlinepath")
						{
							$fval=DoReqDownPath($fval);
						}
					}
				}
				else
				{
					$fval='';
					if($ecms==1)
					{
						$fval=$infor[$f];
						//特殊字段
						if($f=="downpath"||$f=="onlinepath")
						{
							$fval=DoReqDownPath($fval);
						}
					}
				}
			}
		}
		elseif($f=='newstime')//時間
		{
			if($add[$f])
			{
				$fval=to_time($add[$f]);
			}
			else
			{
				$fval=time();
			}
		}
		elseif($f=='newstext')//內容
		{
			if($ecms==0)
			{
				$fval=DoReplaceKeyAndWord($add[$f],1,$classid);//替換關鍵字和字符
			}
			else
			{
				$fval=$add[$f];
			}
		}
		elseif($f=='infoip')	//ip
		{
			$fval=egetip();
		}
		elseif($f=='infoipport')	//ip端口
		{
			$fval=egetipport();
		}
		elseif($f=='infozm')	//字母
		{
			$fval=$add[$f]?$add[$f]:GetInfoZm($add[title]);
		}
		else
		{
			$add[$f]=ReturnCheckboxAddF($add[$f],$mid,$f);//復選框
			$add[$f]=ReturnMoreValueAddF($add,$add[$f],$mid,$f,$ecms);//多值
			$fval=$add[$f];
		}
		$fval=eDoInfoTbfToQj($emod_r[$mid]['tbname'],$f,$fval,$public_r['qtoqjf']);
		$fval=DoFFun($mid,$f,$fval,$isadd,1);//執行函數
		$modispagef=$pagef==$f?1:0;
		$fval=RepTempvarPostStrT($fval,$modispagef);
		if($pagef!=$f)
		{
			$fval=RepTempvarPostStr($fval);
		}
		ChIsOnlyAddF($mid,$infor[id],$f,$fval,1);//唯一值
		$fval=DoqValue($mid,$f,$fval);
		$fval=DoqSpecialValue($mid,$f,$fval,$add,$infor,$ecms);
		$fval=RepPostStr2($fval);
		if($ecms==1)
		{
			SameDataAddF($info[id],$classid,$mid,$f,$fval);
		}
		$fval=addslashes($fval);
		if($ecms==0)//添加
		{
			if(strstr($emod_r[$mid]['tbdataf'],','.$f.','))//副表
			{
				$ret_r[2].=",".$f;
				$ret_r[3].=",'".$fval."'";
			}
			else
			{
				$ret_r[0].=",".$f;
				$ret_r[1].=",'".$fval."'";
			}
		}
		else//編輯
		{
			if($f=='infoip'||$f=='infoipport')	//ip
			{
				continue;
			}
			if(strstr($emod_r[$mid]['tbdataf'],','.$f.','))//副表
			{
				$ret_r[3].=",".$f."='".$fval."'";
			}
			else
			{
				$ret_r[0].=",".$f."='".$fval."'";
			}
		}
	}
	//上傳附件
	if($tranf)
	{
		if($ecms==0)
		{
			$infoid=0;
		}
		else
		{
			$infoid=$infor['id'];
			$filepass=0;
		}
		$tranr=explode(",",$tranf);
		$count=count($tranr);
		for($i=0;$i<$count;$i++)
		{
			$tf=$tranr[$i];
			$tffile=$tf."file";
			$tfr=DoTranFile($_FILES[$tffile]['tmp_name'],$_FILES[$tffile]['name'],$_FILES[$tffile]['type'],$_FILES[$tffile]['size'],$classid);
			if($tfr['tran'])
			{
				//文件類型
				$mvf=$tf."mtfile";
				if(strstr($emod_r[$mid]['imgf'],','.$tf.','))//圖片
				{
					$type=1;
				}
				elseif(strstr($emod_r[$mid]['flashf'],','.$tf.','))//flash
				{
					$type=2;
				}
				elseif($add[$mvf]==1)//多媒體
				{
					$type=3;
				}
				else//附件
				{
					$type=0;
				}
				//寫入數據庫
				$filetime=time();
				$filesize=(int)$_FILES[$tffile]['size'];
				$classid=(int)$classid;
				eInsertFileTable($tfr[filename],$filesize,$tfr[filepath],'[Member]'.$username,$classid,'['.$tf.']'.addslashes(RepPostStr($add[title])),$type,$infoid,$filepass,$public_r[fpath],0,0,($ecms==1?$infor['fstb']:$public_r['filedeftb']));
				//刪除舊文件
				if($ecms==1&&$infor[$tf])
				{
					DelYQTranFile($classid,$infor['id'],$infor[$tf],$tf,$infor['fstb']);
				}
				$repfval=$tfr['url'];
			}
			else
			{
				$repfval=$infor[$tf];
				//特殊字段
				if($tf=="downpath"||$tf=="onlinepath")
				{
					$repfval=DoReqDownPath($repfval);
				}
			}
			if($ecms==0)//添加
			{
				$ret_r[1]=str_replace("[!#@-".$tf."-@!]",$repfval,$ret_r[1]);
				$ret_r[3]=str_replace("[!#@-".$tf."-@!]",$repfval,$ret_r[3]);
			}
			else//編輯
			{
				$ret_r[0]=str_replace("[!#@-".$tf."-@!]",$repfval,$ret_r[0]);
				$ret_r[3]=str_replace("[!#@-".$tf."-@!]",$repfval,$ret_r[3]);
			}
		}
	}
	$ret_r[4]=$emod_r[$mid]['deftb'];
	return $ret_r;
}

//刪除原附件
function DelYQTranFile($classid,$id,$file,$tf,$fstb='1'){
	global $empire,$dbtbpre;
	//特殊字段
	if($tf=="downpath"||$tf=="onlinepath")
	{
		$file=DoReqDownPath($file);
	}
	if(empty($file))
	{
		return "";
	}
	$r=explode("/",$file);
	$count=count($r);
	$filename=$r[$count-1];
	$filename=addslashes(RepPostStr($filename));
	$fr=$empire->fetch1("select filename,path,fileid,fpath,classid from {$dbtbpre}enewsfile_{$fstb} where classid='$classid' and id='$id' and filename='$filename' limit 1");
	if($fr['fileid'])
	{
		$sql=$empire->query("delete from {$dbtbpre}enewsfile_{$fstb} where fileid='$fr[fileid]'");
		DoDelFile($fr);
	}
}

//信息投稿
function DodoInfo($add,$ecms=0){
	global $empire,$public_r,$emod_r,$level_r,$class_r,$dbtbpre,$fun_r;
	//驗證來源
	if($ecms==0||$ecms==1)
	{
		CheckCanPostUrl();
	}
	//開啟投稿
	if($public_r['addnews_ok'])
	{
		printerror("CloseQAdd","",1);
	}
	//驗證本時間允許操作
	eCheckTimeCloseDo('info');
	$classid=(int)$add['classid'];
	$mid=(int)$class_r[$classid]['modid'];
	if(!$mid||!$classid)
	{
		printerror("EmptyQinfoCid","",1);
	}
	$tbname=$emod_r[$mid]['tbname'];
	$qenter=$emod_r[$mid]['qenter'];
	if(!$tbname||!$qenter||$qenter==',')
	{
		printerror("ErrorUrl","history.go(-1)",1);
	}
	$muserid=(int)getcvar('mluserid');
	$musername=RepPostVar(getcvar('mlusername'));
	$mrnd=RepPostVar(getcvar('mlrnd'));
	//取得欄目信息
	$isadd=0;
	if($ecms==0)
	{
		$isadd=1;
	}
	$setuserday='';
	$cr=DoQCheckAddLevel($classid,$muserid,$musername,$mrnd,$ecms,$isadd);
	$setuserday=$cr['checkaddnumquery'];
	$filepass=(int)$add['filepass'];
	$id=(int)$add['id'];
	$infor=array();
	//組合標題屬性
	$titlecolor=addslashes(RepPostStr(RepPhpAspJspcodeText($add[titlecolor])));
	$titlefont=dgdb_tosave(TitleFont($add[titlefont],$titlecolor));
	$titlecolor="";
	$titlefont="";
	$ttid=(int)$add['ttid'];
	$keyboard=addslashes(RepPostStr(trim(DoReplaceQjDh($add[keyboard]))));
	$keyid='';
	//返回關鍵字組合
	if($keyboard&&strstr($qenter,',special.field,'))
	{
		$keyboard=str_replace('[!--f--!]','ecms',$keyboard);
		$keyid=GetKeyid($keyboard,$classid,$id,$class_r[$classid][link_num]);
		$keyid=dgdb_tosave($keyid);
	}
	else
	{
		$keyboard='';
		$keyid='';
	}
	//驗證碼
	$keyvname='checkinfokey';
	//moreport
	if(Moreport_ReturnMustDt())
	{
		define('ECMS_SELFPATH',eReturnEcmsMainPortPath());
		Moreport_ResetMainTempGid();
	}
	$epreid=0;
	//-----------------增加
	if($ecms==0)
	{
		//時間
		$lasttime=getcvar('lastaddinfotime');
		if($lasttime)
		{
			if(time()-$lasttime<$public_r['readdinfotime'])
			{
				printerror("QAddInfoOutTime","",1);
			}
		}
		//驗證碼
		if($cr['qaddshowkey'])
		{
			ecmsCheckShowKey($keyvname,$add['key'],1);
		}
		//IP發佈數限制
		$check_ip=egetip();
		$check_checked=$cr['wfid']?0:$cr['checkqadd'];
		eCheckIpAddInfoNum($check_ip,$tbname,$mid,$check_checked);
		//驗證單信息
		qCheckMemberOneInfo($tbname,$mid,$classid,$muserid);
		//返回字段
		$ret_r=ReturnQAddinfoF($mid,$add,$infor,$classid,$filepass,$muserid,$musername,0);
		$checked=$cr['checkqadd'];
		$havehtml=0;
		$newspath=date($cr['newspath']);
		$truetime=time();
		$newstime=$truetime;
		$newstempid=$cr['newstempid'];
		$haveaddfen=0;
		//強制簽發
		$isqf=0;
		if($cr['wfid'])
		{
			$checked=0;
			$isqf=1;
		}
		//增扣點
		if($muserid)
		{
			if($checked)
			{
				AddInfoFen($cr['addinfofen'],$muserid);
				$haveaddfen=1;
			}
			else
			{
				if($cr['addinfofen']<0&&!$public_r['qinfoaddfen'])
				{
					AddInfoFen($cr['addinfofen'],$muserid);
					$haveaddfen=1;
				}
			}
		}
		if(empty($muserid))
		{
			$musername=$fun_r['guest'];
		}
		//會員投稿數更新
		if($setuserday)
		{
			$empire->query($setuserday);
		}
		//發佈時間
		if(!strstr($qenter,',newstime,'))
		{
			$ret_r[0]=",newstime".$ret_r[0];
			$ret_r[1]=",'$newstime'".$ret_r[1];
		}
		else
		{
			if($add['newstime'])
			{
				$newstime=to_time($add['newstime']);
				$newstime=intval($newstime);
			}
		}
		//附加鏈接參數
		$addecmscheck=empty($checked)?'&ecmscheck=1':'';
		//索引表
		$indexsql=$empire->query("insert into {$dbtbpre}ecms_".$tbname."_index(classid,checked,newstime,truetime,lastdotime,havehtml) values('$classid','$checked','$newstime','$truetime','$truetime','$havehtml');");
		$id=$empire->lastid();
		//返回表信息
		$infotbr=ReturnInfoTbname($tbname,$checked,$ret_r[4]);
		//主表
		$sql=$empire->query("insert into ".$infotbr['tbname']."(id,classid,ttid,onclick,plnum,totaldown,newspath,filename,userid,username,firsttitle,isgood,istop,isqf,ismember,isurl,truetime,lastdotime,havehtml,groupid,userfen,titlefont,titleurl,stb,fstb,restb,keyboard".$ret_r[0].") values('$id','$classid','$ttid',0,0,0,'$newspath','','".$muserid."','".addslashes($musername)."',0,0,0,'$isqf',1,0,'$truetime','$truetime','$havehtml',0,0,'$titlefont','','$ret_r[4]','$public_r[filedeftb]','$public_r[pldeftb]','$keyboard'".$ret_r[1].");");
		//副表
		$fsql=$empire->query("insert into ".$infotbr['datatbname']."(id,classid,keyid,dokey,newstempid,closepl,haveaddfen,infotags".$ret_r[2].") values('$id','$classid','$keyid',1,'$newstempid',0,'$haveaddfen',''".$ret_r[3].");");
		//扣點記錄
		if($haveaddfen)
		{
			if($cr['addinfofen']<0)
			{
				BakDown($classid,$id,0,$muserid,$musername,addslashes(RepPostStr($add[title])),abs($cr['addinfofen']),3);
			}
		}
		//簽發
		if($isqf==1)
		{
			InfoInsertToWorkflow($id,$classid,$cr['wfid'],$muserid,addslashes($musername));
		}
		//文件命名
		$filename=ReturnInfoFilename($classid,$id,'');
		//信息地址
		$infourl=GotoGetTitleUrl($classid,$id,$newspath,$filename,0,0,'');
		$usql=$empire->query("update ".$infotbr['tbname']." set filename='$filename',titleurl='$infourl' where id='$id'");
		//修改ispic
		UpdateTheIspic($classid,$id,$checked);
		//修改附件
		if($filepass)
		{
			UpdateTheFile($id,$filepass,$classid,$public_r['filedeftb']);
		}
		//更新欄目信息數
		AddClassInfos($classid,'+1','+1',$checked);
		//更新新信息數
		DoUpdateAddDataNum('info',$class_r[$classid]['tid'],1);
		//處理函數
		DoMFun($class_r[$classid]['modid'],$classid,$id,1,1);
		//清除驗證碼
		ecmsEmptyShowKey($keyvname);
		esetcookie("qeditinfo","",0);
		//生成頁面
		if($checked&&!$cr['showdt'])
		{
			$titleurl=qAddGetHtml($classid,$id);
		}
		//生成列表
		$epreid=0;
		if($checked)
		{
			qAddListHtml($classid,$mid,$cr['qaddlist'],$cr['listdt']);
			//生成上一篇
			if($cr['repreinfo'])
			{
				$prer=$empire->fetch1("select * from {$dbtbpre}ecms_".$tbname." where id<$id and classid='$classid' order by id desc limit 1");
				$epreid=$prer['id'];
				GetHtml($prer['classid'],$prer['id'],$prer,1);
			}
		}
		//更新動態緩存
		if($public_r['ctimeopen']&&$checked)
		{
			eUpCacheInfo(0,$classid,0,$epreid,$ttid,'','',0,0);
		}
		if($sql)
		{
			$reurl=DoingReturnUrl("AddInfo.php?classid=$classid&mid=$mid".$addecmscheck,$add['ecmsfrom']);
			if($add['gotoinfourl']&&$checked)//返回內容頁
			{
				if($cr['showdt']==1)
				{
					$reurl=$public_r[newsurl]."e/action/ShowInfo/?classid=$classid&id=$id";
				}
				elseif($cr['showdt']==2)
				{
					$rewriter=eReturnRewriteInfoUrl($classid,$id,1);
					$reurl=$rewriter['pageurl'];
				}
				else
				{
					$reurl=$titleurl;
				}
			}
			esetcookie("lastaddinfotime",time(),time()+3600*24);//設置最後發表時間
			printerror("AddQinfoSuccess",$reurl,1);
		}
		else
		{printerror("DbError","history.go(-1)",1);}
	}
	//---------------修改
	elseif($ecms==1)
	{
		if(!$id)
		{
			printerror("ErrorUrl","history.go(-1)",1);
		}
		//檢測權限
		$infor=CheckQdoinfo($classid,$id,$muserid,$tbname,$cr['adminqinfo'],1);
		//檢測時間
		if($public_r['qeditinfotime'])
		{
			if(time()-$infor['truetime']>$public_r['qeditinfotime']*60)
			{
				printerror("QEditInfoOutTime","history.go(-1)",1);
			}
		}
		//簽發信息
		if($infor['isqf'])
		{
			$qck_qfr=$empire->fetch1("select wfid,checktno from {$dbtbpre}enewswfinfo where id='$infor[id]' and classid='$infor[classid]' limit 1");
			if($qck_qfr['checktno']<100)
			{
				$qck_qfwfr=$empire->fetch1("select wfid,canedit from {$dbtbpre}enewsworkflow where wfid='$qck_qfr[wfid]' limit 1");
				if($qck_qfwfr['wfid']&&!$qck_qfwfr['canedit'])
				{
					printerror("qWorkflowCanNotEditInfo","history.go(-1)",1);
				}
			}
		}
		$iaddfield='';
		$addfield='';
		$faddfield='';
		//返回字段
		$ret_r=ReturnQAddinfoF($mid,$add,$infor,$classid,$filepass,$muserid,$musername,1);
		if($keyboard)
		{
			$addfield=",keyboard='$keyboard'";
			$faddfield=",keyid='$keyid'";
		}
		//時間
		if(strstr($qenter,',newstime,'))
		{
			if($add['newstime'])
			{
				$newstime=to_time($add['newstime']);
				$newstime=intval($newstime);
				$iaddfield.=",newstime='$newstime'";
			}
		}
		//修改是否需要審核
		$ychecked=$infor['checked'];
		if($cr['qeditchecked'])
		{
			$infor['checked']=0;
			$iaddfield.=",checked=0";
			$relist=1;
			//刪除原頁面
			DelNewsFile($infor[filename],$infor[newspath],$infor[classid],$infor[newstext],$infor[groupid]);
		}
		//會員投稿數更新
		if($setuserday)
		{
			//$empire->query($setuserday);
		}
		$lastdotime=time();
		//附加鏈接參數
		$addecmscheck=empty($infor['checked'])?'&ecmscheck=1':'';
		//索引表
		$indexsql=$empire->query("update {$dbtbpre}ecms_".$tbname."_index set lastdotime=$lastdotime,havehtml=0".$iaddfield." where id='$id'");
		//返回表信息
		$infotbr=ReturnInfoTbname($tbname,$ychecked,$infor['stb']);
		//主表
		$sql=$empire->query("update ".$infotbr['tbname']." set lastdotime=$lastdotime,havehtml=0,ttid='$ttid'".$addfield.$ret_r[0]." where id=$id and classid=$classid and userid='$muserid' and ismember=1");
		//副表
		$fsql=$empire->query("update ".$infotbr['datatbname']." set classid='$classid'".$faddfield.$ret_r[3]." where id='$id'");
		//修改ispic
		UpdateTheIspic($classid,$id,$ychecked);
		//更新附件
		UpdateTheFileEdit($classid,$id,$infor['fstb']);
		//未審核信息互轉
		if($ychecked!=$infor['checked'])
		{
			MoveCheckInfoData($tbname,$ychecked,$infor['stb'],"id='$id'");
			//更新欄目信息數
			if($infor['checked'])
			{
				AddClassInfos($classid,'','+1');
			}
			else
			{
				AddClassInfos($classid,'','-1');
			}
		}
		//處理函數
		DoMFun($class_r[$classid]['modid'],$classid,$id,0,1);
		esetcookie("qeditinfo","",0);
		//生成頁面
		if($infor['checked']&&!$cr['showdt'])
		{
			$titleurl=qAddGetHtml($classid,$id);
		}
		//生成列表
		if($infor['checked']||$relist==1)
		{
			qAddListHtml($classid,$mid,$cr['qaddlist'],$cr['listdt']);
		}
		//生成上一篇
		$epreid=0;
		if($cr['repreinfo']&&$infor['checked'])
		{
			$prer=$empire->fetch1("select * from {$dbtbpre}ecms_".$tbname." where id<$id and classid='$classid' order by id desc limit 1");
			$epreid=$prer['id'];
			GetHtml($prer['classid'],$prer['id'],$prer,1);
		}
		//更新動態緩存
		if($public_r['ctimeopen']&&$infor['checked'])
		{
			eUpCacheInfo(0,$classid,0,$epreid,$ttid,'','',0,0);
		}
		if($sql)
		{
			$reurl=DoingReturnUrl("ListInfo.php?mid=$mid".$addecmscheck,$add['ecmsfrom']);
			if($add['editgotoinfourl']&&$infor['checked'])//返回內容頁
			{
				if($cr['showdt']==1)
				{
					$reurl=$public_r[newsurl]."e/action/ShowInfo/?classid=$classid&id=$id";
				}
				elseif($cr['showdt']==2)
				{
					$rewriter=eReturnRewriteInfoUrl($classid,$id,1);
					$reurl=$rewriter['pageurl'];
				}
				else
				{
					$reurl=$titleurl;
				}
			}
			printerror("EditQinfoSuccess",$reurl,1);
		}
		else
		{printerror("DbError","history.go(-1)",1);}
	}
	//---------------刪除
	elseif($ecms==2)
	{
		if(!$id)
		{
			printerror("ErrorUrl","history.go(-1)",1);
		}
		//檢測權限
		$r=CheckQdoinfo($classid,$id,$muserid,$tbname,$cr['adminqinfo'],2);
		//附加鏈接參數
		$addecmscheck=empty($r['checked'])?'&ecmscheck=1':'';
		//返回表信息
		$infotbr=ReturnInfoTbname($tbname,$r['checked'],$r['stb']);
		$stf=$emod_r[$mid]['savetxtf'];
		$pf=$emod_r[$mid]['pagef'];
		//分頁字段
		if($pf)
		{
			if(strstr($emod_r[$mid]['tbdataf'],','.$pf.','))
			{
				$finfor=$empire->fetch1("select ".$pf." from ".$infotbr['datatbname']." where id='$id' limit 1");
				$r[$pf]=$finfor[$pf];
			}
		}
		//存文本
		if($stf)
		{
			$newstextfile=$r[$stf];
			$r[$stf]=GetTxtFieldText($r[$stf]);
			//刪除文件
			DelTxtFieldText($newstextfile);
		}
		//刪除信息文件
		DelNewsFile($r[filename],$r[newspath],$classid,$r[$pf],$r[groupid]);
		$indexsql=$empire->query("delete from {$dbtbpre}ecms_".$tbname."_index where id='$id'");
		$sql=$empire->query("delete from ".$infotbr['tbname']." where id=$id and classid=$classid and userid='$muserid' and ismember=1");
		$fsql=$empire->query("delete from ".$infotbr['datatbname']." where id=$id");
		esetcookie("qdelinfo","",0);
		//更新欄目信息數
		AddClassInfos($classid,'-1','-1',$r['checked']);
		//刪除其它表記錄和附件
		DelSingleInfoOtherData($classid,$id,$r,0,0);
		//生成列表
		$epreid=0;
		$enextid=0;
		if($r['checked'])
		{
			qAddListHtml($classid,$mid,$cr['qaddlist'],$cr['listdt']);
			//生成上一篇
			if($cr['repreinfo'])
			{
				$prer=$empire->fetch1("select * from {$dbtbpre}ecms_".$tbname." where id<$id and classid='$classid' order by id desc limit 1");
				$epreid=$prer['id'];
				GetHtml($prer['classid'],$prer['id'],$prer,1);
				//下一篇
				$nextr=$empire->fetch1("select * from {$dbtbpre}ecms_".$tbname." where id>$id and classid='$classid' order by id limit 1");
				if($nextr['id'])
				{
					$enextid=$nextr['id'];
					GetHtml($nextr['classid'],$nextr['id'],$nextr,1);
				}
			}
		}
		//更新動態緩存
		if($public_r['ctimeopen']&&$r['checked'])
		{
			eUpCacheInfo(0,$classid,$enextid,$epreid,$r['ttid'],'','',0,0);
		}
		if($sql)
		{
			$reurl=DoingReturnUrl("ListInfo.php?mid=$mid",$add['ecmsfrom']);
			printerror("DelQinfoSuccess",$reurl,1);
		}
		else
		{printerror("DbError","history.go(-1)",1);}
	}
	else
	{
		printerror("ErrorUrl","",1);
	}
}

//投稿權限檢測
function DoQCheckAddLevel($classid,$userid,$username,$rnd,$ecms=0,$isadd=0){
	global $empire,$dbtbpre,$level_r,$public_r;
	$classid=(int)$classid;
	$user=array();
	$r=$empire->fetch1("select * from {$dbtbpre}enewsclass where classid='$classid'");
	if(!$r['classid']||$r[wburl])
	{
		printerror("EmptyQinfoCid","",1);
	}
	if(!$r['islast'])
	{
		printerror("MustLast","",1);
	}
	if($r['openadd'])
	{
		printerror("NotOpenCQInfo","",1);
	}
	//是否登陸
	if($ecms==1||$ecms==2||($r['qaddgroupid']&&$r['qaddgroupid']<>','))
	{
		$user=islogin($userid,$username,$rnd);
		//驗證新會員投稿
		if($isadd==1&&$public_r['newaddinfotime'])
		{
			qCheckNewMemberAddInfo($user[registertime]);
		}
	}
	//會員組
	if($r['qaddgroupid']&&$r['qaddgroupid']<>',')
	{
		if(!strstr($r['qaddgroupid'],','.$user[groupid].','))
		{
			printerror("HaveNotLevelAQinfo","history.go(-1)",1);
		}
	}
	if($isadd==1)
	{
		//檢測是否足夠點數
		if($r['addinfofen']<0&&$user['userid'])
		{
			MCheckEnoughFen($user['userfen'],$user['userdate'],$r['addinfofen']);
		}
		//檢測投稿數
		if($r['qaddgroupid']&&$r['qaddgroupid']<>','&&$level_r[$user[groupid]]['dayaddinfo'])
		{
			$r['checkaddnumquery']=DoQCheckAddNum($user['userid'],$user['groupid']);
		}
	}
	//審核
	if(($ecms==0||$ecms==1)&&$userid)
	{
		if(!$user[groupid])
		{
			$user=islogin($userid,$username,$rnd);
		}
		if($level_r[$user[groupid]]['infochecked'])
		{
			$r['checkqadd']=1;
			$r['qeditchecked']=0;
		}
	}
	//實名驗證
	eCheckHaveTruename('info',$user['userid'],$user['username'],$user['isern'],$user['checked'],0);

	return $r;
}

//檢查投稿數
function DoQCheckAddNum($userid,$groupid){
	global $empire,$dbtbpre,$level_r,$public_r;
	$userid=(int)$userid;
	$ur=$empire->fetch1("select userid,todayinfodate,todayaddinfo from {$dbtbpre}enewsmemberpub where userid='$userid' limit 1");
	$thetoday=date("Y-m-d");
	if($ur['userid'])
	{
		if($thetoday!=$ur['todayinfodate'])
		{
			$query="update {$dbtbpre}enewsmemberpub set todayinfodate='$thetoday',todayaddinfo=1 where userid='$userid'";
		}
		else
		{
			if($ur['todayaddinfo']>=$level_r[$groupid]['dayaddinfo'])
			{
				printerror("CrossDayInfo",$public_r['newsurl'],1);
			}
			$query="update {$dbtbpre}enewsmemberpub set todayaddinfo=todayaddinfo+1 where userid='$userid'";
		}
	}
	else
	{
		$query="replace into {$dbtbpre}enewsmemberpub(userid,todayinfodate,todayaddinfo) values('$userid','$thetoday',1);";
	}
	return $query;
}

//上傳附件
function DoQTranFile($add,$file,$file_name,$file_type,$file_size,$userid,$username,$rnd,$ecms=0){
	global $empire,$dbtbpre,$class_r,$public_r,$ecms_config;
	if($public_r['addnews_ok'])//關閉投稿
	{
		$ecms!=1?printerror("NotOpenCQInfo","",9):ECMS_QEditorPrintError(1,'','','NotOpenCQInfo','','');
	}
	$filepass=(int)$add['filepass'];
	$classid=(int)$add['classid'];
	$infoid=(int)$add['infoid'];
	if(!$file_name||!$filepass||!$classid||!$class_r[$classid][tbname])
	{
		$ecms!=1?printerror("EmptyQTranFile","",9):ECMS_QEditorPrintError(1,'','','EmptyQTranFile','','');
	}
	//信息
	if($infoid)
	{
		$index_r=$empire->fetch1("select classid,checked from {$dbtbpre}ecms_".$class_r[$classid][tbname]."_index where id='$infoid'");
		if(!$index_r['classid']||$classid!=$index_r['classid'])
		{
			$ecms!=1?printerror("EmptyQTranFile","",9):ECMS_QEditorPrintError(1,'','','EmptyQTranFile','','');
		}
		$infotb=ReturnInfoMainTbname($class_r[$classid][tbname],$index_r['checked']);
		$infor=$empire->fetch1("select classid,fstb from ".$infotb." where id='$infoid'");
		if(!$infor['fstb']||$classid!=$infor['classid'])
		{
			$ecms!=1?printerror("EmptyQTranFile","",9):ECMS_QEditorPrintError(1,'','','EmptyQTranFile','','');
		}
		$fstb=$infor['fstb'];
	}
	else
	{
		$fstb=$public_r['filedeftb'];
	}
	//驗證權限
	$userid=(int)$userid;
	$username=RepPostVar($username);
	$rnd=RepPostVar($rnd);
	DoQCheckAddLevel($classid,$userid,$username,$rnd,0,0);
	$filetype=GetFiletype($file_name);//取得文件類型
	if(CheckSaveTranFiletype($filetype))
	{
		$ecms!=1?printerror("NotQTranFiletype","",9):ECMS_QEditorPrintError(1,'','','NotQTranFiletype','','');
	}
	$type=(int)$add['type'];
	$pr=$empire->fetch1("select qaddtran,qaddtransize,qaddtranimgtype,qaddtranfile,qaddtranfilesize,qaddtranfiletype from {$dbtbpre}enewspublic limit 1");
	if($type==1)//圖片
	{
		if(!$pr['qaddtran'])
		{
			$ecms!=1?printerror("CloseQTranPic","",9):ECMS_QEditorPrintError(1,'','','CloseQTranPic','','');
		}
		if(!strstr($pr['qaddtranimgtype'],"|".$filetype."|"))
		{
			$ecms!=1?printerror("NotQTranFiletype","",9):ECMS_QEditorPrintError(1,'','','NotQTranFiletype','','');
		}
		if($file_size>$pr['qaddtransize']*1024)
		{
			$ecms!=1?printerror("TooBigQTranFile","",9):ECMS_QEditorPrintError(1,'','','TooBigQTranFile','','');
		}
		if(!strstr($ecms_config['sets']['tranpicturetype'],','.$filetype.','))
		{
			$ecms!=1?printerror("NotQTranFiletype","",9):ECMS_QEditorPrintError(1,'','','NotQTranFiletype','','');
		}
	}
	elseif($type==2)//flash
	{
		if(!$pr['qaddtranfile'])
		{
			$ecms!=1?printerror("CloseQTranFile","",9):ECMS_QEditorPrintError(1,'','','CloseQTranFile','','');
		}
		if(!strstr($pr['qaddtranfiletype'],"|".$filetype."|"))
		{
			$ecms!=1?printerror("NotQTranFiletype","",9):ECMS_QEditorPrintError(1,'','','NotQTranFiletype','','');
		}
		if($file_size>$pr['qaddtranfilesize']*1024)
		{
			$ecms!=1?printerror("TooBigQTranFile","",9):ECMS_QEditorPrintError(1,'','','TooBigQTranFile','','');
		}
		if(!strstr($ecms_config['sets']['tranflashtype'],','.$filetype.','))
		{
			$ecms!=1?printerror("NotQTranFiletype","",9):ECMS_QEditorPrintError(1,'','','NotQTranFiletype','','');
		}
	}
	else//附件
	{
		if(!$pr['qaddtranfile'])
		{
			$ecms!=1?printerror("CloseQTranFile","",9):ECMS_QEditorPrintError(1,'','','CloseQTranFile','','');
		}
		if(!strstr($pr['qaddtranfiletype'],"|".$filetype."|"))
		{
			$ecms!=1?printerror("NotQTranFiletype","",9):ECMS_QEditorPrintError(1,'','','NotQTranFiletype','','');
		}
		if($file_size>$pr['qaddtranfilesize']*1024)
		{
			$ecms!=1?printerror("TooBigQTranFile","",9):ECMS_QEditorPrintError(1,'','','TooBigQTranFile','','');
		}
	}
	$r=DoTranFile($file,$file_name,$file_type,$file_size,$classid);
	if(empty($r[tran]))
	{
		$ecms!=1?printerror("TranFail","",9):ECMS_QEditorPrintError(1,'','','TranFail','','');
	}
	//寫入數據庫
	$filetime=time();
	$r[filesize]=(int)$r[filesize];
	$classid=(int)$classid;
	eInsertFileTable($r[filename],$r[filesize],$r[filepath],'[Member]'.$username,$classid,$r[filename],$type,$filepass,$filepass,$public_r[fpath],0,0,$fstb);
	//編輯器
	if($ecms==1)
	{
		ECMS_QEditorPrintError(0,$r[url],$r[filename],'',$r[filename],$r[filesize]);
	}
	else
	{
		eCheckStrType(4,$add['field'],1);
		echo"<script>opener.document.add.".$add['field'].".value='".$r['url']."';window.close();</script>";
	}
	db_close();
	$empire=null;
	exit();
}

//----------- 編輯器 --------------

//提示信息
function ECMS_QEditorPrintError($errorNumber,$fileUrl,$fileName,$customMsg,$fileno,$filesize){
	if(empty($errorNumber))
	{
		$errorNumber=0;
		$filesize=ChTheFilesize($filesize);
	}
	else
	{
		@include LoadLang("pub/q_message.php");
		$customMsg=$qmessage_r[$customMsg];
	}
	$errorNumber=(int)$errorNumber;
	$typer=ECMS_EditorReturnType('');
	$type=$typer['ftype'];
	//附件
	if($type==0)
	{
		$fileUrl=$fileUrl.'##'.$fileno.'##'.$filesize;
	}
	ECMS_PTEditorShowError($type,addslashes($customMsg),addslashes($fileUrl),$add,0);
	db_close();
	exit();
}
?>