<?php
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/shopunit.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/shopunitcont.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/shopunitdiscuss.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/shopunitdiscusscont.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Shop/Sale/shopunit.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Shop/Sale/shopunitdiscuss.php');


class PaDefault extends CustomPage {
	public function PaDefault(){
		$this->CustomPage();
	}
	public function OnBInitial(){
		$this->sMetaTitle='商品详细信息';
		$this->getUser('1,2,3,4,5,');
		$this->sApp=new shopunit($this->sConnString);
		$this->sTemplatePath='shop/unitDetail_Normal.php';

		//-- ------ #ActionType ------ --
		
	}
	public function OnAdd(){
		$tmpApp=new shopsalediscuss($this->sConnString);
		$tmpTable=array(
			array('sttTableName'=>$this->sysTableHead.'shopunitdiscuss','sttColumnHead'=>'shudt'),
			array('sttTableName'=>$this->sysTableHead.'shopunitdiscusscont','sttColumnHead'=>'shudct'),);
		
		$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
		$tmpAR0=$this->AnalyerRequest('mainID','',1);
		$tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'Parid']['Value']=$this->sCode->Int32($tmpAR0[0],0);
		$tmpAR0=$this->AnalyerRequest($tmpTable[1]['sttColumnHead'].'ContentTxt','',1);
		$tmpDbDescriptions[1]['Columns'][$tmpTable[1]['sttColumnHead'].'Content']['Value']=$tmpAR0[0];
		$tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'CreateBy']['Value']=$this->sCode->Int32($this->sUserInfo[0]['Columns']['uitID']['Value'],0);
		
		//-- #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'].'CreateTime']['Value']=date($this->sysTimeFormat);
		$tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'Checked']['Value']=$this->sysFileConfig['CheckCmsDocDiscuss'];
		if ($tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'CreateBy']['Value']==0) {
			$tmpDbDescriptions[0]['Columns'][$tmpTable[0]['sttColumnHead'].'CreateBy']['Value']=2;
		}
		//#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;
		}
		
		$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',1,0);
		$this->sMainID=$tmpAR0[0];
		//-- ------ #Initial ------ --
		$tmpINT=$this->sApp->initialObject($this->sMainID);
		//-- ------ #Datas ------ --
		$tmpSQL=' SELECT *
			FROM {Nets.TableHead}shopunit AS A 
			INNER JOIN {Nets.TableHead}shopunitcont AS B ON B.shuctIndexID=A.shutID
			WHERE 1=1 AND A.shutRecycle=0 AND A.shutChecked>1 AND A.shutID={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.shutID,A.shutName,A.shutParid,A.shutCreateTime
				FROM {Nets.TableHead}shopunit AS A 
				WHERE 1=1 AND A.shutRecycle=0 AND A.shutChecked>1
				ORDER BY A.shutOrderBy DESC,A.shutID 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]['shutID'];
		$this->sMetaTitle=$this->sDetailData[0]['shutName'];
		$this->sParid=$this->sDetailData[0]['shutParid'];
		
		//-- ------ #Group ------ --
		$tmpSQL=' SELECT A.shugtID,A.shugtName,B.shugctTemplateid_Detail
			FROM {Nets.TableHead}shopunitgroup AS A
			INNER JOIN {Nets.TableHead}shopunitgroupcont AS B ON B.shugctIndexID=A.shugtID
			WHERE 1=1 AND A.shugtRecycle=0 AND A.shugtChecked>1 AND A.shugtID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sParid,$tmpSTR);
		$this->sData_Group=$this->sDb->Search($tmpSTR);
		if(count($this->sData_Group)==0){
			//#Non group
			//#Other
			$this->sData_Group[0]=array(
				'shugctTemplateid_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]['shugctTemplateid_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]['shuctTemplateid_Detail'],$tmpSTR);
		$tmpData0=$this->sDb->Search($tmpSTR);
		if(count($tmpData0)!=0){
			$this->sTemplatePath=$tmpData0[0]['stemctPath'];
		}
		//-- ------ #Evaluation ------ --
		//-- ------ #Navigation ------ --
		$this->sNavigation=$this->sDb->getParent($this->sDetailData[0]['shutParid'],$this->sysTableHead.'shopunitgroup','shugt');
		//-- ------ #Other ------ --
		//Next
		$tmpSQL=' SELECT A.shutID,A.shutName,A.shutCreateTime
			FROM {Nets.TableHead}shopunit AS A 
			WHERE 1=1 AND A.shutRecycle=0 AND A.shutChecked>1 AND shutID>{Nets.ID} AND A.shutParid={Nets.Parid}
			ORDER BY A.shutOrderBy DESC,A.shutID DESC LIMIT 0,1 ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sDetailData[0]['shutID'],$tmpSTR);
		$tmpSTR=str_replace('{Nets.Parid}',$this->sDetailData[0]['shutParid'],$tmpSTR);
		$this->sNextData=$this->sDb->Search($tmpSTR);
		//Previous
		$tmpSQL=' SELECT A.shutID,A.shutName,A.shutCreateTime
			FROM {Nets.TableHead}shopunit AS A 
			WHERE 1=1 AND A.shutRecycle=0 AND A.shutChecked>1 AND shutID<{Nets.ID} AND A.shutParid={Nets.Parid}
			ORDER BY A.shutOrderBy DESC,A.shutID DESC LIMIT 0,1 ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sDetailData[0]['shutID'],$tmpSTR);
		$tmpSTR=str_replace('{Nets.Parid}',$this->sDetailData[0]['shutParid'],$tmpSTR);
		$this->sNextData=$this->sDb->Search($tmpSTR);
		//Other
		$tmpSQL=' SELECT A.shutID,A.shutName,A.shutCreateTime
			FROM {Nets.TableHead}shopunit AS A 
			WHERE 1=1 AND A.shutRecycle=0 AND A.shutChecked>1 AND A.shutParid={Nets.Parid}
			ORDER BY A.shutOrderBy DESC,A.shutID DESC LIMIT 0,8 ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSTR);
		$tmpSTR=str_replace('{Nets.Parid}',$this->sDetailData[0]['shutParid'],$tmpSTR);
		$this->sOtherData=$this->sDb->Search($tmpSTR);
		//-- ------ #Discuss ------ --
		$tmpListSTR0='DList0';
		$tmpListAR0=$this->getQueryString($tmpListSTR0);
		$tmpSortSTR0='DSort0';
		$tmpSortAR0=$this->AnalyerRequest($tmpSortSTR0,'cddtID,2',0);
		//Data
		$tmpSQL=' SELECT A.shudtID,A.shudtCreateTime,B.shudctPublisher_Name,B.shudctContent
			FROM {Nets.TableHead}shopunitdiscuss AS A
			INNER JOIN {Nets.TableHead}shopunitdiscusscont AS B ON B.shudctIndexID=A.shudtID
			WHERE 1=1 AND A.shudtRecycle=0 AND A.shudtChecked>1 AND A.shudtParid={Nets.ID}
			ORDER BY A.shudtOrderBy DESC,A.shudtID ';
		$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=$this->sDb->sysPageInfo[3];
		//#Set page button
		$this->sPButton->resetTemlate('../../../Config/m_default/File/pageButton3.htm');
		$this->sPButton->sPage=$this->sysPage;
		$this->sPButton->sExtendParameter='&ID='.$this->sMainID;
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		//-- ------ #Sales ------ --
		$tmpListSTR0='DList0';
		$tmpListAR0=$this->getQueryString($tmpListSTR0);
		$tmpSortSTR0='DSort0';
		$tmpSortAR0=$this->AnalyerRequest($tmpSortSTR0,'cddtID,2',0);
		//Data
		$tmpSQL=' SELECT A.shstID,A.shstName
			FROM {Nets.TableHead}shopsale AS A
			INNER JOIN {Nets.TableHead}shopsalecont AS B ON B.shsctIndexID=A.shstID
			WHERE 1=1 AND A.shstRecycle=0 AND A.shstChecked>1 AND A.shstUnitid={Nets.ID}
			ORDER BY A.shstOrderBy DESC,A.shstID ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$this->sMainID,$tmpSTR);
		$this->sData_Sales=$this->sDb->SearchP($tmpSTR,$tmpListAR0);
		$this->sCount_Sales=$this->sDb->sysPageInfo[3];
		//#Set page button
		$this->sPButton->resetTemlate('../../../Config/m_default/File/pageButton3.htm');
		$this->sPButton->sPage=$this->sysPage;
		$this->sPButton->sExtendParameter='&ID='.$this->sMainID;
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		//-- ------ #Discuss form ------ --
		$this->sUiDescription_0=array();
		$tmpSTR=$this->sUiDescriptionPath.'Plus/shop/unit_discuss.php';
		if(file_exists($tmpSTR)){
			require($tmpSTR);
			$this->sUiDescription_0=$sysUiDescriptions['unit_discuss'];
			$sysUiDescriptions=array();
		}
		
	}
	public function DefUiPanel(&$pColumn,$pFlag){
		if($pColumn['stcotName']=='shudctContent' && $pFlag=='Normal'){
			$pColumn['ControlStyle']='width:500px;height:40px;';
			$pColumn['Parameter_JS_Onfocus']="tmpMCommon.OnDiscussInput(this.name,0);CCodeTxt_ShowCACode(0);";
		}
		
	}
	
}


?>