<?php
require($netsFileConfig['sysCoreRoot_Real'].'Cache/DbDescription/gsnavigationunit.php');
require($netsFileConfig['sysCoreRoot_Real'].'Cache/DbDescription/gsnavigationunitcont.php');
require($netsFileConfig['sysCoreRoot_Real'].'Cache/DbDescription/gsnavigationunitdiscuss.php');
require($netsFileConfig['sysCoreRoot_Real'].'Cache/DbDescription/gsnavigationunitdiscusscont.php');
require($netsFileConfig['sysCoreRoot_Real'].'Inc/m_Gsnavigation/Gsnavigation/gsnavigationunit.php');
require($netsFileConfig['sysCoreRoot_Real'].'Inc/m_Gsnavigation/Gsnavigation/gsnavigationunitdiscuss.php');


class PaDefault extends CustomPage {
	public function PaDefault(){
		$this->CustomPage();
	}
	public function OnBInitial(){
		$this->sMetaTitle='团购首页';
		$this->getUser('1,2,3,4,5,');
		$this->sTemplatePath='Gsnavigation/gsnavigationunitDetail_Normal.php';
		$this->sApp=new gsnavigationunit($this->sConnString);
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'gsnavigationunit','sttColumnHead'=>'gsnut'),
			array('sttTableName'=>$this->sysTableHead.'gsnavigationunitcont','sttColumnHead'=>'gsnuct'),);

		//-- #Share link --
		$this->sData_LinkShare=array();
		$tmpCacheFlag='nets/options_LinkShare_Groupsale';
		$tmpAR_Cache=$this->sDb->readCache($tmpCacheFlag);
		if(count($tmpAR_Cache)==0){
			$tmpParid=20;
			$tmpSQL=' SELECT A.cltID,A.cltName,A.cltURL,A.cltTarget,B.clctSourceR00
				FROM {Nets.TableHead}cmslink AS A
				INNER JOIN {Nets.TableHead}cmslinkcont AS B ON B.clctIndexID=A.cltID
				WHERE 1=1 AND A.cltRecycle=0 AND A.cltChecked>1 AND A.cltParid={Nets.Parid}
				ORDER BY A.cltOrderBy DESC,A.cltID DESC ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.Parid}',$tmpParid,$tmpSTR);
			$this->sData_LinkShare=$this->sDb->Search($tmpSTR);
			
			if($this->sysFileConfig['CacheDbAble']==1){
				$this->sDb->writeCache($tmpCacheFlag,$this->sData_LinkShare);
			}
		}else {
			$this->sData_LinkShare=$tmpAR_Cache;
		}
		
		
	}
	public function OnAdd(){
		$tmpApp=new gsnavigationunitdiscuss($this->sConnString);
		$tmpTable=array(
			array('sttTableName'=>$this->sysTableHead.'gsnavigationunitdiscuss','sttColumnHead'=>'gsnudt'),
			array('sttTableName'=>$this->sysTableHead.'gsnavigationunitdiscusscont','sttColumnHead'=>'gsnudct'),);
		
		$tmpDbDescriptions=array();
		foreach ($tmpTable 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 ------ --
		$tmpApp->TransStart();
		//#Get numCode
		$tmpSTR=$tmpTable[0]['sttColumnHead'].'NumCode';
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N_'.date('YmdHis');
		$tmpApp->numCode($tmpDbDescriptions[0]);
		//#Set value
		$tmpDbDescription0=$tmpDbDescriptions;
		$Coun0=0;
		foreach ($tmpDbDescription0 as $tableCell){
			foreach ($tableCell['Columns'] as $Column){
				if($Column['stcotName']!=$tmpTable[$Coun0]['sttColumnHead'].'ID' &&
					$Column['stcotName']!=$tmpTable[$Coun0]['sttColumnHead'].'NumCode' &&
					$Column['stcotName']!=$tmpTable[$Coun0]['sttColumnHead'].'CreateBy' &&
					$Column['stcotName']!=$tmpTable[$Coun0]['sttColumnHead'].'CreateTime' &&
					$Column['stcotName']!=$tmpTable[$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'][$tmpTable[0]['sttColumnHead'].'CreateBy']['Value'])){
			$tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'CreateBy']['Value']=$tmpMainUserid[0];
		}
		if(isset($tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'CreateTime'])){
			$tmpDbDescriptions[0]['Columns'][$tmpTable[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'][$tmpTable[1]['sttColumnHead'].$Row0[0]])){
					if ($tmpDbDescriptions[1]['Columns'][$tmpTable[1]['sttColumnHead'].$Row0[0]]['Value']==$Row0[1]) {
						$tmpFlag=1;
					}
				}
			}
			if ($this->sUserInfo[0]['Columns']['uitID']['Value']==0 && $tmpFlag==1) {
				$tmpDbDescriptions[1]['Columns'][$tmpTable[1]['sttColumnHead'].$Row0[0]]['Value']=$Row0[4];
			}else if ($tmpFlag==1 && isset($tmpDbDescriptions[1]['Columns'][$tmpTable[1]['sttColumnHead'].$Row0[0]])) {
				$tmpDbDescriptions[1]['Columns'][$tmpTable[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 --
		$tmpDbDescriptions[0]['Columns']['gsnudtParid']['Value']=$this->sMainID;
		$tmpDbDescriptions[0]['Columns']['gsnudtChecked']['Value']=2;
		
		
		//#Add
		$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']=$tmpTable[$Coun0]['sttColumnHead'].'NumCode,'.$tmpTable[$Coun0]['sttColumnHead'].'ID';
			}else {
				$tmpDbDescriptions[$Coun0]['TableDescription']['SearchColumn']=$tmpTable[$Coun0]['sttColumnHead'].'IndexID';
			}
			$Coun0++;
		}
		$tmpINT=$tmpApp->add($tmpDbDescriptions);
		if($tmpINT!=0){
			$tmpApp->TransRollback();
			$this->sJscript=$this->Message('ERROR','',$tmpApp->sysLastError,'');
			return 1;
		}
		
		foreach ($this->sDb->sysDbCacheClear as $Cell){
			$this->clearCache($Cell);
		}
		foreach ($this->sysPageCacheClear as $Cell){
			$this->clearCache($Cell);
		}
		$tmpApp->TransCommit();
		$this->sJscript=$this->Message('SUCCESS','','添加成功',$this->sysPage.'?ID='.$this->sMainID);
		/*
		$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];
		//-- ------ #Initial ------ --
		$tmpINT=$this->sApp->initialObject($this->sMainID);
		//-- ------ #Datas ------ --
		$tmpSQL=' SELECT A.gsnutID,A.gsnutName,A.gsnutParid,A.gsnutNameStyle,A.gsnutURL,
			B.gsnuctCount_Discuss,B.gsnuctPageAble,B.gsnuctTemplateid_Detail,B.gsnuctIntroduct,B.gsnuctContent,B.gsnuctSourceR00,
			B.gsnuctInfo_PublishTime,B.gsnuctInfo_SaleType,B.gsnuctInfo_SiteType,B.gsnuctInfo_ActiveFrequency,
			B.gsnuctInfo_OrderCount,B.gsnuctFlow_Alex
			
			FROM {Nets.TableHead}gsnavigationunit AS A 
			INNER JOIN {Nets.TableHead}gsnavigationunitcont AS B ON B.gsnuctIndexID=A.gsnutID
			WHERE 1=1 AND A.gsnutRecycle=0 AND A.gsnutChecked>1 AND A.gsnutID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sMainID,$tmpSTR);
		$this->sDetailData=$this->sDb->Search($tmpSTR);
		if(count($this->sDetailData)==0){
			//#Error
			//#Other
			$tmpSQL=' SELECT A.gsnutID,A.gsnutName,A.gsnutCreateTime
				FROM {Nets.TableHead}gsnavigationunit AS A 
				WHERE 1=1 AND A.gsnutRecycle=0 AND A.gsnutChecked>1
				ORDER BY A.gsnutOrderBy DESC,A.gsnutID DESC LIMIT 0,8 ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$this->sOtherData=$this->sDb->Search($tmpSTR);
			return 1;
		}
		$this->sMainID=$this->sDetailData[0]['gsnutID'];
		$this->sMetaTitle=$this->sDetailData[0]['gsnutName'];
		$this->sParid=$this->sDetailData[0]['gsnutParid'];
		
		if($this->sDetailData[0]['gsnuctPageAble']==1){
			$tmpCListSTR0='DCList0';
			$tmpCListAR0=$this->AnalyerRequest($tmpCListSTR0,'1,0',0);
			$this->sCPButton=new netsConPButton();
			$this->sCPButton->sPage=$this->sysPage;
			$this->sCPButton->sExtendParameter='&ID='.$this->sMainID;
			$this->sCPButton->setPage($tmpCListAR0,$this->sDetailData[0]['gsnuctContent']);
			$this->sDetailData[0]['gsnuctContent']=$this->sCPButton->getContent();
		}else {
			$this->sDetailData[0]['gsnuctContent']=str_replace($this->sysSPLIT12,'',$this->sDetailData[0]['gsnuctContent']);
		}
		//-- ------ #Group ------ --
		$tmpSQL=' SELECT A.gsnugtID,A.gsnugtName,B.gsnugctTemplateid_Detail
			FROM {Nets.TableHead}gsnavigationunitgroup AS A
			INNER JOIN {Nets.TableHead}gsnavigationunitgroupcont AS B ON B.gsnugctIndexID=A.gsnugtID
			WHERE 1=1 AND A.gsnugtRecycle=0 AND A.gsnugtChecked>1 AND A.gsnugtID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sMainID,$tmpSTR);
		$this->sData_Group=$this->sDb->Search($tmpSTR);
		if(count($this->sData_Group)==0){
			//#Non group
			//#Other
			$this->sData_Group[0]=array(
				'gsnugctTemplateid_Detail'=>0
				);
		}
		//-- ------ #Template ------ --
		//#List
		$tmpSQL=' SELECT A.stemtID,A.stemtName,B.stemctPath 
			FROM {Nets.TableHead}netssystemplate AS A
			INNER JOIN {Nets.TableHead}netssystemplatecont AS B ON B.stemctIndexID=A.stemtID
			WHERE 1=1 AND A.stemtRecycle=0 AND A.stemtChecked>1 AND A.stemtID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sData_Group[0]['gsnugctTemplateid_Detail'],$tmpSTR);
		$tmpData0=$this->sDb->Search($tmpSTR);
		if(count($tmpData0)!=0){
			$this->sTemplatePath=$tmpData0[0]['stemctPath'];
		}
		//#Detail
		$tmpSQL=' SELECT A.stemtID,A.stemtName,B.stemctPath 
			FROM {Nets.TableHead}netssystemplate AS A
			INNER JOIN {Nets.TableHead}netssystemplatecont AS B ON B.stemctIndexID=A.stemtID
			WHERE 1=1 AND A.stemtRecycle=0 AND A.stemtChecked>1 AND A.stemtID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sDetailData[0]['gsnuctTemplateid_Detail'],$tmpSTR);
		$tmpData0=$this->sDb->Search($tmpSTR);
		if(count($tmpData0)!=0){
			$this->sTemplatePath=$tmpData0[0]['stemctPath'];
		}
		//-- ------ #Navigation ------ --
		$this->sNavigation=$this->sDb->getParent($this->sDetailData[0]['gsnutParid'],$this->sysTableHead.'gsnavigationunitgroup','gsnugt');
		//-- ------ #Other ------ --
		//Next
		$tmpSQL=' SELECT A.gsnutID,A.gsnutName,A.gsnutCreateTime
			FROM {Nets.TableHead}gsnavigationunit AS A 
			WHERE 1=1 AND A.gsnutRecycle=0 AND A.gsnutChecked>1 AND gsnutID>{Nets.ID} AND A.gsnutParid={Nets.Parid}
			ORDER BY A.gsnutOrderBy DESC,A.gsnutID DESC LIMIT 0,1 ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sDetailData[0]['gsnutID'],$tmpSTR);
		$tmpSTR=str_replace('{Nets.Parid}',$this->sDetailData[0]['gsnutParid'],$tmpSTR);
		$this->sNextData=$this->sDb->Search($tmpSTR);
		//Previous
		$tmpSQL=' SELECT A.gsnutID,A.gsnutName,A.gsnutCreateTime
			FROM {Nets.TableHead}gsnavigationunit AS A 
			WHERE 1=1 AND A.gsnutRecycle=0 AND A.gsnutChecked>1 AND gsnutID<{Nets.ID} AND A.gsnutParid={Nets.Parid}
			ORDER BY A.gsnutOrderBy DESC,A.gsnutID DESC LIMIT 0,1 ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sDetailData[0]['gsnutID'],$tmpSTR);
		$tmpSTR=str_replace('{Nets.Parid}',$this->sDetailData[0]['gsnutParid'],$tmpSTR);
		$this->sPreviousData=$this->sDb->Search($tmpSTR);
		//Other
		$tmpSQL=' SELECT A.gsnutID,A.gsnutName,A.gsnutCreateTime
			FROM {Nets.TableHead}gsnavigationunit AS A 
			WHERE 1=1 AND A.gsnutRecycle=0 AND A.gsnutChecked>1 AND A.gsnutParid={Nets.Parid}
			ORDER BY A.gsnutOrderBy DESC,A.gsnutID DESC LIMIT 0,8 ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSTR);
		$tmpSTR=str_replace('{Nets.Parid}',$this->sDetailData[0]['gsnutParid'],$tmpSTR);
		$this->sOtherData=$this->sDb->Search($tmpSTR);
		//-- ------ #Discuss ------ --
		$tmpListSTR0='DList0';
		$tmpListAR0=$this->AnalyerRequest($tmpListSTR0,'1,0,12,0',0);
		$tmpSortSTR0='DSort0';
		$tmpSortAR0=$this->AnalyerRequest($tmpSortSTR0,'gsnudtID,2',0);
		//Data
		$tmpSQL=' SELECT A.gsnudtID,A.gsnudtCreateTime,B.gsnudctPublisher_Name,B.gsnudctContent
			FROM {Nets.TableHead}gsnavigationunitdiscuss AS A
			INNER JOIN {Nets.TableHead}gsnavigationunitdiscusscont AS B ON B.gsnudctIndexID=A.gsnudtID
			WHERE 1=1 AND A.gsnudtRecycle=0 AND A.gsnudtChecked>1 AND A.gsnudtParid={Nets.ID}
			ORDER BY A.gsnudtOrderBy DESC,A.gsnudtID DESC ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sMainID,$tmpSTR);
		$this->sDiscussData=$this->sDb->SearchP($tmpSTR,$tmpListAR0);
		$this->sRecordCount_Discuss=$this->sDb->sysPageInfo[3];
		//#Set page button
		$this->sPAjaxButton->sPage=$this->sysPage;
		$this->sPAjaxButton->sFlag='discussBox';
		$this->sPAjaxButton->sPanel='discussBox';
		$this->sPAjaxButton->resetTemlate('../../../Config/m_default/File/pageAjaxButton3.htm');
		$this->sPAjaxButton->sExtendParameter='&ID='.$this->sMainID;
		$this->sPAjaxButton->setPage($this->sDb->sysPageInfo);
		//-- ------ #Active ------ --
		$tmpListSTR1='DList1';
		$tmpListAR1=$this->AnalyerRequest($tmpListSTR1,'1,0,8,0',0);
		$tmpSortSTR1='DSort1';
		$tmpSortAR1=$this->AnalyerRequest($tmpSortSTR1,'gsnatID,2',0);
		//Data
		$tmpSQL=' SELECT A.gsnatID,A.gsnatName,A.gsnatParid,A.gsnatState,
			B.gsnactPrice_EndTime,B.gsnactPrice_Origin,B.gsnactPrice_Now,B.gsnactPrice_Sale,B.gsnactCount_Order,B.gsnactSourceR00,
			B.gsnactCount_Views,B.gsnactCount_Discuss,
			C.gsnutID,C.gsnutName
			FROM {Nets.TableHead}gsnavigationactive AS A
			INNER JOIN {Nets.TableHead}gsnavigationactivecont AS B ON B.gsnactIndexID=A.gsnatID
			INNER JOIN {Nets.TableHead}gsnavigationunit AS C ON C.gsnutID=A.gsnatUnitid
			WHERE 1=1 AND A.gsnatRecycle=0 AND A.gsnatChecked>1 AND A.gsnatUnitid={Nets.ID}
			ORDER BY A.gsnatOrderBy DESC,A.gsnatID DESC ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sMainID,$tmpSTR);
		$this->sActiveData=$this->sDb->SearchP($tmpSTR,$tmpListAR1);
		$this->sRecordCount_Active=$this->sDb->sysPageInfo[3];
		//#Set page button
		$this->sPAjaxButton_Active=new netsPAjaxButton();
		$this->sPAjaxButton_Active->sPage=$this->sysPage;
		$this->sPAjaxButton_Active->sPageName=$tmpListSTR1;
		$this->sPAjaxButton_Active->sSortName=$tmpSortSTR1;
		$this->sPAjaxButton_Active->sFlag='activeBox';
		$this->sPAjaxButton_Active->sPanel='activeBox';
		$this->sPAjaxButton_Active->resetTemlate('../../../Config/m_default/File/pageAjaxButton3.htm');
		$this->sPAjaxButton_Active->sExtendParameter='&ID='.$this->sMainID;
		$this->sPAjaxButton_Active->setPage($this->sDb->sysPageInfo);
		
		//-- ------ #Discuss form ------ --
		$this->sUiDescription_0=array();
		$tmpSTR=$this->sUiDescriptionPath.'Plus/gsnavigation/gsnavigationunit_discuss.php';
		if(file_exists($tmpSTR)){
			require($tmpSTR);
			$this->sUiDescription_0=$sysUiDescriptions['gsnavigationunit_discuss'];
			$sysUiDescriptions=array();
		}
		
		
	}
	public function DefUiPanel(&$pColumn,$pFlag){
		if($pColumn['stcotName']=='gsnudctContent' && $pFlag=='Normal'){
			$pColumn['ControlStyle']='width:500px;height:40px;';
			$pColumn['Parameter_JS_Onfocus']="tmpMCommon.OnDiscussInput(this.name,0);CCodeTxt_ShowCACode(0);";
		}
	}
	
	
}

?>