<?
require"ygl.php";
if(!isset($ses_user_id)||!isset($ses_user_psd)){errorview("对不起，你没有登陆！！");exit;}
$user_login_id=$ses_user_id;
$user_login_psd=$ses_user_psd;
if(!ynjoinclass($user_login_id)){errorview("对不起，你没有加入该班！！");exit;}
#############删除重复用户
$onlinefile=read_file("data/online");
$onlinefile=explode("\n",$onlinefile);
$onlineusercount=count($onlinefile);
for ($j=0;$j<$onlineusercount;$j++)
    {
    $onlineuserdetail=explode("\t",$onlinefile[$j]);
    if($onlineuserdetail[0]==$user_login_id){$ynonlinedel=1;break;}else $ynonlinedel=0;
    }
if($ynonlinedel==1)
   {
   $hastitles = file("data/online");
   $ccc=count($hastitles);
   $fp = fopen("data/online","w");
   for ($i=0;$i<$ccc;$i++)
        {
        list($con_id,$con_etime)=explode("\t",$hastitles[$i]);
        if($con_id!=$user_login_id)fputs($fp,$hastitles[$i]);
        }
   fclose($fp);
   }
########写入用户
$classcountfile=read_file("data/online");
$classcountfile=explode("\n",$classcountfile);
$listcount=count($classcountfile);
for ($j=0;$j<$listcount;$j++)
    {
    $classcountdetail=explode("\t",$classcountfile);
    if($classcountdetail[0]==$user_login_id){$writeyn="0";break;}else $writeyn="1";
    }
for ($j=0;$j<$listcount;$j++)
    {
    $classcountdetail=explode("\t",$classcountfile);
    if($stemp-$classcountdetail[1]>1000){$writeyn2="1";break;}else $writeyn2="0";
    }
if($writeyn=="1")
{
$newdat=$user_login_id."\t".$stemp."\n";
$fp=fopen("data/online","a+");
fwrite($fp,$newdat);
fclose($fp);
}
########删除超出时间范围内的用户
$onlinetimefile=read_file("data/online");
$onlinetimefile=explode("\n",$onlinetimefile);
$onlineusercount=count($onlinetimefile);
for ($j=0;$j<$onlineusercount;$j++)
    {
    $onlineuserdetail=explode("\t",$onlinetimefile[$j]);
    if($stemp-$onlineuserdetail[1]>1000)
       {
       $hastitles = file("data/online");
       $ccc=count($hastitles);
       $fp = fopen("data/online","w");
       for ($i=0;$i<$ccc;$i++)
            {
            list($con_id1,$con_etime1)=explode("\t",$hastitles[$i]);
            if($con_id1!=$onlineuserdetail[0])fputs($fp,$hastitles[$i]);
            }
   fclose($fp);
       }
    }

?>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv=refresh content=300>
<style>
<!--
a:link{text-decoration:none;color:#000000}
a:active{text-decoration:none}
a:visited{text-decoration:none;color:#004080}
a:hover{text-decoration:underline;color:#ff0000}
textarea,input,br,td,p,div,body,input,form {font-size:9pt;color:#000000;font-family:宋体,Arial}
.gb3{font-family: 宋体; font-size: 14px}
.text{background-color:#FEFEFF; border: 1 double #B4B4B4}
.3dfont{FILTER: glow(color=ffffff,strength=0) shadow(color=aaaaaa,direction:135); POSITION: relative; WIDTH: 100%;font-size: 14px}
-->
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000" background="image/bgs.jpg">
<?
$on_file=read_file("data/online");
$on_count=count(file("data/online"));
print"<table width=100% border=0 cellspacing=0 cellpadding=2><tr><td align=center>在线人数：".$on_count."人</td></tr>";
$on_file=explode("\n",$on_file);
for ($j=0;$j<$onlineusercount;$j++)
    {
    $on_userdetail=explode("\t",$on_file[$j]);
    print "<tr><td>$on_userdetail[0]</td></tr>";
    }
?>
</table>
</body>
</body>
</html>