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

class PaDefault extends CustomPage {
	public $ssetParid=1;
	
	public function PaDefault(){
		$this->CustomPage();
	}
	public function OnPInitial(){
		$this->checkUser('1,2,3,');
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'commposts','sttColumnHead'=>'copt'),
			array('sttTableName'=>$this->sysTableHead.'commpostscont','sttColumnHead'=>'copct'),);
		$this->sUiName='User/comm/commposts';
		
	}
	public function OnBInitial(){
		$this->sMetaTitle='帖子';
		$this->sLimitCount=0;
		$this->sApp=new commposts($this->sConnString);
		//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']=$this->ssetParid;
		$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);
		//Icon
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=69;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='nets/options_Commposts_Icon';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sIcon1);
		$this->sIcon2=$this->sIcon1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有类型]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sIcon2,$tmpAR0);
		//Essence
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=68;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='nets/options_Commposts_Essence';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sEssence1);
		$this->sEssence2=$this->sEssence1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有类型]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sEssence2,$tmpAR0);
		
		
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'coptID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1,-1,-1',0);
		//#Spell sql
		$tmpSQL=' SELECT A.coptID,A.coptName,A.coptParid,B.copctTop,B.copctHot
			FROM '.$this->sysTableHead.'commposts AS A 
			INNER JOIN '.$this->sysTableHead.'commpostscont AS B ON B.copctIndexID=A.coptID
			WHERE 1=1 
			AND A.coptID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.coptName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!=-1){
			$tmpSQL.=' AND A.coptParid='.$this->sSearchData[1].' ';
		}
		if($this->sSearchData[2]!=-1){
			$tmpSQL.=' AND A.copctTop='.$this->sSearchData[2].' ';
		}
		if($this->sSearchData[3]!=-1){
			$tmpSQL.=' AND A.copctHot='.$this->sSearchData[3].' ';
		}
		if($tmpAR1[1]==1){
			$tmpSQL.=' ORDER BY '.$tmpAR1[0].' ';
		}else if($tmpAR1[1]==2){
			$tmpSQL.=' ORDER BY '.$tmpAR1[0].' DESC ';
		}
		$this->sListData=$this->sDb->SearchP($tmpSQL,$tmpAR0);
		//#Set page button
		$this->sPButton->sPage=$this->sysPage;
		$this->sPButton->sExtendParameter='&'.$tmpSTR2.'='.$this->sSearchData[0].$this->sysSPLIT1.$this->sSearchData[1].$this->sysSPLIT1.$this->sSearchData[2].$this->sysSPLIT1.$this->sSearchData[3];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'coptID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'coptName','stcoctUiName'=>'帖子名称');
		
		return 0;
	}
	public function OnExternal_Search(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'coptID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,'',0);
		$this->sExternal_SearchData=$this->AnalyerRequest($this->sActionType,',-1',0);
		//#Spell sql
		$tmpSQL=' SELECT A.coptID,A.coptName,A.coptParid
			FROM '.$this->sysTableHead.'commposts AS A 
			WHERE 1=1 
			AND A.coptID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.coptName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($tmpAR1[1]==1){
			$tmpSQL.=' ORDER BY '.$tmpAR1[0].' ';
		}else if($tmpAR1[1]==2){
			$tmpSQL.=' ORDER BY '.$tmpAR1[0].' DESC ';
		}
		$this->sListData=$this->sDb->SearchP($tmpSQL,$tmpAR0);
		//#Set page button
		$this->sExtendParameter='&ActionType='.$this->sActionType.'&'.$this->sActionType.'='.$this->sExternal_SearchData[0].','.$this->sExternal_SearchData[1];
		$this->sysPages[0]=$this->sysPage.'?'.$this->sExtendParameter;
		
		$this->sPButton->sPage=$this->sysPage;
		$this->sPButton->sExtendParameter='&'.$tmpSTR2.'='.$this->sSearchData[0].$this->sExtendParameter;
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'coptID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'coptName','stcoctUiName'=>'帖子名称');
		
		return 0;
	}
	public function OnExternal_ChildChoose(){
		//-- ------ #Search data ------ --
		$tmpSTR0='External_ChildChoose';
		$this->sExternal_ChildChooseSData=$this->AnalyerRequest($tmpSTR0,'0,,0,0',0);
		//#Spell sql
		$tmpSQL='';
		if($this->sExternal_ChildChooseSData[0]==0 || $this->sExternal_ChildChooseSData[0]==2){
			//-- Same grade --
			$tmpSQL=' SELECT A.coptID,A.coptName,A.coptParid 
				FROM '.$this->sysTableHead.'commposts AS A
				WHERE 1=1 AND A.coptRecycle=0 AND A.coptChecked>1 AND 
				A.coptParid=(SELECT coptParid FROM commposts WHERE 1=1 AND coptRecycle=0 AND coptChecked>1 AND coptID={Nets.ID})
				ORDER BY A.coptOrderBy DESC,A.coptID DESC ';
		}else if($this->sExternal_ChildChooseSData[0]==1 || $this->sExternal_ChildChooseSData[0]==3){
			//-- Child grade --
			$tmpSQL=' SELECT A.coptID,A.coptName,A.coptParid 
				FROM '.$this->sysTableHead.'commposts AS A
				WHERE 1=1 AND A.coptRecycle=0 AND A.coptChecked>1 AND A.coptParid={Nets.ID}
				ORDER BY A.coptOrderBy DESC,A.coptID DESC ';
		}
		$tmpSTR=str_replace('{Nets.ID}',$this->sExternal_ChildChooseSData[2],$tmpSQL);
		$this->sExternal_ChildChooseData=$this->sDb->Search($tmpSTR);
		
		return 0;
	}
	public function OnNormal(){
		$tmpINT=0;
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'commposts AS A 
			INNER JOIN '.$this->sysTableHead.'commpostscont AS B ON B.copctIndexID=A.coptID ';
		$Coun0=2;
		foreach ($this->sTable as $Row0){
			if (count($this->sTable)>2) {
				$tmpSQL.=' INNER JOIN '.$Row0['sttTableName'].' AS '.$this->sysTableMark[$Coun0].' ON '.$this->sysTableMark[$Coun0].'.'.$Row0['sttColumnHead'].'IndexID=A.coptID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.coptID='.$tmpAR0[0].' ';
		$tmpDataCollection0=$this->sDb->Search($tmpSQL);
		if(count($tmpDataCollection0)>0){
			$tmpRow=$tmpDataCollection0[0];
			$this->sMainID=$tmpRow[$this->sTable[0]['sttColumnHead'].'ID'];
			//-- #Get value --
			$Coun0=0;
			while (count($this->sUiDescription_Normal)>$Coun0) {
				if(isset($tmpRow[$this->sUiDescription_Normal[$Coun0]['stcotName']])){
					$this->sUiDescription_Normal[$Coun0]['Value']=$tmpRow[$this->sUiDescription_Normal[$Coun0]['stcotName']];
					//-- ------ #Spical set ------ --
					if($this->sUiDescription_Normal[$Coun0]['stcotName']=='coptParid'){
					}else if($this->sUiDescription_Normal[$Coun0]['stcotName']=='coptModelid_Detail'){
						$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
						
					}else if($this->sUiDescription_Normal[$Coun0]['stcotName']=='coptCircleid'){
						//cdctChannelid
						$tmpSQL=' SELECT A.coctID,A.coctName FROM '.$this->sysTableHead.'commcircle AS A
							WHERE 1=1 AND A.coctRecycle=0 AND A.coctChecked>1 AND (1=2 {Nets.IDS}) ';
						$tmpAR0=explode($this->sysSPLIT1,$tmpRow[$this->sUiDescription_Normal[$Coun0]['stcotName']]);
						$tmpSTR='';
						foreach ($tmpAR0 as $Cell0){
							$tmpSTR.=' OR A.coctID='.$this->sCode->Int32($Cell0,0);
						}
						$tmpSTR=str_replace('{Nets.IDS}',$tmpSTR,$tmpSQL);
						$tmpData0=$this->sDb->Search($tmpSTR);
						foreach ($tmpData0 as $Row0){
							$this->sUiDescription_Normal[$Coun0]['ShowValue']=$Row0['coctName'];
							
						}
						
						
						
					}
				}
				$Coun0++;
			}
		}else {
			$Coun0=0;
			foreach($this->sUiDescription_Normal as $Row0){
				if($Row0['stcotName']=='coptTableid'){
					$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
				}
				$Coun0++;
			}
		}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='coptParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='coptParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sParid1;
		}else if($pColumn['stcotName']=='copctTop' && $pFlag=='Search'){
			$pColumn['Option']=$this->sBoolean2;
		}else if($pColumn['stcotName']=='copctTop' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sBoolean1;
		}else if($pColumn['stcotName']=='copctHot' && $pFlag=='Search'){
			$pColumn['Option']=$this->sBoolean2;
		}else if($pColumn['stcotName']=='copctHot' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sBoolean1;
		}else if($pColumn['stcotName']=='copctIcon' && $pFlag=='Search'){
			$pColumn['Option']=$this->sIcon2;
		}else if($pColumn['stcotName']=='copctIcon' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sIcon1;
		}else if($pColumn['stcotName']=='copctEssence' && $pFlag=='Search'){
			$pColumn['Option']=$this->sEssence2;
		}else if($pColumn['stcotName']=='copctEssence' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sEssence1;

		}else if($pColumn['stcotName']=='coptCircleid'){
			$pColumn['Parameter']='chooseSearch;coptCircleidTxt;External_Search;'.$this->sysFileConfig['sysCoreRoot'].'Mana/m_comm/circle/circle.php';


		}
		return $pColumn;
	}
	public function DefUiButton($pFlag,$Exception){
		parent::DefUiButton($pFlag,array('List','Normal','ListChildLink',));
		if($pFlag=='List' && !in_array($pFlag,$Exception)){ ?>
<li class="ButBut Button_Normal"><a href="<?php echo($this->sysFileConfig['PathRoot']); ?>" class="Link1 FBlack2" target=“_blank”>查看</a></li>

<?php }else if ($pFlag=='Normal' && !in_array($pFlag,$Exception)) { ?>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpCommon.confirmDo('删除后将不能恢复，您确定删除本信息吗?');tmpCommon.setActionType('','DDelete','',''); tmpCommon.netsSubmit();">删除</a></li>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpCommon.setActionType('Normal','DModify','',''); tmpCommon.netsSubmit();">修改</a></li>

<?php }else if ($pFlag=='ListChildLink' && !in_array($pFlag,$Exception)) { ?>
<li id="ListTabChild_0" class="TabChildNormal"><a href="../../../Plus/Common/Cms/ask_public.php?ActionType=Publish" class="Link1 SBlue1">添加<?php echo ($this->sMetaTitle); ?></a></li>
<!--
<li class="TabChildSelected"><a href="#Here" class="Link2 FBlue1"><?php echo ($this->sMetaTitle); ?>管理</a></li>
<li class="DLeft"><img src="<?php echo($this->sysFileConfig['sysUiCoreRoot']); ?>Ui/m_nets/Img/Mana/34.jpg" /></li>
<li class="TabChildNomal"><a href="#Here" class="Link1 FBlue1"><?php echo ($this->sMetaTitle); ?>管理</a></li>
-->

<?php }
	}
	
	
}

?>