<?php
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/shopcodesale.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/shopcodesalecont.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/shopcodesalediscuss.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/shopcodesalediscusscont.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/shopcodesaleorder.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/shopcodesaleordercont.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Shop/Sale/shopcodesale.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Shop/Sale/shopcodesalediscuss.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Shop/Sale/shopcodesaleorder.php');

class PaDefault extends CustomPage {
	public $sDetailTab=0;
	public $sIsAuction=0;
	
	public function PaDefault(){
		$this->CustomPage();
	}
	public function OnBInitial(){
		$this->sMetaTitle='首页';
		$this->getUser('1,2,3,4,5,');
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'shopcodesale','sttColumnHead'=>'shcst'),
			array('sttTableName'=>$this->sysTableHead.'shopcodesalecont','sttColumnHead'=>'shcsct'),);
		$this->sApp=new shopcodesale($this->sConnString);
		$this->sTemplatePath='Shop/codeDetail_Normal.php';
		
		if ($this->sActionType=='DOrder') {
			$this->OnOrder();
			$this->OnList();
		}

	}
	public function OnOrder(){
		$tmpAR0=$this->AnalyerRequest('ID',0,0);
		$this->sMainID=$tmpAR0[0];
		//-- ------ #Initial ------ --
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'shopcodesaleorder','sttColumnHead'=>'shcsot'),
			array('sttTableName'=>$this->sysTableHead.'shopcodesaleordercont','sttColumnHead'=>'shcsoct'),);
		$tmpDbDescriptions=array();
		foreach ($this->sTable as $tableCell){
			$tmpDbDescriptions[]=$this->sDbDescriptions[$tableCell['sttTableName']];
		}
		
		$tmpDbDescriptions[0]['Columns']['shcsotCreateBy']['Value']=$this->sUserInfo[0]['Columns']['uitID']['Value'];
		$tmpDbDescriptions[1]['Columns']['shcsoctSales']['Value']=$this->sMainID.$this->sysSPLIT1.'1'.$this->sysSPLIT2;
		//-- ------ #Add ------ --
		$tmpCount=0;
		$tmpINT=$this->sApp->MakeOrder($tmpDbDescriptions);
		if ($tmpINT!=0) {
			$this->sMessage=$this->sApp->sysLastError;
			$this->sJscript=$this->Message('ERROR','',$this->sMessage,'');
			return 1;
		}
		
		$this->sMessage='您已成功投票。'.$this->sysSPLIT1.$tmpCount;
		$this->sJscript=$this->Message('ERROR','',$this->sMessage,'');
		return 0;
	}
	public function OnAdd(){
		$tmpApp=new shopcodesalediscuss($this->sConnString);
		$tmpTable=array(
			array('sttTableName'=>$this->sysTableHead.'shopcodesalediscuss','sttColumnHead'=>'shcsdt'),
			array('sttTableName'=>$this->sysTableHead.'shopcodesalediscusscont','sttColumnHead'=>'shcsdct'),);

		$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];
		//-- ------ #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=$tmpTable[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']!=$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]])){
					$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) {
				$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($tmpDbDescription[$Cell[0]]['Columns'][$Cell[1]]['Value'])){
				$tmpDbDescription[$Cell[0]]['Columns'][$Cell[1]]['Value']=$Cell[2];
			}
		}
		//-- #Set spical --
		$tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'Name']['Value']=$this->sCode->SubString($tmpDbDescriptions[1]['Columns'][$tmpTable[1]['sttColumnHead'].'Content']['Value'],0,60);
		$tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'Parid']['Value']=$this->sMainID;
		$tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'Checked']['Value']=2;
		if ($tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'CreateBy']['Value']==0) {
			$tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'CreateBy']['Value']=2;
		}
		$tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'CreateTime']['Value']=date($this->sysTimeFormat);
		
		//#Add
		$tmpDbDescriptions[1]['Columns'][$tmpTable[1]['sttColumnHead'].'Content']['Value']=$this->sCode->FilterINPUT($tmpDbDescriptions[1]['Columns'][$tmpTable[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']=$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;
		}
		
		$tmpApp->TransCommit();
		$this->submitLimitWrite($this->sysPage,-1,-1,-1);
		$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',0,0);
		$this->sMainID=$tmpAR0[0];
		//-- ------ #Initial ------ --
		$tmpINT=$this->sApp->initialObject($this->sMainID);
		//-- ------ #Datas ------ --
		$tmpSQL=' SELECT *
			FROM {Nets.TableHead}shopcodesale AS A
			INNER JOIN {Nets.TableHead}shopcodesalecont AS B ON B.shcsctIndexID=A.shcstID
			WHERE 1=1 AND A.shcstRecycle=0 AND A.shcstChecked>1 AND A.shcstID={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.shcstID,A.shcstName,A.shcstParid,A.shcstCreateTime
				FROM {Nets.TableHead}shopcodesale AS A 
				WHERE 1=1 AND A.shcstRecycle=0 AND A.shcstChecked>1
				ORDER BY A.shcstOrderBy DESC,A.shcstID DESC LIMIT 0,8 ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$this->sOtherData=$this->sDb->Search($tmpSTR);
			return 1;
		}
		$this->sMetaTitle=$this->sDetailData[0]['shcstName'];
		//-- ------ #Navigation ------ --
		$this->sNavigation=$this->sDb->getParent($this->sDetailData[0]['shcstParid'],$this->sysTableHead.'shopcodesalegroup','shcsgt');
		//-- ------ #Unit ------ --
		$tmpSQL=' SELECT *
			FROM {Nets.TableHead}netsuserinfo AS A
			INNER JOIN {Nets.TableHead}netsuserinfocont AS B ON B.uictIndexID=A.uitID
			INNER JOIN {Nets.TableHead}netsuserunit AS C ON C.uutID=A.uitUnitid
			INNER JOIN {Nets.TableHead}netsuserunitcont AS D ON D.uuctIndexID=C.uutID
			WHERE 1=1 AND A.uitRecycle=0 AND A.uitChecked>1 AND C.uutRecycle=0 AND C.uutChecked>1 AND A.uitID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sDetailData[0]['shcstCreateBy'],$tmpSTR);
		$this->sUnitData=$this->sDb->Search($tmpSTR);
		if(count($this->sUnitData)==0){
			//Error
		}
		//-- ------ #Other ------ --
		//Next
		$tmpSQL=' SELECT A.shcstID,A.shcstName,A.shcstCreateTime
			FROM {Nets.TableHead}shopcodesale AS A 
			WHERE 1=1 AND A.shcstRecycle=0 AND A.shcstChecked>1 AND shcstID>{Nets.ID} AND A.shcstParid={Nets.Parid}
			ORDER BY A.shcstOrderBy DESC,A.shcstID DESC LIMIT 0,1 ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sDetailData[0]['shcstID'],$tmpSTR);
		$tmpSTR=str_replace('{Nets.Parid}',$this->sDetailData[0]['shcstParid'],$tmpSTR);
		$this->sNextData=$this->sDb->Search($tmpSTR);
		//Previous
		$tmpSQL=' SELECT A.shcstID,A.shcstName,A.shcstCreateTime
			FROM {Nets.TableHead}shopcodesale AS A 
			WHERE 1=1 AND A.shcstRecycle=0 AND A.shcstChecked>1 AND shcstID<{Nets.ID} AND A.shcstParid={Nets.Parid}
			ORDER BY A.shcstOrderBy DESC,A.shcstID DESC LIMIT 0,1 ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sDetailData[0]['shcstID'],$tmpSTR);
		$tmpSTR=str_replace('{Nets.Parid}',$this->sDetailData[0]['shcstParid'],$tmpSTR);
		$this->sPreviousData=$this->sDb->Search($tmpSTR);
		//Other
		$tmpSQL=' SELECT A.shcstID,A.shcstName,A.shcstCreateTime
			FROM {Nets.TableHead}shopcodesale AS A 
			WHERE 1=1 AND A.shcstRecycle=0 AND A.shcstChecked>1 AND A.shcstParid={Nets.Parid}
			ORDER BY A.shcstOrderBy DESC,A.shcstID DESC LIMIT 0,8 ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.Parid}',$this->sDetailData[0]['shcstParid'],$tmpSTR);
		$this->sOtherData=$this->sDb->Search($tmpSTR);
		//-- ------ #Orders ------ --
		$tmpListSTR0='DList0_Order';
		$tmpListAR0=$this->AnalyerRequest($tmpListSTR0,'1,0,18,0',0);
		$tmpSortSTR0='DSort0_Order';
		$tmpSortAR0=$this->AnalyerRequest($tmpSortSTR0,'shcsotID,2',0);
		//-- #Spell SQL --
		$tmpSQL=' SELECT A.shcsotID,A.shcsotState,A.shcsotTotalPrice
			FROM {Nets.TableHead}shopcodesaleorder AS A 
			INNER JOIN {Nets.TableHead}shopcodesaleordercont AS B ON B.shcsoctIndexID=A.shcsotID
			WHERE 1=1
			ORDER BY A.shcsotID DESC ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.Parid}',$this->sMainID,$tmpSTR);
		$this->sListData_Order=$this->sDb->SearchP($tmpSTR,$tmpListAR0);
		$this->sRecordCount_Order=$this->sDb->sysPageInfo[3];
		//#Set page button
		$this->sPButton_Order=new netsPButton();
		$this->sPButton_Order->resetTemlate('../../../Config/m_default/File/pageButton3.htm');
		$this->sPButton_Order->sPage=$this->sysPage;
		$this->sPButton_Order->sExtendParameter='&ID='.$this->sMainID;
		$this->sPButton_Order->setPage($this->sDb->sysPageInfo);
		//-- ------ #Discuss ------ --
		$tmpListSTR0='DList0_Discuss';
		$tmpListAR0=$this->AnalyerRequest($tmpListSTR0,'1,0,12,0',0);
		$tmpSortSTR0='DSort0_Discuss';
		$tmpSortAR0=$this->AnalyerRequest($tmpSortSTR0,'shcsdtID,2',0);
		//-- #Spell SQL --
		$tmpSQL=' SELECT A.shcsdtID,A.shcsdtCreateTime,
			B.shcsdctPublisher_Name,B.shcsdctContent
			
			FROM {Nets.TableHead}shopcodesalediscuss AS A 
			INNER JOIN {Nets.TableHead}shopcodesalediscusscont AS B ON B.shcsdctIndexID=A.shcsdtID
			WHERE 1=1 AND A.shcsdtRecycle=0 AND A.shcsdtChecked>1 AND A.shcsdtParid={Nets.Parid}
			ORDER BY A.shcsdtOrderBy DESC,A.shcsdtID DESC ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.Parid}',$this->sMainID,$tmpSTR);
		$this->sListData_Discuss=$this->sDb->SearchP($tmpSTR,$tmpListAR0);
		$this->sRecordCount_Discuss=$this->sDb->sysPageInfo[3];
		//#Set page button
		$this->sPButton_Discuss=new netsPButton();
		$this->sPButton_Discuss->resetTemlate('../../../Config/m_default/File/pageButton3.htm');
		$this->sPButton_Discuss->sPage=$this->sysPage;
		$this->sPButton_Discuss->sExtendParameter='&ID='.$this->sMainID;
		$this->sPButton_Discuss->setPage($this->sDb->sysPageInfo);
		//-- ------ #Auction ------ --
		
		//-- ------ #Control ------ --
		$this->sUiDescription_Discuss=array();
		$tmpSTR=$this->sUiDescriptionPath.'Plus/shop/codesale_discuss.php';
		if(file_exists($tmpSTR)){
			require($tmpSTR);
			$this->sUiDescription_Discuss=$sysUiDescriptions['codesale_discuss'];
			$sysUiDescriptions=array();
		}
		
	}
	public function DefUiPanel(&$pColumn,$pFlag){
		if($pColumn['stcotName']=='shcsdctContent' && $pFlag=='Normal'){
			$pColumn['ControlStyle']='width:500px;height:40px;';
			$pColumn['Parameter_JS_Onfocus']="tmpMCommon.OnDiscussInput(this.name,0);CCodeTxt_ShowCACode(0);";

		}

	}
	
}
?>