<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Func/netsSimpleXml.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Nets/System/netssyszone.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.'netssyszone','sttColumnHead'=>'szt'),
			array('sttTableName'=>$this->sysTableHead.'netssyszonecont','sttColumnHead'=>'szct'),);
		$this->sUiName='Platform/nets/system_zone';
	}
	public function OnBInitial(){
		$this->sMetaTitle='地区';
		$this->sLimitCount=0;
		$this->sApp=new netssyszone($this->sConnString);

		//Type
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=17;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$this->sType1=$this->sType2=$this->sControl->bindDropdown($tmpAR0);
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有类型]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sType2,$tmpAR0);
		
		
	}
	public function OnBEvent(){
		if($this->sActionTypeF=='DData_Save'){
			$this->OnData_Save();
		}
	}
	public function OnData_Save(){
		//-- ------ ### ------ --
		$this->sApp->saveToFile();
		
		$this->sJscript=$this->Message('SUCCESS','','地区缓存数据生成成功',$this->sysPage);
		return 0;
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'sztID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1,-1',0);
		//#Spell sql
		$tmpSQL=' SELECT A.sztID,A.sztName,A.sztParid,A.sztType,A.sztAlphabet
			FROM '.$this->sysTableHead.'netssyszone AS A
			WHERE 1=1 
			AND A.sztID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.sztName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.sztParid='.$this->sSearchData[1].' ';
		}
		if($this->sSearchData[2]!='-1'){
			$tmpSQL.=' AND A.sztType='.$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->sSearchData[1].','.$this->sSearchData[2];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'sztID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'sztName','stcoctUiName'=>'地区名称');
		
		return 0;
	}
	public function OnExternal_Search(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'sztID,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.sztID,A.sztName,A.sztParid
			FROM '.$this->sysTableHead.'netssyszone AS A 
			WHERE 1=1 
			AND A.sztID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.sztName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.sztType='.$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'=>'sztID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'sztName','stcoctUiName'=>'地区名称');
		
		return 0;
	}
	public function OnExternal_ChildChoose(){
		//-- ------ #Search data ------ --
		$tmpSTR0='External_ChildChoose';
		$this->sExternal_ChildChooseSData=$this->AnalyerRequest($tmpSTR0,'0,,0,0',0);
		//#Spell sql 4,sztParidTxt,13,2
		$tmpSQL='';
		if($this->sExternal_ChildChooseSData[0]==0 || $this->sExternal_ChildChooseSData[0]==2){
			//-- Same grade --
			$tmpSQL=' SELECT A.sztID,A.sztName,A.sztParid FROM '.$this->sysTableHead.'netssyszone AS A
				WHERE 1=1 AND A.sztRecycle=0 AND A.sztChecked>1 AND 
				A.sztParid=(SELECT sztParid FROM '.$this->sysTableHead.'netssyszone WHERE 1=1 AND sztRecycle=0 AND sztChecked>1 AND sztID={Nets.ID})
				ORDER BY A.sztOrderBy DESC,A.sztID DESC ';
		}else if($this->sExternal_ChildChooseSData[0]==1 || $this->sExternal_ChildChooseSData[0]==3){
			//-- Child grade --
			$tmpSQL=' SELECT A.sztID,A.sztName,A.sztParid FROM '.$this->sysTableHead.'netssyszone AS A
				WHERE 1=1 AND A.sztRecycle=0 AND A.sztChecked>1 AND A.sztParid={Nets.ID}
				ORDER BY A.sztOrderBy DESC,A.sztID DESC ';
		}else if($this->sExternal_ChildChooseSData[0]==4){
			//-- Child grade --
			$tmpSQL=' SELECT A.sztID,A.sztName,A.sztParid FROM '.$this->sysTableHead.'netssyszone AS A
				WHERE 1=1 AND A.sztRecycle=0 AND A.sztChecked>1 AND A.sztParid={Nets.ID}
				ORDER BY A.sztOrderBy DESC,A.sztID DESC ';
			$this->sExternal_ChildChooseSData[3]+=1;
		}
		$tmpSTR=str_replace('{Nets.ID}',$this->sExternal_ChildChooseSData[2],$tmpSQL);
		$this->sExternal_ChildChooseData=$this->sDb->Search($tmpSTR);
		
		
		return 0;
	}
	public function OnExternal_TextChooses_Checkbox(){
		//-- ------ #Search data ------ --
		//sName,Type,Panel,Flag,ID,Keyword
		$tmpSTR0='External_TextChooses_Checkbox';
		$this->sExternal_TextChooses_Checkbox_Data=$this->AnalyerRequest($tmpSTR0,'TextChooses_Checkbox,0,External_TextChooses_Checkbox,External_TextChooses_Checkbox,-1,',0);
		$tmpSTR0='DList0';
		$tmpAR0=$this->AnalyerRequest($tmpSTR0,'1,0,60,0',0);
		//#Spell sql
		$tmpSQL=' SELECT A.sztID,A.sztName,A.sztParid,A.sztType,A.sztAlphabet
			FROM {Nets.TableHead}netssyszone AS A
			WHERE 1=1 
			AND A.sztID>'.$this->sLimitCount;
		if($this->sExternal_TextChooses_Checkbox_Data[4]!='-1'){
			$tmpSQL.=' AND A.sztParid='.$this->sExternal_TextChooses_Checkbox_Data[4].' ';
		}
		if($this->sExternal_TextChooses_Checkbox_Data[5]!=''){
			$tmpSQL.=' AND A.sztName LIKE \'%'.$this->sExternal_TextChooses_Checkbox_Data[5].'%\' ';
		}
		$tmpSQL.=' ORDER BY A.sztOrderBy DESC,A.sztID DESC ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$this->sData_List=$this->sDb->SearchP($tmpSTR,$tmpAR0);
		//#Set page button
		$this->sPAjaxButton->sPage=$this->sysPage;
		$this->sPAjaxButton->resetTemlate('../../../Config/m_default/File/pageAjaxButton3.htm');
		$this->sPAjaxButton->sExtendParameter='&ActionType=External_TextChooses_Checkbox&External_TextChooses_Checkbox='.
			$this->sExternal_TextChooses_Checkbox_Data[0].$this->sysSPLIT1.
			$this->sExternal_TextChooses_Checkbox_Data[1].$this->sysSPLIT1.
			$this->sExternal_TextChooses_Checkbox_Data[2].$this->sysSPLIT1.
			$this->sExternal_TextChooses_Checkbox_Data[3].$this->sysSPLIT1.
			$this->sExternal_TextChooses_Checkbox_Data[4].$this->sysSPLIT1.
			$this->sExternal_TextChooses_Checkbox_Data[5];
		$this->sPAjaxButton->sPanel=$this->sExternal_TextChooses_Checkbox_Data[2];
		$this->sPAjaxButton->sFlag=$this->sExternal_TextChooses_Checkbox_Data[3];
		$this->sPAjaxButton->setPage($this->sDb->sysPageInfo);
		
		
		return 0;
	}
	public function OnNormal(){
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'netssyszone AS A 
			INNER JOIN '.$this->sysTableHead.'netssyszonecont AS B ON B.szctIndexID=A.sztID ';
		$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.sztID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.sztID='.$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']];
				}
				$Coun0++;
			}
		}else {}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		$tmpSimpleXml=new netsSimpleXml();
		
		if($pColumn['stcotName']=='sztType' && ($pFlag=='Search' || $pFlag=='External_Search_Search')){
			$pColumn['Option']=$this->sType2;
		}else if($pColumn['stcotName']=='sztType' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sType1;
		}else if($pColumn['stcotName']=='sztParid' && $pFlag=='Normal'){
			$tmpSimpleXml->loadXml_UiParameter($this->readFile($this->sysFileConfig['sysCoreRoot'].$this->sysFileConfig['sysUiParameterPath'].'Mana/nets/Zone_Parid.php'));
			$pColumn['Parameter']=$tmpSimpleXml->sXmlElement->Parameters[1]->Value;
			
		}else if($pColumn['stcotName']=='sztParid' && ($pFlag=='Search' || $pFlag=='List')){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_nets/system/zone.php';
			$pColumn['Parameter']=$tmpParameters;
			
			$tmpSQL=' SELECT A.sztName AS tName FROM {Nets.TableHead}netssyszone AS A
				WHERE 1=1 AND A.sztID={Nets.ID} ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$this->sCode->Int32($pColumn['Value'],0),$tmpSTR);
			$tmpData0=$this->sDb->Search($tmpSTR);
			if(count($tmpData0)>0){
				$pColumn['ShowValue']=$tmpData0[0]['tName'];
			}
			
		}else if($pColumn['stcotName']=='szctMapControl' && $pFlag=='Normal'){
			$tmpSimpleXml->loadXml_UiParameter($this->readFile($this->sysFileConfig['sysCoreRoot'].$this->sysFileConfig['sysUiParameterPath'].'Mana/nets/Zone_Map.php'));
			$pColumn['Parameter']=$tmpSimpleXml->sXmlElement->Parameters[0]->Value;
		
		}
		return $pColumn;
	}
	public function DefUiButton($pFlag,$Exception){
		parent::DefUiButton($pFlag,array('List',));
		if($pFlag=='List'){ ?>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpControl.onDelete_Multiple();tmpCommon.setActionType('','DDelete_Multiple','',''); tmpCommon.netsSubmit();">批量删除</a></li>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpControl.onModify_Page();tmpCommon.setActionType('','DModify_Page','',''); tmpCommon.netsSubmit();">保存本页修改</a></li>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpCommon.setActionType('','DData_Save','',''); tmpCommon.netsSubmit();">生成地区缓存</a></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'); ?>