<?php
require($netsFileConfig['sysCoreRoot'].'Inc/m_comm/microblogging/commmicroblogging.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.'commmicroblogging','sttColumnHead'=>'combt'),
			array('sttTableName'=>$this->sysTableHead.'commmicrobloggingcont','sttColumnHead'=>'combct'),);
		$this->sUiName='User/comm/microblogging';
	}
	public function OnBInitial(){
		$this->sMetaTitle='微博';
		$this->sLimitCount=0;
		$this->sApp=new commmicroblogging($this->sConnString);
		
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.combgtID,A.combgtName,A.combgtParid 
			FROM '.$this->sysTableHead.'commmicroblogginggroup AS A
			WHERE 1=1 AND A.combgtRecycle=0 AND A.combgtChecked>1 AND A.combgtParid={Nets.Parid}
			ORDER BY A.combgtOrderBy DESC,A.combgtID DESC ';
		$tmpAR0['SQL0']=' SELECT A.combgtID,A.combgtName,A.combgtParid 
			FROM '.$this->sysTableHead.'commmicroblogginggroup AS A
			WHERE 1=1 AND A.combgtRecycle=0 AND A.combgtChecked>1 AND A.combgtID={Nets.Parid}
			ORDER BY A.combgtOrderBy DESC,A.combgtID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='combgtID';
		$tmpAR0['Text']='combgtName';
		$tmpAR0['Value']='combgtID';
		$tmpAR0['Type']=0;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='comm/comm_Microblogginggroup_UserList';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sParid1);
		$this->sParid2=$this->sParid1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有分类]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sParid2,$tmpAR0);
		//Type
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=67;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='nets/Comm_Microblogging_Type';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sType1);
		$this->sType2=$this->sType1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sType2,$tmpAR0);
		
	}
	public function OnAdd_Frame(){
		$tmpDbDescriptions=array();
		foreach ($this->sTable as $tableCell){
			$tmpDbDescriptions[]=$this->sDbDescriptions[$tableCell['sttTableName']];
		}
		$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];
		//-- ------ #Add ------ --
		$this->sApp->TransStart();
		//#Get numCode
		$tmpSTR=$this->sTable[0]['sttColumnHead'].'NumCode';
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N_'.date('YmdHis');
		$this->sApp->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]])){
					if ($tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].$Row0[0]]['Value']==$Row0[1]) {
						$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($tmpDbDescriptions[$Cell[0]]['Columns'][$Cell[1]]['Value'])){
				$tmpDbDescriptions[$Cell[0]]['Columns'][$Cell[1]]['Value']=$Cell[2];
			}
		}
		//-- #Set spical --
		$tmpAR0=$this->AnalyerRequest('combctContent_ParTxt','',1);
		$tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].'Content']['Value'].='<div class="MBlog_Quote"><b>原文：</b>'.$tmpAR0[0].'</div>';
		
		$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'Name']['Value']=$this->sCode->FilterHTML($this->sCode->SubString($tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].'Content']['Value'],0,60),'',0);
		$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'Checked']['Value']=2;
		$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateBy']['Value']=$this->sUserInfo[0]['Columns']['uitID']['Value'];
		
		//#Add
		$tmpINT=$this->sApp->Check($tmpDbDescriptions,array(),array());
		if($tmpINT!=0){
			$this->sApp->TransRollback();
			$this->sJscript=$this->Message('ERROR','',$this->sApp->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=$this->sApp->add($tmpDbDescriptions);
		if($tmpINT!=0){
			$this->sApp->TransRollback();
			$this->sJscript=$this->Message('ERROR','',$this->sApp->sysLastError,'');
			return 1;
		}
		
		foreach ($this->sDb->sysDbCacheClear as $Cell){
			$this->clearCache($Cell);
		}
		foreach ($this->sysPageCacheClear as $Cell){
			$this->clearCache($Cell);
		}
		$this->sApp->TransCommit();
		/*
		$this->sJscript=$this->Message('SUCCESS','','添加成功',$this->sysPage.'?ActionType=Normal&Normal='.$tmpMainid[0].','.$tmpMainTableid[0].'');
		*/
		$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),
			'');
		return 0;
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'combtID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1,-1',0);
		//#Spell sql
		$tmpSQL=' SELECT A.combtID,A.combtName,A.combtParid,A.combtType
			FROM '.$this->sysTableHead.'commmicroblogging AS A 
			WHERE 1=1
			AND A.combtCreateBy='.$this->sUserInfo[0]['Columns']['uitID']['Value'].' AND A.combtID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.combtName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.combtParid='.$this->sSearchData[1].' ';
		}
		if($this->sSearchData[2]!='-1'){
			$tmpSQL.=' AND A.combtType='.$this->sSearchData[2].' ';
		}
		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->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'combtID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'combtName','stcoctUiName'=>'微博名称');
		
		return 0;
	}
	public function OnExternal_Search(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'combtID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',,-1',0);
		$this->sExternal_SearchData=$this->AnalyerRequest($this->sActionType,',-1',0);
		//#Spell sql
		$tmpSQL=' SELECT A.combtID,A.combtName,A.combtParid
			FROM '.$this->sysTableHead.'commmicroblogging AS A 
			WHERE 1=1 
			AND A.combtID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.combtName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.combtParid='.$this->sSearchData[1].' ';
		}
		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'=>'combtID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'combtName','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.combtID,A.combtName,A.combtParid 
				FROM '.$this->sysTableHead.'commmicroblogging AS A
				WHERE 1=1 AND A.combtRecycle=0 AND A.combtChecked>1 AND 
				A.combtParid=(SELECT combtParid FROM commmicroblogging WHERE 1=1 AND combtRecycle=0 AND combtChecked>1 AND combtID={Nets.ID})
				ORDER BY A.combtOrderBy DESC,A.combtID DESC ';
		}else if($this->sExternal_ChildChooseSData[0]==1 || $this->sExternal_ChildChooseSData[0]==3){
			//-- Child grade --
			$tmpSQL=' SELECT A.combtID,A.combtName,A.combtParid 
				FROM '.$this->sysTableHead.'commmicroblogging AS A
				WHERE 1=1 AND A.combtRecycle=0 AND A.combtChecked>1 AND A.combtParid={Nets.ID}
				ORDER BY A.combtOrderBy DESC,A.combtID 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.'commmicroblogging AS A 
			INNER JOIN '.$this->sysTableHead.'commmicrobloggingcont AS B ON B.combctIndexID=A.combtID ';
		if($this->sMainTableid!=0 && $this->sMainTableid!=-1){
			$tmpSQL.=' LEFT OUTER JOIN '.$this->sTable[2]['sttTableName'].' AS C ON C.'.$this->sTable[2]['sttColumnHead'].'IndexID=A.combtID ';
		}
		$tmpSQL.=' WHERE 1=1 AND A.combtID='.$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']=='combtParid'){
					}else if($this->sUiDescription_Normal[$Coun0]['stcotName']=='combtModelid_Detail'){
						$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
					}
				}
				$Coun0++;
			}
		}else {
			$Coun0=0;
			foreach($this->sUiDescription_Normal as $Row0){
				if($Row0['stcotName']=='combtTableid'){
					$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
				}
				$Coun0++;
			}
		}
	}
	public function OnNormal_Frame(){
		$tmpAR0=$this->AnalyerRequest('DParid',0,0);
		//-- ------ #Get par ------ --
		$tmpSQL=' SELECT A.combtID,A.combtName,B.combctContent
			FROM {Nets.TableHead}commmicroblogging AS A
			INNER JOIN {Nets.TableHead}commmicrobloggingcont AS B ON B.combctIndexID=A.combtID
			WHERE 1=1 AND A.combtRecycle=0 AND A.combtChecked>1 AND A.combtID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$tmpAR0[0],$tmpSTR);
		$tmpData0=$this->sDb->Search($tmpSTR);
		if (count($tmpData0)==0) {
			$this->sJscript=$this->Message_Frame('A,0',
				$this->sysFileConfig['sysCoreRoot'].$this->sysFileConfig['PathManaFrameMessage'],
				$this->sCode->URL_MakeParameter('转发失败',0),
				$this->sCode->URL_MakeParameter('对不起，您要转发的微博并不存在',0),
				'');
			return 1;
		}
		//-- ------ #SET ------ --
		$Coun0=0;
		while (count($this->sUiDescription_Normal_Frame)>$Coun0) {
			if ($this->sUiDescription_Normal_Frame[$Coun0]['stcotName']=='combtURL') {
				$this->sUiDescription_Normal_Frame[$Coun0]['ShowValue']='<a href="../../../Plus/m_default/Comm/microbloggingDetail.php?ID='.$tmpData0[0]['combtID'].'" target="_blank">../../../Plus/m_default/Comm/microbloggingDetail.php?ID='.$tmpData0[0]['combtID'].'</a>';
			}else if ($this->sUiDescription_Normal_Frame[$Coun0]['stcotName']=='combctContent_Par') {
				$this->sUiDescription_Normal_Frame[$Coun0]['Value']=$tmpData0[0]['combctContent'];
				$this->sUiDescription_Normal_Frame[$Coun0]['ShowValue']=$tmpData0[0]['combctContent'];

			}
			$Coun0++;
		}
		
		return 0;
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='combtParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='combtParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sParid1;
		}else if($pColumn['stcotName']=='combtType' && $pFlag=='Search'){
			$pColumn['Option']=$this->sType2;
		}else if($pColumn['stcotName']=='combtType' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sType1;
			
		}
		return $pColumn;
	}
	public function DefUiButton($pFlag,$Exception){
		parent::DefUiButton($pFlag,array('Normal_Frame',));
		if ($pFlag=='Normal_Frame' && !in_array($pFlag,$Exception)) { ?>
<input type="submit" value="保存" class="Control2" onclick="tmpCommon.setActionType('','DAdd_Frame','','');" />

<?php }
	}
	
}

?>