<?php
//-- 引入檔案 --//
include_once "header.php";
//引入共用函數
//允許傳送變數
$allowvar =array("modulesid","typesid","sortid","centerid","namefile","zipenable","downloadtype","applyid","basid","fileid","types","pinquiryid");
//接收變數區
foreach($_REQUEST as $var=> $value) {
	if(in_array($var,$allowvar)) {
		$$var=sqlinjectionfound($val=trim(isset($value)?$value:""));
	}
}
switch($modulesid) {
	case "neilmfdcms":
	include_once XOOPS_ROOT_PATH."/modules/neilmfdcms/function.php";
	if(empty(alignmenturl())) redirect_header(XOOPS_URL,0 , _MS_SHARED75);
	//類別觀看權限
	if(empty(admingroupfunction($dbneme="neilmfdcmstypes",$where=" where `typesid` = '".$typesid."' && `enable` = '1'  ",$admintype="browsegroup")) ) {
		redirect_header(XOOPS_URL. "/modules/".$modulesid."/index.php" ,0 , _MS_SHARED18);
	}
	//群組觀看權限
	if(empty(grouppermission($dbneme="neilmfdcmssort",$where="  where `typesid` = '".$typesid."' &&  `sortid` = '".$sortid."' order by  sortid  ASC",$var="browsegroup",$type=true))) {
		redirect_header(XOOPS_URL. "/modules/".$modulesid."/index.php" ,0 , _MS_SHARED18);
	}
	//ZIP下載判斷
	$themefolder=empty($zipenable) ? 'phone' : $themefolder;
	// get TRUE
	$url="".XOOPS_ROOT_PATH."/uploads/".$modulesid."/types".$typesid."/".$sortid."file/file/".$namefile."";
	//設定檔案路徑
	$zipname = timedate($datevar="Y-m-d-H-i-s").'.zip';
	//輸出的zip檔名 (可自行修改)  
	zipArchivefunction($url,$zipname,$type=$themefolder);
	break;
	
	case "neilfilefolder":
	include_once XOOPS_ROOT_PATH."/modules/neilfilefolder/function.php";
	include_once XOOPS_ROOT_PATH."/modules/neilfilefolder/language/".$xoopsConfig['language']."/main.php";
	//防機器人
	//機器人檢查
	if(empty(alignmenturl())) redirect_header(XOOPS_URL,0 , _MS_SHARED75);
	if(empty(defenserobot($var=$_POST['verification'],$type=2))) redirect_header(XOOPS_URL,0 , _MS_SHARED75);
	//機器人關閉JS判斷
	if(!empty(robottimeip($type="1"))) redirect_header(XOOPS_URL,0 , _MS_SHARED75);
	//人工時間驗證
	if(empty(robottime($var=$_POST['enable']))) redirect_header(XOOPS_URL,0 , _MS_SHARED75);
	//群組觀看權限
	if(empty(grouppermission($dbneme="neilfilefoldersort",$where="  where `sortid` = '".$sortid."' order by  sortid  ASC",$var="browsegroup",$type=true))) {
		redirect_header(XOOPS_URL. "/modules/".$modulesid."/index.php" ,0 , _MS_SHARED18);
	}
	//下載權限 	 
	if(!empty(admingroupfunction($dbneme="neilfilefoldercenter",$where=" where `centerid` = '".$centerid."' ",$admintype="browsegroup")) || !empty($isAdmin)) {
		neilfilefolder_downloadfunction();
	} else {
		redirect_header(XOOPS_URL. "/modules/".$modulesid."/index.php" ,0 , _MS_SHARED99);
	}
	break;
	
	case "neilhonorlist":   
	//zip下載	
	$url="".XOOPS_ROOT_PATH."/uploads/neilhonorlist/file/".$namefile."";
	//設定檔案路徑
	$zipname = timedate($datevar="Y-m-d-H-i-s").'.zip';
	//輸出的zip檔名 (可自行修改)  
	zipArchivefunction($url,$zipname,$type=$themefolder);
	break;
	
	case "neilsignedup_a":   		
	include_once XOOPS_ROOT_PATH."/modules/neilsignedup_a/function.php";
	
    switch($types) {
	case "1":
	//群組觀看權限
	if(empty(grouppermission($dbneme="neilsignedup_a_sort",$where="  where `sortid` = '".$sortid."' order by  sortid  ASC",$var="browsegroup",$type=true))) {
		redirect_header(XOOPS_URL. "/modules/".$modulesid."/index.php" ,0 , _MS_SHARED18);
	}
	//內容下載			
	$url="".XOOPS_ROOT_PATH."/uploads/".$modulesid."/".$sortid."file/".$namefile."";
	//設定檔案路徑
	zipArchivefunction($url,$zipname="",$type='phone');
	break;
	default:
	//自訂表單下載	
	$ListDB=moduledb($dbneme="neilsignedup_a_center",$where="   where `centerid` = '".$centerid."'   ");
	//下載權限
	if(empty(neilsignedup_a_applicantfunction($uid=$xoopsUser->getVar('uid'),$applyid)) && (($xoopsUser->getVar('uid')!=$ListDB['uid']  || empty(grouppermission($dbneme="neilsignedup_a_sort",$where=" where  `sortid` = '".$ListDB['sortid']."' order by  sortid  ASC",$var="admingroup",$type=true))) && empty($isAdmin)) ) exit;
	$url="".XOOPS_ROOT_PATH."/uploads/".$namefile."";
	//設定檔案路徑
	zipArchivefunction($url,$zipname="",$type='phone');
    }
	
	break;	
	case "neilsignedup_c":   		
	include_once XOOPS_ROOT_PATH."/modules/neilsignedup_c/function.php";
	
    switch($types) {
	case "1":
	//群組觀看權限
	if(empty(grouppermission($dbneme="neilsignedup_c_sort",$where="  where `sortid` = '".$sortid."' order by  sortid  ASC",$var="browsegroup",$type=true))) {
		redirect_header(XOOPS_URL. "/modules/".$modulesid."/index.php" ,0 , _MS_SHARED18);
	}
	//內容下載			
	$url="".XOOPS_ROOT_PATH."/uploads/".$modulesid."/".$sortid."file/".$namefile."";
	//設定檔案路徑
	zipArchivefunction($url,$zipname="",$type='phone');
	break;
	default:
	//自訂表單下載	
	$ListDB=moduledb($dbneme="neilsignedup_c_center",$where="   where `centerid` = '".$centerid."'   ");
	//下載權限
	if(empty(neilsignedup_c_applicantfunction($uid=$xoopsUser->getVar('uid'),$applyid)) && (($xoopsUser->getVar('uid')!=$ListDB['uid']  || empty(grouppermission($dbneme="neilsignedup_c_sort",$where=" where  `sortid` = '".$ListDB['sortid']."' order by  sortid  ASC",$var="admingroup",$type=true))) && empty($isAdmin)) ) exit;
	$url="".XOOPS_ROOT_PATH."/uploads/".$namefile."";
	//設定檔案路徑
	zipArchivefunction($url,$zipname="",$type='phone');
    }
	
	break;		
	case "neilproduct":   	
    switch($types) {
	case "1":
	//內容下載			
	$url="".XOOPS_ROOT_PATH."/uploads/".$modulesid."/".$sortid."file/".$namefile."";
	//設定檔案路徑
	zipArchivefunction($url,$zipname="",$type='phone');
	break;
	default:
	include_once XOOPS_ROOT_PATH."/modules/neilproduct/function.php";
	//下載權限
    if(empty(neilproduct_authority($pinquiryid))  && empty($isAdmin))exit;	
    $url="".XOOPS_ROOT_PATH."/uploads/".$namefile."";
	//設定檔案路徑
	zipArchivefunction($url,$zipname="",$type='phone');
	break;
	}
	break;	
	case "neilenglishresults":

	//檔案下載權限
	if(empty(grouppermission($dbneme="neilenfile",$where="  where `fileid` = '".$fileid."' order by  fileid  ASC",$var="browsegroup",$type=true))) {
		redirect_header(XOOPS_URL. "/modules/".$modulesid."/index.php" ,0 , _MS_SHARED18);
	}
	//儲存瀏覽次數
	$ListDB=moduledb($dbneme="neilenfile",$where="   where `fileid` = '".$fileid."'   ");
	switch($types) {
		case "1":
		//ZIP下載判斷
		$themefolder=empty($zipenable) ? 'phone' : $themefolder;
		// get TRUE
		$url="".XOOPS_ROOT_PATH."/uploads/neilenglishresults/enf".$basid."/file/".$namefile."";
		$frequency=1;
		break;
		case "2":
    //防機器人
	//機器人檢查
	if(empty(alignmenturl())) redirect_header(XOOPS_URL,0 , _MS_SHARED75);
	if(empty(defenserobot($var=$_POST['verification'],$type=2))) redirect_header(XOOPS_URL,0 , _MS_SHARED75);
	//機器人關閉JS判斷
	if(!empty(robottimeip($type="1"))) redirect_header(XOOPS_URL,0 , _MS_SHARED75);
	//人工時間驗證
	if(empty(robottime($var=$_POST['enable']))) redirect_header(XOOPS_URL,0 , _MS_SHARED75);
			
		//ZIP下載判斷
		$themefolder='zipArr';
		// get TRUE
		//解上傳檔案
		$i=0;$d=0;
		//已上傳檔案
		$namefileList=phpconversion($conversion=$ListDB['namefile'],$type="unserialize");
		foreach($Arr=$namefileList['file_id'] as $key=> $val) {
			//判斷檔案是否存在
			if(file_exists(XOOPS_ROOT_PATH.'/uploads/neilenglishresults/enf'.$basid.'/file/'.$namefileList['file_d'][$i].'.'.$namefileList['file_e'][$i].'')) {
				$url[$i]="".XOOPS_ROOT_PATH."/uploads/neilenglishresults/enf".$basid."/file/".$namefileList['file_d'][$i].'.'.$namefileList['file_e'][$i]."";
				$d++;
			}
			$i++;
		}
		$frequency=$d;
		break;
	}
	//設定檔案路徑
	$zipname = timedate($datevar="Y-m-d-H-i-s").'.zip';
	//輸出的zip檔名 (可自行修改)  
	zipArchivefunction($url,$zipname,$type=$themefolder);
	$setvar="set  frequency='".($ListDB['frequency']+$frequency)."'  where fileid='".$fileid."'";
	update($dbname="neilenfile",$set=$setvar);
	break;
	default:
    exit;
}
?>