<?php
/*
\* ========================================================
\* 项目: CTB文本论坛
\* 版本: 1.3
\* 团队: 实易数码
\* 小组: CTB论坛组
\* 作者: 险情
\* 功能: 论坛杂项----论坛插件
\* ========================================================
\* Copyright (c) 2002 
\* 团队主页: http://www.11cn.org
\* 团队信箱: ------------------
\* 创建日期: 2002/9/1/
\* 修改日期: 2003-4-10
\* 修改说明: ------------------
\* 版权声明: 这个程序是免费软件.
\* ========================================================
*/


class Module extends CommonClass
{
//-----------------------------------------------------------------------------
	/**
     *构造函数
     *
     */
    function execute()
    {
        switch ($this->input['action']) {
            case "ctbhelp":
                $this->ctbHelp();
                break;
			case "ctbnews":
				$this->openLimit();
                $this->ctbNews();
                break;
			case "index_news":
                $this->indexNews();
                break;
			case "forum_news":
                $this->forumNews();
                break;
			case "index_vote":
                $this->indexVote();
                break;
			case "getPhpInfo":
                $this->getPhpInfo();
                break;
        }
    } // end func

//-----------------------------------------------------------------------------
//---、显示论坛帮助页面:ctbHelp();
//---、显示论坛最新文章:ctbNews();
//<<<<
//---、ctb论坛首页最新调用:indexNews()
//---、显示分论坛最新文章:forumNews()  //还没有写
//---、在首页显示投票:indexVote()
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
    /**
     *显示帮助
     *
     */
    function ctbHelp()
    {
        $this->BAN = " &gt; CTB文本论坛帮助文件";
        $header = $this->header("CTB文本论坛帮助文件");

        eval("\$this->outPut(\"".$this->getTemplate("ctbHelp")."\");");

    } // end func

//-----------------------------------------------------------------------------
    /**
     *显示论坛最新文章
     *
     */
    function ctbNews()
    {
        $this->BAN = "&gt; 查看最新文章";
        $header = $this->header($this->BAN);
		if($this->input['shumu'] and $this->input['shumu']<250){
			$showTopicNum = $this->input['shumu'];
		}
		else $showTopicNum = "20";

        $this->file = $this->set[dataPath]."/forums.php";
        $forumLines = $this->read_file();
		$optionLine="<option value=\"no\">跳转论坛至...</option>";
		$topicLine = array(); 
        $linesNew = array();   		
		foreach ($forumLines as $forumLines) {
			$forum = $this->make_array($forumLines);
			if ($forum[1] == "cat") {
				$optionLine.="<option value=\"no\">╋".$forum[3]."</option>";
				}
			if ($forum[1] == "forum") {
				$forumid = $forum[2];
				$optionLine .= $forum[2] != $this->input['forumid'] ? "<option value=".$forum[2].">　|-".$forum[3]."</option>" : "<option value=".$forum[2]." selected=\"selected\">　|-".$forum[3]."</option>";  //changed by cx

				$this->input['forumid']=$forumid;
				$check = $this->checkForum($forumid);
				if ($check[0] == "0")
					continue;

				$this->file = $this->set[dataPath]."/".$forumid."/list.php";
                $lines = $this->read_file();

                for ($i=0; $i<count($lines);$i++ ) {
                    $linesNew[]=$lines[$i]."\x0E".$forumid;
                }

                $topicLine = $topicLine + $linesNew; //<<以后考虑是否用array_merge_recursive();可以防止丢失元素;

			}
		}

		$newTopic=$this->orderTopic3($topicLine,3,$showTopicNum);
 
        for( $i=0;$i<$showTopicNum;$i++) {		
            $forumNew = $this->make_array($newTopic[$i]);
			$this->file = $this->set[dataPath]."/forums.php";
			$forums = $this->read_file();
			foreach ($forums as $line) {
		    	$lineCode = $this->make_array($line);
				if($lineCode[2]==$forumNew[12]){
                  $forum=$lineCode;
				  break;
				}
		    }
			$forumName=$forum[3];
                $this->file = $this->set[dataPath]."/".$forumNew[12]."/".$forumNew[1]."_.php";
                if (file_exists($this->file)) {
				$line = $this->get();
                $postTitle = $line[2];
				$postTitle = $this->set[replaceWhenPost] == 'Y' ? $postTitle : $this->replaceBadWord($postTitle);
                $id = $line[1];
                $clickNum = $line[4];
                $topicNum = $line[3];
				$replyNum = $topicnum-1;
                $reUsername = $line[5];
                $lastTime = date("Y-m-d H:i:s",$line[6]);
                $topicPic = $line[7];
                if (empty($topic_pic)) {
					$topic_pic="smileyface.gif";
				}
				$topicAuth =$forumNew[2];
				
                if (($this->sess['sess_last_login'] != "") && ($line[6] > $this->sess['sess_last_login']) && ($line[6] > $this->sess['markRead'][ $this->input['forumid'] ])) {
                    $newMode = "<img src=\"{$this->tplPath}/images/system/topic_new.gif\" width=25>";
                } else {
                    $newMode = "";
                }
				
				if ($topicCode[6]=="1") {
					$postFitle = "<font color=red>[精华]</font>".$post_title;
				}                
				//
                if ($topicCode[5]=="1" and $topicCode[4]!="1") {
					$newFlag = "foldertop.gif";
				} elseif ($topicCode[4]=="1" and $topicCode[5]=="1") {
					$newFlag = "folder_lock_top.gif";
				} elseif ($topicCode[4]=="1" and $topicCode[5]!="1") {
					$newFlag = "folderlock.gif";
				} elseif ($topicNum >=10 and $topicNum <20) {
					$newFlag = "folderhot.gif";
				} elseif ($topicNum >=20) {
					$newFlag = "folderhot1.gif";
				} else {
					$newFlag = "folder.gif";
				}
				if ($topicCode[8]=="vote") {
					$newFlag = "folderpoll.gif";
				}
				              
				$count_file = $line[3];
                $page_num = ($count_file % $this->set[postList]) == "0" ? intval(($count_file)/$this->set[postList]) : intval(($count_file)/$this->set[postList])+1;
                if ($page_num < 2) {
					$lastPage = "";
				} else {
					$lastPage = "&#171; <a href=./index.php?mods=topicdisplay&forumid=$forumNew[12]&postid=$forumNew[1]&p=$page_num>$page_num</a> &#187;";
				}
                eval ("\$post_list .= \"".$this->gettemplate("ctbNewPost")."\";");
		  }
		}

        $forum_list="<select name='forumid'  class='input5'>".$optionLine."</select>";
       
	   eval("\$this->outPut(\"".$this->gettemplate("ctbNews")."\");");

     } // end func


//-----------------------------------------------------------------------------
    /**
     *论坛首页调用
     *
     */
    function indexNews()
    {
		//
		if($this->input['topicNum']) $topicNum=$this->input['topicNum'];
		else $topicNum=8;

        $this->file = $this->set[dataPath]."/forums.php";
        $forumLines = $this->read_file();
		$topicLine = array();
		foreach ($forumLines as $forumLine) {
			$forum = $this->make_array($forumLine);
			if ($forum[1] == "forum") {
				$forumid = $forum[2];

				$check = $this->checkForum($forumid);
				if ($check[0] == "0")
					continue;

				$this->file = $this->set[dataPath]."/".$forumid."/list.php";
                $lines = $this->read_file();

                for ($i=0; $i<count($lines);$i++ ) {
                    $linesNew[]=$lines[$i]."\x0E".$forumid;
                }

                $topicLine = $topicLine + $linesNew; //<<以后考虑是否用array_merge_recursive();可以防止丢失元素;

			}
		}
		$newTopic=$this->orderTopic3($topicLine,3,$topicNum-1);
        for( $i=0;$i<count($newTopic);$i++) {		
            $forumNew = $this->make_array($newTopic[$i]);
			$this->file = $this->set[dataPath]."/forums.php";
			$forums = $this->read_file();
			foreach ($forums as $line) {
		    	$lineCode = $this->make_array($line);
				if($lineCode[2]==$forumNew[12]){
                  $forum=$lineCode;
				  break;
				}
		    }
			$forumName=$forum[3];
                $this->file = $this->set[dataPath]."/".$forumNew[12]."/".$forumNew[1]."_.php";
                if (file_exists($this->file)) {
				$line = $this->get();
                $postid = $line[1];
                $topicAuth = $line[5];
				$lastTopic =$this->keepLen($line[2],22);
				$lastTopic = $this->set[replaceWhenPost] == 'Y' ? $lastTopic : $this->replaceBadWord($lastTopic);

		echo "document.write('<TR><TD>&nbsp;-&nbsp;<a target=_blank href=\'".$this->set[webPath]."/index.php?mods=topicdisplay&forumid=$forumNew[12]&postid=$forumNew[1]\' target=_blank>$lastTopic</a>&nbsp;');";
		echo "document.write('</TD></TR>');"; 

		}
	}
   
} // end func



    /**
     *显示分论坛最新文章
     *
     */
    function forumNews()
    {
		//
		if($this->input['topicNum']) $topicNum=$this->input['topicNum'];
		else $topicNum=8;

		$this->file = $this->set[dataPath]."/".$this->input['forumid']."/list.php";
        $newTopic = $this->read_file();

        for( $i=0;$i<$topicNum;$i++) {		
            $forumNew = $this->make_array($newTopic[$i]);
			$this->file = $this->set[dataPath]."/forums.php";
			$forums = $this->read_file();
			foreach ($forums as $line) {
		    	$lineCode = $this->make_array($line);
				if($lineCode[2]==$this->input['forumid']){
                  $forum=$lineCode;
				  break;
				}
		    }
			$forumName=$forum[3];
                $this->file = $this->set[dataPath]."/".$this->input['forumid']."/".$forumNew[1]."_.php";
                if (file_exists($this->file)) {
				$line = $this->get();
                $postid = $line[1];
                $topicAuth = $line[5];
				$lastTopic =$this->keepLen($line[2],22);
				$lastTopic = $this->set[replaceWhenPost] == 'Y' ? $lastTopic : $this->replaceBadWord($lastTopic);

				echo "document.write('<TR><TD>&nbsp;-&nbsp;<a target=_blank href=\'".$this->set[webPath]."/index.php?mods=topicdisplay&forumid=$forumNew[12]&postid=$forumNew[1]\' target=_blank>$lastTopic</a>&nbsp;');";
				echo "document.write('</TD></TR>');"; 

		       }
	     }    
    } // end func


//-----------------------------------------------------------------------------
    /**
     *在首页显示投票
     *
     */
    function indexVote()
    {

		$this->file = $this->set[dataPath]."/".$this->input['forumid']."/".$this->input['postid']."_.php";
		$line = $this->get();
        $vote_title=$line[2];
		$vote_title = $this->set[replaceWhenPost] == 'Y' ? $vote_title : $this->replaceBadWord($vote_title);

        echo "document.write('<tr><FORM METHOD=POST ACTION=\'$web_path/index.php?mods=post&forumid=$forumid&action=submitpoll&postid=$postid\'  target=\'KIMSVOTE\'><td colspan=2><SCRIPT LANGUAGE=javascript>function VOTE(URL) {window.open(URL,\'VOTE\');}function KIMSVOTE(){window.open(\'\',\'KIMSVOTE\');}</SCRIPT><img src=\"".$this->set[webPath].$this->tplPath."/images/icon/fish.gif\" border=0 width=10>&nbsp;$vote_title</td></tr>');";

		$this->file = $this->set[dataPath]."/".$this->input['forumid']."/".$this->input['postid'].".php4";
		$pollitems = $this->openfile();
        $poll_count=(count($pollitems[0])-3)/2;		
		$poll_totalnum=$line[16];
		if ($poll_totalnum=="0") $poll_totalnum_1="1";
		else $poll_totalnum_1=$poll_totalnum;
		for ($i=1;$i<=$poll_count;$i++) { 
			if ($pollitems[0][$i*2+1] and $pollitems[0][$i*2]>=0) {
		  $poll_itemtopic=$pollitems[0][$i*2+1];
			$poll_itemtopic = $this->set[replaceWhenPost] == 'Y' ? $poll_itemtopic : $this->replaceBadWord($poll_itemtopic);
		  $poll_itemnum=$pollitems[0][$i*2];
		  $poll_width=($poll_itemnum/$poll_totalnum_1)*30;
		  if ($line[14]=="0")
		echo "document.write('<tr><td><input type=\"radio\" name=\"vote_id\" value=\"$i\">$poll_itemtopic</td><td valign=middle><img src=\"".$this->set[webPath].$this->tplPath."/images/poll/$i.gif\" width=$poll_width height=10 align=absMiddle>&nbsp;$poll_itemnum 票.</td></tr>');";  
			  if ($line[14]=="1")
		echo "document.write('<tr><td><input type=\"checkbox\" name=\"vote_id[$i]\" value=\"1\">$poll_itemtopic</td><td valign=middle><img src=\"".$this->set[webPath].$this->tplPath."/images/poll/$i.gif\" width=$poll_width height=10 align=absMiddle>&nbsp;$poll_itemnum 票.</td></tr>');";  
			}
		}

		echo "document.write('<tr><td align=center colspan=2><INPUT type=image src=\'".$this->set[webPath].$this->tplPath."/images/system/vote_button.gif\' border=0 onClick=\'KIMSVOTE()\' target=\'KIMSVOTE\'>&nbsp;&nbsp;<A href=javascript:VOTE(\'$web_path/index.php?mods=topicdisplay&forumid=$forumid&postid=$postid\')><IMG src=\'".$this->set[webPath].$this->tplPath."/images/system/vote_button1.gif\' border=0></A></td></FORM></tr>');";
		//echo $poll_show;  


    } // end func


//-----------------------------------------------------------------------------
    /**
     *显示空间信息
     *
     */
    function getPhpInfo()
    {
	    phpinfo();
	    exit;

    } // end func



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