<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Oa/Oa/oatask.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.'oatask','sttColumnHead'=>'otat'),
			array('sttTableName'=>$this->sysTableHead.'oataskcont','sttColumnHead'=>'otact'),);
		$this->sUiName='Platform/my/oatask';
	}
	public function OnBInitial(){
		$this->sMetaTitle='我的任务';
		$this->sLimitCount=0;
		$this->sApp=new oatask($this->sConnString);
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.otagtID,A.otagtName,A.otagtParid FROM '.$this->sysTableHead.'oataskgroup AS A
			WHERE 1=1 AND A.otagtChecked>1 AND A.otagtParid={Nets.Parid}
			ORDER BY A.otagtOrderBy DESC,A.otagtID DESC ';
		$tmpAR0['SQL0']=' SELECT A.otagtID,A.otagtName,A.otagtParid FROM '.$this->sysTableHead.'oataskgroup AS A
			WHERE 1=1 AND A.otagtChecked>1 AND A.otagtID={Nets.Parid}
			ORDER BY A.otagtOrderBy DESC,A.otagtID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='otagtID';
		$tmpAR0['Text']='otagtName';
		$tmpAR0['Value']='otagtID';
		$tmpAR0['Type']=0;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='oa/oatask_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);
		//State
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=142;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Source']='sotSourceR00';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='nets/options_OaTaskState';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sState1);
		$this->sState2=$this->sState1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有状态]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sState2,$tmpAR0);
		//Urgency
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=143;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Source']='sotSourceR00';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='nets/options_OaTaskUrgency';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sUrgency1);
		$this->sUrgency2=$this->sUrgency1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有紧急状态]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sUrgency2,$tmpAR0);
		
		
		
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'otatID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',,-1,-1,-1,-1,-1,,',0);
		//#Spell sql
		$tmpSQL=' SELECT A.otatID,A.otatName,A.otatNumCode,A.otatParid,A.otatState,A.otatParentid,A.otatViewid,A.otatUrgency
			FROM '.$this->sysTableHead.'oatask AS A 
			WHERE 1=1 
			AND A.otatID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.otatName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!=''){
			$tmpSQL.=' AND A.otatNumCode LIKE \'%'.$this->sSearchData[1].'%\' ';
		}
		if($this->sSearchData[2]!='-1'){
			$tmpSQL.=' AND A.otatParid='.$this->sSearchData[2].' ';
		}
		if($this->sSearchData[3]!='-1'){
			$tmpSQL.=' AND A.otatState='.$this->sSearchData[3].' ';
		}
		if($this->sSearchData[4]!='-1'){
			$tmpSQL.=' AND A.otatParentid='.$this->sSearchData[4].' ';
		}
		if($this->sSearchData[5]!='-1'){
			$tmpSQL.=' AND A.otatViewid='.$this->sSearchData[5].' ';
		}
		if($this->sSearchData[6]!='-1'){
			$tmpSQL.=' AND A.otatUrgency='.$this->sSearchData[6].' ';
		}
		if($this->sSearchData[7]!=''){
			$tmpSQL.=' AND A.otatPStartTime LIKE \'%'.$this->sSearchData[1].'%\' ';
		}
		if($this->sSearchData[8]!=''){
			$tmpSQL.=' AND A.otatPEndTime LIKE \'%'.$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->sysSPLIT1.
			$this->sSearchData[1].$this->sysSPLIT1.
			$this->sSearchData[2].$this->sysSPLIT1.
			$this->sSearchData[3].$this->sysSPLIT1.
			$this->sSearchData[4].$this->sysSPLIT1.
			$this->sSearchData[5].$this->sysSPLIT1.
			$this->sSearchData[6].$this->sysSPLIT1.
			$this->sSearchData[7].$this->sysSPLIT1.
			$this->sSearchData[8];
		$this->sPButton->sExtendParameter='&'.$tmpSTR2.'='.$this->sSearchData[0].$this->sysSPLIT1.$this->sSearchData[1];
		$this->sPButton->setPage($this->sDb->sysPageInfo);
		$this->sPButton->setSort($tmpAR1);
		$this->sSortButton[0]=array('stcotName'=>'otatID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'otatName','stcoctUiName'=>'任务名称');
		
		return 0;
	}
	public function OnExternal_Search(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'otatID,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.otatID,A.otatName,A.otatParid
			FROM '.$this->sysTableHead.'oatask AS A 
			WHERE 1=1 
			AND A.otatID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.otatName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.otatParid='.$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'=>'otatID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'otatName','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.otatID,A.otatName,A.otatParid 
				FROM '.$this->sysTableHead.'oatask AS A
				WHERE 1=1 AND A.otatRecycle=0 AND A.otatChecked>1 AND 
				A.otatParid=(SELECT otatParid FROM oatask WHERE 1=1 AND otatRecycle=0 AND otatChecked>1 AND otatID={Nets.ID})
				ORDER BY A.otatOrderBy DESC,A.otatID DESC ';
		}else if($this->sExternal_ChildChooseSData[0]==1 || $this->sExternal_ChildChooseSData[0]==3){
			//-- Child grade --
			$tmpSQL=' SELECT A.otatID,A.otatName,A.otatParid 
				FROM '.$this->sysTableHead.'oatask AS A
				WHERE 1=1 AND A.otatRecycle=0 AND A.otatChecked>1 AND A.otatParid={Nets.ID}
				ORDER BY A.otatOrderBy DESC,A.otatID 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.'oatask AS A 
			INNER JOIN '.$this->sysTableHead.'oataskcont AS B ON B.otactIndexID=A.otatID ';
		$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.otatID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.otatID='.$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']];
					//-- ------ #Spical set ------ --
					if($this->sUiDescription_Normal[$Coun0]['stcotName']=='otatParid'){
					}else if($this->sUiDescription_Normal[$Coun0]['stcotName']=='otatModelid_Detail'){
						$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
					}
				}
				$Coun0++;
			}
		}else {
			$Coun0=0;
			foreach($this->sUiDescription_Normal as $Row0){
				if($Row0['stcotName']=='otatTableid'){
					$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
				}
				$Coun0++;
			}
		}
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='otatParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='otatParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sParid1;
		}else if($pColumn['stcotName']=='otatUrgency' && $pFlag=='Search'){
			$pColumn['Option']=$this->sUrgency2;
		}else if($pColumn['stcotName']=='otatUrgency' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sUrgency1;
		}else if($pColumn['stcotName']=='otatState' && $pFlag=='Search'){
			$pColumn['Option']=$this->sState2;
		}else if($pColumn['stcotName']=='otatState' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sState1;
			
		}else if($pColumn['stcotName']=='otatParentid'){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_nets/my/oatask.php';
			$pColumn['Parameter']=$tmpParameters;
			//otatParentid
			$tmpSQL=' SELECT A.otatID,A.otatName AS tName
				FROM {Nets.TableHead}oatask AS A
				WHERE 1=1 AND A.otatID={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']=='otatTagid'){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_nets/my/oatasktag.php';
			$pColumn['Parameter']=$tmpParameters;
			//otatTagid
			$tmpSQL=' SELECT A.otatatID,A.otatatName AS tName
				FROM {Nets.TableHead}oatasktag AS A
				WHERE 1=1 AND A.otatatChecked>1 AND A.otatatID={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']=='otatViewid'){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_nets/my/oataskview.php';
			$pColumn['Parameter']=$tmpParameters;
			//otatViewid
			$tmpSQL=' SELECT A.otavitID,A.otavitName AS tName
				FROM {Nets.TableHead}oataskview AS A
				WHERE 1=1 AND A.otavitChecked>1 AND A.otavitID={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']=='otatDoBy'){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_nets/user/manaUserinfo.php';
			$pColumn['Parameter']=$tmpParameters;
			//otatDoBy
			$tmpSQL=' SELECT A.uitID,A.uitName AS tName
				FROM {Nets.TableHead}netsuserinfo AS A
				WHERE 1=1 AND A.uitRecycle=0 AND A.uitChecked>1 AND A.uitID={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']=='otatPostBy'){
			$tmpParameters=$this->sControl->textChooseParameter_Template;
			$tmpParameters['Controlname']=$pColumn['stcotName'];
			$tmpParameters['URL']=$this->sysFileConfig['sysCoreRoot'].'QPlatform/m_nets/user/manaUserinfo.php';
			$pColumn['Parameter']=$tmpParameters;
			//otatPostBy
			$tmpSQL=' SELECT A.uitID,A.uitName AS tName
				FROM {Nets.TableHead}netsuserinfo AS A
				WHERE 1=1 AND A.uitRecycle=0 AND A.uitChecked>1 AND A.uitID={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'); ?>