<?
session_start();
$ip1=$REMOTE_ADDR;
$today_time=date("Y")."年".date("n")."月".date("j")."日";
$todate=date("Y")."/".date("n")."/".date("j");
$stemp=date("YmjHis");
require"./config.php";
function errorview($msg)
{
print "<html><head></head><body><script>alert('$msg');history.back();</script></body></html>";
}
##################
function safe_cover($s)
          {
            $s=str_replace("|","",$s);
            $s=str_replace("<","&lt",$s);
            $s=str_replace(">","&gt",$s);
            $s=str_replace("\t","",$s);
            $s=str_replace("\n","<br>",$s);
            $s=str_replace("\r","",$s);
            $bad="他妈的|妈的|他爸的|操你妈|狗娘的|狗日的|shit|日你娘|日你妈|娘的|日你姐|fuck|龟儿子|龟孙子|兔崽子";
            $bad_array=explode("|",$bad);
            $co=count($bad_array)-1;
            for ($i=0;$i<=$co;$i++)
                {
                $s=str_replace($bad_array[$i],"xxx",$s);
                }
            return $s;
            }
#########
function ubb($Text) {
  $Text=htmlspecialchars($Text);
  $Text=ereg_replace("\r\n","<br>",$Text);
  $Text=ereg_replace("\r","<br>",$Text);
  $Text=nl2br($Text);
  $Text=preg_replace("/\\t/is","  ",$Text);
  $Text=preg_replace("/\[h1\](.+?)\[\/h1\]/is","<h1>\\1</h1>",$Text);
  $Text=preg_replace("/\[h2\](.+?)\[\/h2\]/is","<h2>\\1</h2>",$Text);
  $Text=preg_replace("/\[h3\](.+?)\[\/h3\]/is","<h3>\\1</h3>",$Text);
  $Text=preg_replace("/\[h4\](.+?)\[\/h4\]/is","<h4>\\1</h4>",$Text);
  $Text=preg_replace("/\[h5\](.+?)\[\/h5\]/is","<h5>\\1</h5>",$Text);
  $Text=preg_replace("/\[h6\](.+?)\[\/h6\]/is","<h6>\\1</h6>",$Text);
  $Text=preg_replace("/\[url\](http:\/\/.+?)\[\/url\]/is","<a href=\\1 target=_blank>\\1</a>",$Text);
  $Text=preg_replace("/\[url\](.+?)\[\/url\]/is","<a href=\"http://\\1\" target=_blank>http://\\1</a>",$Text);
  $Text=preg_replace("/\[url=(http:\/\/.+?)\](.*)\[\/url\]/is","<a href=\\1 target=_blank>\\2</a>",$Text);
  $Text=preg_replace("/\[url=(.+?)\](.*)\[\/url\]/is","<a href=http://\\1 target=_blank>\\2</a>",$Text);
  $Text=preg_replace("/\[img\](.+?)\[\/img\]/is","<img src=\\1>",$Text);
  $Text=preg_replace("/\[color=(.+?)\](.+?)\[\/color\]/is","<font color=\\1>\\2</font>",$Text);
  $Text=preg_replace("/\[size=(.+?)\](.+?)\[\/size\]/is","<font size=\\1>\\2</font>",$Text);
  $Text=preg_replace("/\[sup\](.+?)\[\/sup\]/is","<sup>\\1</sup>",$Text);
  $Text=preg_replace("/\[sub\](.+?)\[\/sub\]/is","<sub>\\1</sub>",$Text);
  $Text=preg_replace("/\[pre\](.+?)\[\/pre\]/is","<pre>\\1</pre>",$Text);
  $Text=preg_replace("/\[email\](.+?)\[\/email\]/is","<a href=\\1>\\1</a>",$Text);
  $Text=preg_replace("/\[i\](.+?)\[\/i\]/is","<i>\\1</i>",$Text);
  $Text=preg_replace("/\[b\](.+?)\[\/b\]/is","<b>\\1</b>",$Text);
  $Text=preg_replace("/\[quote\](.+?)\[\/quote\]/is","<blockquote><font size='1' face='Courier New'>quote:</font><hr>\\1<hr></blockquote>", $Text);
  $Text=preg_replace("/\[code\](.+?)\[\/code\]/is","<blockquote><font size='1' face='Times New Roman'>code:</font><hr color='lightblue'><i>\\1</i><hr color='lightblue'></blockquote>", $Text);
  $Text=preg_replace("/\[sig\](.+?)\[\/sig\]/is","<div style='text-align: left; color: darkgreen; margin-left: 5%'><br><br>--------------------------<br>\\1<br>--------------------------</div>", $Text);
return $Text;
}
function str($msg){
  $msg=ubb($msg);
  $msg=nl2br($msg); #处理message
  $msg=str_replace("\n","",$msg); #处理message
  $msg=str_replace("\r","",$msg); #处理message
  return $msg;
}
###############
function alol($onfile)
{
global $asize;
$all_ol=file("count/$onfile","r");
$asize=count($all_ol);
}
###################
function read_user_zl($user_login_id)
{
global $oo,$user_id,$username,$userpass1,$birth,$star,$usersex,$userblood,$userfrom,$userhobby,$userpage,$useroicq,$usericq,$usermail,$usermobi,$usertel,$useraddr,$usercode,$userly,$userdate,$biryear,$birmon,$birday;
$lines = file("user/$user_login_id.php");
while (list($tmpkey,$line) = each($lines))
   {
   $line=ereg_replace("\n","",$line);
   list($oo,$user_id,$username,$userpass1,$birth,$star,$usersex,$userblood,$userfrom,$userhobby,$userpage,$useroicq,$usericq,$usermail,$usermobi,$usertel,$useraddr,$usercode,$userly,$userdate)=split("\t",$line);
   list($biryear,$birmon,$birday)=split('\/',$birth);
   }
}
########
function class_read_user($user_login_id)
{
global $oo,$cuser_id,$cusername,$cuserpass1,$cbirth,$cstar,$cusersex,$cuserblood,$cuserfrom,$cuserhobby,$cuserpage,$cuseroicq,$cusericq,$cusermail,$cusermobi,$cusertel,$cuseraddr,$cusercode,$cuserly,$cuserdate;
if(file_exists("user/$user_login_id.php")){
$lines=file("user/$user_login_id.php");
while (list($tmpkey,$line) = each($lines))
   {
   $line=ereg_replace("\n","",$line);
   list($oo,$cuser_id,$cusername,$cuserpass1,$cbirth,$cstar,$cusersex,$cuserblood,$cuserfrom,$cuserhobby,$cuserpage,$cuseroicq,$cusericq,$cusermail,$cusermobi,$cusertel,$cuseraddr,$cusercode,$cuserly,$cuserdate)=split("\t",$line);
   }
   }
}
#########
function read_card($userid)
{
global $my_id,$my_name,$w_addr,$gu_tel,$m_phone,$my_mail;
  $lines = file("user/$userid.crd");
while (list($tmpkey,$line) = each($lines))
   {
   $line=ereg_replace("\n","",$line);
   list($my_id,$my_name,$w_addr,$gu_tel,$m_phone,$my_mail)=split("\t",$line);
   }
}
###################
function read_file($file_name) {
        $filenum=fopen($file_name,"r");
        flock($filenum,LOCK_SH);
        $file_data=fread($filenum,filesize($file_name));
        fclose($filenum);
        return $file_data;
}
####################
function write_file($file_name,$data,$method="w") {
        $filenum=@fopen($file_name,$method);
        flock($filenum,LOCK_EX);
        $file_data=fwrite($filenum,$data);
        fclose($filenum);
        return $file_data;
}
##################
function logincount($user_id)
{
global $stemp,$result,$ip1;
$lines = file("count/$user_id.php");
while (list($tmpkey,$line) = each($lines))
   {
   $line=ereg_replace("\n","",$line);
   if($line!=$user_id)$writeyn="0";else $writeyn="1";
   list($result,$oldip,$ontime)=split("\t",$line);
   }
if($oldip!=$ip1||$stemp-$ontime>3000)
   {
   $result++;
   }else $result=$result;
if($stemp-$ontime<3000)$newtime=$ontime;else $newtime=$stemp;
$newdat=$result."\t".$ip1."\t".$newtime."\n";
$fp=fopen("count/$user_id.php","w+");
fwrite($fp,$newdat);
fclose($fp);
}
############
function onlinetime($onfile)
{
global $stemp;
$onlinetimefile=read_file("count/$onfile");
$onlinetimefile=explode("\n",$onlinetimefile);
$onlineusercount=count($onlinetimefile);
for ($j=0;$j<$onlineusercount;$j++)
    {
    $onlineuserdetail=explode("\n",$onlinetimefile[$j]);
    $on_user_file=$onlineuserdetail[$j];
    $logincount=file("count/$on_user_file.php");
    list($on_u_id,$on_u_ip,$on_u_time)=explode("\t",$logincount);
    if($stemp-$on_u_time>3000)
       {
       $hastitles = file("count/$onfile");
       $ccc=count($hastitles);
       $fp = fopen("count/$onfile","w");
       for ($i=0;$i<$ccc;$i++)
            {
            list($con_id1)=explode("\n",$hastitles[$i]);
            if($con_id1!=$onlineuserdetail[$j])fputs($fp,$hastitles[$i]);
            }
   fclose($fp);
       }
    }



/*$lines = file("user/$onfile");
$size = count($lines);
for($i=0; $i<$size; $i++)
    {
    $linea=$lines[$i];
    $linea=ereg_replace("\n","", $linea);
    if($linea != "") {
    $lines1a=file("user/$onfile");
    while(list($tmpkey, $line1a) = each($lines1a))
         {
         $line1=ereg_replace("\n","", $line1);
         list($onlineuser)=split("\t",$linea);
         }
    $liness = file("count/$onlineuser.php");
    while (list($tmpkey,$line) = each($liness))
           {
           $line=ereg_replace("\n","",$line);
           list($e_num,$e_ip,$e_time)=split("\t",$line);
           }
    if($stemp-$e_time>3000)
       {
       $hastitles = file("$onfile");
       $TITLES = fopen("$onfile","w");
       while (list($tmpkey,$m)=each($hastitles))
              {
              $m = ereg_replace("\n","",$m);
              if($m!="")
                 {
                 list($index)=split("\n",$m);
                 if($index!=$onlineuser){fwrite($TITLES,$m."\n");}
                 }
              }
       }
    }
} */
}
#######
function delonline($onfile,$user_id)
{
$onlinefile=read_file("count/$onfile");
$onlineusercount=count($onlinefile);
for ($j=0;$j<$onlineusercount;$j++)
    {
    $onlineuserdetail=explode("\n",$onlinefile);
    if($onlineuserdetail[0]==$user_id){$ynonlinedel=1;break;}else $ynonlinedel=0;
    }
if($ynonlinedel==1)
   {
   $hastitles = file("count/$onfile");
   $TITLES = fopen("count/$onfile","w");
   while (list($tmpkey,$m)=each($hastitles))
          {
          $m = ereg_replace("\n","",$m);
          if($m!="")
             {
             list($index)=split("\n",$m);
             if($index!=$user_id){fwrite($TITLES,$m."\n");}
             }
          }
   }
}
####################
function writetofile ($path,$data) {
if ($data!="") {
        $filenum=fopen($path,"w");
        flock($filenum,LOCK_EX);
        fwrite($filenum,$data);
        fclose($filenum);
        }
}
###########
function readclass($id)
{
global $cjadmin,$schoolx,$schoolc,$schooln,$classn,$creatdate,$admin1,$admin2,$admin3;
$lines = file("class/$id/config.php");
while (list($tmpkey,$line) = each($lines))
   {
   $line=ereg_replace("\n","",$line);
   list($oo,$cjadmin,$schoolx,$schoolc,$schooln,$classn,$creatdate,$admin1,$admin2,$admin3)=split("\t",$line);
   }
}
##########
function haveclass($claid)
{
$classlist=read_file("class/classlist.php");
$classlist=explode("\n",$classlist);
$listcount=count($classlist);
for ($j=0;$j<$listcount;$j++)
    {
    $classlistdetail=explode("\t",$classlist[$j]);
    if($classlistdetail[0]==$claid){$yn=1;break;}else $yn=0;
    }
return $yn;
}
#########
function ynjoinclass($claid,$userid)
{
$classuser=read_file("class/$claid/list");
$classuser=explode("\n",$classuser);
$listcount=count($classuser);
for ($j=0;$j<$listcount;$j++)
    {
    $classuserdetail=explode("\t",$classuser[$j]);
    if($classuserdetail[0]==$userid){$yn=1;break;}else $yn=0;
    }
return $yn;
}
##########
function gotNewMessage($u_name)
{
global $gotNewMessage,$myclass;
        $gotNewMessage=0;
        if (file_exists("class/$myclass/msg/$u_name.rec"))
        {
                $messages=file("class/$myclass/msg/$u_name.rec");
                $msgcount=count($messages);
                for ($i=0; $i<$msgcount; $i++)
                {
                $msgdetail=explode("|",$messages[$i]);
                if ($msgdetail[4]==0) $gotNewMessage++;
                }
        }
}
#######
?>