<?php
require "../Run.php";
require root_path."/include/page.inc.php";
if ($_GET['cid'] <= 0 || $_GET['cid'] == '' || $_GET['cid'] == NULL) {
    header("location: http://" . $_SERVER["HTTP_HOST"]);
}
function huifunums($groid) {
    $sql = "SELECT hid,userid,htext,touserid,siteid,gro,time FROM bbscomm WHERE siteid='" . WAPID . "' AND gro='" . $groid . "';";
    $result = mysql_query($sql);
    if ($result && mysql_num_rows($result) > 0) {
        return mysql_num_rows($result);
    } else {
        return 0;
    }
}
$page = $_GET['page'];
if ($page == '' || $page == NULL || $page < 1) {
    $page = 1;
}
$s = ($page - 1) * 15;
if ($_GET['cid'] == NULL || $_GET['cid'] == '' || $_GET['cid'] == '0' || $_GET['cid'] == 0) {
    $cid = 'siteid=\'' . WAPID . '\'';
} else {
    $cid = 'gro = \'' . $_GET['cid'] . '\' AND siteid=\'' . WAPID . '\'';
}
//置顶贴
$sql = "SELECT bbsid,userid,gro,title,v,content,time,name,zip,top,waptop,good FROM bbs WHERE siteid='{$wapid}' AND waptop='1' ORDER BY bbsid DESC LIMIT 4";
$result = mysql_query($sql);
if ($result && mysql_num_rows($result) > 0) {
    $i = 0;
    while (list($bbsid, $userid, $gro, $title, $v, $content, $time, $bname, $zip, $top, $waptop, $good) = mysql_fetch_row($result)) {
        if ($zip != NULL || $zip != '') {
            $file = '<img src="../style/fj.png" />';
        } else {
            $file = '';
        }
        if ($top == 1) {
            $top = '[顶]';
        } else {
            $top = '';
        }
        if ($waptop == 1) {
            $waptop = '[总顶]';
        } else {
            $waptop = '';
        }
        if ($good == 1) {
            $good = '<img src="../style/good.gif" align="absmiddle" style="height:20px;height:20px;"/>';
        } else {
            $good = '';
        }
        $html1.= '<div class="subtitle">' . $waptop . $top . $good . '<a href="content.php?cid=' . $gro . '&id=' . $bbsid . '&" target="_blank">' . $title . '(' . huifunums($bbsid) . '回/' . $v . '阅)</a>' . $file . '<br>[<a href="http://' . HTTP_HOST . '/user/userinfo.php?toid=' . user('xid', 'id', $userid) . '">' . $bname . '</a>发布于' . date('Y/m/d H:i:s', $time) . ']</div>';
    }
}
$sql = "SELECT bbsid,userid,gro,title,v,content,time,name,zip,top,waptop,good FROM bbs WHERE {$cid} AND top='1' ORDER BY bbsid DESC LIMIT 4";
$result = mysql_query($sql);
if ($result && mysql_num_rows($result) > 0) {
    $i = 0;
    while (list($bbsid, $userid, $gro, $title, $v, $content, $time, $bname, $zip, $top, $waptop, $good) = mysql_fetch_row($result)) {
        if ($zip != NULL || $zip != '') {
            $file = '<img src="../style/fj.png" />';
        } else {
            $file = '';
        }
        if ($top == 1) {
            $top = '[顶]';
        } else {
            $top = '';
        }
        if ($waptop == 1) {
            $waptop = '[总顶]';
        } else {
            $waptop = '';
        }
        if ($good == 1) {
            $good = '<img src="../style/good.gif" align="absmiddle" style="height:20px;height:20px;"/>';
        } else {
            $good = '';
        }
        $html2.= '<div class="subtitle">' . $waptop . $top . $good . '<a href="content.php?cid=' . $gro . '&id=' . $bbsid . '&" target="_blank">' . $title . '(' . huifunums($bbsid) . '回/' . $v . '阅)</a>' . $file . '<br>[<a href="http://' . HTTP_HOST . '/user/userinfo.php?">' . $bname . '</a>发布于' . date('Y/m/d H:i:s', $time) . ']</div>';
    }
}
//分类贴
if ($_GET['action'] == 'new' || $_GET['action'] == '') {
    $bbssql = "SELECT count(*) FROM bbs WHERE {$cid}";
    $result = mysql_query($bbssql);
    list($nums) = mysql_fetch_row($result);
    $bbssql = "SELECT bbsid,userid,gro,title,v,content,time,name,zip,top,waptop,good,endtime,view_time FROM bbs WHERE {$cid} ORDER BY bbsid DESC LIMIT {$s},15";
    $result = mysql_query($bbssql);
} elseif ($_GET['action'] == 'good') {
    $bbssql = "SELECT count(*) FROM bbs WHERE {$cid} AND good='1'";
    $result = mysql_query($bbssql);
    list($nums) = mysql_fetch_row($result);
    $bbssql = "SELECT bbsid,userid,gro,title,v,content,time,name,zip,top,waptop,good,endtime,view_time FROM bbs WHERE {$cid} AND good='1' ORDER BY bbsid DESC LIMIT {$s},15";
    $result = mysql_query($bbssql);
} elseif ($_GET['action'] == 'hot') {
    $bbssql = "SELECT count(*) FROM bbs WHERE {$cid}";
    $result = mysql_query($bbssql);
    list($nums) = mysql_fetch_row($result);
    $sql = "SELECT bbsid,userid,gro,title,v,content,time,name,zip,top,waptop,good,endtime,view_time FROM bbs WHERE {$cid} ORDER BY v DESC LIMIT {$s},15";
    $result = mysql_query($bbssql);
} elseif ($_GET['action'] == 'dt') {
    $bbssql = "SELECT count(*) FROM bbs WHERE {$cid}";
    $result = mysql_query($bbssql);
    list($nums) = mysql_fetch_row($result);
    $bbssql = "SELECT bbsid,userid,gro,title,v,content,time,name,zip,top,waptop,good,endtime,view_time FROM bbs WHERE {$cid} ORDER BY view_time DESC LIMIT {$s},15";
    $result = mysql_query($bbssql);
}
if ($result && mysql_num_rows($result) > 0) {
    $i = 0;
    while (list($bbsid, $userid, $gro, $title, $v, $content, $time, $bname, $zip, $top, $waptop, $good, $endtime, $view_time) = mysql_fetch_row($result)) {
        if ($zip != NULL || $zip != '') {
            $file = '<img src="../style/rar.gif" />';
        } else {
            $file = '';
        }
        if ($top == 1) {
            $top = '[顶]';
        } else {
            $top = '';
        }
        if ($waptop == 1) {
            $waptop = '[总顶]';
        } else {
            $waptop = '';
        }
        if ($good == 1) {
            $good = '<img src="../style/good.gif" align="absmiddle" style="height:20px;height:20px;"/>';
        } else {
            $good = '';
        }
        $div = $num++ % 2 == 0 ? 'line1' : 'line2';
        $html.= '<div class="' . $div . '">' . $waptop . $top . $good . '<a href="content.php?cid=' . $gro . '&id=' . $bbsid . '" target="_blank">' . $title . '(' . huifunums($bbsid) . '回/' . $v . '阅)' . $file . '</a><br>[<a href="http://' . HTTP_HOST . '/user/userinfo.php?toid=' . user('xid', 'id', $userid) . '">' . $bname . '</a> 发布于' . date('Y/m/d H:i:s', $time) . ']</div>';
    }
} else {
    $html = '<div class="tip">暂时还没有记录哦</div>';
}
$html = $html1 . $html2 . $html;
$classcon = mysql_query("SELECT cid,cn,url,xuhao,q,siteid,gro FROM class WHERE siteid='{$wapid}' AND cid='{$_GET['cid']}'");
list($cid, $cn, $url, $xuhao, $q, $siteid, $gro) = mysql_fetch_row($classcon);
if ($url == 'NULL') {
    $sitetitle = '网站首页';
} else {
    $sitetitle = $cn;
}
$url = 'list.php?action=' . $_GET['action'] . '&cid=' . $_GET['cid'] . '&';
echo head($sitetitle);
echo topNav($sitetitle, '<a href="../index.php?cid=' . $gro . '">返回</a>', '<a href="http://' . HTTP_HOST . '/index.php?">首页</a>');
echo '<table class="bbs_sub"><tr><td><a href="add.php?cid=' . $_GET['cid'] . '">发帖</a></td><td><a href="list.php?action=new&cid=' . $_GET['cid'] . '">最新</a></td><td><a href="list.php?action=dt&cid=' . $_GET['cid'] . '">动态</a></td><td><a href="list.php?action=good&cid=' . $_GET['cid'] . '">精华</a></td><td><a href="admin.php?cid=' . $_GET['cid'] . '">版务</a></td></tr></table>';
echo UBB(class_get_info($_GET['cid'], "top_two") . $html);
echo page($nums, 15, $url, NULL, 'view');
echo class_get_info($_GET['cid'], "bottom_two");
echo footer(1); 