<?php
/*
 BMForum Bulletin Board Systems
 Code Name: Datium! (MySQL)
 
 This is a freeware, but don't change the copyright information.
 A SourceForge Project.
 Web Site: http://www.bmforum.com
 Copyright (C) Bluview Technology
*/
if (!defined('INBMFORUM')) die("Access Denied");
require_once("include/version.php");
// -----------------------------------------------------------
// PHP 5.1 supported.
// -----------------------------------------------------------
require("include/db/db_{$sqltype}.php");
require("lang/$language/global.php");
set_magic_quotes_runtime(0);
$mqgpc = get_magic_quotes_gpc();
$rggps = ini_get("register_globals");

if ($mqgpc == 0) {
    if ($rggps == 0) {
        @extract(addsd($_SESSION), EXTR_SKIP);
        @extract(addsd($_POST), EXTR_SKIP);
        @extract(addsd($_GET), EXTR_SKIP);
    } else {
        @extract(addsd($_SESSION), EXTR_OVERWRITE);
        @extract(addsd($_POST), EXTR_OVERWRITE);
        @extract(addsd($_GET), EXTR_OVERWRITE);
    } 
} else {
    @extract($_SESSION, EXTR_SKIP);
    @extract($_POST, EXTR_SKIP);
    @extract($_GET, EXTR_SKIP);
} 
// END
$begin_time = micro_time();
bmbdb_connect($db_server, $db_username, $db_password, $db_name, 0, $mysqlchar);
$timestamp = mktime();
$datestime = $timestamp + ($time_1 * 60 * 60);
$nowhours = gmdate("H", $datestime);
$ddwtail = explode("|", $scclose);

$querynum = 0;

$tmpdir = getdate($timestamp);
if ($saveattbyym == 1) $monthdir = "month" . $tmpdir['year'] . $tmpdir['mon'] . "/";
$tmpdir = $tmpdir['year'] . $tmpdir['yday'];

if (!$sess_cust) {
    @session_save_path("tmp");
} 
@session_name('bmsess');
@session_cache_limiter("private, post-check=0, pre-check=0, max-age=0");
@session_start();

$ip = $_SERVER['REMOTE_ADDR'];
$ip1 = $_SERVER['HTTP_X_FORWARDED_FOR'];
if (($ip1 != "") && ($ip1 != "unknown")) $ip = $ip1;
$ip = str_replace('|', '', htmlspecialchars(addslashes($ip)));
// --refresh check --
$cookietime = $timestamp + 3153600;

$REQUEST_URI = $_SERVER['REQUEST_URI'] ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'];

if ($refresh_allowed) {
    if ($REQUEST_URI == $_COOKIE['lastpath'] && ($timestamp - $_COOKIE['lastvisit_fr'] < $refresh_allowed)) {
        @header("Content-Type: $encode_info");
        die("$gl[374]");
    } 
    bmb_setcookie('lastpath', $REQUEST_URI);
    bmb_setcookie('lastvisit_fr', $timestamp);
} 
$ugsocount = 0;
include_once("datafile/cache/usergroup.php");
include_once("datafile/cache/forumdata.php");
$addquery = $plusug = "";

// Filter
if (!is_numeric($forumid)) $forumid = "";
if (!is_numeric($tid)) $tid = "";
if (!is_numeric($filename)) $filename = "";
if (!is_numeric($article) && $article != "all" && $article != "multi") $article = "";
$actionreason = htmlspecialchars ($actionreason);
// END

$username = $tcode_item = $tcode_count = "";
if (!empty($_SESSION['bmforumerboardidnum']) && !empty($_SESSION['bmforumerboardpwd']) && checkpass("", $_SESSION['bmforumerboardpwd'], $_SESSION['bmforumerboardidnum'])) {
    // Copyright(C) Blue Magic Board BMForum.com
    $login_status = 1;
    if ($_COOKIE['bmforumerboardidnum'] == $_SESSION['bmforumerboardidnum']) {
        $password = $_SESSION['bmforumerboardpwd'];
    } else {
        if (checkpass("", $_COOKIE['bmforumerboardpbmfym'], $_COOKIE['bmforumerboardidnum'])) {
            $password = $_COOKIE['bmforumerboardpbmfym'];
        } else {
            $usermoney = $userpoint = $userbym = $postamount = $login_status = 0;
            add_guest();
        } 
    } 
    if ($login_status != 0) {
        getUserInfo();
        if ($username != "") add_online();
        $o_username = urlencode($username); 
        // 记入上次访问时间开始
        if ($hisipa != $ip) {
            $hisipc = $hisipb;
            $hisipb = $hisipa;
            $hisipa = $ip;
        } 
        $tlastvisit = $timestamp;
    } 
} elseif (!empty($_COOKIE['bmforumerboardidnum']) && !empty($_COOKIE['bmforumerboardpbmfym']) && checkpass("", $_COOKIE['bmforumerboardpbmfym'], $_COOKIE['bmforumerboardidnum'])) {
    // Logon
    $login_status = 1;
    // Read vars from cookie&session;
    $bmforumerboardpwd = $_COOKIE['bmforumerboardpbmfym'];
    $password = $_COOKIE['bmforumerboardpbmfym'];
    $bmblogonskin = $_COOKIE['bmbskin'];
    $privacy = $_COOKIE['privacybym'];
    $TNM = $_COOKIE['TNM'];
    $_SESSION["bmforumerboardpwd"] = $_COOKIE['bmforumerboardpbmfym'];
    $_SESSION["bmforumerboardidnum"] = $_COOKIE['bmforumerboardidnum'];
    $_SESSION["privacy"] = $_COOKIE['privacybym'];
    $_SESSION["TNM"] = $_COOKIE['TNM'];
    
    // Processing Data
        
    getUserInfo();
    if ($usertype[22] == 1) error_reporting(E_ERROR | E_WARNING | E_PARSE);
    if ($username != "bmforumerboardid") add_online();
    $o_username = urlencode($username); 
    // Last Visit
    list($openit, $eudate, $eugroup) = explode(",", $foreuser);
    if ($openit == "yes" && $timestamp >= $eudate) {
        $addquery = " ugnum='" . str_replace("\n", "", $eugroup) . "',";
        $foreuser = "";
    } 
    if ($hisipa != $ip) {
        $hisipc = $hisipb;
        $hisipb = $hisipa;
        $hisipa = $ip;
    } 

    $tlastvisit = $timestamp;
    $lastlogin = $timestamp;
    $nquery = "UPDATE {$database_up}userlist SET $addquery foreuser='$foreuser',hisipa='$hisipa',hisipb='$hisipb',hisipc='$hisipc',tlastvisit='$tlastvisit',lastlogin='$lastlogin' WHERE userid='$userid'";
    $result = bmbdb_query($nquery);
} else {
    $usermoney = $userpoint = $userbym = $postamount = $login_status = 0;
    add_guest();
} 
// Check permission
if ($usertype[22] == 1 && $login_status == 1) error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Ban IP&ID
idbanned();
ipbanned();

$log_hash = substr(md5($password.$userid), 0, 6);

// -------------- Processed Time ------------
function micro_time()
{
    preg_match('/^0(\\.\d+) (\d+)$/', microtime(), $tmp);
    return (real)$tmp[2] . $tmp[1];
} 
// ---------Display the Message Table-------------------
function msg_box($title, $content, $showtips = '1')
{
    global $bm_skin, $pgo, $temfilename, $gl;
    
    if ($showtips) {
        $msg_box_title = "$gl[375] $title";
        $msg_box_detail = "$gl[376] {$title} $gl[377]<br /><br />";
    } else {
    	$msg_box_title = "$title";
    }
    require("newtem/$temfilename/global.php");
    
    echo $pgo[0];
} 
// +------------------------------------------------------------------------------------------------------
// ---------Display the Navigation Bar-------------------
function navi_bar($des = "", $l2 = "", $l3 = "", $echorefresh = "yes", $nolimit = "1")
{
    global $bbs_title, $pgo, $fjsjump, $echonaved, $snavi_bar_url, $snavi_bar, $otherimages, $navimode;
    if ($nolimit == 0 && $echonaved == 1) return;
    $echonaved = 1;
    $closepic = "<a href=\"$site_url\"><img border=\"0\" src=\"$otherimages/system/closedfold.gif\" alt=\"$site_name\" /></a>";
    $openpic = " &gt;&gt; ";
    $barpic = "";
    $space = "";
    if (empty($des)) global $des;
    $count = count($snavi_bar);
    if ($fjsjump) $fjsjump_t = "onmouseover=\"showmenu(event,linkset[0],0);\" onmouseout=\"delayhidemenu();\"";
    print $pgo[4] . $space . $closepic . "<a href=\"index.php\" $fjsjump_t>$bbs_title</a>";
    if ($l3) $l2pic = $closepic;
    else $l2pic = $openpic;
    if ($navimode == newmode) {
        for ($i = 0; $i < $count; $i++) {
            echo $space . $barpic . $openpic;
            if (!empty($snavi_bar_url[$i])) echo "<a href=\"$snavi_bar_url[$i]\">$snavi_bar[$i]</a>";
            else echo $snavi_bar[$i];
        } 
    } else {
        echo $space . $barpic . $openpic . "$l2";
        if ($l3) echo $space . $space . $barpic . $openpic . $l3;
    } 
    print $pgo[5] . $des;
    echo $pgo[6];
} 
// +------------------------------------------------------------------------------------------------------
// +-----------read & write------------
function readfromfile($file_name)
{
    if (file_exists($file_name)) {
    	if (PHP_VERSION >= "4.3.0") return file_get_contents($file_name);
        $filenum = fopen($file_name, "r");
        flock($filenum, LOCK_SH);
        $file_data = @fread($filenum, @filesize($file_name));
        fclose($filenum);
        return $file_data;
    } 
} 
function writetofile($file_name, $data, $method = "w")
{
	global $usertype, $gl;
	
    $filenum = fopen($file_name, $method);
    flock($filenum, LOCK_EX);
    if ($usertype[22] == 1) {
    	if (!($file_data = fwrite($filenum, $data)) && !empty($data)) {
    		echo "<span style='color:red;font-weight:bold;'>$gl[514] $file_name</span>";
    	}
    } else {
    	$file_data = fwrite($filenum, $data);
    }
    fclose($filenum);
    return $file_data;
} 
function big_write($file_name, $buf, $length = -1) 
{
	global $usertype, $gl;

    $ret = 0;
    
    if ($length < 0) $length = strlen($buf);
    
    $fd = @fopen($file_name, "r+");
    if (!$fd) $fd = @fopen($file_name, "w");
    if (!$fd) return $ret;

    flock($fd, LOCK_EX);
    fseek($fd, 0, SEEK_SET);
    if (@fwrite($fd, $buf, $length)) {
        ftruncate($fd, $length);
        $ret = 1;
    }elseif ($usertype[22] == 1 && $length > 0) {
    	echo "<span style='color:red;font-weight:bold;'>$gl[514] $file_name</span>";
    }
    flock($fd, LOCK_UN);
    fclose($fd); 
    return $ret;
}
// +------------------------------------------------------------------------------------------------------
// Check Permission of forum
function check_permission($user, $type)
{
    global $usertype, $login_status, $forum_admin, $detail;
    if ($type == 'forum' || $type == 'subforum') return 1;
    if ($login_status == 1 && ($type == 'former' || $type == 'subformer')) return 1;
    if ($login_status == 1 && ($type == 'forumhid' || $type == 'subforumhid')) return 1;
    if ($login_status == 1 && $usertype[22] == "1") return 1;
    if ($login_status == 1 && $usertype[24] == "1" && ($forum_admin && in_array($user, $forum_admin))) return 1;
    if ($login_status == 1 && $usertype[21] == "1") return 1;
    if ($login_status == 1 && $usertype[12] == "1" && ($type == "locked" || $type == "sublocked" || $type == "hidden" || $type == "subhidden")) return 1;
    return 0;
} 
// +------------------------------------------------------------------------------------------------------
// Get Forum Information from cache
function get_forum_info($nrow)
{
    global $info_forum, $levelgroupdata, $forum_name, $level_id, $plusug, $trashcount, $digestcount, $pincount, $todaypt, $forumscount, $sxfourmrow, $fcaterows, $lock_true, $ttopicnum, $a, $thisamount, $database_up, $clean_true, $aviewpost, $del_reply_true, $edit_true, $move_true, $copy_true, $ztop_true, $ctop_true, $uptop_true, $bold_true, $sej_true, $autorip_true, $ttop_true, $modcenter_true, $modano_true, $post_money_reply, $post_jifen_reply, $del_self_topic, $del_self_post, $modban_true, $p_read_post, $view_list, $groupname, $spusergroup, $canpost, $post_allow_ww, $re_allow_ww, $poll_allow_ww, $vote_allow_ww, $enter_allow_ww, $pri_allow_ww, $forum_allow_ww, $recy_allow_ww, $read_allow_ww, $down_attach, $down_attach_ww, $set_a_tags, $see_a_tags, $max_tags_num, $min_post_length, $max_post_title, $max_post_des, $browse_add_point, $login_status, $canreply, $canpoll, $canvote, $enter_this_forum, $max_post_length, $bmfcode_post, $max_upload_size, $upload_type_available, $mod, $max_upload_num, $html_codeinfo, $max_daily_upload_size, $logon_post_second, $post_sell_max, $del_true, $del_rec, $can_rec, $delrmb, $post_money, $deljifen, $post_jifen, $allow_upload, $max_upload_post, $allow_forb_ub, $forum_icon, $uginfo, $nopostpic, $postdontadd, $forum_upid, $forum_type, $guestpost, $noheldtop, $forum_ford, $forum_cid, $forumid, $forumlist, $forum_style, $forum_pwd, $can_visual_post;

    for($i = 0;$i < $forumscount;$i++) {
        if ($sxfourmrow[$i]['id'] == $forumid) {
            $detail = $sxfourmrow[$i];
            break;
        } 
    } 
    
    $info_forum = $detail;

    $forum_name = $detail['bbsname'];
    $forum_icon = $detail['forum_icon'];
    $forum_upid = $detail['blad'];
    $forum_type = $detail['type'];
    $forum_style = $detail['filename'];
    $forum_pwd = $detail['forumpass'];
    $forum_cid = $detail['forum_cid'];
    $guestpost = explode("_", $detail['guestpost']);
    $noheldtop = $guestpost[2];
    $nopostpic = $guestpost[1];
    $guestpost = $guestpost[0];
    $forum_ford = $detail['forum_ford'];
    $postdontadd = $detail['postdontadd'];
    $spusergroup = $detail['spusergroup'];
    $aviewpost = $detail['naviewpost'];
    $thisamount = $detail['topicnum'] + $detail['replysnum'];
    $ttopicnum = $detail['topicnum'];
    $fcaterows = $detail['caterows'];
    $todaypt = $detail['todaypt'];
    $pincount = $detail['pincount'];
    $posttrashcount = $detail['posttrash'];
    $trashcount = $detail['trashcount'];
    $digestcount = $detail['digestcount'];
    

	if ($forum_type == "jump" || $forum_type == "subjump") {
		header("Location: {$info_forum['jumpurl']}");
		exit;
	}

    if ($spusergroup == "1") {
        global $usertype;
        if ($login_status == 0) $uginfo = 6;
        $usergroupdata = explode("\n", $detail['usergroup']);
        if ($uginfo == 4) {
        	include_once("datafile/cache/levels/level_fid_{$forumid}.php");
        	if ($levelgroupdata[$forumid][$level_id]) {
        		$usertype = explode("|", $levelgroupdata[$forumid][$level_id]);
        	} else {
        		$usertype = explode("|", $usergroupdata[$uginfo]);
        	}
        } else {
        	$usertype = explode("|", $usergroupdata[$uginfo]);
        }
        if (is_array($plusug)) {
            $count = count($plusug);
            for ($i = 0; $i < $count; $i++){
            	if ($plusug[$i] == "" || $plusug[$i] == $uginfo) continue;
                $tmpusertype = explode("|", $usergroupdata["{$plusug[$i]}"]);
                $countut = count($tmpusertype);
                for ($s = 0; $s < $countut; $s++) {
                	if ($tmpusertype[$s] == 1 && $usertype[$s] == 0) $usertype[$s] = 1; 
                }
            }
        }

        list($groupname, , , $canpost, $canreply, $canpoll, $canvote, , , , , , $enter_this_forum, , $max_post_length, , , , , $max_upload_size, $upload_type_available, , , , $mod, $max_upload_num, $html_codeinfo, $max_daily_upload_size, $logon_post_second, $post_sell_max, $del_true, $del_rec, $can_rec, $delrmb, $post_money, $deljifen, $post_jifen, $allow_upload, $max_upload_post, , , , , , , , $p_read_post, $view_list, $lock_true, $del_reply_true, $edit_true, $move_true, $copy_true, $ztop_true, $ctop_true, $uptop_true, $bold_true, $sej_true, $autorip_true, $ttop_true, $modcenter_true, $modano_true, $modban_true, $clean_true, , $post_money_reply, $post_jifen_reply, $del_self_topic, $del_self_post, $bmfcode_post['pic'], $bmfcode_post['reply'], $bmfcode_post['jifen'], $bmfcode_post['sell'], $bmfcode_post['flash'], $bmfcode_post['mpeg'], $bmfcode_post['iframe'], $bmfcode_post['fontsize'], $bmfcode_post['hpost'], $bmfcode_post['hmoney'], $allow_forb_ub, $can_visual_post, $member_list, $search_fun, $nwpost_list, $porank_list, $gvf, $see_amuser, $view_recybin, $post_allow_ww, $re_allow_ww, $poll_allow_ww, $vote_allow_ww, $enter_allow_ww, $pri_allow_ww, $forum_allow_ww, $recy_allow_ww, $read_allow_ww, $down_attach, $down_attach_ww, $set_a_tags, $see_a_tags, $max_tags_num, $min_post_length, $max_post_title, $max_post_des, $browse_add_point) = $usertype;
    } 
} 
// +------------------------------------------------------------------------------------------------------
// +------------Display the Jump-page---------------
function jump_page($URL, $title, $content, $type = 1)
{
    global $bm_skin, $username, $usertype, $_SESSION, $verandproname, $otherimages, $bbs_title, $add_title, $cssinfo, $login_status, $usertype, $ads_select, $admin_email, $site_url, $showtime, $site_name, $writefilenum, $readfilenum, $begin_time, $temfilename, $gl, $plugyescolor;
    $jumppagetrue = "yes";
    if ($title) $add_title = " &gt; " . $title;
    require("newtem/$temfilename/global.php");
    echo $pgo[7].$pgo[$type];
    exit;
} 
// +------------------------------------------------------------------------------------------------------
// +---------Ban some IP&IDs---------------

function idbanned()
{
    global $username, $id_bannedmembers, $gl, $encode_info, $bannedip;
    if (!file_exists("datafile/idbans.php")) return;
    $id_bannedmembers = file("datafile/idbans.php");
    if (empty($id_bannedmembers)) return;
    $count = count($id_bannedmembers);
    for ($i = 0; $i < $count; $i++) {
        $bannedid = trim($id_bannedmembers[$i]);
        if (!$bannedid) continue;
        if ($username == $bannedid) {
			$no_allow = 1;
            break;
        } 
    } 

    
    if ($no_allow == 1) {
    	@header("Content-Type: $encode_info");
        print ($gl[378]);
        exit;
    }
} 
function ipbanned()
{
    global $ip, $term_bannedmembers, $gl, $encode_info, $bannedip;
    if (!file_exists("datafile/ipbans.php")) return;
    $term_bannedmembers = file("datafile/ipbans.php");
    if (empty($term_bannedmembers)) return;
    $count = count($term_bannedmembers);
    for ($i = 0; $i < $count; $i++) {
        $bannedip = trim($term_bannedmembers[$i]);
        if (!$bannedip) continue;
        if (strpos($ip , $bannedip) === 0) {
        	@header("Content-Type: $encode_info");
            print ($gl[379]);
            exit;
        } 
    } 
} 
// +------------------------------------------------------------------------------------------------------
// +-----------User functions---------------------
function get_user_portait($usericon, $swf = "")
{
    $portait = explode('%', $usericon);
    if (empty($usericon)) return '';
    $swfyes = "swf";
    if ($portait[1] && $portait[2] && $portait[3]) {
        if (eregi("\.\\$swfyes$", $portait[1]) && $swf) {
            return "<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=$portait[2] height=$portait[3]><PARAM NAME=movie VALUE='$portait[1]'><PARAM NAME=quality VALUE=high><embed src='$portait[1]' quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=$portait[2] height=$portait[3]>$portait[1]</embed></OBJECT>";
        } else {
            $nameuri = urlencode($portait[1]);
            $nameuri = str_replace("%2F", "/", $nameuri);
            $nameuri = str_replace("%3A", ":", $nameuri);
            $nameuri = str_replace("%3F", "?", $nameuri);
            $nameuri = str_replace("%3F", "?", $nameuri);
            $nameuri = str_replace("%3D", "=", $nameuri);
            $nameuri = str_replace("%26", "&", $nameuri);
            return "<img src='$nameuri' width='$portait[2]' alt='' height='$portait[3]' border='0' />";
        } 
    } else {
        return "<img src='images/avatars/$portait[0]' alt='' border='0' />";
    } 
} 
// ----------- Get Members' Info ----------
function getUserInfo()
{
    global $username, $levelgroupdata, $plusug, $activestatus, $baoliu1, $lock_true, $userpoint, $gotNewMessage, $sguiresult, $runned, $userid, $userddata, $thisavarts, $foreuser, $hisipc, $clastupload, $uploadfiletoday, $hisipb, $hisipa, $database_up, $usergroupdata, $logonutnum, $del_reply_true, $edit_true, $move_true, $copy_true, $ztop_true, $ctop_true, $uptop_true, $bold_true, $sej_true, $autorip_true, $ttop_true, $modcenter_true, $modano_true, $post_money_reply, $post_jifen_reply, $del_self_topic, $del_self_post, $modban_true, $clean_true, $showpic, $p_read_post, $view_list, $allow_upload, $uginfo, $max_upload_post, $allow_forb_ub, $opencutusericon, $openupusericon, $max_avatars_upload_size, $max_avatars_upload_post, $upload_avatars_type_available, $maxwidth, $maxheight, $delrmb, $post_money, $deljifen, $post_jifen, $del_true, $del_rec, $can_rec, $regdate, $post_sell_max, $html_codeinfo, $_SESSION, $_COOKIE, $postamount, $max_upload_num, $userbym, $usermoney, $post_allow_ww, $re_allow_ww, $poll_allow_ww, $vote_allow_ww, $enter_allow_ww, $pri_allow_ww, $forum_allow_ww, $recy_allow_ww, $read_allow_ww, $down_attach, $down_attach_ww, $set_a_tags, $see_a_tags, $max_tags_num, $min_post_length, $max_post_title, $max_post_des, $browse_add_point, $level, $canpost, $canreply, $canpoll, $canvote, $max_sign_length, $send_msg_max, $sign_use_bmfcode, $bmfcode_sign, $enter_tb, $send_msg, $max_post_length, $bmfcode_post, $short_msg_max, $use_own_portait, $swf, $max_upload_size, $upload_type_available, $id_unique, $usertype, $max_daily_upload_size, $logon_post_second, $can_visual_post, $member_list, $search_fun, $nwpost_list, $porank_list, $gvf, $see_amuser, $view_recybin;

	$userid = $_SESSION['bmforumerboardidnum'] ? $_SESSION['bmforumerboardidnum'] : $_COOKIE['bmforumerboardidnum'];

    if ($userid != "") {
        if ($runned == 1) {
            $row = $sguiresult;
        } else {
            $runned = 1;
            $query = "SELECT * FROM {$database_up}userlist WHERE userid='$userid' LIMIT 0,1";
            $result = bmbdb_query($query);
            $sguiresult = bmbdb_fetch_array($result);
            $row = $sguiresult;
        } 
        $username = $row['username'];
        $gotNewMessage = $row['newmess'];
        $regdate = $row['regdate'];
        $thisavarts = $row['avarts'];
        $postamount = $row['postamount'];
        $userbym = $row['point'];
        $userpoint = floor($userbym / 10);
        $userid = $row['userid'];
        $usermoney = $row['money'];
        $usertype = $row['ugnum'];
        $baoliu1 = $row['baoliu1'];
        $activestatus = $row['activestatus'];
        $userddata = $row;

        $uploadfiletoday = $row['uploadfiletoday'];
        $clastupload = $row['lastupload'];
        $foreuser = $row['foreuser'];
        $hisipc = $row['hisipc'];
        $hisipb = $row['hisipb'];
        $hisipa = $row['hisipa'];
        
        $logonutnum = $uginfo = $usertype;
        

        if ($usertype == 4) {
        	global $level_id;
        	
        	include_once("datafile/cache/levels/level_fid_0.php");
        	$level = getUserLevel($postamount, $userbym, $username, $logonutnum);
        	$usertype = explode("|", $levelgroupdata[0][$level_id]); 
        } else {
        	$usertype = explode("|", $usergroupdata[$usertype]); 
        }
        
        if ($row['baoliu1'] && $row['baoliu1'] != ",") {
            $plusug = explode(",", $row['baoliu1']);
            $count = count($plusug);
            for ($i = 0; $i < $count; $i++){
            	if ($plusug[$i] == "" || $plusug[$i] == $uginfo) continue;
                $tmpusertype = explode("|", $usergroupdata["{$plusug[$i]}"]);
                $countut = count($tmpusertype);
                for ($s = 0; $s < $countut; $s++) { if ($tmpusertype[$s] == 1 && $usertype[$s] == 0) $usertype[$s] = 1; }
            }
        }
        
        list($groupname, $groupimg, $systemg, $canpost, $canreply, $canpoll, $canvote, $max_sign_length, $sign_use_bmfcode, $bmfcode_sign['pic'], $bmfcode_sign['flash'], $bmfcode_sign['fontsize'], $enter_tb, $send_msg, $max_post_length, $short_msg_max, $send_msg_max, $use_own_portait, $swf, $max_upload_size, $upload_type_available, $supermod, $admin, $groupimg2, $mod, $max_upload_num, $html_codeinfo, $max_daily_upload_size, $logon_post_second, $post_sell_max, $del_true, $del_rec, $can_rec, $delrmb, $post_money, $deljifen, $post_jifen, $allow_upload, $max_upload_post, $opencutusericon, $openupusericon, $max_avatars_upload_size, $max_avatars_upload_post, $upload_avatars_type_available, $maxwidth, $maxheight, $p_read_post, $view_list, $lock_true, $del_reply_true, $edit_true, $move_true, $copy_true, $ztop_true, $ctop_true, $uptop_true, $bold_true, $sej_true, $autorip_true, $ttop_true, $modcenter_true, $modano_true, $modban_true, $clean_true, $showpic, $post_money_reply, $post_jifen_reply, $del_self_topic, $del_self_post, $bmfcode_post['pic'], $bmfcode_post['reply'], $bmfcode_post['jifen'], $bmfcode_post['sell'], $bmfcode_post['flash'], $bmfcode_post['mpeg'], $bmfcode_post['iframe'], $bmfcode_post['fontsize'], $bmfcode_post['hpost'], $bmfcode_post['hmoney'], $allow_forb_ub, $can_visual_post, $member_list, $search_fun, $nwpost_list, $porank_list, $gvf, $see_amuser, $view_recybin, $post_allow_ww, $re_allow_ww, $poll_allow_ww, $vote_allow_ww, $enter_allow_ww, $pri_allow_ww, $forum_allow_ww, $recy_allow_ww, $read_allow_ww, $down_attach, $down_attach_ww, $set_a_tags, $see_a_tags, $max_tags_num, $min_post_length, $max_post_title, $max_post_des, $browse_add_point) = $usertype;
    } 
} 
function getLevelGroup($ugid, $usergroupdata, $forumid, $postamount, $userbym, $p_lid = "") 
{
	global $levelgroupdata, $level_id, $spusergroup;
	
	if ($spusergroup != 1) $forumid = 0;
	
	include_once("datafile/cache/levels/level_fid_$forumid.php");
	
	$forumid = $forumid ? $forumid : 0;

	if ($ugid == 4) {
       	if (!$p_lid) {
       		$level = getUserLevel($postamount, $userbym, "", $ugid);
       	} else $level_id = $p_lid;
       	
       	$author_type = explode("|", $levelgroupdata[$forumid][$level_id]); 

	} else {
		$author_type = explode("|", $usergroupdata[$ugid]);
	}
	
	return $author_type;
}
// ------------- Members' Level Title
function getUserLevel($amount, $score, $username, $usertype = "")
{
    global $mtitle, $mgraphic, $modgraphic, $admingraphic, $supmodgraphic, $level_score_mode, $level_id, $level_score_php, $mpostmark, $countmtitle, $usergroupdata, $admintitle, $id_unique, $motitle, $supmotitle;
	include_once("datafile/usertitle.php");
    
    $level_id = 0;
    
    $usertype = explode("|", $usergroupdata[$usertype]);
    $user_level = $mtitle[a0];
    
    if ($level_score_mode == 1) $amount = $score / 10;
    elseif ($level_score_mode == 2) {
    	$score = $score / 10;
        eval($level_score_php);
    }
    $count = $countmtitle;

    for ($i = 1; $i < $count; $i++) {
        $ia = "a" . $i;
        if ($mpostmark[$ia] && $amount >= $mpostmark[$ia]) {
        	$user_level = $mtitle[$ia];
        	$level_id = $i;
        }
    } 
    
	if ($motitle && $usertype[24] == "1") $user_level = $motitle;
	if ($supmotitle && $usertype[21] == "1") $user_level = $supmotitle;
	if ($admintitle && $usertype[22] == "1") $user_level = $admintitle;

    return $user_level;
} 
// ------------------ Members' Level Picture
function getUserIcon($amount, $score, $username, $usertype = "")
{
    global $mgraphic, $motitle, $supmotitle, $admintitle, $level_score_mode, $level_score_php, $mpostmark, $countmtitle, $usergroupdata, $admingraphic, $id_unique, $modgraphic, $supmodgraphic;
	include_once("datafile/usertitle.php");

    $usertype = explode("|", $usergroupdata[$usertype]);
    $usericon = $mgraphic[a0];
    
    if ($level_score_mode == 1) $amount = $score / 10;
    elseif ($level_score_mode == 2) {
    	$score = $score / 10;
        eval($level_score_php);
    }
    
    $count = $countmtitle;
    for ($i = 1; $i < $count; $i++) {
        $ia = "a" . $i;
        if ($mpostmark[$ia] && $amount >= $mpostmark[$ia]) $usericon = $mgraphic[$ia];
    } 
    
	if ($modgraphic && $usertype[24] == "1") $usericon = $modgraphic;
	if ($supmodgraphic && $usertype[21] == "1") $usericon = $supmodgraphic;
	if ($admingraphic && $usertype[22] == "1") $usericon = $admingraphic; 

    return $usericon;
} 
// ---------------- Get Members' Info From Database
function get_user_info($user, $type = "username")
{
    global $database_up, $userinfocache, $userinfocache_id;
    if (empty($user)) return;
    if ($type == "username") {
        $query = "SELECT * FROM {$database_up}userlist WHERE username='$user' LIMIT 0,1";
    } elseif ($type == "usrid") {
        $query = "SELECT * FROM {$database_up}userlist WHERE userid='$user' LIMIT 0,1";
    } 
    
    if ((!is_array($userinfocache[$user]) && $type == "username") || (!is_array($userinfocache_id[$user]) && $type == "usrid")) {
        $result = bmbdb_query($query, 0);
        $userinfo = bmbdb_fetch_array($result);
        $userinfocache_id["{$userinfo['userid']}"] = $userinfo;
        $userinfocache["{$userinfo['username']}"] = $userinfo;
    } else {
        if (is_array($userinfocache[$user]) && $type == "username") $userinfo = $userinfocache[$user];
        elseif (is_array($userinfocache_id[$user]) && $type == "usrid")  $userinfo = $userinfocache_id[$user];
    } 
    return $userinfo;
} 
// --------------- Check if member is exists.
function check_user_exi($user, $nametype = 0)
{
    global $database_up;
    if (empty($user)) return 0;
    $query = "SELECT COUNT(*) FROM {$database_up}userlist WHERE ".($nametype == 1 ? "userid" : "username")."='$user'  LIMIT 0,1";
    $result = bmbdb_query($query, 0);
    $fcount = bmbdb_fetch_array($result);
    $row = $fcount['COUNT(*)'];
    return $row;
} 
// ------------- Check the member if online
function check_online($username)
{
    global $new_online_user, $online_limit, $timestamp;

    if (empty($new_online_user)) $new_online_user = readfromfile("datafile/online.php");
    if (strstr($new_online_user ,"//|$username")) return 1;
    else return 0;
} 
// ----------------- Check Name and Password
function checkpass($username, $password, $userid = "")
{
    global $database_up, $userinfocache, $userinfocache_id, $user_check_id;

    if ((!is_array($userinfocache[$username]) && !$userid) || (!is_array($userinfocache_id[$userid]) && $userid)) {
    	if ($userid) $query = "SELECT * FROM {$database_up}userlist WHERE userid='$userid' LIMIT 0,1";
    	else $query = "SELECT * FROM {$database_up}userlist WHERE username='$username' LIMIT 0,1";
    	
        $result = bmbdb_query($query);
        $userinfo = bmbdb_fetch_array($result);
        $user_check_id = $userinfo['userid'];
        $userinfocache_id[user_check_id] = $userinfo;
        $userinfocache[$username] = $userinfo;
    } else {
    	if ($username) $userinfo = $userinfocache[$username];
    	    else  $userinfo = $userinfocache_id[$userid];
        $user_check_id = $userinfo['userid'];
    } 
    if ($password == $userinfo['pwd']) return 1;
    else return 0;
} 
// +-------------Online Functions------------------
// -----Add members to online file--------
function add_online($nodelay = 0)
{
    global $privacy, $rcordosbr, $new_online_user, $_SESSION, $logonutnum, $_COOKIE, $browseinfo, $osinfo, $username, $timestamp, $ip, $online_limit, $gl, $filename, $forumid;
    if (defined('onlinedelay') && $nodelay != 1) return;
    $onlinefile = "datafile/online.php";
    if ($_COOKIE['privacybym']) $prioption = "yes";

    if ($username != "") {
        if (!$forumid || strlen($forumid)>15) $forumid = 0;
        if (file_exists($onlinefile)) {
            $online_user = file($onlinefile);
            $online_user_content = implode("", $online_user);
            // find the member information line number
            $online_user_count = count($online_user);
            $find_this_user = stristr($online_user_content, "|$username|");
            $below_count = count(explode("\n", $find_this_user));
            $member_line = $online_user_count - $below_count + 1;
            unset($online_user[$member_line]);

            for($i = 0; $i < $online_user_count; $i++) {
                $online_user_detail = explode("|", $online_user[$i]);
                if ($timestamp - $online_user_detail[2] <= $online_limit && $online_user_detail[2] <= $timestamp) break;
                    else unset($online_user[$i]);
            } 
            if ($rcordosbr) {
                $browseinfo = browseinfo();
                $osinfo = osinfo();
            } 
            
            $online_user[]= "<?php //$prioption|$username|$timestamp|$ip|f|$forumid|$browseinfo|$osinfo|t|$filename|$logonutnum|$prioption|\n";
            $new_online_user = implode("", $online_user);

        } else {
            if ($rcordosbr) {
                $browseinfo = browseinfo();
                $osinfo = osinfo();
            } 
            $new_online_user = "<?php //$prioption|$username|$timestamp|$ip|f|$forumid|$browseinfo|$osinfo|t|$filename|$logonutnum|$prioption|\n";
        } 
        big_write($onlinefile, $new_online_user);
    } 
} 
// +-----------add guests to online file-----------------
function add_guest($nodelay = 0)
{
    global $timestamp, $usertype, $post_allow_ww, $re_allow_ww, $poll_allow_ww, $vote_allow_ww, $enter_allow_ww, $pri_allow_ww, $forum_allow_ww, $recy_allow_ww, $read_allow_ww, $down_attach, $down_attach_ww, $set_a_tags, $see_a_tags, $max_tags_num, $min_post_length, $max_post_title, $max_post_des, $browse_add_point, $ip, $rcordosbr, $usergroupdata, $browseinfo, $logonutnum, $gl, $osinfo, $online_limit, $filename, $forumid, $groupname, $groupimg, $systemg, $canpost, $canreply, $canpoll, $canvote, $max_sign_length, $sign_use_bmfcode, $bmfcode_sign, $enter_tb, $send_msg, $max_post_length, $bmfcode_post, $short_msg_max, $send_msg_max, $use_own_portait, $swf, $member_list, $search_fun, $nwpost_list, $porank_list, $gvf, $see_amuser, $view_recybin, $max_upload_size, $upload_type_available, $supermod, $admin, $groupimg2, $mod, $max_upload_num, $html_codeinfo, $max_daily_upload_size, $logon_post_second, $post_sell_max, $del_true, $del_rec, $can_rec, $delrmb, $post_money, $deljifen, $post_jifen, $allow_upload, $max_upload_post, $opencutusericon, $openupusericon, $max_avatars_upload_size, $max_avatars_upload_post, $upload_avatars_type_available, $maxwidth, $maxheight, $p_read_post, $view_list, $lock_true, $del_reply_true, $edit_true, $move_true, $copy_true, $ztop_true, $ctop_true, $uptop_true, $bold_true, $sej_true, $autorip_true, $ttop_true, $modcenter_true, $modano_true, $modban_true, $clean_true, $showpic, $post_money_reply, $post_jifen_reply, $del_self_topic, $del_self_post, $can_visual_post;

    if (defined('onlinedelay') && $nodelay != 1) return;
    
    $onlinefile = "datafile/guest.php";
    if (!$forumid || strlen($forumid)>15) $forumid = 0;
    if (file_exists($onlinefile)) {
        $online_user = file($onlinefile);
        $online_user_content = implode("", $online_user);
        // find the guest information line number
        $online_user_count = count($online_user);
        $find_this_user = stristr($online_user_content, "|$ip|");
        $below_count = count(explode("\n", $find_this_user));
        $member_line = $online_user_count - $below_count + 1;

        unset($online_user[$member_line]);

        for($i = 0; $i < $online_user_count; $i++) {
            $online_user_detail = explode("|", $online_user[$i]);
            if ($timestamp - $online_user_detail[2] <= $online_limit && $online_user_detail[2] <= $timestamp) break;
                else unset($online_user[$i]);
        } 
        
        if ($rcordosbr) {
            $browseinfo = browseinfo();
            $osinfo = osinfo();
        } 
        
        $online_user[]= "<?php //|$gl[174]|$timestamp|$ip|f|$forumid|$browseinfo|$osinfo|t|$filename|\n";
        $new_online_user = implode("", $online_user);
    } else {
        if ($rcordosbr) {
            $browseinfo = browseinfo();
            $osinfo = osinfo();
        } 
        $new_online_user = "<?php //|$gl[174]|$timestamp|$ip|f|$forumid|$browseinfo|$osinfo|t|$filename|";
    } 
    $logonutnum = 6;
    $usertype = explode("|", $usergroupdata[6]);
    list($groupname, $groupimg, $systemg, $canpost, $canreply, $canpoll, $canvote, $max_sign_length, $sign_use_bmfcode, $bmfcode_sign['pic'], $bmfcode_sign['flash'], $bmfcode_sign['fontsize'], $enter_tb, $send_msg, $max_post_length, $short_msg_max, $send_msg_max, $use_own_portait, $swf, $max_upload_size, $upload_type_available, $supermod, $admin, $groupimg2, $mod, $max_upload_num, $html_codeinfo, $max_daily_upload_size, $logon_post_second, $post_sell_max, $del_true, $del_rec, $can_rec, $delrmb, $post_money, $deljifen, $post_jifen, $allow_upload, $max_upload_post, $opencutusericon, $openupusericon, $max_avatars_upload_size, $max_avatars_upload_post, $upload_avatars_type_available, $maxwidth, $maxheight, $p_read_post, $view_list, $lock_true, $del_reply_true, $edit_true, $move_true, $copy_true, $ztop_true, $ctop_true, $uptop_true, $bold_true, $sej_true, $autorip_true, $ttop_true, $modcenter_true, $modano_true, $modban_true, $clean_true, $showpic, $post_money_reply, $post_jifen_reply, $del_self_topic, $del_self_post, $bmfcode_post['pic'], $bmfcode_post['reply'], $bmfcode_post['jifen'], $bmfcode_post['sell'], $bmfcode_post['flash'], $bmfcode_post['mpeg'], $bmfcode_post['iframe'], $bmfcode_post['fontsize'], $bmfcode_post['hpost'], $bmfcode_post['hmoney'], $allow_forb_ub, $can_visual_post, $member_list, $search_fun, $nwpost_list, $porank_list, $gvf, $see_amuser, $view_recybin, $post_allow_ww, $re_allow_ww, $poll_allow_ww, $vote_allow_ww, $enter_allow_ww, $pri_allow_ww, $forum_allow_ww, $recy_allow_ww, $read_allow_ww, $down_attach, $down_attach_ww, $set_a_tags, $see_a_tags, $max_tags_num, $min_post_length, $max_post_title, $max_post_des, $browse_add_point) = $usertype;
    big_write($onlinefile, $new_online_user);
} 
// +------------------------------------------------------------------------------------------------------
// +----------kick out the dangerous Char---------
function safe_convert($d, $replace = 0, $visual = 0)
{
    global $html_codeinfo, $openhtmlcode;
    if ($html_codeinfo == "yes" && $openhtmlcode != "checkbox") {
        $d = str_replace("&lt;", "&bmbamplt;", $d);
        $d = str_replace("&gt;", "&bmbampgt;", $d);
    }
    $d = htmlspecialchars($d);
	
	if ($visual == 1) $d = str_replace("&amp;", "&", $d);
	
    $d = str_replace("&#", "&amp;#", $d);
    $d = str_replace("'", "&#039;", $d);
    $d = str_replace('"', "&quot;", $d);
    $d = str_replace("\t", "", $d);
    if ($html_codeinfo == "yes" && $openhtmlcode != "checkbox") {
    	if ($visual == 0) $d = str_replace("&amp;", "&", $d);
    	if ($replace == 0) {
            $d = str_replace("&#039;", "'", $d);
            $d = str_replace("&quot;", '"', $d);
            $d = str_replace("&quot;", "\"", $d);
	    }
        $d = str_replace("&lt;", "<", $d);
        $d = str_replace("&gt;", ">", $d);
        $d = str_replace("&bmbamplt;", "&lt;", $d);
        $d = str_replace("&bmbampgt;", "&gt;", $d);
        // for AJAX, replace special chars.
        $d = str_replace('bmbajaxpagebar', '_bmbajaxpagebar', $d);
    }
    $d = str_replace("\r", "<br />", $d);
    $d = str_replace("\n", "", $d);
    $d = str_replace("  ", " &nbsp;", $d);
    return $d;
} 
function restore_post_htmt($orcontent) 
{
	global $html_codeinfo, $openhtmlcode;
	
    $orcontent = str_replace("&#039;", "'", $orcontent);
    $orcontent = str_replace("&quot;", '"', $orcontent);
    $orcontent = str_replace("&quot;", "\"", $orcontent);
    if (!($html_codeinfo == "yes" && $openhtmlcode != "checkbox")) {
    	$orcontent = str_replace("&lt;", "<", $orcontent);
    	$orcontent = str_replace("&amp;", "&", $orcontent);
    	$orcontent = str_replace("&gt;", ">", $orcontent);
    }
    
    return $orcontent;
}
// +------------------------------------------------------------------------------------------------------
// +-------To see where the IP comes from------------------
function bmfwwz($user, $rmb, $jifen, $postn, $deltopic = "0", $delreply = "0" ,$mode = 0)
{
    global $database_up;
    if ($mode == 0) {
        $sqladd = "WHERE username='$user'";
    } else {
        $sqladd = "WHERE userid='$user'";
    }
    $nquery = "UPDATE {$database_up}userlist SET delreply=delreply+'$delreply',deltopic=deltopic+'$deltopic',postamount=postamount+'$postn',point=point+'$jifen',money=money+'$rmb' $sqladd";
    $result = bmbdb_query($nquery);
} 
// +--------------To tell the user's Browser--------------------------
function browseinfo()
{
    $browser = "";
    $browserver = "";
    $Browsers = array("Lynx", "MOSAIC", "AOL", "Opera", "JAVA", "MacWeb", "WebExplorer", "OmniWeb");
    $Agent = trim($_SERVER["HTTP_USER_AGENT"]);
    for ($i = 0; $i <= 7; $i++) {
        if (strpos($Agent, $Browsers[$i])) {
            $browser = $Browsers[$i];
            $browserver = "";
        } 
    } 
    if (ereg("Mozilla", $Agent) && !ereg("Netscape", $Agent)) {
        $temp = explode("(", $Agent);
        $Part = $temp[0];
        $S_Part = $temp[1];
        $temp = explode("/", $Part);
        $browserver = $temp[1];
        if (strstr($S_Part, "http://")) {
            $AS_Part = explode(")", $S_Part);
            $AS_Part_2 = explode(";", $AS_Part[0]);
            $browser = $AS_Part_2[1];
        } else {
            $temp = explode(";", $S_Part);
            $temp = explode(")", $temp[1]);
            $browser = $temp[0];
        } 
    } 
    if (ereg("Mozilla", $Agent) && ereg("Opera", $Agent)) {
        $temp = explode("(", $Agent);
        $Part = $temp[1];
        $temp = explode(")", $Part);
        $browserver = $temp[1];
        $temp = explode(" ", $browserver);
        $browserver = $temp[2];
        $browserver = preg_replace("/([\d\.]+)/", "\\1", $browserver);
        $browserver = $browserver;
        $browser = "Opera";
    } 
    if (ereg("Firefox", $Agent)) {
        $temp = explode("Firefox/", $Agent);
        $browserver = $temp[1];
        $browserver = $browserver;
        $browser = "Firefox";
    } 
    if (ereg("Mozilla", $Agent) && ereg("MSIE", $Agent) && !ereg("Opera", $Agent)) {
        $temp = explode("(", $Agent);
        $Part = $temp[1];
        $temp = explode(";", $Part);
        $Part = $temp[1];
        $temp = explode(" ", $Part);
        $browserver = $temp[2];
        $browserver = preg_replace("/([\d\.]+)/", "\\1", $browserver);
        $browserver = $browserver;
        $browser = "Internet Explorer";
    } 
    if ($browser != "") {
        $browseinfo = "$browser $browserver";
    } else {
        $browseinfo_t = explode("(", $Agent);
        $browseinfo = $browseinfo_t[0];
    } 
    $browseinfo = str_replace('|', '', safe_convert($browseinfo));
    if (strlen($browseinfo)>50) $browseinfo = substr($browseinfo, 0, 20);
    return $browseinfo;
} 
// -----------------To tell the User's OS------------------------
function osinfo()
{
    $os = "";
    $Agent = trim($_SERVER["HTTP_USER_AGENT"]);
    if (eregi('win', $Agent) && strpos($Agent, '95')) {
        $os = "Windows 95";
    } elseif (eregi('win 9x', $Agent) && strpos($Agent, '4.90')) {
        $os = "Windows ME";
    } elseif (eregi('win', $Agent) && ereg('98', $Agent)) {
        $os = "Windows 98";
    } elseif (eregi('win', $Agent) && eregi('nt 5\.0', $Agent)) {
        $os = "Windows 2000";
    } elseif (eregi('win', $Agent) && eregi('nt 5\.1', $Agent)) {
        $os = "Windows XP";
    } elseif (eregi('win', $Agent) && eregi('nt 5\.2', $Agent)) {
        $os = "Windows 2003";
    } elseif (eregi('win', $Agent) && eregi('nt 6\.0', $Agent)) {
        $os = "Windows Vista";
    } elseif (eregi('win', $Agent) && eregi('nt', $Agent)) {
        $os = "Windows NT";
    } elseif (eregi('win', $Agent) && ereg('32', $Agent)) {
        $os = "Windows 32";
    } elseif (eregi('linux', $Agent)) {
        $os = "Linux";
    } elseif (eregi('unix', $Agent)) {
        $os = "Unix";
    } elseif (eregi('sun', $Agent) && eregi('os', $Agent)) {
        $os = "SunOS";
    } elseif (eregi('ibm', $Agent) && eregi('os', $Agent)) {
        $os = "IBM OS/2";
    } elseif (eregi('Mac', $Agent) && eregi('PC', $Agent)) {
        $os = "Macintosh";
    } elseif (eregi('PowerPC', $Agent)) {
        $os = "PowerPC";
    } elseif (eregi('AIX', $Agent)) {
        $os = "AIX";
    } elseif (eregi('HPUX', $Agent)) {
        $os = "HPUX";
    } elseif (eregi('NetBSD', $Agent)) {
        $os = "NetBSD";
    } elseif (eregi('BSD', $Agent)) {
        $os = "BSD";
    } elseif (ereg('OSF1', $Agent)) {
        $os = "OSF1";
    } elseif (ereg('IRIX', $Agent)) {
        $os = "IRIX";
    } elseif (eregi('FreeBSD', $Agent)) {
        $os = "FreeBSD";
    } 
    if ($os == '') {
        $os_t = explode("(", $Agent);
        $os = $os_t[0];
    } 
    $os = str_replace('|', '', safe_convert($os));
    
    if (strlen($os)>50) $os = substr($os, 0, 20);
    return $os;
} 
// +----------------------------------------------------------------------
// +--------Date & Time Functions-----------------------------------------
// ------- GMT is base time - Full Date
function get_date_chi($datetime)
{
    global $minoffset, $time_1, $time_f;
    $datetime = $datetime + ($time_1 * 60 * 60);
    return gmdate("$time_f ", $datetime);
} 
// ------ xxxx Minutes ago. Later time.
function get_add_date($datetime)
{
    global $time_1, $gl;
    
    $datetime = $datetime + ($time_1 * 60 * 60);
    $timetmp_a = explode("|", gmdate("j|s|i|G|n", $datetime));
    $mday = $timetmp_a[0] - 1;
    $seconds = $timetmp_a[1] + 0;
    $minutes = $timetmp_a[2] + 0;
    $hours = $timetmp_a[3] - $time_1;
    $mon = $timetmp_a[4];

    if ($seconds < 60 && empty($minutes) && empty($hours) && empty($mday) && $mon < 2) {
        return "1 $gl[444]";
    } elseif ($minutes < 60 && empty($hours) && empty($mday) && $mon < 2) {
        return "$minutes $gl[444]";
    } elseif ($hours < 24 && empty($mday) && $mon < 2) {
        return "$hours $gl[445]";
    } elseif ($mday < 7 && $mon < 2) {
        return "$mday $gl[446]";
    } elseif ($mday < 14 && $mday >= 7 && $mon < 2) {
        return "1 $gl[447]";
    } elseif ($mday < 21 && $mday >= 14 && $mon < 2) {
        return "2 $gl[447]";
    } elseif ($mday < 28 && $mday >= 21 && $mon < 2) {
        return "3 $gl[447]";
    } else {
        return "getfulldate";
    } 
} 
// ------- Full date and time
function getfulldate($datetime)
{
    global $minoffset, $time_1, $time_f;
    $datetime = $datetime + ($time_1 * 60 * 60);
    return gmdate("$time_f H:i", $datetime);
} 
// ------- Full Time
function get_time($datetime)
{
    global $minoffset, $time_1;
    $datetime = $datetime + ($time_1 * 60 * 60);
    return gmdate("H:i", $datetime);
} 
// Full Date
function get_date($datetime)
{
    global $minoffset, $time_1, $time_f;
    $datetime = $datetime + ($time_1 * 60 * 60);
    return gmdate("$time_f", $datetime);
} 
// -------- Check the post Hidden info
function checkhiden($code, $type = "")
{
    global $code4, $username, $userbym, $postamount, $usermoney, $qbgcolor, $id_unique, $usertype, $login_status, $author, $check_sup, $forum_admin1, $otherimages, $bcode_post;
    $code4 = 0;
    if ($bcode_post['jifen'] || ($type == "hpost" && $bcode_post['hpost']) || ($type == "hmoney" && $bcode_post['hmoney'])) {
        $code = stripslashes($code);
        $code = trim($code);
        if (ereg("^[0-9]{1,}$", $code)) {
            if ($login_status == 1) {
                if ($type == "hpost") {
                    $codeww = $postamount;
                } elseif ($type == "hmoney") {
                    $codeww = $usermoney;
                } else {
                    $codeww = floor($userbym / 10);
                } 
                if ($codeww >= $code || $username == $author || $usertype[22] == "1" || $usertype[21] == "1" || $check_sup == 1 || ($forum_admin1 && in_array($username, $forum_admin1))) $code4 = 1;
                else $code4 = 0;
            } else {
                $code4 = 0;
            } 
        } else {
            $code4 = 1;
        } 
    } 
} 
// ---- Check if the post need purchase and list the buyer lis
function checkpaid($code)
{
    global $username, $code14, $line, $bmfcode_post, $userid, $username, $login_status, $author, $usertype, $check_sup, $forum_admin1, $articlelist, $qbgcolor, $id_unique, $otherimages;
    if ($bmfcode_post['sell']) {
    	$code14 = 0;
        $buyeres = explode(',', $line['sellbuyer']);
        if ($username == $author || in_array($userid, $buyeres)) $code14 = 1;
    } else {
        $code14 = 1;
    } 
} 
// ---- Check if the post need replys and list the repliers lis
function checkpost($code)
{
    global $username, $code1, $userid, $replyerlist, $bmfcode_post, $username, $login_status, $author, $usertype, $check_sup, $forum_admin1, $articlelist, $qbgcolor, $id_unique, $otherimages;
    if ($bmfcode_post['reply']) {
        if ($login_status == 1 && ($username == $author || $usertype[22] == "1" || $usertype[21] == "1" || $check_sup == 1 || ($forum_admin1 && in_array($username, $forum_admin1)) || ($replyerlist && in_array($userid, $replyerlist)))) $code1 = 1;
        else $code1 = 0;
    } else {
        $code1 = 1;
    } 
} 

function error_page($info, $title, $msg_i, $msg_t, $nav_t = "", $nofooter = 0)
{
    global $closeforum, $spusergroup, $bm_skin, $footer_copyright, $headername, $footername, $read_alignment, $styleidcode, $html_lang, $enter_allow_ww, $enter_this_forum, $userpoint, $enter_tb, $plugyescolor, $usertype, $forum_type, $forumid, $username, $login_status, $limitlist, $forum_admin, $verandproname, $otherimages, $bbs_title, $add_title, $cssinfo, $login_status, $ads_select, $admin_email, $site_url, $showtime, $site_name, $writefilenum, $readfilenum, $begin_time, $temfilename, $gl;
    require("header.php");
	navi_bar($info, $title, $nav_t);
	msg_box($msg_i, $msg_t);
	if ($nofooter == 0) {
		if (defined("USERCP_LOGGED")) {
			$lang_zone = array("bm_skin"=>$bm_skin, "otherimages"=>$otherimages);
			$template_name['usercp_foot'] = newtemplate("usercp_foot", $temfilename, $styleidcode, $lang_zone);
			require($template_name['usercp_foot']);
		}
		require("footer.php");
		exit;
	}
}
function tbuser()
{
    global $closeforum, $spusergroup, $footer_copyright, $headername, $footername, $read_alignment, $html_lang, $enter_allow_ww, $enter_this_forum, $userpoint, $enter_tb, $plugyescolor, $usertype, $forum_type, $forumid, $username, $login_status, $limitlist, $forum_admin, $verandproname, $otherimages, $bbs_title, $add_title, $cssinfo, $login_status, $ads_select, $admin_email, $site_url, $showtime, $site_name, $writefilenum, $readfilenum, $begin_time, $temfilename, $gl;

    $limitlist = explode("|", $closeforum);
    $closecount = count($limitlist);
    for ($cf = 0;$cf < $closecount;$cf++) {
        if ($forumid == $limitlist[$cf] && $limitlist[$cf] <> "") {
            $thisforum = "limit";
        } 
    } 

    if ($thisforum == "limit") {
        $qqmm = 0;
        if ($usertype[21] == "1") $qqmm = 1;

        if ($login_status != 1 || $qqmm != 1) {
            require("datafile/pluginheader.php");
            require("newtem/". $headername);
            navi_bar($gl[382], $gl[383]);
            msg_box($gl[383], $gl[384]);
            require("newtem/". $footername);
            exit;
        } 
    } 
    // +--------forum type-----------------------------------------
    get_forum_info("");

    if ($forum_type == "locked" || $forum_type == "former" || $forum_type == "forumhid" || $forum_type == "subforumhid" || $forum_type == "closed" || $forum_type == "hidden" || $forum_type == "sublocked" || $forum_type == "subformer" || $forum_type == "subclosed" || $forum_type == "subhidden") {
        if ($forum_type == "locked" || $forum_type == "sublocked") {
            $bar1 = "$gl[385]";            $bar2 = "$gl[386]";            $error = "$gl[387]";
        } elseif ($forum_type == "former" || $forum_type == "subformer" || $forum_type == "forumhid" || $forum_type == "subforumhid") {
            $bar1 = "$gl[388]";            $bar2 = "$gl[389]";            $error = "$gl[390]";
        } elseif ($forum_type == "closed" || $forum_type == "subclosed") {
            $bar1 = "$gl[391]";            $bar2 = "$gl[392]";            $error = "$gl[393]";
        } elseif ($forum_type == "hidden" || $forum_type == "subhidden") {
            $bar1 = "$gl[394]";            $bar2 = "$gl[395]";            $error = "$gl[396]";
        } 
        $qqmm = 0;

        if ($usertype[24] == "1" && $login_status == 1 && $forum_admin && in_array($username, $forum_admin)) $qqmm = 1;
        if ($usertype[12] == "1" && $forum_type == "locked")    $qqmm = 1;
        if ($usertype[12] == "1" && $forum_type == "sublocked")    $qqmm = 1;
        if ($usertype[22] == "1" && $forum_type == "locked")    $qqmm = 1;
        if ($usertype[22] == "1" && $forum_type == "sublocked")    $qqmm = 1;
        if ($usertype[22] == "1" && $forum_type == "hidden")    $qqmm = 1;
        if ($usertype[22] == "1" && $forum_type == "subhidden")    $qqmm = 1;
        if ($usertype[12] == "1" && $forum_type == "hidden")   $qqmm = 1;
        if ($usertype[12] == "1" && $forum_type == "subhidden")   $qqmm = 1;
        // ************
        
        if (($login_status == 1 && $forum_type == "subforumhid") || ($login_status == 1 && $forum_type == "forumhid") || ($login_status == 1 && $forum_type == "former") || ($login_status == 1 && $forum_type == "subformer")) $qqmm = 1;
        if ($forum_type == "closed" || $forum_type == "subclosed") $qqmm = 0;
        if ($usertype[22] == "1" || $usertype[21] == "1") $qqmm = 1;

        if (($enter_tb != "1" || $userpoint < $enter_allow_ww) && ($forum_type == "locked" || $forum_type == "sublocked" || $forum_type == "subhidden" || $forum_type == "hidden")) $qqmm = 0;
        if ($enter_this_forum == "1" && $userpoint >= $enter_allow_ww && $spusergroup == 1) $qqmm = 1;
        if ($login_status != 1 || $qqmm != 1) {
            require("datafile/pluginheader.php");

            require("newtem/". $headername);
            navi_bar($bar1, $bar2);
            msg_box($bar2, $error."<br/><br/>".$gl[399]);
            require("newtem/". $footername);
            exit;
        } 
    } 
} 
// ---- process astrology
function astrology($m, $d)
{
    global $gl;
    if ($m == 1 && $d <= 19) $y = 1982;
    else $y = 1981;
    $yours = mktime(0, 0, 0, $m, $d, $y);
    if ($yours >= 348768000 && $yours < 351360000) $n = "<img src=\"images/star/z11.gif\"  width=\"16\" alt=\"$gl[400]\" align=\"middle\" />";
    if ($yours >= 351360000 && $yours < 353952000) $n = "<img src=\"images/star/z12.gif\"  width=\"16\" alt=\"$gl[401]\" align=\"middle\" />";
    if ($yours >= 353952000 && $yours < 356544000) $n = "<img src=\"images/star/z1.gif\"  width=\"16\" alt=\"$gl[402]\" align=\"middle\" />";
    if ($yours >= 356544000 && $yours < 359222400) $n = "<img src=\"images/star/z2.gif\"  width=\"16\" alt=\"$gl[403]\" align=\"middle\" />" ;
    if ($yours >= 359222400 && $yours < 361987200) $n = "<img src=\"images/star/z3.gif\"  width=\"16\" alt=\"$gl[404]\" align=\"middle\" />";
    if ($yours >= 361987200 && $yours < 364665600) $n = "<img src=\"images/star/z4.gif\"  width=\"16\" alt=\"$gl[405]\" align=\"middle\" />";
    if ($yours >= 364665600 && $yours < 367344000) $n = "<img src=\"images/star/z5.gif\"  width=\"16\" alt=\"$gl[406]\" align=\"middle\" />";
    if ($yours >= 367344000 && $yours < 370022400) $n = "<img src=\"images/star/z6.gif\"  width=\"16\" alt=\"$gl[407]\" align=\"middle\" />";
    if ($yours >= 370022400 && $yours < 372700800) $n = "<img src=\"images/star/z7.gif\"  width=\"16\" alt=\"$gl[408]\" align=\"middle\" />";
    if ($yours >= 372700800 && $yours < 375206400) $n = "<img src=\"images/star/z8.gif\"  width=\"16\" alt=\"$gl[409]\" align=\"middle\" />";
    if ($yours >= 375206400 && $yours < 377798400) $n = "<img src=\"images/star/z9.gif\"  width=\"16\" alt=\"$gl[410]\" align=\"middle\" />";
    if ($yours >= 377798400 && $yours <= 380304000) $n = "<img src=\"images/star/z10.gif\" width=\"16\" alt=\"$gl[411]\" align=\"middle\" />";
    return $n;
} 
// ----- process national info
function nationalget($nationalname, $nameonly = 0)
{
    global $language, $show_form_lng;
    include_once("lang/$language/usercp.php");
    if ($nationalname == "") $nationalname = "blank";
    elseif ($nationalname == China) $nationalnametemp = "$show_form_lng[4]";
    elseif ($nationalname == Angola) $nationalnametemp = "$show_form_lng[5]";
    elseif ($nationalname == Antigua) $nationalnametemp = "$show_form_lng[6]";
    elseif ($nationalname == Argentina) $nationalnametemp = "$show_form_lng[7]";
    elseif ($nationalname == Armenia) $nationalnametemp = "$show_form_lng[8]";
    elseif ($nationalname == Australia) $nationalnametemp = "$show_form_lng[9]";
    elseif ($nationalname == Austria) $nationalnametemp = "$show_form_lng[10]";
    elseif ($nationalname == Bahamas) $nationalnametemp = "$show_form_lng[11]";
    elseif ($nationalname == Bahrain) $nationalnametemp = "$show_form_lng[12]";
    elseif ($nationalname == Bangladesh) $nationalnametemp = "$show_form_lng[13]";
    elseif ($nationalname == Barbados) $nationalnametemp = "$show_form_lng[14]";
    elseif ($nationalname == Belgium) $nationalnametemp = "$show_form_lng[15]";
    elseif ($nationalname == Bermuda) $nationalnametemp = "$show_form_lng[16]";
    elseif ($nationalname == Bolivia) $nationalnametemp = "$show_form_lng[17]";
    elseif ($nationalname == Brazil) $nationalnametemp = "$show_form_lng[18]";
    elseif ($nationalname == Brunei) $nationalnametemp = "$show_form_lng[19]";
    elseif ($nationalname == Canada) $nationalnametemp = "$show_form_lng[20]";
    elseif ($nationalname == Chile) $nationalnametemp = "$show_form_lng[21]";
    elseif ($nationalname == Colombia) $nationalnametemp = "$show_form_lng[22]";
    elseif ($nationalname == Croatia) $nationalnametemp = "$show_form_lng[23]";
    elseif ($nationalname == Cuba) $nationalnametemp = "$show_form_lng[24]";
    elseif ($nationalname == Cyprus) $nationalnametemp = "$show_form_lng[25]";
    elseif ($nationalname == Czech_Republic) $nationalnametemp = "$show_form_lng[26]";
    elseif ($nationalname == Denmark) $nationalnametemp = "$show_form_lng[27]";
    elseif ($nationalname == Dominican_Republic) $nationalnametemp = "$show_form_lng[28]";
    elseif ($nationalname == Ecuador) $nationalnametemp = "$show_form_lng[29]";
    elseif ($nationalname == Egypt) $nationalnametemp = "$show_form_lng[30]";
    elseif ($nationalname == Estonia) $nationalnametemp = "$show_form_lng[31]";
    elseif ($nationalname == Finland) $nationalnametemp = "$show_form_lng[32]";
    elseif ($nationalname == France) $nationalnametemp = "$show_form_lng[33]";
    elseif ($nationalname == Germany) $nationalnametemp = "$show_form_lng[34]";
    elseif ($nationalname == Great_Britain) $nationalnametemp = "$show_form_lng[35]";
    elseif ($nationalname == Greece) $nationalnametemp = "$show_form_lng[36]";
    elseif ($nationalname == Guatemala) $nationalnametemp = "$show_form_lng[37]";
    elseif ($nationalname == Honduras) $nationalnametemp = "$show_form_lng[38]";
    elseif ($nationalname == Hungary) $nationalnametemp = "$show_form_lng[39]";
    elseif ($nationalname == Iceland) $nationalnametemp = "$show_form_lng[40]";
    elseif ($nationalname == India) $nationalnametemp = "$show_form_lng[41]";
    elseif ($nationalname == Indonesia) $nationalnametemp = "$show_form_lng[42]";
    elseif ($nationalname == Iran) $nationalnametemp = "$show_form_lng[43]";
    elseif ($nationalname == Iraq) $nationalnametemp = "$show_form_lng[44]";
    elseif ($nationalname == Ireland) $nationalnametemp = "$show_form_lng[45]";
    elseif ($nationalname == Israel) $nationalnametemp = "$show_form_lng[46]";
    elseif ($nationalname == Italy) $nationalnametemp = "$show_form_lng[47]";
    elseif ($nationalname == Jamaica) $nationalnametemp = "$show_form_lng[48]";
    elseif ($nationalname == Japan) $nationalnametemp = "$show_form_lng[49]";
    elseif ($nationalname == Jordan) $nationalnametemp = "$show_form_lng[50]";
    elseif ($nationalname == Kazakstan) $nationalnametemp = "$show_form_lng[51]";
    elseif ($nationalname == Kenya) $nationalnametemp = "$show_form_lng[52]";
    elseif ($nationalname == Kuwait) $nationalnametemp = "$show_form_lng[53]";
    elseif ($nationalname == Latvia) $nationalnametemp = "$show_form_lng[54]";
    elseif ($nationalname == Lebanon) $nationalnametemp = "$show_form_lng[55]";
    elseif ($nationalname == Lithuania) $nationalnametemp = "$show_form_lng[56]";
    elseif ($nationalname == Malaysia) $nationalnametemp = "$show_form_lng[57]";
    elseif ($nationalname == Malawi) $nationalnametemp = "$show_form_lng[58]";
    elseif ($nationalname == Malta) $nationalnametemp = "$show_form_lng[59]";
    elseif ($nationalname == Mauritius) $nationalnametemp = "$show_form_lng[60]";
    elseif ($nationalname == Morocco) $nationalnametemp = "$show_form_lng[61]";
    elseif ($nationalname == Mozambique) $nationalnametemp = "$show_form_lng[62]";
    elseif ($nationalname == Netherlands) $nationalnametemp = "$show_form_lng[63]";
    elseif ($nationalname == New_Zealand) $nationalnametemp = "$show_form_lng[64]";
    elseif ($nationalname == Nicaragua) $nationalnametemp = "$show_form_lng[65]";
    elseif ($nationalname == Nigeria) $nationalnametemp = "$show_form_lng[66]";
    elseif ($nationalname == Norway) $nationalnametemp = "$show_form_lng[67]";
    elseif ($nationalname == Pakistan) $nationalnametemp = "$show_form_lng[68]";
    elseif ($nationalname == Panama) $nationalnametemp = "$show_form_lng[69]";
    elseif ($nationalname == Paraguay) $nationalnametemp = "$show_form_lng[70]";
    elseif ($nationalname == Peru) $nationalnametemp = "$show_form_lng[71]";
    elseif ($nationalname == Poland) $nationalnametemp = "$show_form_lng[72]";
    elseif ($nationalname == Portugal) $nationalnametemp = "$show_form_lng[73]";
    elseif ($nationalname == Romania) $nationalnametemp = "$show_form_lng[74]";
    elseif ($nationalname == Russia) $nationalnametemp = "$show_form_lng[75]";
    elseif ($nationalname == Saudi_Arabia) $nationalnametemp = "$show_form_lng[76]";
    elseif ($nationalname == Singapore) $nationalnametemp = "$show_form_lng[77]";
    elseif ($nationalname == Slovakia) $nationalnametemp = "$show_form_lng[78]";
    elseif ($nationalname == Slovenia) $nationalnametemp = "$show_form_lng[79]";
    elseif ($nationalname == Solomon_Islands) $nationalnametemp = "$show_form_lng[80]";
    elseif ($nationalname == Somalia) $nationalnametemp = "$show_form_lng[81]";
    elseif ($nationalname == South_Africa) $nationalnametemp = "$show_form_lng[82]";
    elseif ($nationalname == South_Korea) $nationalnametemp = "$show_form_lng[83]";
    elseif ($nationalname == Spain) $nationalnametemp = "$show_form_lng[84]";
    elseif ($nationalname == Sri_Lanka) $nationalnametemp = "$show_form_lng[285]";
    elseif ($nationalname == Surinam) $nationalnametemp = "$show_form_lng[85]";
    elseif ($nationalname == Sweden) $nationalnametemp = "$show_form_lng[86]";
    elseif ($nationalname == Switzerland) $nationalnametemp = "$show_form_lng[87]";
    elseif ($nationalname == Thailand) $nationalnametemp = "$show_form_lng[88]";
    elseif ($nationalname == Trinidad_Tobago) $nationalnametemp = "$show_form_lng[89]";
    elseif ($nationalname == Turkey) $nationalnametemp = "$show_form_lng[90]";
    elseif ($nationalname == Ukraine) $nationalnametemp = "$show_form_lng[91]";
    elseif ($nationalname == United_Arab_Emirates) $nationalnametemp = "$show_form_lng[92]";
    elseif ($nationalname == United_States) $nationalnametemp = "$show_form_lng[93]";
    elseif ($nationalname == Uruguay) $nationalnametemp = "$show_form_lng[94]";
    elseif ($nationalname == Venezuela) $nationalnametemp = "$show_form_lng[95]";
    elseif ($nationalname == Vietnam) $nationalnametemp = "$show_form_lng[160]";
    elseif ($nationalname == Yugoslavia) $nationalnametemp = "$show_form_lng[96]";
    elseif ($nationalname == Zambia) $nationalnametemp = "$show_form_lng[97]";
    elseif ($nationalname == Zimbabwe) $nationalnametemp = "$show_form_lng[98]";
    $nationalname = $nameonly ? $nationalnametemp : "<img src=\"images/flags/{$nationalname}.gif\" height=\"14\" alt=\"{$nationalnametemp}\" align=\"middle\" />";
    return $nationalname;
} 
// ----- chinese shengxiao
function robertsx($y, $m, $d)
{
    global $gl;

    $sx_detail = explode("|", "218|206|126|214|203|123|211|201|220|208|128|216|205|124|213|202|123|210|130|217|206|126|214|204|124|211|131|219|208|127|215|205|125|213|202|122|210|129|217|206|127|214|203|124|212|131|218|208|128|215|205|125|213|202|121|209|130|217|206|127|215|203|123|211|131|218|207|128|216|205|125|213|202|220|209|129|217|206|127|215|204|123|210|131|219|207|128|216|205|124|212|201|122|209|129|218|207|126|214|");
    $mymd = $m * 100 + $d;
    $t = $y-1912;
    $tarmd = $sx_detail[$t];
    if ($mymd < $tarmd) $y = $y-1;
    $myy = ($y-1912) % 12;
    if ($myy == 0) $mysx = "<img src=\"images/sx/sx1s.gif\"  width=\"15\" alt\"=$gl[412]\" align=\"middle\" />";
    elseif ($myy == 1) $mysx = "<img src=\"images/sx/sx2s.gif\"  width=\"15\" alt=\"$gl[413]\" align=\"middle\" />";
    elseif ($myy == 2) $mysx = "<img src=\"images/sx/sx3s.gif\"  width=\"15\" alt=\"$gl[414]\" align=\"middle\" />";
    elseif ($myy == 3) $mysx = "<img src=\"images/sx/sx4s.gif\"  width=\"15\" alt=\"$gl[415]\" align=\"middle\" />";
    elseif ($myy == 4) $mysx = "<img src=\"images/sx/sx5s.gif\"  width=\"15\" alt=\"$gl[416]\" align=\"middle\" />";
    elseif ($myy == 5) $mysx = "<img src=\"images/sx/sx6s.gif\"  width=\"15\" alt=\"$gl[417]\" align=\"middle\" />";
    elseif ($myy == 6) $mysx = "<img src=\"images/sx/sx7s.gif\"  width=\"15\" alt=\"$gl[418]\" align=\"middle\" />";
    elseif ($myy == 7) $mysx = "<img src=\"images/sx/sx8s.gif\"  width=\"15\" alt=\"$gl[419]\" align=\"middle\" />";
    elseif ($myy == 8) $mysx = "<img src=\"images/sx/sx9s.gif\"  width=\"15\" alt=\"$gl[420]\" align=\"middle\" />";
    elseif ($myy == 9) $mysx = "<img src=\"images/sx/sx10s.gif\" width=\"15\" alt=\"$gl[421]\" align=\"middle\" />";
    elseif ($myy == 10) $mysx = "<img src=\"images/sx/sx11s.gif\" width=\"15\" alt=\"$gl[422]\" align=\"middle\" />";
    else $mysx = "<img src=\"images/sx/sx12s.gif\" width=\"15\" alt=\"$gl[423]\" align=\"middle\" />";
    return $mysx;
} 
// UTF-8 substr
function substrfor($str, $start, $end)
{
    preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", bmb_unhtmlentities($str), $info);
    return join("", array_slice($info[0], $start, $end));
} 
// ------- html_entity_decode
function bmb_unhtmlentities($string) 
{
	if (@function_exists("html_entity_decode")) {
        return html_entity_decode($string);
	} else {
        $trans_tbl = get_html_translation_table(HTML_ENTITIES);
        $trans_tbl = array_flip($trans_tbl);
        return strtr($string, $trans_tbl);
    }
}
// --------- Replace the vars in pre-processed templates
function reparray($a, $input)
{ 
    // 模板快速替换函数 by 2003-12-29
    foreach ($a as $k => $v) {
        $input = str_replace("$k", "$v", $input);
    } 
    return $input;
} 
// Safe filter
function addsd($array)
{ 
    // 安全过滤函数 18:52 2004-5-22
    foreach($array as $key => $value) {
        if (!is_array($array[$key])) {
            $array[$key] = addslashes($value);
        } else {
            $array[$key] = addsd($array[$key]);
        } 
    } 
    return $array;
} 
// UTF-8 Strlen
function utf8_strlen($str)
{
    return preg_match_all('/[\x00-\x7F\xC0-\xFD]/', $str, $dummy);
} 
// Refresh the Forum's Cache to file from database
function refresh_forumcach($type = "forumdata", $lname = "sxfourmrow", $cn = "forumscount", $oby = "showorder")
{
    global $database_up;
    
    $nquery = "SELECT * FROM {$database_up}$type ORDER BY `$oby` ASC";
    $nresult = bmbdb_query($nquery);
    while (false !== ($fourmrow = bmbdb_fetch_array($nresult))) {
        $xfourmrow[] = $fourmrow;
    } 
    $wrting = "<?php \n";
    $count = count($xfourmrow);
    for ($i = 0; $i < $count; $i++) {
        $tmp = $xfourmrow[$i];
        foreach ($tmp as $key => $value) {
            if ($key != "fltitle") $wrting .= "\${$lname}[$i]['{$key}']='" . str_replace("\\\'", "\\\\\'", str_replace("'", "\'", $value)) . "'; \n";
            else $wrting .= "\${$lname}[$i]['{$key}']='" . str_replace("&amp;#039;", "&#039;", str_replace("'", "&#039;", htmlspecialchars(bmb_unhtmlentities($value)))) . "'; \n";
        } 
        $forumscount++;
    } 
    $wrting .= "\${$cn}='$forumscount';";
    big_write("datafile/cache/{$type}.php", $wrting);
} 
// Rand numbers and letters
function getCode ($length = 9, $type = 0)
{
    $str = $type ? 'ABCEFHJKMNPRSTUVWXY13456789' : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
    $result = '';
    $l = strlen($str) - 1;

    for($i = 0;$i < $length;$i ++){
        $num = rand(0, $l);
        $result .= $str{$num};
    }
    return $result;
}
// Show row's ads.
function show_row_ads ($openvar, $forumid = "")
{
	if ($forumid && @file_exists("datafile/rowads/{$forumid}.php")) {
		$forumid = basename($forumid);
		@include_once("datafile/rowads/{$forumid}.php");
		if ($row_show[$openvar] && $ads_showit) {
			echo $ads_showit;
			return;
		}
	}
    if (@file_exists("datafile/row_text.php")) {
        @include_once("datafile/row_text.php");
        if ($row_show[$openvar]) echo $ads_showit;
    } 
}
// check forum permission
function check_forum_permission($no_read_post = 0, $no_output = 0, $this_line = "", $no_forum_limit = 0)
{
    global $usermoney, $plusug, $level_id, $ajax_online, $levelgroupdata, $view_list, $forum_allow_ww, $uginfo, $enter_this_forum, $gl, $forumid, $forum_name, $p_read_post, $pgo, $ajax_reply, $error, $language, $read_allow_ww, $spusergroup, $postamount, $userbym , $forum_ford, $footer_copyright, $headername, $footername, $read_alignment, $html_lang, $enter_allow_ww, $userpoint, $enter_tb, $plugyescolor, $usertype, $forum_type, $forumid, $username, $login_status, $limitlist, $forum_admin, $verandproname, $otherimages, $bbs_title, $add_title, $cssinfo, $login_status, $ads_select, $admin_email, $site_url, $showtime, $site_name, $writefilenum, $readfilenum, $begin_time, $temfilename, $gl;
	// ===================================
	// Permission
	// ===================================
	
	$thissp_forumid = $forumid;
	$thissp_spusergroup = $spusergroup;
	$thissp_forum_ford = $forum_ford;
	$thissp_enter_this_forum = $enter_this_forum;
	
	if ($this_line) {
		$thissp_forum_ford	=	$this_line['forum_ford'];
		$thissp_spusergroup	=	$this_line['spusergroup'];
		$thissp_forumid	=	$this_line['id'];
		
        if ($login_status == 0) $uginfo = 6;
        
        $group_usergroupdata = explode("\n", $this_line['usergroup']);
        
        if ($thissp_spusergroup == 1) {
	        if ($uginfo == 4) {
	        	include_once("datafile/cache/levels/level_fid_{$thissp_forumid}.php");
	        	if ($levelgroupdata[$thissp_forumid][$level_id]) {
	        		$group_usertype = explode("|", $levelgroupdata[$thissp_forumid][$level_id]);
	        	} else {
	        		$group_usertype = explode("|", $group_usergroupdata[$uginfo]);
	        	}
	        } else {
	        	$group_usertype = explode("|", $group_usergroupdata[$uginfo]);
	        }
	        
	        if (is_array($plusug)) {
	            $count = count($plusug);
	            for ($i = 0; $i < $count; $i++){
	            	if ($plusug[$i] == "" || $plusug[$i] == $uginfo) continue;
	                $tmpusertype = explode("|", $group_usergroupdata["{$plusug[$i]}"]);
	                $countut = count($tmpusertype);
					if ($tmpusertype[12] == 1 && $group_usertype[12] == 0) $group_usertype[12] = 1; 
	            }
	        }
	        
			$thissp_enter_this_forum	=	$group_usertype[12];
	    }
        

	}

	$ford = explode("_", $thissp_forum_ford);
	if ($ford[0] == 1 && ($postamount < $ford[1] || $userbym < $ford[2] || $usermoney < $ford[3]) && $usertype[21] != "1" && $usertype[22] != "1") {
		if ($no_output) return 0;
		else {
			if ($ajax_reply == 1) ajax_browse_error($error[6]);
			if ($ajax_online == 1) ajax_browse_error($error[6]);
			$ford[2] = floor($ford[2] / 10);
			$userbym = floor($userbym / 10);
			include("lang/$language/global.php");
		    include("header.php");
		    navi_bar("$gl[191]",
		        "<a href=\"forums.php?forumid=$thissp_forumid\">$forum_name</a>",
		        "$gl[192]", "no");
		    msg_box($gl[193], "$gl[194]");
		    include("footer.php");
		    exit;
		}
	} 

	// ===================================
	// Usergroup in this forum
	// ===================================

	if (($thissp_spusergroup == "1" && $thissp_enter_this_forum == "0" && $login_status == "1") || ($no_forum_limit == 1  && ($view_list == "0" || $userpoint < $forum_allow_ww)) || ($no_read_post == 1 && ($p_read_post == "0" || $userpoint < $read_allow_ww))) {
		if ($no_output) return 0;
		else {
			if ($ajax_reply == 1) ajax_browse_error($gl[438]);
			if ($ajax_online == 1) ajax_browse_error($gl[438]);
			include("header.php");
		    navi_bar($error[3],
		        "<a href=\"forums.php?forumid=$thissp_forumid\">$forum_name</a>",
		        $gl[192], "no");
		    msg_box($gl[192], $gl[438]);
		    include("footer.php");
		    exit;
		}
	}     
	if ($no_output) return 1;
} 
function ajax_browse_error($info = "Access Denied")
{
    header("HTTP/1.0 689 Access Denied");
    echo $info;
    exit;
}
function safe_upload_name($upload)
{
	$upload = str_replace("(", "", $upload);
	$upload = str_replace("'", "", $upload);
	$upload = str_replace('"', "", $upload);
	$upload = basename($upload);
	$upload = htmlspecialchars($upload);
	
	return $upload;
}