<?php
/*
\* ===========================================
\* 项目: CTB文本论坛
\* 版本: 1.0
\* 团队: 实易数码
\* 小组: CTB文本论坛小组
\* 作者: 险情
\* 功能: 后台版块处理程式
\* ===========================================
\* Copyright (c) 2002
\* 团队主页: http://www.11cn.org
\* 团队信箱: ------
\* 创建日期: 2002/7/19
\* 修改日期: 2002-12-27
\* 修改说明: ------
\* 版权声明: 这个程序是免费软件.
\* ===========================================
*/

//=============================================================================
class Module extends CommonClass
{
    //构造函数
    function execute()
    {
      global $action;
      switch($this->input['action']) {
        //
        case 'forumAcce':
            $this->forumAcce();
            break;
        case 'seeForumAcce':
            $this->seeForumAcce();
            break;
        case 'delForumAcce':
                $this->doAdminOrder("您确定要删除此文件吗？");
                break;
        case 'delForumAcce2':
                $this->delForumAcce();
                break;   
        //
		default:
            $this->forumAcce();
            break;
      }    
    } // end func

//-----------------------------------------------------------------------------
//---1、论坛版块排序。------作者：险情
//---2、
//---3、
//-----------------------------------------------------------------------------

//=============================================================================
//删除论坛分类或版块
    function forumAcce()
    {
        //获取论坛分类列表
        $optionLine = $this->getForumLine($this->input[forumId]);
		if($this->input[searchName]){
            $getUserId = $this->getIdFromName($this->input[searchName]);
		}

		if ($this->input[forumId]=="all" or !$this->input[forumId]) { 
			$msg = "查看论坛所有版块";
			$openUserFile = array();
			//
			$filenameSet=array();
			$dirHandle=opendir("../".$this->set[dataPath]."/upfile");
			while ($file = readdir($dirHandle)) {
				if($file!=".." and $file!="." and $file!=""){
					$fileInfo = explode("_", $file);
					if($this->input[searchName] and $getUserId==$fileInfo[2]){
						$openUserFile_1[] =trim($file);
						//exit("ccc:".$getUserId);

					}
					else{
						$openUserFile[] =trim($file);
					}
				}
			}//end while

		}
		else{
			$msg = $this->getForumName($this->input[forumId]);
			$openUserFile = array();
			//
			$filenameSet=array();
			$dirHandle=opendir("../".$this->set[dataPath]."/upfile");
			while ($file = readdir($dirHandle)) {
			   if($file!=".." and $file!="." and $file!=""){
				   $fileInfo = explode("_", $file);
                   if ($fileInfo[0] == $this->input[forumId]){
					   if($this->input[searchName] and $getUserId==$fileInfo[2]){
				           $openUserFile_1[]=trim($file);
                           continue;
					   }
					   else{
				           $openUserFile[]=trim($file);
						 
					   }
				   }
			    }
			}//end while
			closedir($dirHandle); 

			//
		}//end if
		if($this->input[searchName]){
            $openUserFile = $openUserFile_1;
		}

		//+--------------------------------------------------------------------
			//
			$p = $this->input['p'];
    	    if ( !$p ) { $p = 1; } 
			$totalFile = count($openUserFile);
			$recnum = 20;//$userlist;
			$totalnum = ($totalFile % $recnum) == "0" ? intval(($totalFile)/$recnum) : intval(($totalFile)/$recnum)+1;
            
			//exit("ccc:".$totalFile);
			$num = 0;
			for( $i = $totalFile-(($p-1)*$recnum); $i > $totalFile-($p*$recnum);$i--) {
	
					if ($openUserFile[$i]){
					$UserFile = $openUserFile[$i];	
					//exit("ccc".$openUserFile[1]);
					//将文件名称分割以取得属性
					$fileSplit = split("\.", $UserFile);
					$fileInfo = split("_", $fileSplit[0]);
					$getUserName = $this->getNameFromId($fileInfo[0]);
					$getFaceTime = date("Y-m-d",$fileInfo[3]);
					
					//获取文件类型
					$fileTypeInfo = split("\.", $UserFile);
					$$fileTypeInfoNum=count($fileTypeInfo)-1;
					$fileType = $fileTypeInfo[$fileTypeInfoNum];
					
					//获取文件大小
					$fSize = filesize("../".$this->set[dataPath]."/upfile/".$UserFile);
					$fSize = $fSize/1024;
					$fSize = substr($fSize, 0,4); 

					//获取文件所属版块
					$getFileForumName = $this->getForumName($fileInfo[0]);

                    //获取附件作者
					$getFileUserName = $this->getNameFromId($fileInfo[2]);

					//获取文件原始名称
					if (file_exists("../".$this->set[dataPath]."/".$fileInfo[0]."/".$fileInfo[1]."_.php")){
			            $this->file = "../".$this->set[dataPath]."/".$fileInfo[0]."/".$fileInfo[1]."_.php";
                        $getTopicInfo = $this->get();
					}
					else{
                        $getTopicInfo[2] = "帖子已经被删除";
					}
                     
					 //exit("ccc:".$getTopicInfo[11]);
					//
					$getTopicAcce = explode("|",$getTopicInfo[11]);
                    for($j=0;$j<count($getTopicAcce);$j++){
						$getAcceOne = explode("%",$getTopicAcce[$j]);
						if($getAcceOne[3]==$UserFile){
                            $getFileOldName = $getAcceOne[0];
							break;
						}
					}

                    //获取文件所属标题
                    $getTopicName = $getTopicInfo[2];
					//获取文件显示列表
					$num++;
					$UserFileList .= " <tr bgcolor='#f5f5f5'> 
					<td  align=center>$num</td>
					<td><a href=\"main.php?mod=forumacce&action=seeForumAcce&id=$UserFile\" title=\"所属主题：$getTopicName 发表时间：$getFaceTime\" target=\"blank\">$UserFile</a></td>
					<td>$getFileOldName </td>
					<td  align=center>$getFileForumName</td>
					<td  align=center>$getFileUserName</td>
					<!--<td  align=center>$getFaceTime</td>-->
					<td  align=center>$fSize</td>

					<td  align=center><a href=\"main.php?mod=forumacce&action=seeForumAcce&id=$UserFile\" target=blank>查看</a></td>
					<td  align=center><a href=\"main.php?mod=forumacce&action=delForumAcce&id=$UserFile\">删除</a></td>

					</tr>";

					}
			}
           $page = $this->getPage("$PHP_SELF?mod=forumacce&action=forumAcce&forumId={$this->input[forumId]}",$totalnum);

      eval("\$this->outPut(\"".$this->getTemplate("forumAcce")."\");");
    } // end func

//=============================================================================
//显示文件
	function seeForumAcce()
	{
		$getFileDir = $this->set[dataPath];

		$memberFace = "../".$getFileDir."/upfile/".$this->input[id];
        header("location:$memberFace");  
	}//end func 

//=============================================================================
//删除文件
	function delForumAcce()
	{
        if (@unlink("../".$this->set[dataPath]."/upfile/".$this->input['id'])){
        //
            $this->adminShowMsg("./main.php?mod=forumacce","您已经成功删除此文件");
        }else {
            $this->adminShowWrong("./main.php?mod=forumacce","删除失败");
        }
	}//end func 







//<<
//=============================================================================
} // end class
