<?php
class netsPAjaxButton extends netsControl {
	public $sInstanctName='PAjaxButton0';
	public $sTemplatePath='../../../Config/m_default/File/pageAjaxButton1.htm';
	public $sTemplate=array();
	public $sPageName='DList0';
	public $sPageArray=array();
	public $sPageParameter='&DList0=1,0,0,0';
	public $sSortName='DSort0';
	public $sSortArray=array();
	public $sSortParameter='&DSort0=uitName,0';
	public $sPage='';
	public $sExtendParameter='&ID=0';
	public $sFlag='tmpFlag';
	public $sPanel='tmpPanel';
	
	public function netsPAjaxButton(){
		$this->sTemplate=explode($this->sysSPLIT10,$this->readFile($this->sTemplatePath));
	}
	
	public function setPage($pInfo){
		//-- ------ #pInfo ------ --
		//[0].Page index
		//[1].Page count
		//[2].Page size
		//[3].Page collection count
		if(count($pInfo)!=4){
			$pInfo=array(1,0,12,0);
		}
		$this->sPageArray=$pInfo;
		$this->sPageParameter='&'.$this->sPageName.'='.$pInfo[0].','.$pInfo[1].','.$pInfo[2].','.$pInfo[3];
	}
	public function showPage(){
		if(count($this->sTemplate)<12){
			return 1;
		}
		if(count($this->sPageArray)<3){
			return 1;
		}
		//-- ------ #Spell template ------ --
		$tmpOut=$this->sTemplate[0];
		$tmpOut.=$this->sTemplate[1];
		//#First
		$tmpINT=1;
		$tmpSTR=$this->sTemplate[2];
		$tmpAR0=explode($this->sysSPLIT5,$tmpSTR);
		if($this->sPageArray[0]<2){
			$tmpSTR=$tmpAR0[0].$this->sysSPLIT10;
		}else {
			$tmpSTR=str_replace('{Nets.PageButtonLink}',
				$this->sPage.'?'.$this->sPageName.'='.
				$tmpINT.','.$this->sPageArray[1].','.$this->sPageArray[2].','.$this->sPageArray[3].
				$this->sSortParameter.$this->sExtendParameter,
				$tmpAR0[1]);
		}
		$tmpOut.=$tmpSTR;
		//#Prev
		$tmpINT=$this->sPageArray[0]-1;
		$tmpSTR=$this->sTemplate[3];
		$tmpAR0=explode($this->sysSPLIT5,$tmpSTR);
		if($this->sPageArray[0]<2){
			$tmpSTR=$tmpAR0[0].$this->sysSPLIT10;
		}else {
			$tmpSTR=str_replace('{Nets.PageButtonLink}',
				$this->sPage.'?'.$this->sPageName.'='.
				$tmpINT.','.$this->sPageArray[1].','.$this->sPageArray[2].','.$this->sPageArray[3].
				$this->sSortParameter.$this->sExtendParameter,
				$tmpAR0[1]);
		}
		$tmpOut.=$tmpSTR;
		//#Num
		$tmpSTR=$this->sTemplate[4];
		$tmpAR0=explode($this->sysSPLIT5,$tmpSTR);
		$Coun0=0;
		while($Coun0<7){
			$tmpINT=-3;
			$tmpINT=$Coun0+$tmpINT+$this->sPageArray[0];
			if($tmpINT==$this->sPageArray[0]){
				$tmpSTR=str_replace('{Nets.IndexButtonText}',$tmpINT,$tmpAR0[0]).$this->sysSPLIT10;
			}else {
				$tmpSTR=str_replace('{Nets.IndexButtonText}',$tmpINT,$tmpAR0[1]);
				$tmpSTR=str_replace('{Nets.PageButtonLink}',
					$this->sPage.'?'.$this->sPageName.'='.
					$tmpINT.','.$this->sPageArray[1].','.$this->sPageArray[2].','.$this->sPageArray[3].
					$this->sSortParameter.$this->sExtendParameter,
					$tmpSTR);
			}
			if($tmpINT>0 && $tmpINT<=$this->sPageArray[1]){
				$tmpOut.=$tmpSTR;
			}
			$Coun0++;
		}
		//#Next
		$tmpINT=$this->sPageArray[0]+1;
		$tmpSTR=$this->sTemplate[5];
		$tmpAR0=explode($this->sysSPLIT5,$tmpSTR);
		if($this->sPageArray[0]==$this->sPageArray[1]){
			$tmpSTR=$tmpAR0[0].$this->sysSPLIT10;
		}else {
			$tmpSTR=str_replace('{Nets.PageButtonLink}',
				$this->sPage.'?'.$this->sPageName.'='.
				$tmpINT.','.$this->sPageArray[1].','.$this->sPageArray[2].','.$this->sPageArray[3].
				$this->sSortParameter.$this->sExtendParameter,
				$tmpAR0[1]);
		}
		$tmpOut.=$tmpSTR;
		//#End
		$tmpINT=$this->sPageArray[1];
		$tmpSTR=$this->sTemplate[6];
		$tmpAR0=explode($this->sysSPLIT5,$tmpSTR);
		if($this->sPageArray[0]==$this->sPageArray[1]){
			$tmpSTR=$tmpAR0[0].$this->sysSPLIT10;
		}else {
			$tmpSTR=str_replace('{Nets.PageButtonLink}',
				$this->sPage.'?'.$this->sPageName.'='.
				$tmpINT.','.$this->sPageArray[1].','.$this->sPageArray[2].','.$this->sPageArray[3].
				$this->sSortParameter.$this->sExtendParameter,
				$tmpAR0[1]);
		}
		$tmpOut.=$tmpSTR;
		//#Info
		$tmpSTR=str_replace('{Nets.Index}',$this->sPageArray[0],$this->sTemplate[7]);
		$tmpSTR=str_replace('{Nets.PageCount}',$this->sPageArray[1],$tmpSTR);
		$tmpSTR=str_replace('{Nets.RecordCount}',$this->sPageArray[3],$tmpSTR);
		$tmpOut.=$tmpSTR;
		$tmpOut.=$this->sTemplate[8];
		//Ajax string
		$tmpOut=str_replace('{Nets.AjaxFlag}',$this->sFlag,$tmpOut);
		$tmpOut=str_replace('{Nets.AjaxPanel}',$this->sPanel,$tmpOut);
		
		echo ($tmpOut);
		return 0;
	}
	public function setSort($pInfo){
		//-- ------ #pInfo ------ --
		//[0].Sort key
		//[1].Sort flag - 0.Non choose , 1.DESC , 2.ESC
		$this->sSortArray=$pInfo;
		$this->sSortParameter='&'.$this->sSortName.'='.$pInfo[0].','.$pInfo[1];
	}
	public function showSort($pSort){
		if(count($this->sTemplate)<12){
			return 1;
		}
		//-- ------ #Spell template ------ --
		$tmpSTR='';
		$tmpINT=0;
		$tmpAR=explode($this->sysSPLIT5,$this->sTemplate[10]);
		if($this->sSortArray[0]==$pSort['stcotName'] && $this->sSortArray[1]==1){
			$tmpSTR=$tmpAR[1];
			$tmpINT=2;
		}else if($this->sSortArray[0]==$pSort['stcotName'] && $this->sSortArray[1]==2){
			$tmpSTR=$tmpAR[2];
			$tmpINT=1;
		}else {
			$tmpSTR=$tmpAR[0];
			$tmpINT=1;
		}
		$tmpSTR=str_replace('{Nets.ButtonText}',$pSort['stcoctUiName'],$tmpSTR);
		$tmpSTR=str_replace('{Nets.PageButtonLink}',
			$this->sPage.'?'.$this->sSortName.'='.
			$pSort['stcotName'].','.$tmpINT.
			$this->sPageParameter.$this->sExtendParameter,
			$tmpSTR);
		$tmpOut=$this->sTemplate[9].$tmpSTR;
		//Ajax string
		$tmpOut=str_replace('{Nets.AjaxFlag}',$this->sFlag,$tmpOut);
		$tmpOut=str_replace('{Nets.AjaxPanel}',$this->sPanel,$tmpOut);
		
		echo ($tmpOut);
		return 0;
	}
	public function resetTemlate($pTemplatePath){
		$this->sTemplatePath=$pTemplatePath;
		$this->sTemplate=explode($this->sysSPLIT10,$this->readFile($this->sTemplatePath));
	}
}
?>