Location: PHPKode > projects > Chinese Project Forum > upload/functions.php
<?
#Á½´Î·¢±íÎÄÕÂÏà¸ôʱ¼ä£¨·ÀÖ¹¹ý¶È¹àË®¡£µ¥Î»£ºÃ룩
$fctime = 30;

#PHP°æ±¾
$phpversion_array = phpversion();
$phpversion_nr = $phpversion_array[0].".".$phpversion_array[2].$phpversion_array[4];
#Èç¹û×°ÔØÁËzlib²¢ÇÒPHP°æ±¾´óÓÚ4.04£¬ÆôÓÃgzipѹËõÍøÒ³£¬¼Ó¿ìÍøÒ³´«ÊäËÙ¶È
if (extension_loaded("zlib") && ($phpversion_nr >= 4.04)) {
	ob_start("ob_gzhandler");
}

#Session¿ªÊ¼
session_name("sid");
session_start();
if(!$sid) $sid = session_id();
//»ñµÃ·ÃÎÊÕßIP²¢×¢²áΪSession: ssip;
if(!$HTTP_SESSION_VARS[ssip]) {
	$ssip = getenv(REMOTE_ADDR);
	session_register("ssip");
}
elseif($HTTP_SESSION_VARS[ssip]!=getenv(REMOTE_ADDR)) {
	session_unset();
	header("Location: ".basename(getenv("REQUEST_URI"))."");
	exit;
}
if(!$user_id) $user_id = $HTTP_SESSION_VARS[user_id];
if(!$user_password) $user_password = $HTTP_SESSION_VARS[user_password];

if(check_userdata($user_id,$user_password)) {
        $recordset = &$conn->Execute("SELECT ".$prefix."_user_table.*, ".$prefix."_groups.* FROM ".$prefix."_user_table LEFT JOIN ".$prefix."_groups ON (".$prefix."_groups.id=".$prefix."_user_table.groupid) WHERE userid='$user_id'");
		$userdata = $recordset->fields;
        if($userdata[blocked]) $blocked = 1;
        $user_name = $userdata[username];
        $user_group = $userdata[groupid];
        $old_time = $userdata[lastvisit];
        $new_time = $userdata[lastactivity];
        $session_link = $userdata[session_link];
        $hide_signature = $userdata[hide_signature];
        $hide_userpic = $userdata[hide_userpic];
        $prunedays = $userdata[prunedays];
        $umaxposts = $userdata[umaxposts];
        $u_bbcode = $userdata[bbcode];
        if($userdata[style_set]) $styleid = $userdata[style_set];
        if($new_time < (time()-1800)) {
        	$old_time = $new_time;
        	$new_time = time();
        	$conn->Execute("UPDATE ".$prefix."_user_table SET lastvisit = lastactivity, lastactivity = '$new_time' WHERE userid = '$user_id'");
        }
}
else {
	$user_id=0;
	$recordset = &$conn->Execute("SELECT * FROM ".$prefix."_groups WHERE default_group = 1");
	$userdata = $recordset->fields;
	$user_group = $userdata[0];
	eval ("\$user_name = \"".gettemplate("lg_anonymous")."\";");
	$old_time = $HTTP_SESSION_VARS[old_time];
	if(!$old_time) $old_time = time();
	$new_time = time();
	session_register("old_time");
	session_register("new_time");
}

$url_jump = $HTTP_SESSION_VARS[url_ak];
if(!$url_jump) $url_jump = urlencode(basename(getenv("REQUEST_URI")));
if(!strstr(getenv("REQUEST_URI"),"action.php") && !strstr(getenv("REQUEST_URI"),"register.php") && !strstr(getenv("REQUEST_URI"),"misc.php")) $url_ak = urlencode(getenv("REQUEST_URI"));
else $url_ak = $HTTP_SESSION_VARS[url_ak];
session_register("url_ak");
session_register("url_jump");

if(!$session_link) $session = "&sid=".$sid;
if(!$session_link) $session2 = "?sid=".$sid;

$recordset = &$conn->Execute("SELECT * FROM ".$prefix."_config");
$row = $recordset->fields;
$j = $recordset->FieldCount();
for($i = 0; $i < $j; $i++) {
	$fld = $recordset->FetchField($i);
	$k = $fld->name;
	$$k = editDBdata($row[$k]);
}
$recordset->close();
$badwords = explode("\n", $badwords);
if($umaxposts) $eproseite = $umaxposts;

if($styleid) {
  $style_result = &$conn->Execute("SELECT * FROM ".$prefix."_style WHERE styleid = '$styleid'");
} else {
  if($boardid) {
    $board_style = &$conn->Execute("SELECT style_set FROM ".$prefix."_boards WHERE boardid = '$boardid'");
  }
  if($board_style[0]) {
    $style_result = &$conn->Execute("SELECT * FROM ".$prefix."_style WHERE styleid = '$board_style[0]'");
  } else {
    $style_result = &$conn->Execute("SELECT * FROM ".$prefix."_style WHERE default_style = 1");
  }
}

$row = $style_result->fields;
$j = $style_result->FieldCount();
for($i = 0; $i < $j; $i++) {
	$fld = $style_result->FetchField($i);
	$k = $fld->name;
	$$k = editDBdata($row[$k]);
}
$style_result->close();

#½«³£ÓñäÁ¿¸³Öµ

//Ä£°åheadinclude
eval ("\$headinclude = \"".gettemplate("headinclude")."\";");
//Ä£°åfooter
eval ("\$footer = \"".gettemplate("footer")."\";");
//ͼÏóURL
if($imageurl) $imageurl = "<img src=\"$imageurl\">";
//ÏÔʾÓû§ÊÇ·ñÒѾ­µÇ¼µÄ±äÁ¿$pro_reg
if(!$user_id) eval ("\$pro_reg = \"".gettemplate("header_reg")."\";");
else eval ("\$pro_reg = \"".gettemplate("header_profile")."\";");
//Ä£°åheader
//¹ÜÀíÃæ°å°´Å¥ÏÔʾ
if($userdata[canuseacp]) eval ("\$admin = \"".gettemplate("header_admin")."\";");
eval ("\$header = \"".gettemplate("header")."\";");
//Hello À¸ÏÔʾ
if($user_id) eval ("\$navibar_hello = \"".gettemplate("header_logtin")."\";");
else eval ("\$navibar_hello = \"".gettemplate("header_unreg")."\";");

#Session_post ±äÁ¿
if($session) $session_post = "<INPUT TYPE=\"HIDDEN\" NAME=\"sid\" VALUE=\"$sid\">";

#ÂÛ̳ÊÇ·ñÀëÏßÅжÏ
if($boardoff && !$userdata[canviewoffboard]) {
	require("board_jump.php");
	eval("dooutput(\"".gettemplate("wartungsmodus")."\");");
	exit;
}

#ÅжÏÓû§ÊÇ·ñÓÐȨÏÞ·ÃÎÊÂÛ̳ҳÃæ
if(($blocked == 1 || !$userdata[canviewboard]) && !strstr(getenv("REQUEST_URI"),"action.php") && !strstr(getenv("REQUEST_URI"),"misc2.php") && !strstr(getenv("REQUEST_URI"),"register.php")) {
	require("board_jump.php");
	if(!$user_id) eval ("\$login = \"".gettemplate("access_error_login")."\";");
	else eval ("\$login = \"".gettemplate("access_error_logout")."\";");
	eval("dooutput(\"".gettemplate("access_error")."\");");
	exit;
} 

#¸üÐÂÓû§ÔÚÏßÐÅÏ¢
useronline($user_id);

#ÅжÏÌÖÂÛ°æÊÇ·ñ±»ÃÜÂë±£»¤²¢´¦Àí
if((strstr(getenv("REQUEST_URI"),"board.php") || strstr(getenv("REQUEST_URI"),"thread.php") || strstr(getenv("REQUEST_URI"),"newthread.php") || strstr(getenv("REQUEST_URI"),"reply.php") || strstr(getenv("REQUEST_URI"),"edit.php")) && $boardid != "home" && $boardid != "pm" && $boardid != "search" && $boardid != "profil") {
	$password = &$conn->Execute("SELECT boardpassword FROM ".$prefix."_boards WHERE boardid = '$boardid'");
	if($password->fields[0] && md5($password->fields[0]) != $cbpassword[$boardid]) {
     if ($userdata[groupid]!=1 && $userdata[groupid]!=5) {
        //die($userdata[groupid]);
		require("board_jump.php");
		eval("dooutput(\"".gettemplate("boardpw")."\");");
		exit;
     }
    }
} 

#ÌÖÂÛ°æȨÏÞÅжϲ¢´¦Àí
if((strstr(getenv("REQUEST_URI"),"board.php") || strstr(getenv("REQUEST_URI"),"thread.php") || strstr(getenv("REQUEST_URI"),"newthread.php") || strstr(getenv("REQUEST_URI"),"reply.php") || strstr(getenv("REQUEST_URI"),"edit.php")) && $boardid != "home" && $boardid != "pm" && $boardid != "search" && $boardid != "profil" && !check_boardobject($boardid,$user_group,"boardpermission")) {
	require("board_jump.php");
	if(!$user_id) {
		if($session) $session_post = "<input type=\"hidden\" name=\"sid\" value=\"$sid\">";
		eval ("\$login = \"".gettemplate("access_error_login")."\";");
	}
	else eval ("\$login = \"".gettemplate("access_error_logout")."\";");
	eval("dooutput(\"".gettemplate("access_error")."\");");
	exit;
}


#º¯Êý¿ªÊ¼
//È¡µÃÄ£°åÄÚÈÝ
function gettemplate($template,$endung="htm") {
        global $templatefolder;
        if(!$templatefolder) $templatefolder = "templates";
        return str_replace("\"","\\\"",implode("",file($templatefolder."/".$template.".".$endung)));
}
//Êä³ö
function dooutput($template) {
        global $bgcolor, $tablebg, $tableb, $tablec, $tabled, $tablea, $font, $fontcolor, $fontcolorsec, $fontcolorthi, $fontcolorfour, $bgfixed, $bgimage;
        $template = str_replace("{pagebgcolor}","$bgcolor",$template);
        $template = str_replace("{tablebordercolor}","$tablebg",$template);
        $template = str_replace("{tablea}","$tablea",$template);
        $template = str_replace("{tableb}","$tableb",$template);
        $template = str_replace("{tablec}","$tablec",$template);
        $template = str_replace("{tabled}","$tabled",$template);
        $template = str_replace("{font}","$font",$template);
        $template = str_replace("{fontcolorfirst}","$fontcolor",$template);
        $template = str_replace("{fontcolorsecond}","$fontcolorsec",$template);
        $template = str_replace("{fontcolorthird}","$fontcolorthi",$template);
        $template = str_replace("{fontcolorfourth}","$fontcolorfour",$template);

        if($bgimage) $hgpicture = " background=\"$bgimage\"";
        $template = str_replace("{hgpicture}","$hgpicture",$template);
        if($bgfixed) $template = str_replace("{bgproperties}"," bgproperties=fixed",$template);
        else $template = str_replace("{bgproperties}","",$template);
        echo $template;
}
//³õ²½´¦ÀíÊý¾Ý¿âµÄÊý¾ÝÒÔ·½±ãHTMLÏÔʾ
function editDBdata($data) {
 $data = str_replace("&acute;","'", $data);
 $data = str_replace("&quot;","\"", $data); 
 return $data;
}

//»ñµÃÔ·ÝÃû³Æ
function get_month_name($month_number) {
	$name_monat[1]    =  "Ò»ÔÂ";  
	$name_monat[2]    =  "¶þÔÂ";  
	$name_monat[3]    =  "ÈýÔÂ";  
	$name_monat[4]    =  "ËÄÔÂ";  
	$name_monat[5]    =  "ÎåÔÂ";  
	$name_monat[6]    =  "ÁùÔÂ";  
	$name_monat[7]    =  "ÆßÔÂ";  
	$name_monat[8]    =  "°ËÔÂ";  
	$name_monat[9]    =  "¾ÅÔÂ";  
	$name_monat[10]  =  "Ê®ÔÂ";  
	$name_monat[11]  =  "ʮһÔÂ";  
	$name_monat[12]  =  "Ê®¶þÔÂ";
	
	return $name_monat[$month_number];
}
//¸ñʽ»¯ÈÕÆÚ
function formatdate($time,$format,$replacetoday=0) {
	global $conn, $prefix, $timetype, $timeoffset, $today;
	$time = $time+(3600*$timeoffset);
	if(date("dmY", time()+(3600*$timeoffset))==date("dmY", $time) && $replacetoday) {
		$position = strpos($today, "=");
                if($position!==false) {	                		
                	$pcover = substr($today, $position+1);
                	$val = substr($today, 0, $position);
                	$format = str_replace($val,$pcover, $format);
                }
	}
	$out = str_replace("DD",date("d", $time), $format);
	$out = str_replace("MM",date("m", $time), $out);
	$out = str_replace("YYYY",date("Y", $time), $out);
	$out = str_replace("YY",date("y", $time), $out);
	$out = str_replace("MN",get_month_name(date("n", $time)), $out);
	if($timetype) { #12 СʱÖÆ
		$out = str_replace("II","II ".date("A", $time), $out);	
		$out = str_replace("HH",date("h", $time), $out);
	}
	else $out = str_replace("HH",date("H", $time), $out);
	$out = str_replace("II",date("i", $time), $out);
	return $out;
}


//´´½¨ÂÛ̳ÌÖÂÛ°æÏÔʾ
function makeforumbit($boardid,$depth=1,$subscripe=0) {
  global $conn, $prefix, $boardcache, $permissioncache, $modcache, $forumhomedepth, $session, $old_time, $user_group, $longdateformat;

  if ( !isset($boardcache[$boardid]) ) {
    return;
  }

  while ( list($key1,$val1)=each($boardcache[$boardid]) ) {
    while ( list($key2,$boards)=each($val1) ) {
	if($subscripe) eval ("\$delboard = \"".gettemplate("profile_subscripe_delboard")."\";");
	if($boards[invisible] && !$permissioncache[$boards[boardid]]) continue;
	if($boards[isboard]) { //board
		$boards[descriptiontext] = editDBdata($boards[descriptiontext]);
		$boards[boardname] = editDBdata($boards[boardname]);
		if($old_time <= $boards[lastposttime]) {
          if ($boards[boardpassword]) {
              eval ("\$on_or_off = \"".gettemplate("main_locknewposts")."\";");
          } else {
              eval ("\$on_or_off = \"".gettemplate("main_newposts")."\";");
          }
		}else{
          if ($boards[boardpassword]) {
              eval ("\$on_or_off = \"".gettemplate("main_locknonewposts")."\";");
          } else {
              eval ("\$on_or_off = \"".gettemplate("main_nonewposts")."\";");
          }
      }
	
		if($boards[lastpostid]) {
			$lastposttime = formatdate($boards[posttime],$longdateformat,1);
			if($boards[userid]) $lastauthor = "<a href=\"members.php?mode=profile&userid=$boards[userid]$session\"><font color=\"red\">$boards[username]</font></a>";
			else eval ("\$lastauthor = \"".gettemplate("lg_anonymous")."\";");
			$boards[threadname] = editDBdata($boards[threadname]);
			if (!$boards[topicicon]) $ViewPosticon = "<img src=\"images/icons/noicon.gif\">";
			else $ViewPosticon = "<img src=\"$boards[topicicon]\">";
			if ($permissioncache[$boards[boardid]]) $template=main_lastpost;
			else $template=main_lastpost2;
			if (strlen($boards[threadname]) > '30') $ViewThreadname = substr($boards[threadname], 0, 27)."...";
        		else $ViewThreadname = $boards[threadname];
        		eval ("\$last_post = \"".gettemplate("$template")."\";");
		}
		else $last_post = "&nbsp;";
		
		if(isset($modcache[$boards[boardid]])) {
			while (list($mkey,$moderator)=each($modcache[$boards[boardid]])) {
            			if (isset($moderators)) $moderators .= ", ";
            			$moderators .= "<a href=\"members.php?mode=profile&userid=$moderator[userid]$session\">$moderator[username]</a>";
			}
		}
		eval ("\$out .= \"".gettemplate("main_boardbit$depth")."\";");
		unset($moderators);
		
	}
	else { //·ÖÀà
		$boards[descriptiontext] = editDBdata($boards[descriptiontext]);
		$boards[boardname] = editDBdata($boards[boardname]);
		eval ("\$out .= \"".gettemplate("main_catbit$depth")."\";");
	}
        if ($depth<2) {
          $out.=makeforumbit($boards[boardid],$depth+1);
        }
    } 
  } 
  unset($boardcache[$boardid]);
  return $out;
}

function makenavichain($template, $boardid, $threadid=0) {
	global $conn, $prefix, $session;
	//Èç¹ûÒªÉú³ÉÌÖÂÛ°æ
	if($template == "board") {
		$recordset = &$conn->Execute("SELECT boardparentid, boardname FROM ".$prefix."_boards WHERE boardid = '$boardid'");
		$binfo = $recordset->fields;
		$binfo[boardname] = editDBdata($binfo[boardname]);
		$result[boardparentid] = $binfo[boardparentid];
	}
	//·ñÔò
	else $result[boardparentid] = $boardid;
	//µ¼º½À¸ÏîÄ¿·Ö¸îÄ£°æ£¬Ò»°ãΪ¡°->¡±
	eval ("\$split = \"".gettemplate("navi_split")."\";");
	
	//¿ªÊ¼Éú³É
	do {
		$recordset = &$conn->Execute("SELECT boardid, boardparentid, boardname FROM ".$prefix."_boards WHERE boardid = '$result[boardparentid]'");
		$row = $recordset->fields;
		if(!$row[boardid]) break;
		$out = $split."<a href=\"board.php?boardid=$row[boardid]$session\">".editDBdata($row[boardname])."</a>".$out;
	} while($row[boardparentid]!=0);
	
	if($threadid) {
		$recordset = &$conn->Execute("SELECT threadname FROM ".$prefix."_threads WHERE threadid = '$threadid'");
		$tinfo = $recordset->fields;
		$tinfo[threadname] = editDBdata($tinfo[threadname]);
	}
	eval ("\$ende = \"".gettemplate("navi_".$template)."\";");
	return $out.$ende;
}

function getMod($id) {
        global $boardid,$styleid,$session,$conn,$prefix;
        $recordset = &$conn->Execute("SELECT objectid FROM ".$prefix."_object2board WHERE boardid = '$id' AND mod = 1");
        while(!$recordset->EOF) {
        	$row = $recordset->fields;
        	if($mods) $mods .= ", ";
        	$mods .= "<a href=\"members.php?mode=profile&userid=".$row[objectid]."&boardid=$boardid&styleid=$styleid$session\">".getUsername($row[objectid])."</a>";
        	$recordset->MoveNext();
        }
        return $mods;
}

//¼ì²éÊÇ·ñ´æÔÚÒѼ¤»îÓû§$userid,$password
function check_userdata($userid,$password) {
	global $prefix, $conn;
        $recordset = &$conn->Execute("SELECT COUNT(userid) FROM ".$prefix."_user_table WHERE userid='$userid' AND userpassword = '$password' AND activation = 1");
	return $recordset->fields[0];
}


//»»Ðд¦Àí
function nt_wordwrap($text, $width = 75) {
         if($text) return preg_replace("/([^\n\r ?&\.\/<>\"\\-]{".$width."})/i"," \\1\n",$text);
}

//¶ÔÖ÷Ìâ±êÌâ½øÐд¦Àí
function prepare_topic($out) { 
	return htmlspecialchars(nt_wordwrap(editDBdata($out),40)); 
}

//ä¯ÀÀÆ÷ÐÅÏ¢ÏÔʾ
function browseinfo() {
$browser="";$browserver="";
$Browsers =array("Lynx","MOSAIC","AOL","Opera","JAVA","MacWeb","WebExplorer","OmniWeb");
$Agent = $GLOBALS["HTTP_USER_AGENT"];
for ($i=0; $i<=7; $i++) {
if (strpos($Agent,$Browsers[$i])) {
$browser = $Browsers[$i];
$browserver ="";
}
}
   if (ereg("Mozilla",$Agent) && !ereg("MSIE",$Agent)) {
      $temp =explode("(", $Agent); $Part=$temp[0];
      $temp =explode("/", $Part); $browserver=$temp[1];
      $temp =explode(" ",$browserver); $browserver=$temp[0];
      $browserver =preg_replace("/([\d\.]+)/","\\1",$browserver);
      $browserver = " $browserver";
      $browser = "Netscape Navigator";
   } 
   if (ereg("Opera",$Agent) && ereg("Opera",$Agent)) {
      $temp =explode("/", $Agent); $Part=$temp[1];
      $temp =explode("(", $Part); $browserver=$temp[0];
      $browserver =preg_replace("/([\d\.]+)/","\\1",$browserver);
      $browserver = " $browserver";
      $browser = "Opera";
   }

   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("Mozilla",$Agent) && ereg("MSIE",$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(IE)";
}
   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 ($browser!="") {
$browseinfo = "$browser$browserver";
}
else {
$browseinfo = "&Icirc;&acute;&Ouml;&ordf;";
}
return $browseinfo;
}

//²Ù×÷ϵͳÐÅÏ¢ÏÔʾ
function osinfo() {
$os="";
$Agent = $GLOBALS["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.1',$Agent)) {
$os="Windows XP";
}
elseif (eregi('win',$Agent) && eregi('nt 5',$Agent)) {
$os="Windows 2000";
}
elseif (eregi('win',$Agent) && eregi('2000',$Agent)) {
$os="Windows 2000";
}
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 = "Unknown";
return $os;
}

//IPÐÅÏ¢ÏÔʾ
function ip_check($ip){
$ipdatafolder="ipdata";

if ($ip=="")
$ip=$REMOTE_ADDR;
$ipa=split("[\.]",$ip);

$ips=$ipa[0]*1000000000+$ipa[1]*1000000+$ipa[2]*1000+$ipa[3];
$ipa[0]=intval($ipa[0]);
if (file_exists("ipdata/$ipa[0].txt")) {
$datafile="ipdata/$ipa[0].txt";
}
else {
$datafile="ipdata/other.txt";
}
$from1="";
$from2="";
$from="";
$ipdata=file($datafile);
for ($i=0;$i<count($ipdata);$i++) {
$ipb=split("[\_]",$ipdata[$i]);
$from1=$ipb[4];
$from2=$ipb[6];
$ipc=split("[\.]",$ipb[0]);
$ipd=split("[\.]",$ipb[2]);
$ipbegin =$ipc[0]*1000000000+$ipc[1]*1000000+$ipc[2]*1000+$ipc[3];
$ipend =$ipd[0]*1000000000+$ipd[1]*1000000+$ipd[2]*1000+$ipd[3];

if (($ips<=$ipend) && ($ips>=$ipbegin)) {
$from=$from1.$from2;
break;
}
}
if ($from1=="") $from="δ֪";
return $from;
}

//»ñµÃÓû§ÔÚÏßͼÏó
function getrankimage($userid) {
global $conn,$prefix;
$recordset = $conn->Execute("SELECT * FROM ".$prefix."_user_table WHERE userid='$userid'");
switch ($recordset->fields('groupid')) {
    case "1":
    return "<img src=\"images/online/1.gif\" border=0>";break;
    case "5":
    return "<img src=\"images/online/2.gif\" border=0>";break;
    case "2":
    return "<img src=\"images/online/3.gif\" border=0>";break;
    case "3":
    return "<img src=\"images/online/4.gif\" border=0>";break;
    default:
    return "<img src=\"images/online/5.gif\" border=0>";break;
}
}

//Óû§ÔÚÏߺ¯Êý
function useronline($user_id)
{
        global $timeout,$prefix,$conn;
        $deltime = time()-($timeout*60);
        $conn->Execute("DELETE FROM ".$prefix."_useronline WHERE zeit<'$deltime'");
        if($user_id!=0) {
                $recordset = &$conn->Execute("SELECT COUNT(zeit)as anzahl FROM ".$prefix."_useronline WHERE userid='$user_id'");
				$anzahl = $recordset->fields;
                if($anzahl[anzahl]) $conn->Execute("UPDATE ".$prefix."_useronline SET zeit='".time()."' WHERE userid='$user_id'");
                else $conn->Execute("INSERT INTO ".$prefix."_useronline VALUES ('".time()."','','$user_id')");
        }
        else {
        $ip = getenv(REMOTE_ADDR);
        $recordset = &$conn->Execute("SELECT COUNT(zeit)as anzahl FROM ".$prefix."_useronline WHERE ip='$ip'");
		$anzahl = $recordset->fields;
        if($anzahl[anzahl]) $conn->Execute("UPDATE ".$prefix."_useronline SET zeit='".time()."' WHERE ip='$ip'");
        else $conn->Execute("INSERT INTO ".$prefix."_useronline VALUES ('".time()."','$ip','')");
        }
        $recordset = &$conn->Execute("SELECT COUNT(zeit) as anzahl FROM ".$prefix."_useronline");
		$user = $recordset->fields;
		$recordset = &$conn->Execute("SELECT rekord FROM ".$prefix."_config");
		$rekord = $recordset->fields;
 	if($user[anzahl]>$rekord[rekord]) $conn->Execute("UPDATE ".$prefix."_config set rekord='".$user[anzahl]."', rekordtime='".time()."'");
}

//Ìæ´úÈýÔª×ӵĺ¯Êý
function ifelse ($expression,$returntrue,$returnfalse) {
	if (!$expression) return $returnfalse;
	else return $returntrue;
}

//»ñµÃÓû§ËùÔڵȼ¶
function getUserrang($posts,$groupid) {
        global $prefix,$conn;
        $recordset = &$conn->Execute("SELECT rank FROM ".$prefix."_ranks WHERE groupid = $groupid AND posts<='$posts' ORDER by posts DESC");
        $rank = $recordset->fields;
        return $rank[rank];
}

//»ñµÃÓû§ÓµÓÐÐǵĸöÊý
function getUserStars($posts,$groupid) {
        global $conn,$prefix;
        $recordset = &$conn->Execute("SELECT id, rank, grafik, mal FROM ".$prefix."_ranks WHERE groupid = $groupid AND posts<='$posts' ORDER by posts DESC");
        $result = $recordset->fields;
        for($i = 0; $i<$result[mal]; $i++) {
                $out .= "<img src=\"$result[grafik]\" border=\"0\">";
        }
        return "<a href=\"javascript:rank($result[id])\" title=\"Óû§ÅÅÃûÐÅÏ¢£º$result[rank]\">".$out."</a>";
}

//Éú³É±í¸ñÐмä¸ôÑÕÉ«
function rowcolor($zeile) {
        if (($zeile/2) != floor($zeile/2)) $color="tableb";
        else $color="tabled";
        return $color;
}

//´¦Àí·¢±íµÄÎÄÕÂ
function editPost($out,$disable_smilies=0) {
        global $bbcode,$html,$smilies,$badwords;
        $out = editDBdata($out);
        if(!$html)  { 
    		$out = str_replace("&lt;","&amp;lt;",$out);
    		$out = str_replace("&gt;","&amp;gt;",$out);
    		$out = str_replace("<","&lt;",$out);
    		$out = str_replace(">","&gt;",$out);
  	}
        $out = nl2br($out);
        if($smilies && !$disable_smilies) $out = smilies($out);
        if($bbcode) $out = prepare_code($out);
        $out = censor($out);
        $out = nt_wordwrap($out);
        return $out;
}

//´¦Àí±íÇé·û
function smilies($out) {
	global $smiliecache;
	if(!count($smiliecache)) $smiliecache = getsmilies();
	for($i = 0; $i < count($smiliecache); $i++) $out=str_replace ($smiliecache[$i]['text'], "<img src=".$smiliecache[$i]['path']." border=0>", $out);
    return $out;
}

//´ÓÊý¾Ý¿âÖлñµÃ±íÇé·ûÐÅÏ¢
function getsmilies() {
	global $conn, $prefix;
	$recordset = &$conn->Execute("SELECT smiliespath as path, smiliestext as text FROM ".$prefix."_smilies");
	$count = 0;
	while(!$recordset->EOF) {
		$row = $recordset->fields;
		$smiliecache[$count] = $row;
		$count++;
		$recordset->MoveNext();
	}
	return $smiliecache;
}

//BB´úÂëµÄºËÐÄ´úÂë
function prepare_code($out) { 
 global $conn,$prefix,$searcharray,$replacearray;
 $phpversionnum = phpversion();

 if(!isset($searcharray) && !isset($replacearray)) {
  $searcharray[]="/\[list=(['\"]?)([^\"']*)\\1](.*)\[\/list((=\\1[^\"']*\\1])|(\]))/esiU";
  $replacearray[]="formatlist('\\3', '\\2')"; 
  $searcharray[]="/\[list](.*)\[\/list\]/esiU";	
  $replacearray[]="formatlist('\\1')"; 
  $searcharray[]="/\[url=(['\"]?)([^\"']*)\\1](.*)\[\/url\]/esiU";
  $replacearray[]="formaturl('\\2','\\3')";
  $searcharray[]="/\[url]([^\"]*)\[\/url\]/esiU";	
  $replacearray[]="formaturl('\\1')";
  $searcharray[]="/\[code](.*)\[\/code\]/esiU";	
  $replacearray[]="formatcodetag('\\1')";
  $searcharray[]="/\[php](.*)\[\/php\]/esiU";	
  $replacearray[]="phphighlite('\\1')";
  $searcharray[]="/\[img]([^\"]*)\[\/img\]/siU";
  $replacearray[]="<img src=\"\\1\" border=0>"; 
  $searcharray[]="/\[size=(['\"]?)([^\"']*)\\1](.*)\[\/font\]/esiU";
  $replacearray[]="formatsize('\\2','\\3')";
  $searcharray[]="/\[size]([^\"]*)\[\/font\]/esiU";
  $replacearray[]="formatsize('','\\1')";
  $searcharray[]="/\[color=(['\"]?)([^\"']*)\\1](.*)\[\/font\]/esiU";
  $replacearray[]="formatcolor('\\2','\\3')";
  $searcharray[]="/\[color]([^\"]*)\[\/font\]/esiU";
  $replacearray[]="formatcolor('','\\1')";
  $searcharray[]="/\[color]([^\"]*)\[\/color\]/esiU";
  $replacearray[]="formatcolor('','\\1')";
  $searcharray[]="/\[html]([^\"]*)\[\/html\]/esiU";
  $replacearray[]="formathtml('\\1')";

  $threeparams = "/\[%s=(['\"]?)([^\"']*),([^\"']*)\\1](.*)\[\/%s\]/siU";
  $twoparams = "/\[%s=(['\"]?)([^\"']*)\\1](.*)\[\/%s\]/siU";
  $oneparam = "/\[%s](.*)\[\/%s\]/siU"; 

  $recordset = &$conn->Execute("SELECT bbcodetag,bbcodereplace,params FROM ".$prefix."_bbcode");

  while(!$recordset->EOF) {
   $row = $recordset->fields;
   if($row[params]==0) continue;
   if($row[params]==1) $search = sprintf($oneparam, $row[bbcodetag], $row[bbcodetag]);
   if($row[params]==2) $search = sprintf($twoparams, $row[bbcodetag], $row[bbcodetag]);
   if($row[params]==3) $search = sprintf($threeparams, $row[bbcodetag], $row[bbcodetag]);
        	
   $searcharray[] = $search;
   $replacearray[] = $row[bbcodereplace];
   $searcharray[] = $search;
   $replacearray[] = $row[bbcodereplace];
   $searcharray[] = $search;
   $replacearray[] = $row[bbcodereplace];
   $recordset->MoveNext();
  } 
 }
 
 if ($phpversionnum<"4.0.5") $bbcode=str_replace("'", "\'", $out);
 $out = preg_replace($searcharray, $replacearray, $out);
 $out = str_replace("\\'", "'", $out);
 return $out;
}

//BB´úÂëÅäÌ׺¯Êý
function formatcodetag($code) {
	return "<blockquote><pre><font face=\"{font}\">´úÂëÈçÏ£º</font><hr>".str_replace("<br>","",str_replace("\\\"","\"",$code))."<hr></pre></blockquote>";
}

function formaturl($url, $title="", $maxwidth=60, $width1=40, $width2=-15) {
 if(!trim($title)) $title=$url;
 if(!preg_match("/[a-z]:\/\//si", $url)) $url = "http://$url";
 if(strlen($title)>$maxwidth) $title = substr($title,0,$width1)."...".substr($title,$width2);
 return "<a href=\"$url\" target=\"_blank\">".str_replace("\\\"", "\"", $title)."</a>";
}

function formatlist($list, $listtype="") {
 $listtype = ifelse(!trim($listtype), "",  " type=\"$listtype\"");
 $list = str_replace("\\\"","\"",$list);
 if ($listtype) return "<ol$listtype>".str_replace("[*]","<li>", $list)."</ol>";
 else return "<ul>".str_replace("[*]","<li>", $list)."</ul>";
}

function formatsize($size=3,$title) {
 return "<font size=\"$size\">".str_replace("\\\"","\"",$title)."</font>";
}

function formatcolor($color="#000000",$title) {
 return "<font color=\"$color\">".str_replace("\\\"","\"",$title)."</font>";
}

function formathtml($title) {
 return "<p><SPAN>HTML ´úÂëƬ¶ÎÈçÏÂ:<BR><TEXTAREA name=textfield rows=8  COLS=60  id=htmlcontent>".str_replace("\\\"","\"",$title)."</TEXTAREA><BR><INPUT onclick=runEx() type=button value=ÔËÐд˴úÂë name=Button> [Ctrl+A È«²¿Ñ¡Ôñ   Ìáʾ:Äã¿ÉÏÈÐ޸IJ¿·Ö´úÂ룬ÔÙ°´ÔËÐÐ]</SPAN><br>";
}

function phphighlite($code) {
 
 $code = str_replace("&gt;", ">", $code);
 $code = str_replace("&lt;", "<", $code);
 $code = str_replace("&amp;", "&", $code);
 $code = str_replace('$', '\$', $code);
 $code = str_replace('\n', '\\\\n', $code);
 $code = str_replace('\r', '\\\\r', $code);
 $code = str_replace('\t', '\\\\t', $code);
 $code = str_replace("<br>", "\r\n", $code);
 $code = str_replace("<br />", "\r\n", $code);
 
 $code = stripslashes($code);

 ob_start();
 $oldlevel=error_reporting(0);
 highlight_string($code);
 error_reporting($oldlevel);
 $buffer = ob_get_contents();
 ob_end_clean();
 //$buffer = str_replace("&quot;", "\"", $buffer);
 return "<blockquote><pre><font face=\"{font}\">php´úÂëÈçÏÂ:</font><hr>$buffer<hr></pre></blockquote>";
}

function prepare_quote($out) {
        global $zensur;
        $out = editDBdata($out);
        if($zensur == 1) $out = censor($out);
        return $out;
}

//--BB´úÂëÅäÌ׺¯Êý½áÊø

//¶ÔÆÁ±Î´ÊÓï½øÐд¦Àí
function censor($out) {
 global $cover,$badwords;
 reset($badwords);
 if(count($badwords)) {
  while (list($key, $val) = each($badwords)) {
   $val = trim($val);
   if(!$val) continue;
   if(preg_match("/\{(.+)\}/si", $val, $exp)) {
    $val = $exp[1];
    $position = strpos($val, "=");
    if($position===false) {
     $searcharray[] = "/([\s]{1})$val([\s]{1})/si"; 	                		
     $replacearray[] = "\\1".str_repeat($cover, strlen($val))."\\2";
     $searcharray[] = "/^$val([\s]{1})/si"; 	                		
     $replacearray[] = str_repeat($cover, strlen($val))."\\1";
     $searcharray[] = "/([\s]{1})$val$/si"; 	                		
     $replacearray[] = "\\1".str_repeat($cover, strlen($val));
    }
    else {
     $pcover = substr($val, $position+1);
     $val = substr($val, 0, $position);
     $searcharray[] = "/([\s]{1})$val([\s]{1})/si"; 	                		
     $replacearray[] = "\\1".$pcover."\\2";
     $searcharray[] = "/^$val([\s]{1})/si"; 	                		
     $replacearray[] = $pcover."\\1";
     $searcharray[] = "/([\s]{1})$val$/si"; 	                		
     $replacearray[] = "\\1".$pcover;
    }
   }
   else {
    $position = strpos($val, "=");
    if($position===false) {
     $out = eregi_replace("$val","".str_repeat($cover, strlen($val))."", $out);	                		
     $searcharray[] = "/$val/si"; 	                		
     $replacearray[] = str_repeat($cover, strlen($val));
    }
    else {
     $pcover = substr($val, $position+1);
     $val = substr($val, 0, $position);
     $searcharray[] = "/$val/si"; 	                		
     $replacearray[] = $pcover;
    }
   }
  }
 }
 return preg_replace($searcharray, $replacearray, $out);
}

//»ñµÃÎļþÀ©Õ¹Ãû£¨¸½¼þÓã©
function getextension($filename) {
  return strtolower(substr(strrchr($filename,"."),1));
}

//»ñµÃÖ÷Ìâ±êÖ¾
function getThreadflag($threadid) {
        global $prefix,$conn;
        $recordset = &$conn->Execute("SELECT flags FROM ".$prefix."_threads WHERE threadid='$threadid'");
		$result = $recordset->fields;
        return $result[flags];
}

//???
function check_boardobject($boardid,$objectid,$field) {
	global $prefix,$conn;
	$recordset = &$conn->Execute("SELECT COUNT(*) FROM ".$prefix."_object2board WHERE boardid = '$boardid' AND objectid = '$objectid' AND $field = 1");
	$result = $recordset->fields;
	return $result[0];
}

//¼ì²éÓû§ÃûÃÜÂëÊÇ·ñÓÐЧ
function checkUser($username,$password) {
        global $prefix,$conn;
        $recordset = &$conn->Execute("SELECT userpassword FROM ".$prefix."_user_table WHERE username='$username' && activation='1'");
        $result = $recordset->fields;
        if(!$result[userpassword]) return 0;
        elseif($result[userpassword]==$password) return 2;
        else return 1;
}

//È¡Ïû¶©ÔÄÖ÷Ìâ/ÌÖÂÛ°æ
/*$b_or_t²ÎÊý¾ö¶¨È¡ÏûµÄÊÇÖ÷Ì⻹ÊÇÌÖÂÛ°æ*/
function unsubscripe($id,$userid,$b_or_t) {
        global $prefix,$conn;
        $field = "fav".$b_or_t;
        $conn->Execute("DELETE FROM ".$prefix."_object2user WHERE userid = '$userid' AND objectid = '$id' AND $field = 1");
}

//¶©ÔÄÖ÷Ìâ/ÌÖÂÛ°æ
function subscripe($userid,$id,$b_or_t) {
        global $conn,$prefix,$favboards,$favthreads;
        if($b_or_t == "b") $max = $favboards;
        else $max = $favthreads;
        $field = "fav".$b_or_t;
        if(!check_userobject($userid,$id,$field)) {
		$recordset = &$conn->Execute("SELECT COUNT(*) FROM ".$prefix."_object2user WHERE userid = '$userid' AND $field = 1");
		$count = $recordset->fields;
		if($count[0] >= $max) eval ("\$output = \"".gettemplate("error24")."\";");
		else $conn->Execute("INSERT INTO ".$prefix."_object2user (userid,objectid,$field) VALUES ('$userid','$id','1')");
	}
        return $output;
}

//¸ù¾ÝÖ÷ÌâID»ñµÃÖ÷ÌâÃû
function getThreadname($threadid) {
        global $prefix,$conn;
        $recordset = &$conn->Execute("SELECT threadname FROM ".$prefix."_threads WHERE threadid='$threadid'");
        $result = $recordset->fields;
        return prepare_topic($result[threadname]);
}

//¸ù¾ÝÌÖÂÛ°æID»ñµÃÌÖÂÛ°æÃû
function getBoardname($boardid) {
        global $prefix,$conn;
        $recordset = &$conn->Execute("SELECT boardname FROM ".$prefix."_boards WHERE boardid='$boardid'");
        $result = $recordset->fields;
        return prepare_topic($result[boardname]);
}

//¸ù¾ÝÓû§ID»ñµÃÓû§Email
function getUserEmail($userid) {
        global $prefix,$conn;
        $recordset = &$conn->Execute("SELECT useremail FROM ".$prefix."_user_table WHERE userid='$userid'");
        $result = $recordset->fields;
        return $result[useremail];
}

//¸ù¾ÝÓû§ID»ñµÃÓû§Ãû
function getUsername($userid) {
        global $prefix,$conn;
        $recordset = &$conn->Execute("SELECT username FROM ".$prefix."_user_table WHERE userid='$userid'");
        $row = $recordset->fields;
        return $row[username];
}

//¸ù¾ÝÓû§Ãû»ñµÃÓû§ID
function getUserid($usernick) {
        global $conn,$prefix;
        $recordset = &$conn->Execute("SELECT userid FROM ".$prefix."_user_table WHERE username='$usernick'");
        $result = $recordset->fields;
        return $result[userid];
}

//»ñµÃBB´úÂë°´Å¥
function getcodebuttons() {
	$modechecked[0] = "CHECKED";

	eval ("\$bbcode_sizebits = \"".gettemplate("bbcode_sizebits")."\";");
	eval ("\$bbcode_fontbits = \"".gettemplate("bbcode_fontbits")."\";");
	eval ("\$bbcode_colorbits = \"".gettemplate("bbcode_colorbits")."\";");
	eval ("\$bbcode_alignbits = \"".gettemplate("bbcode_alignbits")."\";");
	eval ("\$bbcode_buttons = \"".gettemplate("bbcode_buttons")."\";");
	return $bbcode_buttons;
}

//»ñµÃ±íÇé·û°´Å¥
function getclickysmilies ($tableColumns=3,$maxSmilies=-1) {
	global $session,$boardid,$styleid, $conn, $prefix;

	$recordset = &$conn->Execute("SELECT * FROM ".$prefix."_smilies");
	$totalSmilies = $recordset->RecordCount();

	if (($maxSmilies == -1) || ($maxSmilies >= $totalSmilies)) $maxSmilies = $totalSmilies;
	elseif ($maxSmilies < $totalSmilies) eval ("\$bbcode_smilies_getmore = \"".gettemplate("bbcode_smilies_getmore")."\";");

	$i=0;
	while(!$recordset->EOF) {
		$row = $recordset->fields;
		eval ("\$smilieArray[\"".$i."\"] = \"".gettemplate("bbcode_smiliebit")."\";");
		$i++;
		$recordset->MoveNext();
	}
	$tableRows = ceil($maxSmilies/$tableColumns);
	$count = 0;
	for ($i=0; $i<$tableRows; $i++) {
		$smiliebits .= "\t<tr bgcolor=\"{tableb}\">\n";
		for ($j=0; $j<$tableColumns; $j++) {
			$smiliebits .= "\t<td align=\"center\">".$smilieArray[$count]."&nbsp;</td>\n";
			$count++;
		}
		$smiliebits .= "\t</tr>\n";
	}

	eval ("\$bbcode_smilies = \"".gettemplate("bbcode_smilies")."\";");
	return $bbcode_smilies;
}

//¼ì²é¼´½«·¢±íµÄÎÄÕÂ
function check_posts($text) {
	global $image, $image_ext, $maximage;
	$image_ext = explode("\r\n",$image_ext);
	$count=0;
	do {	
		preg_match("/\[img]([^\"]*)\[\/img\]/siU",$text,$exp);
		if(!$exp[0]) break;
		$text = str_replace($exp[0],"",$text);
		$extension = strtolower(substr($exp[1], strrpos($exp[1],".")+1));
		if(!in_array($extension, $image_ext)) {
			return 1;
			break;
		}
		$count++;
	} while($exp[0]!="" && $count<=$maximage);
	if($count>$maximage) return 1;	
}

//±à¼­¼´½«·¢±íµÄÎÄÕÂÒÔ±ãÊý¾Ý¿â´¢´æ
function editPostdata($data) {
 $data = str_replace("'","&acute;", $data);
 $data = str_replace("\"","&quot;", $data);
 return $data;
}

//×Ô¶¯URL·ÖÎö
function parseURL($out) {
	$urlsearch[]="/([^]_a-z0-9-=\"'\/])((https?|ftp):\/\/|www\.)([^ \r\n\(\)\*\^\$!`\"'\|\[\]\{\};<>]*)/si";
	$urlsearch[]="/^((https?|ftp):\/\/|www\.)([^ \r\n\(\)\*\^\$!`\"'\|\[\]\{\};<>]*)/si";
	$urlreplace[]="\\1[URL]\\2\\4[/URL]";
	$urlreplace[]="[URL]\\1\\3[/URL]";
	$emailsearch[]="/([\s])([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))/si";
	$emailsearch[]="/^([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,}))/si";
	$emailreplace[]="\\1[EMAIL]\\2[/EMAIL]";
	$emailreplace[]="[EMAIL]\\0[/EMAIL]";
	$out = preg_replace($urlsearch, $urlreplace, $out);
	if (strpos($out, "@")) $out = preg_replace($emailsearch, $emailreplace, $out);
	return $out;
}

//±íµ¥Óʼþº¯Êý
function formmail($absender,$message,$betreff,$useremail) {
        global $master_board_name, $php_path;
        $useremail = trim($useremail);
        $message .= "\n\n_________________________________________________________________\nPowered by: ".$master_board_name." - ".$php_path;
        $absender = "From: ".$absender;
        mail($useremail,$betreff,$message,$absender);
}

//±¨¸æÎÊÌâÎÄÕº¯Êý
function report($userid,$postid,$boardid) {
        global $master_board_name, $php_path, $master_email, $conn, $prefix;
        $recordset = &$conn->Execute("SELECT ".$prefix."_object2board.objectid, useremail FROM ".$prefix."_object2board LEFT JOIN ".$prefix."_user_table ON (".$prefix."_object2board.objectid=".$prefix."_user_table.userid) WHERE boardid='$boardid' AND mod=1");
        $mod = $recordset->fields;
        if(!$mod[useremail]) {
        	$recordset = &$conn->Execute("SELECT ".$preifx."_object2board.objectid, useremail FROM ".$prefix."_object2board LEFT JOIN ".$prefix."_user_table ON (".$prefix."_object2board.objectid=".$prefix."_user_table.userid) WHERE mod=1");
        	$mod = $recordset->fields;
        }
        if(!$mod[useremail]) {
        	$recordset = &$conn->Execute("SELECT ".$prefix."_groups.id, useremail FROM ".$prefix."_groups LEFT JOIN ".$prefix."_user_table ON (".$prefix."_groups.id=".$prefix."_user_table.groupid) WHERE ismod=1 OR issupermod=1 ORDER BY ismod DESC");
        	$mod = $recordset->fields;
        }
        $recordset = &$conn->Execute("SELECT userid, message FROM ".$prefix."_posts WHERE postid='$postid'");
        $post = $recordset->fields;
        $authorname = getUsername($post[userid]);
        $username = getUsername($userid);
        eval ("\$betreff = \"".gettemplate("report_betreff")."\";");
        eval ("\$message = \"".gettemplate("report_mail")."\";");
        mail(trim($mod[useremail]),$betreff,$message,"From: ".$master_email);
}

//¼¤»îÓû§º¯Êý
function activat($userid,$code)
{
	global $conn,$prefix;
	$recordset = &$conn->Execute("SELECT COUNT(userid)as anzahl FROM ".$prefix."_user_table WHERE userid='$userid'");
	$anzahluser = $recordset->fields;
	if($anzahluser[anzahl]==0) return 1;
	else {
		$recordset = &$conn->Execute("SELECT activation FROM ".$prefix."_user_table WHERE userid='$userid' && activation!='1'");
		$anzahluser = $recordset->RecordCount();
		if($anzahluser==0) return 2;
			else {
				$result = $recordset->fields;
				if($code==$result[activation]) $conn->Execute("UPDATE ".$prefix."_user_table SET activation='1' WHERE userid='$userid'");
				else return 3;
			}
		}
}

//»ñµÃ×îºó·¢ÌùµÄÁ´½Óº¯Êý
function getLastPost($id,$nr) {
	global $eproseite, $prefix, $conn, $session, $longdateformat, $postorder;
	if($nr==1) {
		$recordset = &$conn->Execute("SELECT threadid,replies FROM ".$prefix."_threads WHERE boardparentid='$id' ORDER by timelastreply DESC LIMIT 1");
		$result = $recordset->fields;
		$threadid = $result[threadid];
		if($postorder) return "thread.php?threadid=".$threadid."&boardid=".$id."$session&page=1#1";
		else {
			$posts = $result[replies]+1;
			$pages=(int)($posts/$eproseite);
			if(($posts/$eproseite)-$pages>0) $pages++;
			return "thread.php?threadid=".$threadid."&boardid=".$id."$session&page=".$pages."#".$posts;
		}
	}
	if($nr==2) {
		$recordset = &$conn->Execute("SELECT boardparentid,replies FROM ".$prefix."_threads WHERE threadid='$id' LIMIT 1");
		$result = $recordset->fields;
		$boardid = $result[boardparentid];
		if($postorder) return "thread.php?threadid=".$id."&boardid=".$boardid."$session&page=1#1";
		else {
			$posts = $result[replies]+1;
			$pages=(int)($posts/$eproseite);
			if(($posts/$eproseite)-$pages>0) $pages++;
			return "thread.php?threadid=".$id."&boardid=".$boardid."$session&page=".$pages."#".$posts;
		}
	}
	if($nr==4) {
		$recordset = &$conn->Execute("SELECT threadparentid, boardparentid FROM ".$prefix."_posts WHERE userid='$id' ORDER by posttime DESC LIMIT 1");
		$result = $recordset->fields;
		$threadid = $result[threadparentid];
		if($postorder) return "thread.php?threadid=".$threadid."&boardid=".$result[boardparentid]."$session&page=1#1";
		else {
			$recordset = &$conn->Execute("SELECT boardparentid,replies FROM ".$prefix."_threads WHERE threadid='$threadid'");
			$result = $recordset->fields;
			$posts = $result[replies]+1;
			$pages=(int)($posts/$eproseite);
			if(($posts/$eproseite)-$pages>0) $pages++;
			return "thread.php?threadid=".$threadid."&boardid=".$result[boardparentid]."&styleid=$styleid$session&page=".$pages."#".$posts;
		}
	}
	if($nr==5) {
		$recordset = &$conn->Execute("SELECT threadparentid, boardparentid FROM ".$prefix."_posts WHERE userid='$id' ORDER by posttime DESC LIMIT 1");
		$result = $recordset->fields;
		$threadid = $result[threadparentid];
		if($postorder) return "thread.php?threadid=".$threadid."&boardid=".$result[boardparentid]."$session&page=1#1";
		else {
			$recordset = &$conn->Execute("SELECT boardparentid,replies FROM ".$prefix."_threads WHERE threadid='$threadid'");
			$result = $recordset->fields;
			$posts = $result[replies]+1;
			$pages=(int)($posts/$eproseite);
			if(($posts/$eproseite)-$pages>0) $pages++;
			return "thread.php?threadid=".$threadid."&boardid=".$result[boardparentid]."&styleid=$styleid$session&page=".$pages."#".$posts;
		}
	}
}

//µÃµ½×îÐÂÌù
function firstnewPost($threadid,$time) {
	global $eproseite,$prefix,$conn,$styleid,$session, $postorder;
			$sthreadname = "sthread_".$threadid;
	global $$sthreadname;
	if($$sthreadname > $time) $time = $$sthreadname+1;
	$recordset = &$conn->Execute("SELECT boardparentid, replies FROM ".$prefix."_threads WHERE threadid='$threadid' ORDER by timelastreply DESC");
	$thread = $recordset->fields;
	$posts = $thread[replies]+1;

	$recordset = $conn->Execute("SELECT posttime FROM ".$prefix."_posts WHERE threadparentid='$threadid' ORDER by posttime ".ifelse($postorder,"DESC","ASC"));
	$i=1;
	while(!$recordset->EOF) {
		$row = $recordset->fields;
		if($time<=$row[posttime]) break;
		$i++;
		$recordset->MoveNext;
	}
	$recordset->close();
	$j=(int)($i/$eproseite);
	if(($i/$eproseite)-$j>0) $j++;

	return "thread.php?threadid=".$threadid."&boardid=".$thread[boardparentid]."&styleid=$styleid$session&page=".$j."#".$i;
}

#ÉÏ´«º¯Êý
function upload($moderate=0) {
	global $attachment,$attachment_name,$attachment_size,$conn;
	global $prefix,$MAX_FILE_SIZE,$allowextensions;

	$attachment_name = strtolower($attachment_name);
	$extension=strtolower(getextension($attachment_name));
	//die($extension);
	$pos=strpos($allowextensions,$extension);
	if ($pos===false) {
    // ÎÞЧµÄÀ©Õ¹Ãû
		// die($extension);
		$output="ÎÞЧµÄÀ©Õ¹Ãû£¡";
		eval("dooutput(\"".gettemplate("action_error")."\");");
    	exit;
  	}

	$time=time();
	$save_filename=$attachment_name+$time; //Éú³É±£´æÎļþµÄÎļþÃû
	if (is_uploaded_file($attachment)) {
	//$filesize=filesize($attachment);
     	if ($MAX_FILE_SIZE!=0 and $attachment_size>$MAX_FILE_SIZE) {
      	// ÎļþÌ«´ó
			$output="ÄúÉÏ´«µÄÎļþÌ«´ó£¡";
			eval("dooutput(\"".gettemplate("action_error")."\");");
			die;
		}
		/*if ($filesize!=$attachment_size) {
      	// Ò»°ã±£»¤ÐÔ´íÎó£¬Îļþ´óС²»Í¬
			$output="ÄúÉÏ´«µÄÎļþÓÐÎó£¬Çë¼ì²éÎÞÎóºóÖØÐÂÉÏ´«£¡";
			eval("dooutput(\"".gettemplate("action_error")."\");");
			exit;
		}*/
		if (strstr($attachment,"..")!="") {
		// Ò»°ã±£»¤ÐÔ´íÎó
			$output="ÄúÉÏ´«µÄÎļþÓÐÎó£¬Çë¼ì²éÎÞÎóºóÖØÐÂÉÏ´«£¡";
			eval("dooutput(\"".gettemplate("action_error")."\");");
			exit;
		}
		copy($attachment,"uploadfiles/$save_filename");
		unlink($attachment);
		//echo "ÉÏ´«³É¹¦£¡";
		$conn->Execute("INSERT INTO ".$prefix."_attachment (originfilename,savefilename,time) VALUES ('$attachment_name','$save_filename',$time)");
	} else {
		$output="ÉÏ´«Îļþ³ö´í£¬ÇëÖØÊÔ¡£Èç¹ûÎÊÌâÒÀÈ»´æÔÚ£¬ÇëÁªÏµ<a href=\"mailto:$adminmail\">¹ÜÀíÔ±</a>¡£";
 		eval("dooutput(\"".gettemplate("action_error")."\");");
	}
}

//¼ì²éEmailÊÇ·ñÕýÈ·
function checkemail($email, $db=0) {
	global $conn, $prefix, $multi_email, $banemail;
	if(!substr_count($email,"@") || substr_count($email,"@")>1) return 1;
	$position1 = strrpos($email,"@");
	if(!$position1) return 1;
	$position2 = strrpos($email,".");
	if(!$position2) return 1;
	if(strlen(substr($email, $position2)) < 3)return 1;
	if(strlen(substr($email, $position1,$position2-$position1-1))<2) return 1;
	if(!$multi_email && !$db) {
		$check = &$conn->Execute("SELECT COUNT(userid) FROM ".$prefix."_user_table WHERE useremail = '$email'");
		if($check->fields[0]) return 1;
	}
	$banemail = explode("\n",$banemail);
	for($i = 0; $i < count($banemail); $i++) {
		if(!trim($banemail[$i])) continue;
		if(ereg("\*", $banemail[$i])) {
			$banemail[$i] = str_replace("*",".*", trim($banemail[$i]));
			if(eregi("$banemail[$i]", $email)) return 1;
			break;
		}
		elseif(strtolower($email)==strtolower(trim($banemail[$i]))) {
			return 1;
			break;
		}  
	}
}

//¼ì²éÓû§ÊÇ·ñÔÚÏß
function checkuseronline($userid) {
        global $prefix,$conn;
        $recordset = &$conn->Execute("SELECT COUNT(userid) as anzahl FROM ".$prefix."_user_table WHERE userid='$userid' AND invisible='0'");
        $user = $recordset->fields;
        if($user[anzahl]) {
        	$recordset = &$conn->Execute("SELECT COUNT(zeit)as anzahl FROM ".$prefix."_useronline WHERE userid='$userid'");
        	$anzahl = $recordset->fields;
        }
        return $anzahl[anzahl];
}

//»Ø¸´º¯Êý
function newPost($boardid,$threadid,$userid,$subject,$message,$posticon,$parseurl,$email,$disablesmilies,$signature,$close) {
	global $attachment,$attachment_name,$attachment_size;
	global $prefix,$conn,$MAX_FILE_SIZE,$allowextensions;
	$recordset = &$conn->Execute("SELECT boardparentid,flags FROM ".$prefix."_threads WHERE threadid='$threadid'");
	$thread_info = $recordset->fields;
	if($thread_info[flags]==1) return 2;
		else {
			$time = time();
			$subject = editPostdata($subject);
			$message = editPostdata($message);
			if($parseurl) $message = parseURL($message);

			if($disablesmilies!=1) $disablesmilies=0;
			//die ($attachment_name);
			if ($attachment_name) {
				upload();
				$attachmentid = &$conn->Execute("SELECT id,time FROM ".$prefix."_attachment ORDER BY id DESC");
				$attachmentid = $recordset->fields;
				//die ($attachmentid[id]);
			}
			if($signature!=1) $signature=0;
                        
			$conn->Execute("UPDATE ".$prefix."_user_table SET userposts=userposts+1 WHERE userid='$userid'");
			$conn->Execute("UPDATE ".$prefix."_threads SET replies=replies+1, timelastreply='$time' WHERE threadid='$threadid'");
			$ip = getenv(REMOTE_ADDR);
			$conn->Execute("INSERT INTO ".$prefix."_posts (boardparentid,threadparentid,userid,posttime,posttopic,message,posticon,disable_smilies,signature,ip,attachmentid) VALUES ('$boardid','$threadid','$userid','$time','$subject','$message','$posticon','$disablesmilies','$signature','$ip','$attachmentid[id]')");
                        
			$postid = $conn->Insert_ID();
			$conn->Execute("UPDATE ".$prefix."_boards SET posts=posts+1, lastposttime = '$time', lastpostid = '$postid' WHERE boardid = '$boardid'");	
			                        
			sendEmail($userid,getLastPost($userid,5),$threadid,$boardid);
			if($email && $userid) {
				$recordset = &$conn->Execute("SELECT COUNT(*) FROM ".$prefix."_notify WHERE threadid = '$threadid' AND userid = '$userid'");
				$check = $recordset->fields;
				if(!$check[0]) $conn->Execute("INSERT INTO ".$prefix."_notify VALUES ($threadid,$userid)");
			}
			if($close) $conn->Execute("UPDATE ".$prefix."_threads SET flags = 1 WHERE threadid = '$threadid'");
			return 4;
		}
}

//·¢ËÍÓʼþ
function sendEmail($userid,$link,$threadid,$boardid) {
	global $boardid, $master_email, $php_path, $conn, $prefix;
	$recordset = &$conn->Execute("SELECT * FROM ".$prefix."_notify WHERE threadid = '$threadid'");
	if($recordset->RecordCount()) {
		$boardname = getBoardname($boardid);
		$threadname = getThreadname($threadid);
		if($userid) $authorname = getUsername($userid);
			else eval ("\$authorname = \"".gettemplate("lg_anonymous")."\";");
		eval ("\$inhalt = \"".gettemplate("notify_inhalt")."\";");
		eval ("\$betreff = \"".gettemplate("notify_betreff")."\";");
		while(!$recordset->EOF) {
			$row = $recordset->fields;
			if($row[userid]==$userid) continue;
			$email = getUserEmail($row[userid]);
			mail($email,$betreff,$inhalt.$row[userid],"From: ".$master_email);
			$recordset->MoveNext();
		}
	}
}

//¼ì²éÓû§ÃûÊÇ·ñºÏ·¨£ºÖØÃû¡¢ÊÇ·ñΪÒѱ£»¤Óû§ÃûµÈ
function checkname($name) {
	global $conn, $prefix, $banname;
	$bannames = explode("\r\n", trim($banname));
	for($i=0;$i<count($bannames);$i++) {
	 $bannames[$i] = trim($bannames[$i]);
	 if(!$bannames[$i]) continue;
	 if($name==$bannames[$i]) return 1;
	}
	$check = &$conn->Execute("SELECT COUNT(userid) FROM ".$prefix."_user_table WHERE username = '$name'");
	return $check->fields[0];
}

//ÅжÏÓû§ÃÜÂëÊÇ·ñºÏ·¨
function checkpw($userid,$password) {
	global $conn, $prefix;
	$check = &$conn->Execute("SELECT COUNT(userid) FROM ".$prefix."_user_table WHERE userid = '$userid' AND userpassword = '$password'");
	return $check->fields[0];
}

//»ñµÃÓû§ÃÜÂë
function getUserPW($userid) {
        global $prefix,$conn;
        $result = &$conn->Execute("SELECT userpassword FROM ".$prefix."_user_table WHERE userid='$userid'");
        return $result->fields[userpassword];
}

//¼ì²éÓû§
function check_userobject($userid,$objectid,$field) {
	global $prefix,$conn;
	$recordset = &$conn->Execute("SELECT COUNT(*) FROM ".$prefix."_object2user WHERE userid = '$userid' AND objectid = '$objectid' AND $field = 1");
	return $recordset->fields[0];
}
?>
Return current item: Chinese Project Forum