<?php
/*
\* ===========================================
\* 项目: CTB文本论坛
\* 版本: 1.0
\* 团队: 实易数码
\* 小组: CTB文本论坛小组
\* 作者: 险情
\* 功能: 用户个人收藏（和好友列表）模块
\* ===========================================
\* Copyright (c) 2002 
\* 团队主页: http://www.11cn.org
\* 团队信箱: ------------------
\* 创建日期: 2002.6
\* 修改日期: ------------------
\* 修改说明: ------------------
\* 版权声明: 这个程序是免费软件.
\* ===========================================
*/


class Module extends CommonClass
{
    
    /**
     *构造函数
     *
     */
    function execute()
    {
        if (!$this->sess['sess_uid'] || !$this->sess['sess_uname'] || !$this->sess['sess_upass']) {
            $this->showMsg("注册用户才可以使用收藏夹功能，请先登陆/注册!","index.php?mods=member&action=login");
        }
        switch($this->input['action']) {
            case 'readShowall':
                $this->readShowAll();
                break;
            case 'readSave':
                $this->readSave();
                break;
            case 'read_del':
                $this->readDel();
                break;
        }
    } // end func

    /**
     *个人收藏保存
     *
     */
   function readSave()
    {
        $this->file = $this->set[dataPath]."/users/".$this->sess['sess_uid']."read.php";
        $getAllRead = $this->select(2, $this->input['forumid']);
        for($i=0;$i<=count($getAllRead);$i++){
            if ($getAllRead[$i][3] == $this->input['postid']){
                $this->showMsg("此文章已经收藏了，请不要重复收藏", "index.php");  // changed by cx
            }
        }

        $this->file = $this->set[dataPath]."/".$this->input['forumid']."/list.php";
        $getAuthor = $this->select_line(1, $this->input['postid']);

        $this->file = $this->set[dataPath]."/users/".$this->sess['sess_uid']."read.php";
        $readLine = array(stripslashes($this->code),time(),$this->input['forumid'],$this->input['postid'],$getAuthor[2],"","","\n");
        $this->insert_line($readLine);
        $postShowMsg = "您已经成功将该主题加入收藏<br><br>
            <li><a href=\"./index.php?mods=userread&action=read_showall\"><font color=red>查看您的收藏</font></a><br><br>
            <li><a href=\"./index.php?mods=topicdisplay&forumid={$this->input['forumid']}&postid={$this->input['postid']}&p=$page_num\">返回查看主题</a><br>
            </li>
            <li><a href=\"./index.php?mods=forumdisplay&forumid={$this->input['forumid']}\">返回查看版块</a><br>
            </li>
            <li><a href=\"./index.php\">返回论坛首页</a></ul>";
        $this->showMsg($postShowMsg,"./index.php?mods=topicdisplay&forumid={$this->input['forumid']}&postid={$this->input['postid']}&p=$page_num");
    } // end func

    /**
     *文章收藏查看
     *
     */
   function readShowAll()
    {
        $this->BAN = " &gt; 您的收藏夹";
        $header = $this->header("您的收藏夹");
          
        $this->file = $this->set[dataPath]."/users/".$this->sess['sess_uid']."read.php";
        $lines = $this->read_file();
        $totalFile = count($lines);
        $recnum = $this->set[userList];
        $totalNum = ($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]);
            $forumid = $topicCode[2];
            $this->file = $this->set[dataPath]."/forums.php";
            $forums = $this->read_file();
            $optionLine = "";
            foreach ($forums as $line) {
                $lineCode = $this->make_array($line);
                if($lineCode[2] == $forumid){
                    $forum = $lineCode;
                    break;
                }
            }
            $forumName = $forum[3];
            $this->file = $this->set[dataPath]."/".$topicCode[2]."/".$topicCode[3]."_.php";
            if (file_exists($this->file)) {
                $line = $this->get();
                $postTitle = $line[2];
				// added by cx for bad words replacement
				$postTitle = $this->set[replaceWhenPost] == 'Y' ? $postTitle : $this->replaceBadWord($postTitle);
                $id = $line[1];
                $clickNumber = $line[4];
                $topicNumber = $line[3];
                $reUserName = $line[5];
                $lastTime = date($this->set[dateformat],$line[6]);
                $topicPic = $line[7];
                if (empty($topicPic)) {
                    $topicPic = "smileyface.gif";
                }            
                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 ($topicNumber >= 10 && $topicNumber < 20) {
                    $newFlag = "folderhot.gif";
                } elseif ($topicNumber >= 20) {
                    $newFlag = "folderhot1.gif";
                } else {
                    $newFlag = "folder.gif";
                }
                if ($topicCode[8] == "vote") {
                    $newFlag = "folderpoll.gif";
                }
                                
                $topicAuthor = $topicCode[4];
                $countFile = $line[3];
                $listNum = $this->set[postList];//$userpage;
                $pageNum = ($countFile % $listNum) == "0" ? intval(($countFile)/$listNum) : intval(($countFile)/$listNum)+1;
                if ($pageNum < 2) {
                    $lastPage = "";
                } else {
                    $lastPage = "&#171; <a href=./iindex.php?mods=userread&action=read_showall&p=$pageNum>$pageNum</a> &#187;";
                }
                // end added
                eval ("\$postList .= \"".$this->getTemplate("readPost")."\";");
            }
        }
        $page = $this->getPage("$PHP_SELF?mods={$this->input['mods']}&forumid={$forumid}&orderby=$orderby",$totalNum);
        eval("\$this->outPut(\"".$this->getTemplate("readShowAll")."\");");
    } // end func

    /**
     *文章收藏删除
     *
     */
   function readDel()
    {
        $countDel = count($this->input['readId']);
        if($countDel <= 0) {
            $this->showMsg("<font color=red>请选择要删除的文章!</font>","index.php?mods=userread&action=read_showall");
        }
        for ($i=0;$i<$countDel;$i++){
            $this->file = $this->set[dataPath]."/users/".$this->sess['sess_uid']."read.php";
            $this->delete2(1,$this->input['readId'][$i]);
        }
        $this->showMsg("您已经成功更新了收藏夹中的数据!","index.php?mods=userread&action=read_showall");
    } // end func

} //end class