<?php
require('../../../QPlatform/Common/Component/ComInitialHead.php');

require($netsFileConfig['sysCoreRoot'].'Inc/m_Nets/System/netssysdbInfo.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.'netssysdbinfo','sttColumnHead'=>'sdit'),
			array('sttTableName'=>$this->sysTableHead.'netssysdbinfocont','sttColumnHead'=>'sdict'),);
		$this->sUiName='Platform/nets/netssysdbInfo';
	}
	public function OnBInitial(){
		$this->sMetaTitle='数据管理';
		$this->sLimitCount=0;
		$this->sApp=new netssysdbInfo($this->sConnString);
		
		$this->sJscriptFiles='<script src="'.$this->sysFileConfig['sysUiCoreRoot'].'Ui/m_nets/Jscript/Mana/Netssysdbinfo.js" type="text/javascript"></script>';
		//-- ------ #ActionType ------ --
		if ($this->sActionType=='DBackup_Do') {
			$this->OnBackup_Do();
		}else if ($this->sActionType=='DRestore_Do') {
			$this->OnRestore_Do();
			
		}
		
		
	}
	public function OnList(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'sditID,2',0);
		$tmpSTR2='Search0';
		$this->sSearchData=$this->AnalyerRequest($tmpSTR2,',,',0);
		//#Spell sql
		$tmpSQL=' SELECT A.sditID,A.sditName,A.sditNumCode,A.sditPath
			FROM '.$this->sysTableHead.'netssysdbInfo AS A 
			WHERE 1=1 
			AND A.sditID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.sditName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!=''){
			$tmpSQL.=' AND A.sditNumCode LIKE \'%'.$this->sSearchData[1].'%\' ';
		}
		if($this->sSearchData[2]!=''){
			$tmpSQL.=' AND A.sditPath 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'=>'sditID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'sditName','stcoctUiName'=>'数据管理名称');
		
		return 0;
	}
	public function OnExternal_Search(){
		//-- ------ #Search data ------ --
		$tmpSTR0='DList0';
		$tmpAR0=$this->getQueryString($tmpSTR0);
		$tmpSTR1='DSort0';
		$tmpAR1=$this->AnalyerRequest($tmpSTR1,'sditID,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.sditID,A.sditName,A.sditParid
			FROM '.$this->sysTableHead.'netssysdbInfo AS A 
			WHERE 1=1 
			AND A.sditID>'.$this->sLimitCount;
		if($this->sSearchData[0]!=''){
			$tmpSQL.=' AND A.sditName LIKE \'%'.$this->sSearchData[0].'%\' ';
		}
		if($this->sSearchData[1]!='-1'){
			$tmpSQL.=' AND A.sditParid='.$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'=>'sditID','stcoctUiName'=>'编号');
		$this->sSortButton[1]=array('stcotName'=>'sditName','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.sditID,A.sditName,A.sditParid 
				FROM '.$this->sysTableHead.'netssysdbInfo AS A
				WHERE 1=1 AND A.sditRecycle=0 AND A.sditChecked>1 AND 
				A.sditParid=(SELECT sditParid FROM netssysdbInfo WHERE 1=1 AND sditRecycle=0 AND sditChecked>1 AND sditID={Nets.ID})
				ORDER BY A.sditOrderBy DESC,A.sditID DESC ';
		}else if($this->sExternal_ChildChooseSData[0]==1 || $this->sExternal_ChildChooseSData[0]==3){
			//-- Child grade --
			$tmpSQL=' SELECT A.sditID,A.sditName,A.sditParid 
				FROM '.$this->sysTableHead.'netssysdbInfo AS A
				WHERE 1=1 AND A.sditRecycle=0 AND A.sditChecked>1 AND A.sditParid={Nets.ID}
				ORDER BY A.sditOrderBy DESC,A.sditID 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.'netssysdbInfo AS A 
			INNER JOIN '.$this->sysTableHead.'netssysdbInfocont AS B ON B.sdictIndexID=A.sditID ';
		$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.sditID ';
				$Coun0++;
			}
		}
		$tmpSQL.=' WHERE 1=1 AND A.sditID='.$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']=='sditParid'){
					}else if($this->sUiDescription_Normal[$Coun0]['stcotName']=='sditModelid_Detail'){
						$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
					}
				}
				$Coun0++;
			}
		}else {
			$Coun0=0;
			foreach($this->sUiDescription_Normal as $Row0){
				if($Row0['stcotName']=='sditTableid'){
					$this->sUiDescription_Normal[$Coun0]['Value']=$this->sMainTableid;
				}
				$Coun0++;
			}
		}
	}
	public function OnBackup_Do(){
		$tmpAR0=$this->AnalyerRequest('DBackup_Do',',,,1,0,120,0,',0);
		$this->sCallback_Flag=$tmpAR0[0];
		$this->sCallback_Numcode=$tmpAR0[1];
		$this->sCallback_Tablename=$tmpAR0[2];
		$this->sCallback_Pageindex=$tmpAR0[3];
		$this->sCallback_Pagecount=$tmpAR0[4];
		$this->sCallback_Pagesize=$tmpAR0[5];
		$this->sCallback_PageRecordcount=$tmpAR0[6];
		$this->sCallback_sNextFlag=$tmpAR0[7];
		$this->sCallback_Message='';
		$this->sCallback_Tablenames='';
		
		if ($tmpAR0[0]=='ALL') {
			//-- #ALL --
			$tmpDbDescriptions=array(
				$this->sDbDescriptions[$this->sysTableHead.'netssysdbinfo'],
				$this->sDbDescriptions[$this->sysTableHead.'netssysdbinfocont'],
				);
			$tmpINT=$this->sApp->onBackup_Getalltable($tmpDbDescriptions,$this->sCallback_Tablenames);
			if ($tmpINT!=0) {
				$this->sCallback_Message=$this->sApp->sysLastError;
				$this->sCallback_Flag='ERROR';
				return 1;
			}
			
			$this->sCallback_Flag='ALL_Callback';
			$this->sCallback_Numcode=$tmpDbDescriptions[0]['Columns']['sditNumCode']['Value'];
			$this->sCallback_sNextFlag=1;
		}else if ($tmpAR0[0]=='STRUCT') {
			//-- #STRUCT --
			$tmpINT=$this->sApp->onBackup_Tablestruct($this->sCallback_Numcode,$this->sCallback_Tablename);
			if ($tmpINT!=0) {
				$this->sCallback_Message=$this->sApp->sysLastError;
				$this->sCallback_Flag='ERROR';
				return 1;
			}
			$this->sCallback_Flag='STRUCT_Callback';
			$this->sCallback_sNextFlag=1;
		}else if ($tmpAR0[0]=='DATA') {
			//-- #DATA --
			$tmpAR0=array(
				$this->sCallback_Pageindex,
				$this->sCallback_Pagecount,
				$this->sCallback_Pagesize,
				$this->sCallback_PageRecordcount,
				);
			$tmpINT=$this->sApp->onBackup_Tabledata($this->sCallback_Numcode,$this->sCallback_Tablename,$tmpAR0);
			if ($tmpINT!=0) {
				$this->sCallback_Message=$this->sApp->sysLastError;
				$this->sCallback_Flag='ERROR';
				return 1;
			}
			
			$this->sCallback_Flag='DATA_Callback';
			$this->sCallback_Pageindex=$tmpAR0[0];
			$this->sCallback_Pagecount=$tmpAR0[1];
			$this->sCallback_Pagesize=$tmpAR0[2];
			$this->sCallback_PageRecordcount=$tmpAR0[3];
			$this->sCallback_sNextFlag=0;
			if ($this->sCallback_Pageindex==$this->sCallback_Pagecount) {
				$this->sCallback_sNextFlag=1;
			}
		}
		
		
		return 0;
	}
	public function OnRestore_Do(){
		$tmpAR0=$this->AnalyerRequest('DRestore_Do',',,,0,0,0,0,',0);
		$this->sCallback_Flag=$tmpAR0[0];
		$this->sCallback_Numcode=$tmpAR0[1];
		$this->sCallback_Tablename=$tmpAR0[2];
		$this->sCallback_Pageindex=$tmpAR0[3];
		$this->sCallback_Pagecount=$tmpAR0[4];
		$this->sCallback_Pagesize=$tmpAR0[5];
		$this->sCallback_PageRecordcount=$tmpAR0[6];
		$this->sCallback_sNextFlag=$tmpAR0[7];
		$this->sCallback_Message='';
		$this->sCallback_Tablenames='';
		
		//-- ### --
		$tmpSTR='localhost,3306,root,K3FCJKDX9WOEA5HZ,nets_installtest,UTF-8';
		$this->sApp=new netssysdbInfo($tmpSTR);
		//-- ### --
		
		if ($tmpAR0[0]=='STRUCT_ALL') {
			//-- #STRUCT_ALL --
			$tmpINT=$this->sApp->onRestore_Getallstruct($this->sCallback_Numcode,$this->sCallback_Tablenames);
			if ($tmpINT!=0) {
				$this->sCallback_Message=$this->sApp->sysLastError;
				$this->sCallback_Flag='ERROR';
				return 1;
			}
			
			$this->sCallback_Flag='STRUCT_ALL_Callback';
			$this->sCallback_sNextFlag=1;
		}else if ($tmpAR0[0]=='STRUCT') {
			//-- #STRUCT --
			$tmpINT=$this->sApp->onRestore_Getstruct($this->sCallback_Numcode,$this->sCallback_Tablename);
			if ($tmpINT!=0) {
				$this->sCallback_Message=$this->sApp->sysLastError;
				$this->sCallback_Flag='ERROR';
				return 1;
			}
			
			$this->sCallback_Flag='STRUCT_Callback';
			$this->sCallback_sNextFlag=1;
		}else if ($tmpAR0[0]=='DATA_ALL') {
			//-- #DATA_ALL --
			$tmpINT=$this->sApp->onRestore_Getalldata($this->sCallback_Numcode,$this->sCallback_Tablenames);
			if ($tmpINT!=0) {
				$this->sCallback_Message=$this->sApp->sysLastError;
				$this->sCallback_Flag='ERROR';
				return 1;
			}
			
			$this->sCallback_Flag='DATA_ALL_Callback';
			$this->sCallback_sNextFlag=1;
		}else if ($tmpAR0[0]=='DATA') {
			//-- #DATA --
			$tmpINT=$this->sApp->onRestore_Getdata($this->sCallback_Numcode,$this->sCallback_Tablename);
			if ($tmpINT!=0) {
				$this->sCallback_Message=$this->sApp->sysLastError;
				$this->sCallback_Flag='ERROR';
				return 1;
			}
			
			$this->sCallback_Flag='DATA_Callback';
			$this->sCallback_sNextFlag=1;
		}
		
		
		//-- ### --
		$this->sApp=new netssysdbInfo($this->sConnString);
		//-- ### --
		return 0;
	}
	
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);

		return $pColumn;
	}
	public function DefUiButton($pFlag,$Exception){
		parent::DefUiButton($pFlag,array('Normal',));
		
		if ($pFlag=='Normal' && !in_array($pFlag,$Exception)) { ?>
<?php if (in_array($this->sFunctionname.'_delete',$this->sAR_UserPower) && count($this->sAR_UserPower)>1) {}else { ?>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpCommon.confirmDo('删除后将不能恢复，您确定删除本信息吗?');tmpCommon.setActionType('','DDelete','',''); tmpCommon.netsSubmit();">删除</a></li>
<?php } if (in_array($this->sFunctionname.'_modify',$this->sAR_UserPower) && count($this->sAR_UserPower)>1) {}else { ?>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpCommon.setActionType('Normal','DModify','',''); tmpCommon.netsSubmit();">修改</a></li>

<?php } if (in_array($this->sFunctionname.'_restore',$this->sAR_UserPower) && count($this->sAR_UserPower)>1) {}else { ?>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpNetssysdbinfo.OnRestore_Start();">还原数据</a></li>
<?php } if (in_array($this->sFunctionname.'_backup',$this->sAR_UserPower) && count($this->sAR_UserPower)>1) {}else { ?>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpNetssysdbinfo.OnBackup_Start();">备份数据</a></li>
<?php } ?>

<?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=='DBackup_Do' || $tmpDefault->sActionType=='DRestore_Do') {
	require($tmpDefault->sysFileConfig['sysCoreRoot_Real'].$tmpDefault->sysManaTemplatePath.'Component/Head_Frame.php');
	require($tmpDefault->sysFileConfig['sysCoreRoot_Real'].$tmpDefault->sysManaTemplatePath.'Nets/netssysdbInfo_do.php');
	require($tmpDefault->sysFileConfig['sysCoreRoot_Real'].$tmpDefault->sysManaTemplatePath.'Component/End_Frame.php');
}else {
	require($tmpDefault->sysFileConfig['sysCoreRoot'].$tmpDefault->sysQPlatformTemplatePath.'Component/Group_0.php');
} ?>