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

class Module extends CommonClass
{
    /*
    * 函数说明： 模块运行
    * 创建时间： 2002-4-25
    */
    function execute()
    {
		if ($this->set[showIndexOnline] == "Y"){
            $this->addOnline();
		}
        $this->showMain();

    } // end func

    /*
    * 函数说明： 显示首页整体页面
    * 创建时间： 2002-4-25
    */
    function showMain()
    {
        global $forum,$status,$mainOnline,$topOnline,$topOnlineTime;
        $header = $this->header("首页");

        $this->file = $this->set[dataPath]."/forums.php";
        $forums = $this->openfile();
        foreach ($forums as $this->forum) {
            if ($this->forum[1] == "cat") {
                $catTitle = $this->forum[3];
                eval ("\$main .= \"".$this->getTemplate("mainCat")."\";");
            } else {
				if($this->set[forumHide] == "N"){
					$check = $this->checkForum($this->forum[2]);
					if ($check[0] != "0") {
						$this->file = $this->set[dataPath]."/".$this->forum[2]."/status.php";
						$this->status = $this->get();
						$topicNum += $this->status[1];
						$postNum += $this->status[2];
						$main .= $this->showForum($this->forum[2]);
					}/**/
				}else{
						$this->file = $this->set[dataPath]."/".$this->forum[2]."/status.php";
						$this->status = $this->get();
						$topicNum += $this->status[1];
						$postNum += $this->status[2];
						$main .= $this->showForum($this->forum[2]);
				}
            }
        }
		if ($this->set[showIndexOnline] == "Y"){
          $mainOnline = $this->showMainOnline();
		}
        $this->file = $this->set[dataPath]."/member.php";
        $memberInfo = $this->get();
        $newMember = stripslashes($memberInfo[4]);
		//
        if (isset($this->sess['sess_uid'])) {
            $this->file = $this->set[dataPath]."/users/".$this->sess['sess_uid'].".php";
            $userInfo = $this->get();
            $userPosts = $userInfo[13];
            $userRates = $userInfo[18];
            $userGradeName = $userInfo[16];            
            eval ("\$mainLogon .= \"".$this->getTemplate("mainLogon")."\";");
        } else {
            eval ("\$mainLogon .= \"".$this->getTemplate("mainLogout")."\";");
        }
		if ($this->set[showLinkForum] == "Y"){
            //
	        $this->file = $this->set[dataPath]."/linkforum.php";
            $linkForumLine = $this->openFile();
			$linkForumNum = count($linkForumLine);
			for($i=0; $i<$linkForumNum; $i++){
				if ($linkForumLine[$i][2]==1){
				  $linkForumName = $linkForumLine[$i][3];
				  $linkForumHtml1 .= "<a href=\"".$linkForumLine[$i][6]."\" target=\"_blank\" ><IMG border=0 height=31 src=\"".$linkForumLine[$i][5]."\" width=88 alt=\"".$linkForumLine[$i][4]."\"></a>&nbsp;&nbsp;";
				}elseif ($linkForumLine[$i][2]=="0"){
				  $linkForumName = $linkForumLine[$i][3];
                  $linkForumHtml2 .= "<a href=\"".$linkForumLine[$i][6]."\" title=".$linkForumLine[$i][4]."  target=\"_blank\">".$linkForumName."</a>&nbsp;&nbsp;";
				}

			}//end for
			if ($this->set[rollLinkForum] == "Y") {
				$linkForumHtml1 = "<marquee direction=\"left\" scrollamount=\"3\" onMouseOver=\"this.stop();\" onMouseOut=\"this.start();\">" . $linkForumHtml1 . "</marquee>";
				$linkForumHtml2 = "<marquee direction=\"left\" scrollamount=\"3\" onMouseOver=\"this.stop();\" onMouseOut=\"this.start();\">" . $linkForumHtml2 . "</marquee>";
			}
            eval ("\$linkForum .= \"".$this->gettemplate("linkForum")."\";");
		}
        eval("\$this->outPut(\"".$this->getTemplate("main")."\");");
    } // end func

    /*
    * 函数说明： 显示分论坛列表
    * 创建时间： 2002-4-25
    */
    function showForum($forumId)
    {
        if ($this->forum[1] == "forum") {
            $forumTitle = htmlspecialchars(stripslashes($this->forum[3]));
            $forumMsg = stripslashes($this->forum[4]);
            $id = $this->forum[2];
            $postNum = $this->status[1];
            $topicNum = $this->status[2];
            $moderatorList = "";
            if ($this->forum[8] != "") {
                $moderators = explode("|",$this->forum[8]);
                foreach ($moderators as $moderator) {
                    if ($moderator != "") {
                        $moderatorInfo = explode(",",$moderator);
                        $moderatorId = $moderatorInfo[0];
                        $moderatorName = $moderatorInfo[1];
                        $moderatorList .= "<a href='./index.php?mods=member&action=info&id=$moderatorId' target=blank>".$moderatorName."</a><BR>"; 
                    }
                }
            } else {
                $moderatorList = "诚邀版主";
            }
            if (file_exists($this->set[dataPath]."/".$forumId."/".$this->status[3]."_.php")) { 
                $lastPostId = $this->status[3]; 
                $lastAuthor = $this->status[7];
                $lastTimeStamp = $this->status[5];
                $lastTime = date($this->set[dateformat],$this->status[5]);
                $countFile = $this->status[8];
                $hiddenTopic = $this->status[4];
                $lastTopic = htmlspecialchars(stripslashes($this->keepLen($this->status[4],26)));
				$lastTopic = $this->set[replaceWhenPost] == 'Y' ? $lastTopic : $this->replaceBadWord($lastTopic);
            } elseif (file_exists($this->set[dataPath]."/".$forumId."/list.php")) { 
                $this->file = $this->set[dataPath]."/".$forumId."/list.php"; 
                $lastPostId = $this->get_max_value("1"); 
                $this->file = $this->set[dataPath]."/".$forumId."/".$lastPostId."_.php"; 
                $lastLine = $this->get();
                $lastAuthor = $lastLine[5];
                $lastTimeStamp = $lastLine[6];
                $lastTime = date($this->set[dateformat],$lastLine[6]);
                $countFile = $lastLine[3];
                $hiddenTopic = $lastLine[2];
                $lastTopic = stripslashes($this->keepLen($lastLine[2],26));
				$lastTopic = $this->set[replaceWhenPost] == 'Y' ? $lastTopic : $this->replaceBadWord($lastTopic);
            } else {
                $newFlag = "forum.gif";
                $lastAuthor = "尚无帖子";
            }
            if (($this->sess['sess_last_login'] != "") && ($lastTimeStamp > $this->sess['sess_last_login']) && ($lastTimeStamp > $this->sess['markRead'][$forumId])) {
                $newFlag = "forumnew.gif";
            } else {
                $newFlag = "forum.gif";
            }
            if ($this->forum[5] == "1"){
                $newFlag = "forumgood.gif";
            }
            if ($this->forum[6] == "1"){
                $newFlag = "forumlock.gif";
            }
            $pageNum = ($countFile % $this->set[postList]) == "0" ? intval(($countFile)/$this->set[postList]) : intval(($countFile)/$this->set[postList])+1;

			//
			if ($this->set[forumHide] == "Y"){
                $check = $this->checkForum($this->forum[2]);
				if ($check[0] == "0"){
					$lastTopic = "";
					$lastAuthor = "<b>-=隐藏版块=-</b>";
					$lastTime = "";
				}
			}
        
		}     

        eval ("\$main .= \"".$this->getTemplate("mainForum")."\";");
        return $main;

    } // end func

    /*
    * 函数说明： 显示用户列表
    * 创建时间： 2002-4-26
    */
    function showMainOnline() {
        global $topOnline,$topOnlineTime;
        
        $showOnline[guestNum] = 0;
        $showOnline[userNum] = 0;
        $showOnline[user] = "<table  cellpadding=1 cellspacing=0 border=0 width=98%>";
        $showOnline[guest] = "<table cellpadding=1 cellspacing=0 border=0 width=98%>";
        $this->file = $this->set[dataPath]."/online.php";
        $arrayOnline = $this->openfile();
        foreach ($arrayOnline as $showOnlineCode) {
            if($showOnlineCode[2] != "0") {
                $showOnline[userNum]++;
                if (is_int($showOnline[userNum]/9)) {
                         if ($showOnlineCode[8] == "0"){
                         $showOnline[user] .= "<td width=11%><font color=black>■</font>隐身会员</td></tr>\n";
				        }elseif($showOnlineCode[7] == "1" and $showOnlineCode[8] != "0") {
                         $showOnline[user] .= "<td width=11%><font color=red>■</font><a href='./index.php?mods=member&action=info&id=$showOnlineCode[1]' target=blank><font color=black>$showOnlineCode[3]</font></a></td></tr>\n";
                       } elseif($showOnlineCode[7] == "3" and $showOnlineCode[8] != "0") {
                         $showOnline[user] .= "<td width=11%><font color=blue>■</font><a href='./index.php?mods=member&action=info&id=$showOnlineCode[1]' target=blank><font color=black>$showOnlineCode[3]</font></a></td></tr>\n";
                       } else {
                           $showOnline[user] .= "<td width=11%><font color=#6394bd>■</font><a href='./index.php?mods=member&action=info&id=$showOnlineCode[1]' target=blank><font color=black>$showOnlineCode[3]</font></a></td></tr>\n";
                       }
                } elseif (is_int(($showOnline[userNum]-1)/9)) {
                    if ($showOnlineCode[8] == "0"){
                         $showOnline[user] .= "<tr><td width=11%><font color=black>■</font>隐身会员</td>\n";
				    }elseif($showOnlineCode[7] == "1" and $showOnlineCode[8] != "0") {
                        $showOnline[user] .= "<tr><td width=11%><font color=red>■</font><a href='./index.php?mods=member&action=info&id=$showOnlineCode[1]' target=blank><font color=black>$showOnlineCode[3]</font></a></td>\n";
                    } elseif($showOnlineCode[7] == "3" and $showOnlineCode[8] != "0") {
                        $showOnline[user] .= "<tr><td width=11%><font color=blue>■</font><a href='./index.php?mods=member&action=info&id=$showOnlineCode[1]' target=blank><font color=black>$showOnlineCode[3]</font></a></td>\n";
                    } else {
                        $showOnline[user] .= "<tr><td width=11%><font color=#6394bd>■</font><a href='./index.php?mods=member&action=info&id=$showOnlineCode[1]' target=blank><font color=black>$showOnlineCode[3]</font></a></td>";
                    }
                } else {
                    if ($showOnlineCode[8] == "0"){
                         $showOnline[user] .= "<td width=11%><font color=black>■</font>隐身会员</td>\n";
				    }elseif($showOnlineCode[7] == "1" and $showOnlineCode[8] != "0") {
                        $showOnline[user] .= "<td width=11%><font color=red>■</font><a href='./index.php?mods=member&action=info&id=$showOnlineCode[1]' target=blank><font color=black>$showOnlineCode[3]</font></a></td>\n";
                    } elseif($showOnlineCode[7] == "3" and $showOnlineCode[8] != "0") {
                        $showOnline[user] .= "<td width=11%><font color=blue>■</font><a href='./index.php?mods=member&action=info&id=$showOnlineCode[1]' target=blank><font color=black>$showOnlineCode[3]</font></a></td>\n";
                    } else {
                        $showOnline[user] .= "<td width=11%><font color=#6394bd>■</font><a href='./index.php?mods=member&action=info&id=$showOnlineCode[1]' target=blank><font color=black>$showOnlineCode[3]</font></a></td>\n";
                    }
                }
            } else {
                $showOnline[guestNum]++;
                if (is_int($showOnline[guestNum]/9)) {
                    $showOnline[guest] .= "<td width=11%>□客人</td></tr>\n";
                } elseif (is_int(($showOnline[guestNum]-1)/9)) {
                    $showOnline[guest] .= "<tr><td width=11%>□客人</td>\n";
                } else {
                    $showOnline[guest] .= "<td width=11%>□客人</td>\n";
                }
            }
        }
        $showOnline[user] .="</tr></table>";
        $showOnline[guest] .="</tr>";

        $this->file = $this->set[dataPath]."/toponline.php";
        $topOnlineCode = $this->get();
        $topOnline = $topOnlineCode[1];
        $topOnlineTime = $topOnlineCode[2];
        eval ("\$mainOnline .= \"".$this->getTemplate("mainOnline")."\";");
        return $mainOnline;

    } //end func

} // end class

?>