if ($byname != '') {
        $cond .= " AND host_name='{$byname}' ";
    }
    if ($rules != -1) {
        $cond .= " AND rules='{$rules}'";
    }
}
//棋局总数
$sql = "SELECT COUNT(*) FROM `{$cfg['tb_newgames']}` AS ng LEFT JOIN `{$cfg['tb_members']}` AS m ON m.u_name=ng.host_name {$cond}";
$result = RenDB_Query($sql);
$row = RenDB_Fetch_Row($result);
$plprfix = "room_new.php?rules={$rules}&showall={$showall}";
if ($byname != '') {
    $plprfix .= "&byname={$encoded_byname}";
}
$pageinfo = MakePageBar($plprfix, $row[0], $cfg['gperpage'], $page);
//显示内容
$sql = "SELECT ng.*,m.u_name,m.skill,m.g_w,m.g_d,m.g_l,m.g_to FROM `{$cfg['tb_newgames']}` AS ng LEFT JOIN `{$cfg['tb_members']}` AS m ON m.u_name=ng.host_name {$cond} ORDER BY app_count LIMIT {$pageinfo['start']},{$cfg['gperpage']}";
$result = RenDB_Query($sql);
$glist = '';
$gnum = 0;
if (RenDB_Num_Rows($result) > 0) {
    $game_cell = LoadTemplate('g_cell_new');
    //$nowtime = time();
    while ($gdata = RenDB_Fetch_Array($result)) {
        if ($gdata['app_count'] > 0) {
            $gtremain = GetNewGameTimeOutInfo();
            if ($gtremain == 0) {
                continue;
            }
            $gtremain = Time2HMS($gtremain) . HLTxt('*');
$page = intval($page);
//消息总数
//$sql = "SELECT COUNT(*) FROM $cfg[tb_pms] WHERE comefrom='$udata[u_name]' OR sendto='$udata[u_name]'";
$sql = "SELECT COUNT(*) FROM {$cfg['tb_pms']} WHERE sendto='{$udata['u_name']}'";
$result = RenDB_Query($sql);
$row = RenDB_Fetch_Row($result);
$pmcount = $row[0];
$outbox = isset($outbox) ? intval($outbox) : 0;
$link_inbox = $outbox ? "□<a href=\"pm_view.php?page={$page}\">收件箱</a>" : HLTxt('■收件箱');
$link_outbox = $outbox ? HLTxt('■发件箱') : "□<a href=\"pm_view.php?page={$page}&outbox=1\">发件箱</a>";
$box_type = $outbox ? 'out' : 'in';
$cond = $outbox ? " WHERE comefrom='{$udata['u_name']}' " : " WHERE sendto='{$udata['u_name']}' ";
$sql = "SELECT COUNT(*) FROM {$cfg['tb_pms']} {$cond}";
$result = RenDB_Query($sql);
$row = RenDB_Fetch_Row($result);
$pageinfo = MakePageBar("pm_view.php?outbox={$outbox}", $row[0], $cfg['pmperpage'], $page);
$sql = "SELECT * FROM {$cfg['tb_pms']} {$cond} ORDER BY pmid DESC LIMIT {$pageinfo['start']},{$cfg['pmperpage']}";
$result = RenDB_Query($sql);
$pmlist = '';
$pmnum = 0;
if (RenDB_Num_Rows($result) > 0) {
    $pm_cell = LoadTemplate('pm_cell');
    //$endid = 0;
    while ($pmdata = RenDB_Fetch_Array($result)) {
        $pmdate = TimeToDate($pmdata['sendtime']);
        //是收件
        $pmnum++;
        if ($pmnum == $cfg['maxpm']) {
            $endid = $pmdata['pmid'];
        }
        if ($pmnum > $cfg['maxpm'] && !$pmdata['isnew']) {
     while ($gdata = RenDB_Fetch_Array($result)) {
         $tar->addPosFile($gdata);
     }
     $tar->addInfo('Generated by RBB, ' . TimeToDate(time(), true));
     $tar->echoTar();
 } else {
     SetNoUseCache();
     $sql = "SELECT COUNT(*) FROM `{$cfg['tb_games']}` {$where_sql}";
     $result = RenDB_Query($sql);
     $row = RenDB_Fetch_Row($result);
     if (!isset($page)) {
         $page = 1;
     }
     $page = intval($page);
     $encodename = urlencode($u_name);
     $pageinfo = MakePageBar("g_search.php?action=list&rules={$rules}&search_time={$search_time}&opening={$opening}&search_all_user={$search_all_user}&u_name={$encodename}&game_status={$game_status}&cp_id={$cp_id}&group_id={$group_id}", $row[0], $cfg['gperpage'], $page);
     $packdownlink = $row[0] ? "[<a href=\"g_search.php?action=list&rules={$rules}&search_time={$search_time}&opening={$opening}&search_all_user={$search_all_user}&u_name={$encodename}&game_status={$game_status}&cp_id={$cp_id}&group_id={$group_id}&packdown=1\">全部打包下载</a>]" : '';
     $sql = "SELECT * FROM `{$cfg['tb_games']}` {$where_sql} ORDER BY {$order_sql} LIMIT {$pageinfo['start']},{$cfg['gperpage']}";
     $result = RenDB_Query($sql);
     $glist = '';
     $gnum = 0;
     if (RenDB_Num_Rows($result) > 0) {
         require_once './include/g_func.php';
         $game_cell = LoadTemplate('g_cell');
         while ($gdata = RenDB_Fetch_Array($result)) {
             $mcount = $gdata['mcount'];
             $curside = ($mcount + 1) % 2;
             $times[0] = $gdata['w_time'];
             $times[1] = $gdata['b_time'];
             $draws[0] = $gdata['w_draw'];
             $draws[1] = $gdata['b_draw'];
require_once './include/common.php';
require_once './include/g_func.php';
SetNoUseCache();
if (!$udata['is_member']) {
    ErrorBox($str['act_noguest']);
}
//$roombar=MakeRoomBar(2);
if (!isset($page)) {
    $page = 1;
}
$page = intval($page);
$sql = "SELECT COUNT(*) FROM `{$cfg['tb_games']}` WHERE b_name='{$udata['u_name']}' OR w_name='{$udata['u_name']}'";
$result = RenDB_Query($sql);
$row = RenDB_Fetch_Row($result);
$pageinfo = MakePageBar("room_my.php?", $row[0], $cfg['gperpage'], $page);
$sql = "SELECT * FROM {$cfg['tb_games']} WHERE b_name='{$udata['u_name']}' OR w_name='{$udata['u_name']}' ORDER BY startdate>='{$nowtime}',status>0,IF(turn_name='{$udata['u_name']}',0,1) LIMIT {$pageinfo['start']},{$cfg['gperpage']}";
$result = RenDB_Query($sql);
$glist = '';
$gnum = 0;
$shownum = 0;
if (RenDB_Num_Rows($result) > 0) {
    require_once './include/g_func.php';
    $game_cell = LoadTemplate('g_cell_my');
    //$nowtime = time();
    while ($gdata = RenDB_Fetch_Array($result)) {
        $gnum++;
        $mcount = $gdata['mcount'];
        $curside = ($mcount + 1) % 2;
        $times[0] = $gdata['w_time'];
        $times[1] = $gdata['b_time'];
        $lks[5] = HLTxt('胜率');
        break;
    case 6:
        $order = 'u_name ASC';
        $lks[6] = HLTxt('用户名');
        break;
    default:
        $order = 'g_w+g_d+g_l=0,skill DESC';
        $lks[0] = HLTxt('积分');
        break;
}
//上榜人数
$sql = "SELECT COUNT(*) FROM {$cfg['tb_members']}";
$result = RenDB_Query($sql);
$row = RenDB_Fetch_Row($result);
$pageinfo = MakePageBar("ranking.php?orderby={$orderby}", $row[0], $cfg['mperpage'], $page);
$sql = "SELECT * FROM {$cfg['tb_members']} ORDER BY {$order} LIMIT {$pageinfo['start']},{$cfg['mperpage']}";
$result = RenDB_Query($sql);
$mlist = '';
$mnum = 0;
if (RenDB_Num_Rows($result) > 0) {
    $member_cell = LoadTemplate('m_cell');
    while ($mdata = RenDB_Fetch_Array($result)) {
        $morder = $pageinfo['start'] + $mnum + 1;
        $mname = MemberLink($mdata['u_name']);
        $mgrade = $mdata['skill'];
        $mrate = $mdata['g_w'] + $mdata['g_d'] + $mdata['g_l'] == 0 ? 0 : round($mdata['g_w'] * 100 / ($mdata['g_w'] + $mdata['g_d'] + $mdata['g_l']), 1);
        $mrate .= '%';
        $minfo = "{$mdata['g_w']}胜{$mdata['g_d']}平{$mdata['g_l']}负";
        $mregtime = TimeToDate($mdata['reg_date']);
        eval("\$mlist .= \"{$member_cell}\";");
    $action = 'list';
}
if (!in_array($action, array('list', 'show', 'update', 'new1', 'new2', 'del', 'makepage'))) {
    ACP_MessageBox($str['act_err']);
}
switch ($action) {
    case 'list':
        SetNoUseCache();
        if (!isset($page)) {
            $page = 1;
        }
        $page = intval($page);
        $sql = "SELECT COUNT(*) FROM `{$cfg['tb_competitions']}`";
        $result = RenDB_Query($sql);
        $row = RenDB_Fetch_Row($result);
        $pageinfo = MakePageBar("index.php?mode=cp_man&action=list", $row[0], $cfg['gperpage'], $page);
        $sql = "SELECT * FROM `{$cfg['tb_competitions']}` ORDER BY cp_id DESC LIMIT {$pageinfo['start']},{$cfg['gperpage']}";
        $result = RenDB_Query($sql);
        $cplist = '';
        if (RenDB_Num_Rows($result) > 0) {
            while ($cpdata = RenDB_Fetch_Array($result)) {
                $cplist .= "<tr bgcolor=\"{$color['cell']}\"><td>";
                $cplist .= "[<a href=\"JavaScript:ConfirmDelCP('{$cpdata['cp_id']}')\">" . HLTxt('删') . "</a>] ";
                $cplist .= "<a href=\"index.php?mode=cp_man&action=show&cp_id={$cpdata['cp_id']}\">{$cpdata['cp_id']}: {$cpdata['cp_name']}</a> <br />时间: ";
                //$cplist.='<hr />';
                //$cplist.=$cpdata['description'];
                $cplist .= TimeToDate($cpdata['starttime']);
                if ($cpdata['endtime']) {
                    $cplist .= ' - ' . TimeToDate($cpdata['endtime']);
                }
                //if(!file_exists("../cpdata/$cpdata[cp_id].html"))
<?php

require_once './include/common.php';
SetNoUseCache();
if (!isset($page)) {
    $page = 1;
}
$page = intval($page);
$sql = "SELECT COUNT(*) FROM `{$cfg['tb_competitions']}`";
$result = RenDB_Query($sql);
$row = RenDB_Fetch_Row($result);
$pageinfo = MakePageBar("cp_list.php?", $row[0], $cfg['gperpage'], $page);
$sql = "SELECT * FROM `{$cfg['tb_competitions']}` ORDER BY cp_id DESC LIMIT {$pageinfo['start']},{$cfg['gperpage']}";
$result = RenDB_Query($sql);
$cplist = '';
if (RenDB_Num_Rows($result) > 0) {
    while ($cpdata = RenDB_Fetch_Array($result)) {
        $cplist .= "<tr bgcolor=\"{$color['cell']}\"><td>";
        if (!file_exists("./cpdata/{$cpdata['cp_id']}.html")) {
            $cplist .= $cpdata['cp_name'];
        } else {
            $cplist .= "<a  href=\"cp_view.php?cp_id={$cpdata['cp_id']}\">{$cpdata['cp_name']}</a>";
        }
        $cplist .= ' ' . TimeToDate($cpdata['starttime']);
        if ($cpdata['endtime']) {
            $cplist .= ' - ' . TimeToDate($cpdata['endtime']);
        }
        $cplist .= '<hr />';
        $cplist .= $cpdata['description'];
        $cplist .= "</td></tr>";
    }