<?php
class netsControl extends netsHtml {
	public $sHeadString='....';
	public $sTreeHeadString='|---';
	public $sDbInTemplate=array(
		'Connection'=>'',
		'SQL'=>'',
		'SQL0'=>'',
		'InitialString'=>'',
		'Type'=>'',
		'Parid'=>'',
		'Text'=>'',
		'Value'=>'',
		'Source'=>'',
		'Introduct'=>'',
		'Style'=>'',
		'Title'=>'',
		'AddOne'=>'',);
	public $sDpReturnTemplate=array(
		'ID'=>'',
		'Name'=>'',
		'Index'=>'',
		'Parid'=>'',
		'Text'=>'',
		'Value'=>'',
		'Source'=>'',
		'Introduct'=>'',
		'Style'=>'',
		'Title'=>'',
		'AddOne'=>'',);
	public $textChooseParameter_Template=array();
	
	
	public function netsControl(){
		$this->netsHtml();
		
		$this->textChooseParameter_Template=array(
			'Type'=>'chooseSearch',
			'Controlname'=>'',
			'ExtendType'=>'External_Search',
			'URL'=>$this->sysFileConfig['sysCoreRoot'].'Mana/m_shop/sale/sale.php',
			'SPLIT0'=>$this->sysSPLIT5,
			'SPLIT1'=>$this->sysSPLIT2,
			'Columns'=>array(
				array('ID','编号','Label',100,),
				array('Name','名称','Text',370,),
				),
			);
		
	}
	public function Control($pColumn){}
	/**
	 * Enter description here...
	 *
	 * @param unknown_type $pOptionAR
	 * $pOptionAR['lSQL0']!='' - Include first record/sort
	 * $pOptionAR['lSQL0']=='' - does not Include first record/sort
	 * @return unknown
	 */
	public function bindDropdown($pOptionAR){
		$tmpCode=new netsCode();
		$tmpHeadSave='HeadSave';
		$saveDataCollection1=array();
		$tmpDb=new netsDb($pOptionAR['Connection'],'');
		//-- ------ #xxxxxx ------ --
		$tmpDataCollection0=array();
		//Initial array
		if($pOptionAR['SQL0']!=''){
			//Self option
			$lSQL=str_replace('{Nets.Parid}',$pOptionAR['InitialString'],$pOptionAR['SQL0']);
			$tmpDataCollection0=$tmpDb->Search($lSQL);
			if(count($tmpDataCollection0)>0){
				$tmpDataCollection0[0][$tmpHeadSave]='';
			}
		}else{
			//Parent option
			$lSQL=str_replace('{Nets.Parid}',$pOptionAR['InitialString'],$pOptionAR['SQL']);
			$tmpDataCollection0=$tmpDb->Search($lSQL);
			$Coun0=0;
			while(count($tmpDataCollection0)>$Coun0){
				$tmpDataCollection0[$Coun0][$tmpHeadSave]='';
				$Coun0++;
			}
		}
		//-- ------ #wheel array ------ --
		//Type==0 - Tree , Type=1 - List
		$Coun0=0;
		while(count($tmpDataCollection0)>$Coun0 && $pOptionAR['Type']==0){
			//
			$lSQL=str_replace('{Nets.Parid}',$tmpDataCollection0[$Coun0][$pOptionAR['Parid']],$pOptionAR['SQL']);
			$tmpDataCollection1=$tmpDb->Search($lSQL);
			$Coun1=0;
			while(count($tmpDataCollection1)>$Coun1){
				$tmpDataCollection1[$Coun1][$tmpHeadSave]=$this->sHeadString.$tmpDataCollection0[$Coun0][$tmpHeadSave];
				$tmpDataCollection1[$Coun1][$pOptionAR['Text']]=$tmpDataCollection1[$Coun1][$tmpHeadSave].$tmpDataCollection1[$Coun1][$pOptionAR['Text']];
				$tmpDataCollection0=$tmpCode->ArrayInsertRow($tmpDataCollection0,$tmpDataCollection1[$Coun1],$Coun0);
				$Coun1++;
			}
			$Coun0++;
		}
		//Push
		$retAR0=array();
		$Coun0=0;
		foreach ($tmpDataCollection0 as $Row0){
			$tmpAR0=$this->sDpReturnTemplate;
			$tmpAR0['Index']=$Coun0;
			if(isset($Row0[$pOptionAR['Parid']])){
				$tmpAR0['Parid']=$Row0[$pOptionAR['Parid']];
			}
			if(isset($Row0[$pOptionAR['Text']])){
				$tmpAR0['Text']=$Row0[$pOptionAR['Text']];
			}
			if(isset($Row0[$pOptionAR['Value']])){
				$tmpAR0['Value']=$Row0[$pOptionAR['Value']];
			}
			if(isset($Row0[$pOptionAR['Source']])){
				$tmpAR0['Source']=$Row0[$pOptionAR['Source']];
			}
			if(isset($Row0[$pOptionAR['Introduct']])){
				$tmpAR0['Introduct']=$Row0[$pOptionAR['Introduct']];
			}
			if(isset($Row0[$pOptionAR['Style']])){
				$tmpAR0['Style']=$Row0[$pOptionAR['Style']];
			}
			if(isset($Row0[$pOptionAR['Title']])){
				$tmpAR0['Title']=$Row0[$pOptionAR['Title']];
			}
			if(isset($Row0[$pOptionAR['AddOne']])){
				$tmpAR0['AddOne']=$Row0[$pOptionAR['AddOne']];
			}
			array_push($retAR0,$tmpAR0);
			$Coun0++;
		}
		return $retAR0;
	}
	public function bindTree($pOptionAR){
		$tmpCode=new netsCode();
		$tmpHeadSave='HeadSave';
		$saveDataCollection1=array();
		$tmpDb=new netsDb($pOptionAR['Connection'],'');
		//-- ------ #xxxxxx ------ --
		//Initial array
		$lSQL=str_replace('{Nets.Parid}',$pOptionAR['InitialString'],$pOptionAR['SQL']);
		$tmpDataCollection0=$tmpDb->Search($lSQL);
		$Coun0=0;
		while(count($tmpDataCollection0)>$Coun0){
			$tmpDataCollection0[$Coun0][$tmpHeadSave]='';
			$Coun0++;
		}
		//-- ------ #wheel array ------ --
		$Coun0=0;
		while(count($tmpDataCollection0)>$Coun0){
			$lSQL=str_replace('{Nets.Parid}',$tmpDataCollection0[$Coun0][$pOptionAR['Parid']],$pOptionAR['SQL']);
			$tmpDataCollection1=$tmpDb->Search($lSQL);
			$Coun1=0;
			while(count($tmpDataCollection1)>$Coun1 && $pOptionAR['Type']==0){
				$tmpDataCollection1[$Coun1][$tmpHeadSave]=$this->sTreeHeadString.$tmpDataCollection0[$Coun0][$tmpHeadSave];
				$tmpDataCollection1[$Coun1][$pOptionAR['Text']]=$tmpDataCollection1[$Coun1][$tmpHeadSave].' '.$tmpDataCollection1[$Coun1][$pOptionAR['Text']];
				$tmpDataCollection0=$tmpCode->ArrayInsertRow($tmpDataCollection0,$tmpDataCollection1[$Coun1],$Coun0);
				$Coun1++;
			}
			$Coun0++;
		}
		
		return $tmpDataCollection0;
	}
	public function getOption($pSTR,$pType,$pSysConfig){
		/*
		$this->sysErrorFuncID=$this->sysErrorClassID.'29';
		$tmpApp=new AppLittleInfo($pSysConfig->GetORMConn('',''),$pSysConfig->GetManaCookieName());
		$retDataCollection1=$tmpApp->getOption($pSTR,$pType);
		*/
		return $retDataCollection1;
	}
	public function getOptionVal($pSTR,$pValue,$pType,$pSysConfig){
		/*
		$this->sysErrorFuncID=$this->sysErrorClassID.'30';
		$tmpApp=new AppLittleInfo($pSysConfig->GetORMConn('',''),$pSysConfig->GetManaCookieName());
		$tmpDataCollection1=$tmpApp->getOption($pSTR,$pType);
		$tmpSTR='None';
		foreach ($tmpDataCollection1 as $Row){
			if($Row['litValue']==$pValue){
				$tmpSTR=$Row['lgtName'];}
		}
		*/
		return $tmpSTR;
	}
	/**
	 * 
	 */
	public function getOptions($pConfig,$pFlag,$pTemplate,&$pOptions){
		//-- ------ ### ------ --
		$tmpAR_Cache=array();
		$tmpPATH=$this->sysFileConfig['PathRoot'].$this->sysFileConfig['sysDataCachePath'].$pFlag.'.php';
		if(file_exists($tmpPATH)){
			$tmpSTR='';
			require($tmpPATH);
			$tmpAR0=explode($this->sysSPLIT7,$tmpSTR);
			$Coun0=0;
			foreach ($tmpAR0 as $Row0){
				$tmpAR1=explode($this->sysSPLIT6,$Row0);
				if (count($pTemplate)==(count($tmpAR1)-1)) {
					$Coun1=0;
					$tmpAR2=array_keys($pTemplate);
					foreach ($tmpAR2 as $Row2){
						$tmpAR_Cache[$Coun0][$Row2]=$tmpAR1[$Coun1];
						$Coun1++;
					}
					
					$Coun0++;
				}
			}
		}
		if(count($tmpAR_Cache)==0){
			$pOptions=$this->bindDropdown($pConfig);
			if($this->sysFileConfig['CacheDbAble']==1){
				$tmpPATH=$this->sysFileConfig['PathRoot'].$this->sysFileConfig['sysDataCachePath'].$pFlag.'.php';
				$tmpContent='';
				foreach ($pOptions as $Row0){
					foreach ($Row0 as $Row1) {
						$tmpContent.=$Row1.$this->sysSPLIT6;
					}
					$tmpContent.=$this->sysSPLIT7;
				}
				$tmpSTR='<?php $tmpSTR=\''.$tmpContent.'\'; ?>';
				$tmpINT=$this->writeFile($tmpPATH,$tmpSTR);
			}
		}else {
			$pOptions=$tmpAR_Cache;
		}
		
		return 0;
	}
	
	
}
?>