<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Cms/Doc/cmsdoc.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Cms/Doc/cmsintroduct.php');

class PaDefault extends CustomPage {
	public $ssetKeyword='网站地图';
	
	public function PaDefault(){
		$this->CustomPage();
	}
	public function OnPInitial(){
		$this->checkUser('1,2,3,');
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'cmsintroduct','sttColumnHead'=>'cit'),
			array('sttTableName'=>$this->sysTableHead.'cmsintroductcont','sttColumnHead'=>'cict'),);
		$this->sUiName='Platform/cms/doc_sitemap';
		$this->sActionType='Normal';
		$this->sApp=new cmsintroduct($this->sConnString);
	}
	public function OnBInitial(){
		$this->sMetaTitle='生成网站地图';
		$this->sLimitCount=0;
	}
	public function OnAdd(){
		$tmpApp=new cmsdoc($this->sConnString);
		$tmpINT=$tmpApp->makeSitemap($this->ssetKeyword);
		if($tmpINT==1){
			$this->sJscript=$this->Message('SUCCESS','','请先在“文档>>文档管理>>说明信息管理”里添加标题为“网站地图”的说明信息。','');
		}else if($tmpINT==2){
			$this->sJscript=$this->Message('SUCCESS','','地图模板设置格式不正确，请与管理员联系。','');
		}
		
		$this->sJscript=$this->Message('SUCCESS','','网站地图生成成功。',$this->sysPage);
		return 0;
	}
	public function OnNormal(){
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'cmsintroduct AS A 
			LEFT OUTER JOIN '.$this->sysTableHead.'cmsintroductcont AS B ON B.cictIndexID=A.citID ';
		$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.citID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.citName LIKE \''.$this->ssetKeyword.'\' LIMIT 0,1 ';
		$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']];
				}
				$Coun0++;
			}
		}else {}
	}
	public function DefUiButton($pFlag,$Exception){
		parent::DefUiButton($pFlag,array('List','Normal','ListChildLink','NormalChildLink',));
		if($pFlag=='Normal'){ ?>
<li class="ButBut"><input type="submit" value="修改" class="Control2" onclick="setActionType('Normal','DModify','','');" /></li>
<li class="ButBut"><input type="submit" value="生成网站地图" class="Control2" onclick="setActionType('Normal','DAdd','','');" /></li>
<?php }
	}
}
//-- ------ #Instanct ------ --
$tmpDefault=new PaDefault();
$tmpDefault->OnPage();
$tmpControls=new CustomControls();
$tmpControlPage=new CustomControlPage();
$tmpComHead->sMenuid=$tmpDefault->sMenuid;
$tmpDefault->sysMetaTitle=$tmpDefault->sMetaTitle.' - '.$tmpDefault->sysFileConfig['sysTitle'];
//-- ------ #Template ------ --
require($tmpDefault->sysFileConfig['sysCoreRoot'].$tmpDefault->sysQPlatformTemplatePath.'Component/Group_0.php'); ?>