<?php
//-- ------ #Initial config ------
require('../../../Config/m_default/Config/netsFileConfig.php');
require($netsFileConfig['sysCoreRoot'].'Config/m_default/Config/netsFileConfig.php');
require($netsFileConfig['sysCoreRoot'].'Config/m_default/Config/netsFileConfig_ADD.php');
require($netsFileConfig['sysCoreRoot'].'Config/m_default/Config/netsConfig.php');
//-- ------ #Require entitry ------
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/netsuserinfo.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/netsuserinfocont.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/netsusergroup.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/netsusergrade.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/netsusertype.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/netsusertypecont.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/netsuserunit.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/netsuserunitcont.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/netsuserdepartment.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/netsuserdepartmentcont.php');
//-- ------ #Require config and base class ------
require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Cache/netsFile.php');
require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Cache/netsError.php');
require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Cache/netsCache.php');
//-- ------ #Require db class ------
require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Cache/netsDbCache.php');
require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Db/netsMySql.php');
require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Db/netsDb.php');
//-- ------ #Require page class ------
require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Cache/netsPageCache.php');
require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Html/netsHtml.php');
require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Html/netsPage.php');
require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Html/netsControl.php');
require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Html/netsControls.php');

require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Func/netsImage.php');
//-- ------ #Require class ------
require($netsFileConfig['sysCoreRoot'].'Inc/m_Nets/User/netsuserinfo.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Nets/System/netssysmenu.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Nets/System/netssystable.php');
//-- ------ #Require function class ------
require($netsFileConfig['sysCoreRoot'].'Inc/netsFunc/Func/netsCode.php');

require($netsFileConfig['sysCoreRoot'].'Mana/Common/Class/ComPage.php');
require($netsFileConfig['sysCoreRoot'].'Mana/Common/Class/ComControls.php');
require($netsFileConfig['sysCoreRoot'].'Mana/Common/Class/ComControlPage.php');
require($netsFileConfig['sysCoreRoot'].'Mana/Common/Class/CustomPage.php');
require($netsFileConfig['sysCoreRoot'].'Mana/Common/Class/CustomControls.php');
require($netsFileConfig['sysCoreRoot'].'Mana/Common/Class/CustomControlPage.php');

require($netsFileConfig['sysCoreRoot'].'Component/Nets/DataList/netsPButton.php');
require($netsFileConfig['sysCoreRoot'].'Component/Nets/DataList/netsPAjaxButton.php');
//-- ------ #Head class ------
class initialHead extends netsControl {
	public $sOpenSort=0;
	public function initialHead(){
		$this->netsControl();
	}
}
$tmpComHead=new initialHead();
//-- ------ # ------ --
class PaDefault extends CustomPage {
	//-- ------ #Common ------ --
	public $sURoot='../../../UploadFiles/';
	public $sUNowDirectory='../../../UploadFiles/';
	public $sUResult='';
	//-- ------ #Manage ------ --
	public $sFFilename='';
	public $sFFiletype='';
	public $sFFilemaxsize=0;
	public $sFFilemixsize=0;
	public $sFFilestartdate='';
	public $sFFileenddate='';
	public $sTOrder=0;
	public $sTListtype=0;
	
	public $sURename=0;
	public $sUThumb=0;
	public $sUThumbPath='';
	public $sUWater=0;
	public $sUWaterPath='';
	public $sUWaterPosition=0;
	public $sDDirectoryName='';
	
	public $sDataFilelist=array();
	public $sDataDirectory=array();
	//-- ------ #Simple ------ --
	public $sRControl='';
	public $sUDirectory='';
	public $sUType=0;
	
	public function PaDefault(){
		$this->CustomPage();
	}
	public function OnPInitial(){
		$this->checkUser('1,2,3,4,5,');
		$this->sFormEnctype=' enctype="multipart/form-data" ';
	}
	public function OnBInitial(){
		$this->sMetaTitle='文件管理';
		$this->sURoot=$this->sysFileConfig['PathRoot'].'UploadFiles/';
		$this->sUNowDirectory=$this->sysFileConfig['PathRoot'].'UploadFiles/';
		//$this->sUNowDirectory=$this->sURoot=$this->sysFileConfig['AttachUrlPath'];
		
		$tmpAR0=$this->AnalyerRequest('RControl','',0);
		$this->sRControl=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('UDirectory','',0);
		$this->sUDirectory=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('UType',0,0);
		$this->sUType=$tmpAR0[0];
		
		if($this->sActionType=='' && $this->sRControl==''){
			$this->OnDirectory();
			$this->OnFilelist();
		}else if($this->sActionType=='UDelete'){
			$this->OnUDelete();
		}else if($this->sActionType=='UDeleteDir'){
			$this->OnUDeleteDir();
		}else if($this->sActionType=='UChangeDir'){
			$this->OnUChangeDir();
		}else if($this->sActionType=='UAjaxDirectory'){
			$this->OnUAjaxDirectory();
		}
		
		if($this->sActionTypeF=='USimple'){
			$this->OnUSimple();
		}else if($this->sActionTypeF=='UManage'){
			$this->OnUManage();
		}else if($this->sActionTypeF=='DDirectory'){
			$this->OnDDirectory();
		}
	}
	
	public function OnUSimple(){
		$tmpImg=new netsImage();
		$tmpAR0=$this->AnalyerRequest('RControlTxt','',1);
		$this->sRControl=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('UDirectoryTxt','',1);
		$this->sUDirectory=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('UTypeTxt',0,1);
		$this->sUType=$tmpAR0[0];
		$tmpUDirectory=$this->sURoot;
		if($this->sUDirectory!=''){
			$tmpUDirectory=$this->sURoot.$this->sUDirectory;
		}
		//Upload
		$tmpAR0=$tmpImg->sysImgConfigTemplate;
		$tmpError='';
		$Coun0=0;
		while (count($_FILES['FileTxt']['name'])>$Coun0){
			$tmpAR0=$tmpImg->sysImgConfigTemplate;
			$tmpAR0['BasePath']=$this->sURoot;
			$tmpAR0['SavePath']=$tmpUDirectory;
			$tmpAR0['File']['name']=$_FILES['FileTxt']['name'][$Coun0];
			$tmpAR0['File']['type']=$_FILES['FileTxt']['type'][$Coun0];
			$tmpAR0['File']['tmp_name']=$_FILES['FileTxt']['tmp_name'][$Coun0];
			$tmpAR0['File']['error']=$_FILES['FileTxt']['error'][$Coun0];
			$tmpAR0['File']['size']=$_FILES['FileTxt']['size'][$Coun0];
			$tmpINT=$tmpImg->CreateFile($tmpAR0);
			if($tmpINT!=0){
				$tmpError=$tmpINT;
			}
			$Coun0++;
		}
		//Message
		if(count($_FILES['FileTxt']['name'])==0){
			$tmpError='请选择要上传的文件.';
		}
		if($tmpError!=''){
			$this->sTopMessage=$tmpError;
		}else {
			$this->sTopMessage='文件已经成功上传.';
			$this->sUResult=$tmpAR0['ResultFile'];
		}
		$this->sActionType='UMessage';
	}
	public function OnUManage(){
		$tmpImg=new netsImage();
		$tmpAR0=$this->AnalyerRequest('URenameTxt',0,1);
		$this->sURename=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('UThumbTxt',0,1);
		$this->sUThumb=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('UThumbPathTxt','',1);
		$this->sUThumbPath=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('UWaterTxt',0,1);
		$this->sUWater=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('UWaterPathTxt','',1);
		$this->sUWaterPath=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('UWaterPositionTxt',0,1);
		$this->sUWaterPosition=$tmpAR0[0];
		
		$tmpAR0=$this->AnalyerRequest('NowDirectory',$this->sURoot,2);
		$this->sUNowDirectory=$tmpAR0[0];
		//Upload
		$tmpAR0=$tmpImg->sysImgConfigTemplate;
		$tmpError='';
		$Coun0=0;
		while (count($_FILES['FileTxt']['name'])-1>$Coun0){
			$tmpAR0=$tmpImg->sysImgConfigTemplate;
			$tmpAR0['Rename']=$this->sURename;
			$tmpAR0['Thumb']=$this->sUThumb;
			$tmpAR0['ThumbSize']=$this->sysFileConfig['userUploadThumbSize'];
			$tmpAR0['ThumbPath']=$this->sUThumbPath;
			$tmpAR0['Water']=$this->sUWater;
			$tmpAR0['WaterDiaphaneity']=$this->sysFileConfig['ThumbWaterDiaphaneity'];
			$tmpAR0['WaterCondition']=$this->sysFileConfig['ThumbWaterCondition'];
			$tmpAR0['WaterPosition']=$this->sUWaterPosition;
			$tmpAR0['WaterPath']=$this->sUWaterPath;
			$tmpAR0['SavePath']=$this->sUNowDirectory;
			$tmpAR0['File']['name']=$_FILES['FileTxt']['name'][$Coun0];
			$tmpAR0['File']['type']=$_FILES['FileTxt']['type'][$Coun0];
			$tmpAR0['File']['tmp_name']=$_FILES['FileTxt']['tmp_name'][$Coun0];
			$tmpAR0['File']['error']=$_FILES['FileTxt']['error'][$Coun0];
			$tmpAR0['File']['size']=$_FILES['FileTxt']['size'][$Coun0];
			$tmpINT=$tmpImg->CreateFile($tmpAR0);
			if($tmpINT!=0){
				$tmpError.=$tmpINT.$this->sysSPLIT8;
			}else {
				$tmpError.='文件<span class="FRed2">['.$tmpAR0['File']['name'].']</span>上传成功.'.$this->sysSPLIT8;
			}
			$Coun0++;
		}
		//Message
		$this->sJscript=$this->Message('ERROR','',$tmpError,$this->sysPage);
	}
	public function OnDDirectory(){
		$tmpAR0=$this->AnalyerRequest('NowDirectory',$this->sURoot,2);
		$this->sUNowDirectory=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('DDirectoryNameTxt','',1);
		$this->sDDirectoryName=$tmpAR0[0];
		
		$tmpINT=$this->CreateDirEx(array('Root'=>$this->sUNowDirectory,'Name'=>$this->sDDirectoryName));
		if($tmpINT==0){
			$this->sJscript=$this->Message('SUCCESS','','目录创建成功',$this->sysPage.'?ActionType=UChangeDir&UChangeDir='.$this->sUNowDirectory.$this->sDDirectoryName);
		}else {
			$this->sJscript=$this->Message('ERROR','',$tmpINT,$this->sysPage);
		}
	}
	
	public function OnUDelete(){
		$tmpAR0=$this->AnalyerRequest('UDelete','',0);
		$tmpAR0=explode($this->sysSPLIT5,$tmpAR0[0]);
		array_pop($tmpAR0);
		foreach ($tmpAR0 as $Cell){
			if(is_file($Cell)){
				unlink($Cell);
			}
		}
		$this->sJscript=$this->Message('SUCCESS','','文件已删除',$this->sysPage);
	}
	public function OnUDeleteDir(){
		$tmpAR0=$this->AnalyerRequest('NowDirectory',$this->sURoot,2);
		$this->sUNowDirectory=$tmpAR0[0];
		
		if($this->sUNowDirectory==$this->sURoot){
			$this->sJscript=$this->Message('SUCCESS','','不能删除此目录',$this->sysPage);
			return 1;
		}
		if($tmpHandle=opendir($this->sUNowDirectory)){
		}else {
			$this->sJscript=$this->Message('SUCCESS','','系统错误，请与管理员联系',$this->sysPage);
			return 1;
		}
		while($dir=readdir($tmpHandle)){
			if($dir!='.' && $dir!='..' && is_dir($this->sUNowDirectory.$dir)){
				$this->sJscript=$this->Message('SUCCESS','','此目录下有子目录，请清空目录内容后再删除',$this->sysPage);
				return 1;
			}else if($dir!='.' && $dir!='..'){
				unlink($this->sUNowDirectory.$dir);
			}
		}
		closedir($tmpHandle);
		rmdir($this->sUNowDirectory);
		
		$this->sJscript=$this->Message('SUCCESS','','目录已删除',$this->sysPage.'?ActionType=UChangeDir&UChangeDir='.$this->sURoot);
	}
	public function OnUChangeDir(){
		$tmpAR0=$this->AnalyerRequest('UChangeDir',$this->sURoot,0);
		$this->writeCookie($this->sysNormalCookiePath,$this->sysCookieHead.'NowDirectory',$tmpAR0[0]);
		header('location:'.$this->sysPage);
	}
	
	public function OnDirectory(){
		if($tmpHandle=opendir($this->sURoot)){
		}else {
			return 1;
		}
		$this->sDataDirectory=array();
		while($dir=readdir($tmpHandle)){
			$dirC=$this->sURoot.$dir;
			if($dir!='.' && $dir!='..' && is_dir($dirC)){
				$tmpAR0=array('Name','Img');
				$tmpAR0['Name']=$dir;
				$tmpAR0['Img']=$dirC;
				array_push($this->sDataDirectory,$tmpAR0);
			}
		}
		closedir($tmpHandle);
	}
	public function OnUAjaxDirectory(){
		$tmpAR0=$this->AnalyerRequest('UAjaxDirectory','/',0);
		$tmpSTR=$tmpAR0[0];
		
		if($tmpHandle=opendir($tmpSTR)){
		}else {
			return 1;
		}
		$this->sDataDirectory=array();
		while($dir=readdir($tmpHandle)){
			$dirC=$tmpSTR.'/'.$dir;
			if($dir!='.' && $dir!='..' && is_dir($dirC)){
				$tmpAR0=array('Name','Img');
				$tmpAR0['Name']=$dir;
				$tmpAR0['Img']=$dirC;
				array_push($this->sDataDirectory,$tmpAR0);
			}
		}
		closedir($tmpHandle);
		return 0;
	}
	public function OnFilelist(){
		$tmpAR0=$this->AnalyerRequest($this->sysCookieHead.'NowDirectory',$this->sURoot,2);
		$this->sUNowDirectory=$tmpAR0[0];
		
		$tmpAR0=$this->AnalyerRequest($this->sysCookieHead.'FFilename','',2);
		$this->sFFilename=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest($this->sysCookieHead.'FFiletype','',2);
		$this->sFFiletype=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest($this->sysCookieHead.'FFilemaxsize',0,2);
		$this->sFFilemaxsize=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest($this->sysCookieHead.'FFilemixsize',0,2);
		$this->sFFilemixsize=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest($this->sysCookieHead.'FFilestartdate','',2);
		$this->sFFilestartdate=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest($this->sysCookieHead.'FFileenddate','',2);
		$this->sFFileenddate=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest($this->sysCookieHead.'TOrder',3,2);
		$this->sTOrder=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest($this->sysCookieHead.'TListtype',0,2);
		$this->sTListtype=$tmpAR0[0];
		
		$tmpAR0=$this->AnalyerRequest('FFilename','',0);
		if(isset($_GET['FFilename'])) $this->sFFilename=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('FFiletype','',0);
		if(isset($_GET['FFiletype'])) $this->sFFiletype=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('FFilemaxsize',-1,0);
		if(isset($_GET['FFilemaxsize'])) $this->sFFilemaxsize=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('FFilemixsize',-1,0);
		if(isset($_GET['FFilemixsize'])) $this->sFFilemixsize=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('FFilestartdate','',0);
		if(isset($_GET['FFilestartdate'])) $this->sFFilestartdate=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('FFileenddate','',0);
		if(isset($_GET['FFileenddate'])) $this->sFFileenddate=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('TOrder',-1,0);
		if($tmpAR0[0]!=-1) $this->sTOrder=$tmpAR0[0];
		$tmpAR0=$this->AnalyerRequest('TListtype',-1,0);
		if($tmpAR0[0]!=-1) $this->sTListtype=$tmpAR0[0];
		
		$this->writeCookie($this->sysNormalCookiePath,$this->sysCookieHead.'FFilename',$this->sFFilename);
		$this->writeCookie($this->sysNormalCookiePath,$this->sysCookieHead.'FFiletype',$this->sFFiletype);
		$this->writeCookie($this->sysNormalCookiePath,$this->sysCookieHead.'FFilemaxsize',$this->sFFilemaxsize);
		$this->writeCookie($this->sysNormalCookiePath,$this->sysCookieHead.'FFilemixsize',$this->sFFilemixsize);
		$this->writeCookie($this->sysNormalCookiePath,$this->sysCookieHead.'FFilestartdate',$this->sFFilestartdate);
		$this->writeCookie($this->sysNormalCookiePath,$this->sysCookieHead.'FFileenddate',$this->sFFileenddate);
		$this->writeCookie($this->sysNormalCookiePath,$this->sysCookieHead.'TOrder',$this->sTOrder);
		$this->writeCookie($this->sysNormalCookiePath,$this->sysCookieHead.'TListtype',$this->sTListtype);
		//-- #List --
		$this->sDataFilelist=array();
		
		if(!is_dir($this->sUNowDirectory)){
			$this->sUNowDirectory=$this->sURoot;
		}
		if($tmpHandle=opendir($this->sUNowDirectory)){
		}else {
			return $this->sysErrorFuncID.'001';
		}
		
		$tmpAR0=explode($this->sysSPLIT1,$this->sysFileConfig['UploadFileType']);
		while($file=readdir($tmpHandle)){
			$fileC=$this->sUNowDirectory.$file;
			$tmpExname=$this->getFileExname($file);
			if($file!='.' && $file!='..' && is_file($fileC) && in_array($tmpExname,$tmpAR0)){
				$tmpFilterName=$this->sFFilename;
				$tmpFileSize=round(filesize($fileC)/1024,2);
				$tmpFileTime=date($this->sysTimeFormat,filemtime($fileC));
				if(($tmpFilterName=='' || strstr(strtoupper($file),strtoupper($tmpFilterName))!=false) &&
					($this->sFFiletype=='' || $this->sFFiletype==$tmpExname)){
					$tmpAR0=array('Name','Type','Size','Time','Img');
					$tmpAR0['Name']=$file;
					$tmpAR0['Type']=$tmpExname;
					$tmpAR0['Size']=$tmpFileSize;
					$tmpAR0['Time']=$tmpFileTime;
					$tmpAR0['Img']=$fileC;
					
					$tmpDefTypeImg=explode($this->sysSPLIT4,$this->sysFileConfig['NoImgFileThumbPath']);
					foreach($tmpDefTypeImg as $Cell){
						$tmpAR1=explode($this->sysSPLIT1,$Cell);
						if($tmpAR1[0]==$tmpExname){
							$tmpAR0['Img']=$tmpAR1[1];
						}
					}
					array_push($this->sDataFilelist,$tmpAR0);
				}			
			}
		}
		closedir($tmpHandle);
		$tmpSTR='Name';
		if($this->sTOrder==0){
			$tmpSTR='Name';
		}else if($this->sTOrder==1){
			$tmpSTR='Type';
		}else if($this->sTOrder==2){
			$tmpSTR='Size';
		}else if($this->sTOrder==3){
			$tmpSTR='Time';
		}
		$this->sDataFilelist=$this->ArraySort($this->sDataFilelist,$tmpSTR,1);
	}
}
?>