<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot_Real'].'Cache/DbDescription/netssyslanguagegroup.php');
require($netsFileConfig['sysCoreRoot_Real'].'Cache/DbDescription/netssyslanguagegroupcont.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Nets/System/netssyslanguagegroup.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.'netssyslanguagegroup','sttColumnHead'=>'slgt'),
			array('sttTableName'=>$this->sysTableHead.'netssyslanguagegroupcont','sttColumnHead'=>'slgct'),);
		$this->sUiName='Platform/nets/system_languagegroup';
	}
	public function OnBInitial(){
		$this->sMetaTitle='语言分类';
		$this->sLimitCount=1;
		$this->sApp=new netssyslanguagegroup($this->sConnString);
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.slgtID,A.slgtName,A.slgtParid FROM '.$this->sysTableHead.'netssyslanguagegroup AS A
			WHERE 1=1 AND A.slgtRecycle=0 AND A.slgtChecked>1 AND A.slgtParid={Nets.Parid}
			ORDER BY A.slgtOrderBy DESC,A.slgtID DESC ';
		$tmpAR0['SQL0']=' SELECT A.slgtID,A.slgtName,A.slgtParid FROM '.$this->sysTableHead.'netssyslanguagegroup AS A
			WHERE 1=1 AND A.slgtRecycle=0 AND A.slgtChecked>1 AND A.slgtID={Nets.Parid}
			ORDER BY A.slgtOrderBy DESC,A.slgtID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='slgtID';
		$tmpAR0['Text']='slgtName';
		$tmpAR0['Value']='slgtID';
		$tmpAR0['Type']=0;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$this->sParid1=$this->sParid2=$this->sControl->bindDropdown($tmpAR0);
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有分类]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sParid2,$tmpAR0);
		
		//-- ------ #ActionType ------ --
		if ($this->sActionType=='DMakePackage') {
			$this->OnMakePackage();
		}
		
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'slgtID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1,',0);
		//#Spell sql
		$tmpSQL=' SELECT A.slgtID,A.slgtName,A.slgtParid,A.slgtPath
			FROM '.$this->sysTableHead.'netssyslanguagegroup AS A 
			WHERE 1=1 
			AND A.slgtID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.slgtName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.slgtParid='.$this->sSearchData[1].' ';
		}
		if($this->sSearchData[2]!=''){
			$tmpSQL.=' AND A.slgtPath LIKE \'%'.$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->sysSPLIT1.
			$this->sSearchData[1].$this->sysSPLIT1.
			$this->sSearchData[2];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'slgtID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'slgtName','stcoctUiName'=>'语言分类名称');
		
		return 0;
	}
	public function OnExternal_Search(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'slgtID,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.slgtID,A.slgtName,A.slgtParid
			FROM '.$this->sysTableHead.'netssyslanguagegroup AS A 
			WHERE 1=1 
			AND A.slgtID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.slgtName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.slgtParid='.$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'=>'slgtID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'slgtName','stcoctUiName'=>'语言分类名称');
		
		return 0;
	}
	public function OnExternal_ChildChoose(){
		//-- ------ #Search data ------ --
		$tmpSTR0='External_ChildChoose';
		$this->sExternal_ChildChooseSData=$this->AnalyerRequest($tmpSTR0,'0,,0,0',0);
		//#Spell sql
		$tmpSQL='';
		if($this->sExternal_ChildChooseSData[0]==0 || $this->sExternal_ChildChooseSData[0]==2){
			//-- Same grade --
			$tmpSQL=' SELECT A.slgtID,A.slgtName,A.slgtParid 
				FROM '.$this->sysTableHead.'netssyslanguagegroup AS A
				WHERE 1=1 AND A.slgtRecycle=0 AND A.slgtChecked>1 AND 
				A.slgtParid=(SELECT slgtParid FROM netssyslanguagegroup WHERE 1=1 AND slgtRecycle=0 AND slgtChecked>1 AND slgtID={Nets.ID})
				ORDER BY A.slgtOrderBy DESC,A.slgtID DESC ';
		}else if($this->sExternal_ChildChooseSData[0]==1 || $this->sExternal_ChildChooseSData[0]==3){
			//-- Child grade --
			$tmpSQL=' SELECT A.slgtID,A.slgtName,A.slgtParid 
				FROM '.$this->sysTableHead.'netssyslanguagegroup AS A
				WHERE 1=1 AND A.slgtRecycle=0 AND A.slgtChecked>1 AND A.slgtParid={Nets.ID}
				ORDER BY A.slgtOrderBy DESC,A.slgtID DESC ';
		}
		$tmpSTR=str_replace('{Nets.ID}',$this->sExternal_ChildChooseSData[2],$tmpSQL);
		$this->sExternal_ChildChooseData=$this->sDb->Search($tmpSTR);
		
		return 0;
	}
	public function OnNormal(){
		$tmpINT=0;
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'netssyslanguagegroup AS A 
			INNER JOIN '.$this->sysTableHead.'netssyslanguagegroupcont AS B ON B.slgctIndexID=A.slgtID ';
		$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.slgtID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.slgtID='.$tmpAR0[0].' ';
		$tmpDataCollection0=$this->sDb->Search($tmpSQL);
		if(count($tmpDataCollection0)>0){
			$tmpRow=$tmpDataCollection0[0];
			$this->sMainID=$tmpRow[$this->sTable[0]['sttColumnHead'].'ID'];
			$this->sMainName=$tmpRow[$this->sTable[0]['sttColumnHead'].'Name'];
			//-- #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']];
					//-- ------ #Spical set ------ --
					if($this->sUiDescription_Normal[$Coun0]['stcotName']=='slgtParid'){
					}else if($this->sUiDescription_Normal[$Coun0]['stcotName']=='slgtModelid_Detail'){
						$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
					}
				}
				$Coun0++;
			}
		}else {
			$Coun0=0;
			foreach($this->sUiDescription_Normal as $Row0){
				if($Row0['stcotName']=='slgtTableid'){
					$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
				}
				$Coun0++;
			}
		}
	}
	public function OnMakePackage(){
		//Action(ALL.---,SINGLE.---),pID,pIndex,pNextflag(0.normal,1.next)
		$tmpAR0=$this->AnalyerRequest('DMakePackage',',0,0,0',0);
		$this->sCallback_Flag='';
		$this->sCallback_ID=0;
		$this->sCallback_Index=0;
		$this->sCallback_NextFlag='';
		
		if ($tmpAR0[0]=='ALL') {
			//-- ------ #Get IDS ------ --
			$tmpSQL=' SELECT A.slgtID
				FROM {Nets.TableHead}netssyslanguagegroup AS A
				WHERE 1=1 AND A.slgtRecycle=0 AND A.slgtChecked>1
				ORDER BY A.slgtID ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpData0=$this->sDb->Search($tmpSTR);
			foreach ($tmpData0 as $Row0) {
				$this->sCallback_ID.=$Row0['slgtID'].$this->sysSPLIT1;
			}
			$this->sCallback_Flag='SETIDS';
			
		}else if ($tmpAR0[0]=='SINGLE') {
			$tmpDbDescriptions=array(
				$this->sysDbDescriptions[$this->sysTableHead.'netssyslanguagegroup'],
				$this->sysDbDescriptions[$this->sysTableHead.'netssyslanguagegroupcont'],);
			$tmpDbDescriptions[0]['Columns']['slgtID']['Value']=$this->sCode->Int32($tmpAR0[1],0);
			$tmpINT=$this->sApp->MakePackage_ID($tmpDbDescriptions);
			
			$this->sCallback_Flag='NEXTID';
			$this->sCallback_ID=0;
			$this->sCallback_Index=0;
		}
		
		return 0;
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='slgtParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='slgtParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sParid1;
		}
		return $pColumn;
	}
	public function DefUiButton($pFlag,$Exception){
		parent::DefUiButton($pFlag,array('List','Normal',));
		if($pFlag=='List' && !in_array($pFlag,$Exception)){ ?>
<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.onNormal_MultipleByTxt('','','');">批量修改所选（文本）</a></li>
<!--<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpControl.onNormal_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="tmpFrames.showContent('采集所有网站的今日团购信息','',0,0,'',0); tmpLanguage.OnMakeLanguage_ALL();">生成所有语言包</a></li>

<script src="<?php echo($this->sysFileConfig['sysUiCoreRoot']); ?>Ui/m_nets/Jscript/Mana/Language.js" type="text/javascript"></script>

<?php }else if ($pFlag=='Normal' && !in_array($pFlag,$Exception)) { ?>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpCommon.confirmDo('删除后将不能恢复，您确定删除本信息吗?');tmpCommon.setActionType('','DDelete','',''); tmpCommon.netsSubmit();">删除</a></li>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpCommon.setActionType('Normal','DModify','',''); tmpCommon.netsSubmit();">修改</a></li>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpCommon.setActionType('Normal','DAdd','',''); tmpCommon.netsSubmit();">添加</a></li>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpFrames.showContent('生成（<?php echo ($this->sMainName); ?>）的语言包','',0,0,'',0); tmpLanguage.OnMakeLanguage_Byid(<?php echo ($this->sMainID); ?>);">生成语言包</a></li>

<script src="<?php echo($this->sysFileConfig['sysUiCoreRoot']); ?>Ui/m_nets/Jscript/Mana/Language.js" type="text/javascript"></script>

<?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 ------ --
if ($tmpDefault->sActionType=='DMakePackage') {
	require($tmpDefault->sysFileConfig['sysCoreRoot'].$tmpDefault->sysQPlatformTemplatePath.'Component/Head_1.php');
	require($tmpDefault->sysFileConfig['sysCoreRoot'].$tmpDefault->sysQPlatformTemplatePath.'Nets/language_make.php');
	require($tmpDefault->sysFileConfig['sysCoreRoot'].$tmpDefault->sysQPlatformTemplatePath.'Component/End_1.php');
}else {
	require($tmpDefault->sysFileConfig['sysCoreRoot_Real'].$tmpDefault->sysManaTemplatePath.'Component/Group_0.php');
} ?>