Exemplo n.º 1
0
function list_tad_web_discuss($WebID = "", $CateID = "", $limit = null)
{
    global $xoopsDB, $xoopsUser, $xoopsTpl;
    if (!$xoopsUser and empty($_SESSION['LoginMemID'])) {
        $xoopsTpl->assign('mode', 'need_login');
    } else {
        $showWebTitle = empty($WebID) ? 1 : 0;
        $andWebID = empty($WebID) ? "" : "and a.WebID='{$WebID}'";
        //取得tad_web_cate所有資料陣列
        $web_cate = new web_cate($WebID, "tad_web_discuss", "discuss");
        if (empty($CateID)) {
            $andCateID = "";
        } else {
            //取得單一分類資料
            $cate = $web_cate->get_tad_web_cate($CateID);
            $xoopsTpl->assign('cate', $cate);
            $andCateID = "and a.`CateID`='{$CateID}'";
        }
        $andLimit = $limit > 0 ? "limit 0,{$limit}" : "";
        $sql = "select a.* from " . $xoopsDB->prefix("tad_web_discuss") . " as a left join " . $xoopsDB->prefix("tad_web") . " as b on a.WebID=b.WebID where b.`WebEnable`='1' and a.ReDiscussID='0' {$andWebID} {$andCateID} order by a.LastTime desc {$andLimit}";
        if (empty($limit)) {
            //getPageBar($原sql語法, 每頁顯示幾筆資料, 最多顯示幾個頁數選項);
            $PageBar = getPageBar($sql, 20, 10);
            $bar = $PageBar['bar'];
            $sql = $PageBar['sql'];
            $total = $PageBar['total'];
        } else {
            $bar = "";
        }
        $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error());
        $main_data = "";
        $i = 0;
        while ($all = $xoopsDB->fetchArray($result)) {
            //`DiscussID`, `ReDiscussID`, `CateID`, `WebID`, `MemID`, `MemName`, `DiscussTitle`, `DiscussContent`, `DiscussDate`, `LastTime`, `DiscussCounter`
            foreach ($all as $k => $v) {
                ${$k} = $v;
            }
            $renum = get_re_num($DiscussID);
            $show_re_num = empty($renum) ? "" : " ({$renum}) ";
            $LastTime = substr($LastTime, 0, 10);
            $Class = getWebInfo($WebID);
            $web_cate->set_WebID($WebID);
            $cate = $web_cate->get_tad_web_cate_arr();
            $main_data[$i]['cate'] = $cate[$CateID];
            $main_data[$i]['DiscussID'] = $DiscussID;
            $main_data[$i]['DiscussTitle'] = $DiscussTitle;
            $main_data[$i]['show_re_num'] = $show_re_num;
            $main_data[$i]['LastTime'] = $LastTime;
            $main_data[$i]['MemName'] = $MemName;
            $main_data[$i]['DiscussCounter'] = $DiscussCounter;
            $main_data[$i]['WebID'] = $WebID;
            $main_data[$i]['WebTitle'] = "<a href='index.php?WebID={$WebID}'>{$Class['WebTitle']}</a>";
            $i++;
        }
        $xoopsTpl->assign('discuss_data', $main_data);
        $xoopsTpl->assign('bar', $bar);
        $xoopsTpl->assign('isMineDiscuss', isMine());
        $xoopsTpl->assign('showWebTitleDiscuss', $showWebTitle);
    }
}