<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Nets/User/netsuserunit.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.'netsuserunit','sttColumnHead'=>'uut'),
			array('sttTableName'=>$this->sysTableHead.'netsuserunitcont','sttColumnHead'=>'uuct'),);
		$this->sUiName='Platform/nets/user_userunit';
		
		
	}
	public function OnBInitial(){
		$this->sMetaTitle='用户单位';
		$this->sLimitCount=0;
		$this->sApp=new netsuserunit($this->sConnString);
		//---- Get commen option ----
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
				$tmpAR0['SQL']=' SELECT A.uugtID,A.uugtName,A.uugtParid 
			FROM '.$this->sysTableHead.'netsuserunitgroup AS A
			WHERE 1=1 AND A.uugtRecycle=0 AND A.uugtChecked>1 AND A.uugtParid={Nets.Parid}
			ORDER BY A.uugtOrderBy DESC,A.uugtID DESC ';
		$tmpAR0['SQL0']=' SELECT A.uugtID,A.uugtName,A.uugtParid 
			FROM '.$this->sysTableHead.'netsuserunitgroup AS A
			WHERE 1=1 AND A.uugtRecycle=0 AND A.uugtChecked>1 AND A.uugtID={Nets.Parid}
			ORDER BY A.uugtOrderBy DESC,A.uugtID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='uugtID';
		$tmpAR0['Text']='uugtName';
		$tmpAR0['Value']='uugtID';
		$tmpAR0['Type']=0;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='cms/netsuserunit_group';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sParid1);
		$this->sParid2=$this->sParid1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有的分类]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sParid2,$tmpAR0);
		//Channel
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.cctID,A.cctName,A.cctParid
			FROM '.$this->sysTableHead.'cmschannel AS A 
			WHERE 1=1 AND A.cctRecycle=0 AND A.cctChecked>1 AND A.cctParid={Nets.Parid}
			ORDER BY A.cctOrderBy DESC,A.cctID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['ParID']='cctID';
		$tmpAR0['Text']='cctName';
		$tmpAR0['Value']='cctID';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$this->sChannelid1=$this->sChannelid2=$this->sControl->bindDropdown($tmpAR0);
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有的频道]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sChannelid2,$tmpAR0);
		
		
		
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'uutID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',-1',0);
		//#Spell sql
		$tmpSQL=' SELECT A.uutID,A.uutName,A.uutParid,A.uutGroupid
			FROM '.$this->sysTableHead.'netsuserunit AS A 
			WHERE 1=1 
			AND A.uutID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.uutName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.uutGroupid='.$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->sPButton->sPage=$this->sysPage;
		$this->sPButton->sExtendParameter='&'.$tmpSTR2.'='.$this->sSearchData[0].','.$this->sSearchData[0];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'uutID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'uutName','stcoctUiName'=>'单位名称');
		
		return 0;
	}
	public function OnExternal_Search(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'uutID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,'',0);
		$tmpSTR3='External_Search';
		$this->sExternal_SearchData=$this->AnalyerRequest($tmpSTR3,',0',0);
		//#Spell sql
		$tmpSQL=' SELECT A.uutID,A.uutName
			FROM '.$this->sysTableHead.'netsuserunit AS A 
			WHERE 1=1 
			AND A.uutID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.uutName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		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->sysSPLIT1.$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'=>'dptID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'dptName','stcoctUiName'=>'单位名称');
		
		return 0;
	}
	public function OnNormal(){
		$tmpAR0=$this->AnalyerRequest('Normal','0,0',0);
		
		$tmpSQL=' SELECT * 
			FROM '.$this->sysTableHead.'netsuserunit AS A 
			INNER JOIN '.$this->sysTableHead.'netsuserunitcont AS B ON B.uuctIndexID=A.uutID ';
		$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.uutID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.uutID='.$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);
		if($pColumn['stcotName']=='uutParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='uutParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sParid1;
		}else if($pColumn['stcotName']=='uutChannelid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sChannelid2;
		}else if($pColumn['stcotName']=='uutChannelid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sChannelid1;
			
		}else if($pColumn['stcotName']=='uutParentid' && $pFlag=='Normal'){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_nets/user/userUnit.php';
			$pColumn['Parameter']=$tmpParameters;
			
			$tmpSQL=' SELECT A.uutName AS tName FROM {Nets.TableHead}netsuserunit AS A
				WHERE 1=1 AND A.uutID={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'];
			}
			
			
		}
		return $pColumn;
	}
}
//-- ------ #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'); ?>