<?php
/*
\* ===========================================
\* 项目: CTB文本论坛
\* 版本: 1.3
\* 团队: 实易数码
\* 小组: CTB文本论坛小组
\* 作者: windnets，16hot，险情
\* 功能: 主题列表模块
\* ===========================================
\* Copyright (c) 2002
\* 团队主页: http://www.11cn.org
\* 团队信箱: -------------------
\* 创建日期: 2002.6
\* 修改日期: 2003-4-10
\* 修改说明: 代码整理/优化
\* 版权声明: 这个程序是免费软件.
\* ===========================================
*/


class Module extends CommonClass
{
    /**
    *构造函数
    *
    */
	function execute()
    {
        $this->display();
		if ($this->set[showForumOnline] == "Y"){
            $this->addOnline();
		}
        $this->postList($this->input['forumid']);
    } // end func


    
    /**
     *将构造函数里的一些代码放到这里来
     *2002-11-16
     */
    function display()
    {
        $this->file = $this->set[dataPath]."/forums.php";
            $forums = $this->read_file();
            $optionLine = "<option value=\"no\">跳转论坛至...</option>";
        	foreach ($forums as $line) {
                $lineCode = $this->make_array($line);
            	if ($lineCode[1] == "forum") {
					$optionLine .= $lineCode[2] != $this->input['forumid'] ? "<option value=".$lineCode[2].">　|-".$lineCode[3]."</option>" : "<option value=".$lineCode[2]." selected=\"selected\">　|-".$lineCode[3]."</option>";  // changed by cx
                }
            	if ($lineCode[1] == "cat") {
                    $optionLine .= "<option value=\"no\">╋".$lineCode[3]."</option>";
                }
            	if($lineCode[2] == $this->input['forumid']){
                    $this->forum = $lineCode;
                }
            }
            $this->forumList = "<select name='forumid' class='input5' onchange=\"window.location=('./index.php?mods=forumdisplay&forumid='+this.options[this.selectedIndex].value+'');\">".$optionLine."</select>";  // changed by cx
        	if (count($this->forum) <= 1 or !$this->input['forumid']) {
                $this->showMsg("您所查看的版块不存在");
            }
        $check = $this->checkForum($this->input['forumid']);
    	if ($check[0] == "0") {
            $this->showMsg("您无权查看这个版块,若想查看，请联系管理员","./index.php");
        }
    	if ($check[1] == "0") {
            $this->showMsg("只有登陆用户才能查看此版块，请先登陆/注册!","index.php?mods=member&action=login");
        }
       	if ($this->input['action'] == "markRead") {
			$forumId = $this->input['forumid'];
			$markTime = time();
			if (isset($_COOKIE['sess_uid'])) {
			    setcookie("markRead[$forumId]",$markTime);
			} else {
	            $_SESSION['markRead'][$forumId] = $markTime;
			}
        }
    } // end func
    



    /**
    *显示主题列表
    *2002-6-7
    */
	function postList($forumId)
    {
        $this->BAN = " &gt; ".$this->forum[3];
        $this->modList = "斑竹：";

    	if ($this->forum[8] != "") {
            $moderators = explode("|",$this->forum[8]);
        	foreach ($moderators as $moderator) {
            	if(trim($moderator)) {
                    $modInfo = explode(",",$moderator);
                    $modId = $modInfo[0]; 
                    $modName = $modInfo[1];
                    $this->modList .= "&nbsp;<a href='./index.php?mods=member&action=info&id=$modId' target=blank>".$modName."</a>&nbsp;";
                }
            }
        } else {
            $this->modList = "诚邀版主&nbsp;";
        }
		if ($this->set[showForumOnline] == "Y"){
			$mainOnline = $this->getMainOnline();
			if (trim($mainOnline[user])) {
				$mainOnlineUser = "&nbsp;&nbsp;&gt;&gt;".$mainOnline['user'];
			}
			if (trim($mainOnline['guest']) && trim($mainOnline['user'])) {
				$mainOnlineGuest = "&nbsp;".$mainOnline['guest'];
			}
			if (trim($mainOnline['guest']) && !trim($mainOnline['user'])) {
				$mainOnlineGuest = "&nbsp;&nbsp;&gt;&gt;".$mainOnline['guest'];
			}
			$mainOnlineList = $mainOnlineUser.$mainOnlineGuest;
    	    eval ("\$this->forumInfo = \"".$this->getTemplate("forumHeader")."\";");
		}
        $header = $this->header($this->forum[3]);;
        
        $this->file = $this->set['dataPath']."/announce.php";
    	if (file_exists($this->file)) {
            $sayLineCode = $this->get_big_file();
            $sayTime     = date($this->set['dateformat'],$sayLineCode[1]);
            $sayUser     = $sayLineCode[5];
            $sayTopic    = $sayLineCode[2];
            $sayIcon     = $sayLineCode[6];
            $sayForumid  = "all";
            $sayClick    = $sayLineCode[7];
            $sayNumber   = $this->getlines();
            $sayType     = "[论坛公告]";
        	eval ("\$postList .= \"".$this->getTemplate("forumSayAll")."\";");
        }

        $this->file = $this->set[dataPath]."/".$this->input['forumid']."/announce.php";
    	if (file_exists($this->file)) {
            $sayLineCode2 = $this->get_big_file();
            $sayTime      = date($this->set[dateformat],$sayLineCode2[1]);
            $sayUser      = $sayLineCode2[5];
            $sayTopic     = $sayLineCode2[2];
            $sayIcon      = $sayLineCode2[6];
            $sayForumid   = $this->input['forumid'];
            $sayClick     = $sayLineCode2[7];
            $sayNumber    = $this->getlines();
            $sayType      = "[本版公告]";
            eval ("\$postList .= \"".$this->getTemplate("forumSay")."\";");
        }

        if ($this->input['orderBy'] && $this->input['orderBy'] != "noOrder"){
            if ($this->input['orderBy'] == "todayTopic" || $this->input['orderBy'] == "threeTopic" || $this->input['orderBy'] == "weekTopic" || $this->input['orderBy'] == "monthTopic" || $this->input['orderBy'] == "halfyearTopic" || $this->input['orderBy'] == "onyearTopic"){
                if ($this->input['orderBy'] == "todayTopic") {
                    $orderTime = "86400";
                    $todayTopicCheck = "selected";
                }
                if ($this->input['orderBy'] == "threeTopic") {
                    $orderTime = "259200";
                }
                if ($this->input['orderBy'] == "weekTopic") {
                    $orderTime = "604800";
                }
                if ($this->input['orderBy'] == "monthTopic") {
                    $orderTime = "2592000";
                }
                if ($this->input['orderBy'] == "halfyearTopic") {
                    $orderTime = "15768000";
                }
                if ($this->input['orderBy'] == "onyearTopic") {
                    $orderTime = "31536000";
                }
                $this->file = $this->set[dataPath]."/".$this->input['forumid']."/list.php";
                $lines  = $this->orderTopic($columnSort,3,$orderTime) ;
            }
            if ($this->input['orderBy'] == "goodTopic" ){
                $this->file = $this->set[dataPath]."/".$this->input['forumid']."/list.php";
                $lines  = $this->orderTopic2($columnSort,6,1) ;
            }
            if ($this->input['orderBy'] == "myTopic" ){
                $this->file = $this->set[dataPath]."/".$this->input['forumid']."/list.php";
                $lines = $this->orderTopic2($columnSort,2,$this->sess['sess_uname']) ;
            }
        }else{
            $this->file = $this->set[dataPath]."/".$this->input['forumid']."/list.php";
            $lines = $this->read_file();
        }

        $totalFile = count($lines);
        $recnum = $this->set[topicList];
        $totalNumber = ($totalFile % $recnum) == "0" ? intval(($totalFile)/$recnum) : intval(($totalFile)/$recnum)+1;
        $p = $this->input['p'];
        if ( !$p ) { $p = 1; }
        for( $i = ($p-1) * $recnum; $i < $p * $recnum ;$i++) {
            $topicCode = $this->make_array($lines[$i]);
            $this->file = $this->set[dataPath]."/".$this->input['forumid']."/".$topicCode[1]."_.php";
            if (file_exists($this->file)) {
                $line = $this->get();
                $postTitle = htmlspecialchars($line[2], ENT_QUOTES);
				$postTitle = $this->set[replaceWhenPost] == 'Y' ? $postTitle : $this->replaceBadWord($postTitle);
                $id = $line[1];
                $clickNumber = $line[4];
                $topicNumber = $line[3];
                $replayUserName = $line[5];
                $lastTime = date($this->set[dateformat],$line[6]);
                $topicPic = $line[7];
                if (!trim($topicPic)) {
                    $topicPic = "smileyface.gif";
                }
                
                if (($this->sess['sess_last_login'] != "") && ($line[6] > $this->sess['sess_last_login']) && ($line[6] > $this->sess['markRead'][$forumId])) {
                    $newMode = "<img src=\"{$this->tplPath}/images/system/topic_new.gif\" width=25>";
                } else {
                    $newMode = "";
                }
                
            	if ($topicCode[6]=="1") {
                    $postTitle = "<font color=red>[精华]</font>".$postTitle;
                }                
                //
                if ($topicCode[5] == "1" && $topicCode[4] != "1") {
                    $newFlag = "foldertop.gif";
                } elseif ($topicCode[4]=="1" && $topicCode[5] == "1") {
                    $newFlag = "folder_lock_top.gif";
                } elseif ($topicCode[4] == "1" && $topicCode[5] != "1") {
                    $newFlag = "folderlock.gif";
                } elseif ($topicnum >= 10 && $topicnum <20) {
                    $newFlag = "folderhot.gif";
                } elseif ($topicnum >= 20) {
                    $newFlag = "folderhot1.gif";
                } else {
                    $newFlag = "folder.gif";
                }
            	if ($topicCode[8] == "vote") {
                    $newFlag = "folderpoll.gif";
                }
                $line[8] = trim($line[8]);
				if (!empty($line[8])) {
                    $fileInfo = split("\.", $line[8]);
                    $fileInfoNum=count($fileInfo)-1;
                    $showUploadFile = $this->getFileType($fileInfo[$fileInfoNum]);
				}
				else $showUploadFile = "";
                $topicAuthor = $topicCode[2];
                $countFile = $line[3];
                $pageNumber = ($countFile % $this->set[postList]) == "0" ? intval(($countFile)/$this->set[postList]) : intval(($countFile)/$this->set[postList])+1;
                if ($pageNumber < 2) {
                    $lastPage = "";
                } else {
                    $lastPage = "&#171; <a href=./index.php?mods=topicdisplay&forumid=".$this->input['forumid']."&postid=$id&p=$pageNumber>$pageNumber</a> &#187;";
                }
                // end added
                eval ("\$postList .= \"".$this->getTemplate("forumPost")."\";");
            }
        }
        $page = $this->getPage("$PHP_SELF?mods=".$this->input['mods']."&forumid=".$this->input['forumid']."&orderBy=".$this->input['orderBy'],$totalNumber);
        eval("\$this->outPut(\"".$this->getTemplate("forum")."\");");
    } // end func

   /**
     *显示用户列表
     *2002-4-26
     */
    function getMainOnline() {
    	global $toponline,$toponline_time,$forumid;
     
        $showOnline[guestNumber] = 0;
        $showOnline[userNumber] = 0;
        $showOnline[user] = "";
        $showOnline[guest] = "";
        $this->file = $this->set[dataPath]."/online.php";
        $arrayOnline = $this->openfile();
        foreach ($arrayOnline as $showOnlineCode) {
        	if($showOnlineCode[2] != "0" && $showOnlineCode[5] == $this->input['forumid']) {
             
        	    ++$showOnline[userNumber];
               if ($showOnlineCode[8] == "0"){
                    $showOnline[user] .= " <font color=black>■</font>隐身会员";
				}elseif($showOnlineCode[7] == "1" and $showOnlineCode[8] != "0") {
                    $showOnline[user] .= " <font color=red>■</font><a href='./index.php?mods=member&action=info&id={$showOnlineCode[1]}' target=blank><font color=black>{$showOnlineCode[3]}</font></a>";
                } elseif($showOnlineCode[7] == "3" and $showOnlineCode[8] != "0") {
                    $showOnline[user] .= " <font color=blue>■</font><a href='./index.php?mods=member&action=info&id={$showOnlineCode[1]}' target=blank><font color=black>{$showOnlineCode[3]}</font></a>";
                } else {
                    $showOnline[user] .= " <font color=#6394bd>■</font><a href='./index.php?mods=member&action=info&id={$showOnlineCode[1]}' target=blank><font color=black>{$showOnlineCode[3]}</font></a>";
                }
            } elseif($showOnlineCode[2] == "0" && $showOnlineCode[5] == $this->input['forumid']) {
                ++$showOnline[guestNumber];
                $showOnline[guest] .= " □客人";
            }
        }
        return $showOnline;
    } //end func

} // end class

?>
