<?php
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/commposts.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/commpostscont.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Comm/Posts/commposts.php');

class PaDefault extends CustomPage {
	public function PaDefault(){
		$this->CustomPage();
	}
	public function OnBInitial(){
		$this->sMetaTitle='发布新话题';
		$this->getUser('1,2,3,4,5,');
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'commposts','sttColumnHead'=>'copt'),
			array('sttTableName'=>$this->sysTableHead.'commpostscont','sttColumnHead'=>'copct'),);
		//-- ------ #Get option ------ --
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.copgtID,A.copgtName,A.copgtParid 
			FROM '.$this->sysTableHead.'commpostsgroup AS A
			WHERE 1=1 AND A.copgtRecycle=0 AND A.copgtChecked>1 AND A.copgtParid={Nets.Parid}
			ORDER BY A.copgtOrderBy DESC,A.copgtID DESC ';
		$tmpAR0['SQL0']=' SELECT A.copgtID,A.copgtName,A.copgtParid 
			FROM '.$this->sysTableHead.'commpostsgroup AS A
			WHERE 1=1 AND A.copgtRecycle=0 AND A.copgtChecked>1 AND A.copgtID={Nets.Parid}
			ORDER BY A.copgtOrderBy DESC,A.copgtID DESC ';
		$tmpAR0['InitialString']=2;
		$tmpAR0['Parid']='copgtID';
		$tmpAR0['Text']='copgtName';
		$tmpAR0['Value']='copgtID';
		$tmpAR0['Type']=0;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$this->sParid1=$this->sParid2=$this->sControl->bindDropdown($tmpAR0);
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[未选择所在版块]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sParid2,$tmpAR0);
	}
	public function OnAdd(){
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'commposts','sttColumnHead'=>'copt'),
			array('sttTableName'=>$this->sysTableHead.'commpostscont','sttColumnHead'=>'copct'),);
		$tmpDbDescriptions=array();
		foreach ($this->sTable as $tableCell){
			$tmpDbDescriptions[]=$this->sDbDescriptions[$tableCell['sttTableName']];
		}
		$tmpApp=new commposts($this->sConnString);
		
		$tmpMainid=$this->AnalyerRequest('mainID',0,1);
		$this->sMainID=$tmpMainid[0];
		$tmpMainUserid=$this->AnalyerRequest('mainUserid',0,1);
		$this->sMainUserid=$tmpMainid[0];
		$tmpMainTableid=$this->AnalyerRequest('mainTableid',0,1);
		$this->sMainTableid=$tmpMainid[0];
		//-- ------ #Submit limit check ------ --
		$tmpINT=$this->submitLimitRead($this->sysPage,-1,-1,-1);
		if($tmpINT!=0){
			/*
			$this->sJscript=$this->Message('SUCCESS','','对不起，您登陆次数过多，请'.$this->sysFileConfig['SubmitLimitFreeze'].'秒后再尝试登陆。','');
			return 1;
			
			*/
		}
		//-- ------ #CCode ------ --
		$tmpSTR='CCode';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt','',1);
		$tmpCCode=$tmpAR0[0];
		$tmpSTR=$tmpSTR.'Txt_IFrame';
		if(!array_key_exists($tmpSTR,$_SESSION)){
			$this->submitLimitWrite($this->sysPage,-1,-1,-1);
			$this->sJscript=$this->Message('ERROR','提交失败','验证码错误','');
			return 1;
		}
		if($_SESSION[$tmpSTR]=='' || $_SESSION[$tmpSTR]!=$tmpCCode){
			$this->submitLimitWrite($this->sysPage,-1,-1,-1);
			$this->sJscript=$this->Message('ERROR','提交失败','验证码错误','');
			return 1;
		}
		//-- ------ #Add ------ --
		$tmpApp->TransStart();
		//#Get numCode
		$tmpSTR=$this->sTable[0]['sttColumnHead'].'NumCode';
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N'.$this->sysSPLIT11.date('YmdHis');
		$tmpApp->numCode($tmpDbDescriptions[0]);
		//#Set value
		$tmpDbDescription0=$tmpDbDescriptions;
		$Coun0=0;
		foreach ($tmpDbDescription0 as $tableCell){
			foreach ($tableCell['Columns'] as $Column){
				if($Column['stcotName']!=$this->sTable[$Coun0]['sttColumnHead'].'ID' &&
					$Column['stcotName']!=$this->sTable[$Coun0]['sttColumnHead'].'NumCode' &&
					$Column['stcotName']!=$this->sTable[$Coun0]['sttColumnHead'].'CreateBy' &&
					$Column['stcotName']!=$this->sTable[$Coun0]['sttColumnHead'].'CreateTime' &&
					$Column['stcotName']!=$this->sTable[$Coun0]['sttColumnHead'].'IndexID'){
					$tmpAR0=$this->AnalyerRequest($Column['stcotName'].'Txt',$Column['stcoctDefaultValue'],1);
					$tmpDbDescriptions[$Coun0]['Columns'][$Column['stcotName']]['Value']=$tmpAR0[0];
				}
			}
			$Coun0++;
		}
		//-- #Set conventional --
		if(isset($tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateBy']['Value'])){
			$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateBy']['Value']=$tmpMainUserid[0];
		}
		if(isset($tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateTime'])){
			$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateTime']['Value']=date($this->sysTimeFormat);
		}
		//DB name,Condition,User index,User column name
		$tmpFlag=0;
		foreach ($this->AnonymousUserData as $Row0){
			if (count($tmpDbDescriptions)>1) {
				if(isset($tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].$Row0[0]])){
					$tmpFlag=1;
				}
			}
			if ($this->sUserInfo[0]['Columns']['uitID']['Value']==0 && $tmpFlag==1) {
				$tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].$Row0[0]]['Value']=$Row0[4];
			}else if ($tmpFlag==1 && isset($tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].$Row0[0]])) {
				$tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].$Row0[0]]['Value']=$this->sUserInfo[$Row0[2]]['Columns'][$Row0[3]]['Value'];
			}
		}
		//Spical value array
		foreach ($this->sSpicalValue as $Cell){
			if(isset($tmpDbDescription[$Cell[0]]['Columns'][$Cell[1]]['Value'])){
				$tmpDbDescription[$Cell[0]]['Columns'][$Cell[1]]['Value']=$Cell[2];
			}
		}
		//-- #Set spical --
		$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'Checked']['Value']=2;
		if ($tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateBy']['Value']==0) {
			$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateBy']['Value']=2;
		}
		$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateTime']['Value']=date($this->sysTimeFormat);
		
		//#Add
		$tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].'Content']['Value']=$this->sCode->FilterINPUT($tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].'Content']['Value'],3);
		$tmpINT=$tmpApp->Check($tmpDbDescriptions,array(),array());
		if($tmpINT!=0){
			$tmpApp->TransRollback();
			$this->sJscript=$this->Message('ERROR','',$tmpApp->sysLastError,'');
			return 1;
		}
		$Coun0=0;
		while (count($tmpDbDescriptions)>$Coun0){
			if($Coun0==0){
				$tmpDbDescriptions[$Coun0]['TableDescription']['SearchColumn']=$this->sTable[$Coun0]['sttColumnHead'].'NumCode,'.$this->sTable[$Coun0]['sttColumnHead'].'ID';
			}else {
				$tmpDbDescriptions[$Coun0]['TableDescription']['SearchColumn']=$this->sTable[$Coun0]['sttColumnHead'].'IndexID';
			}
			$Coun0++;
		}
		$tmpINT=$tmpApp->add($tmpDbDescriptions);
		if($tmpINT!=0){
			$tmpApp->TransRollback();
			$this->sJscript=$this->Message('ERROR','',$tmpApp->sysLastError,'');
			return 1;
		}
		
		$tmpApp->TransCommit();
		$this->submitLimitWrite($this->sysPage,-1,-1,-1);
		$this->sJscript=$this->Message('SUCCESS','','您已成功发布话题','');
		/*
		$this->sJscript=$this->Message_Frame('A,0',
			$this->sysFileConfig['sysCoreRoot'].$this->sysFileConfig['PathManaFrameMessage'],
			$this->sCode->URL_MakeParameter('添加成功',0),
			$this->sCode->URL_MakeParameter($this->sApp->sysLastError,0),
			$this->sCode->URL_MakeParameter($this->sysFileConfig['sysCoreRoot'].'Mana/m_cms/doc/doc.php',0));
		*/
		return 0;
	}
	public function OnList(){
		$tmpAR0=$this->AnalyerRequest('ID',-1,0);
		$this->sMainID=$tmpAR0[0];
		//-- ------ #Group ------ --
		$tmpSQL=' SELECT A.copgtID,A.copgtName,
			B.copgctSourceR00
			FROM '.$this->sysTableHead.'commpostsgroup AS A 
			INNER JOIN '.$this->sysTableHead.'commpostsgroupcont AS B ON B.copgctIndexID=A.copgtID
			WHERE 1=1 AND A.copgtRecycle=0 AND A.copgtChecked>1 AND A.copgtID={Nets.ID}
			ORDER BY A.copgtOrderBy DESC,A.copgtID DESC ';
		$tmpSTR=str_replace('{Nets.ID}',$this->sMainID,$tmpSQL);
		$this->sDetailData=$this->sDb->Search($tmpSTR);
		if(count($this->sDetailData)!=1){
			//Error
		}else {
			$this->sMainID=$this->sDetailData[0]['copgtID'];
			$this->sMetaTitle='在'.$this->sDetailData[0]['copgtName'].$this->sMetaTitle;
			$this->sNavigation=$this->sDb->getParent($this->sMainID,$this->sysTableHead.'commpostsgroup','copgt');
		}
		//-- ------ #Discuss form ------ --
		$this->sUiDescription_0=array();
		$tmpSTR=$this->sUiDescriptionPath.'User/comm/posts_public.php';
		if(file_exists($tmpSTR)){
			require($tmpSTR);
			$this->sUiDescription_0=$sysUiDescriptions['posts_public'];
			$sysUiDescriptions=array();
		}
		
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='coptParid'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='copctContent' && $pFlag=='Normal'){
			$pColumn['ControlStyle']='width:640px;height:40px;';
			$pColumn['Parameter_JS_Onfocus']="tmpMCommon.OnDiscussInput(this.name,0);CCodeTxt_ShowCACode(0);";
			
		}
		if ($pColumn['stcoctUiType']=='Text') {
			$pColumn['ControlStyle']='width:640px;';
		}
		return $pColumn;
	}
	public function DefUiJscript($pFlag){
?>
function jsDCheck(pPara){
	var tmpControl="";
	var tmpError="";
	var tmpChecker=new netsChecker();
	var tmpActionWithOut=document.getElementById("ActionWithOut");
	var Coun0=0;
	//-- ------ #ActionWithOut ------ --
	if(tmpActionWithOut==undefined){
		return true;
	}
	if(tmpActionWithOut.value=="1"){
		return true;
	}else if(tmpActionWithOut.value=="2"){
		return false;
	}
	//-- ------ #Check ------ --
		//#coptName
	tmpCheckCont=document.getElementById("coptNameTxt");
	tmpCheckCont.value=tmpChecker.Filter(tmpCheckCont.value,0);
	if(tmpCheckCont.value.length<3){
		Coun0++;
		tmpError+=Coun0+".标题不能小于3个字符。"+sysSPLIT8;
	}
	//#coptParid
	tmpCheckCont=document.getElementById("coptParidTxt");
	tmpCheckCont.value=tmpChecker.Filter(tmpCheckCont.value,0);
	if(tmpCheckCont.value==-1){
		Coun0++;
		tmpError+=Coun0+".请选择话题所在版块。"+sysSPLIT8;
	}
	//#copctContent
	tmpCheckCont=document.getElementById("copctContentTxt");
	tmpCheckCont.value=tmpChecker.Filter(tmpCheckCont.value,0);
	if(tmpCheckCont.value.length<3){
		Coun0++;
		tmpError+=Coun0+".内容不能小于3个字符。"+sysSPLIT8;
	}
	//#coptCCode
	tmpCheckCont=document.getElementById("coptCCodeTxt");
	tmpCheckCont.value=tmpChecker.Filter(tmpCheckCont.value,0);
	if(tmpCheckCont.value.length!=5){
		Coun0++;
		tmpError+=Coun0+".验证码必须为5位数字。"+sysSPLIT8;
	}
	//-- ------ #Result ------ --
	if(tmpError!=""){
		tmpSTR="<span class=\"FStrong\">对不起，您提交的内容存在以下错误:</span>"+sysSPLIT8+tmpError;
		showMessage("系统消息 - <?php echo ($this->sysFileConfig['bussinessMetaTitle']); ?>",tmpSTR,"","0");
		return false;
	}else{
		return true;
	}
}
<?php
	}
}
?>