<?php
	include_once('./anema.inc.php');
	mt_srand((double)microtime()*1000000);
?>
<html>
<head>
<?php
if (isset($id)) {
	print('<meta http-equiv="Refresh" content="10;URL=liste'.$ext.'?id='.$id.'&connexion='.$gconnexionid.'">');
}
?>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?PHP stylesheet(); ?>
</head>
<body bgcolor="<?PHP echo $color1 ?>" text="#000000" link="#00B4C8" vlink="#00B4C8" alink="#C499A4" TOPMARGIN="0" MARGINHEIGHT="0" LEFTMARGIN="0" MARGINWIDTH="0">
<div align="right" class="chatlist">
<!-- <font face="arial"> //-->
<?php


if (isset($lignes)) {
	do {
		$id=mt_rand(0,9999);
		$db->query("SELECT idSession FROM connectes WHERE idSession='".$id."'");
	}
	while($db->num_rows()>0);

		$nickname= Replace($guser);

        $arrivee=time()-1;
        $ping=time();

        $db->query("DELETE FROM connectes WHERE nick='".$nickname."'");
        $db->query("UPDATE connectes SET bip='1' WHERE bip='0'");
        $db->query("INSERT INTO connectes VALUES ('".$id."','".$nickname."','".$arrivee."','".$ping."','".$lignes."','0')");

        $from="GANESHA";
        $from='<font color="#999999">'.date("H:i:s").'....'.$from.' : </font>';
        $debutStyle='<font color="#CC0000">';
        $finStyle='</font>';
        $msg=$from.$debutStyle.'Arrivée de '.htmlentities($nickname).$finStyle;

        $db->query("INSERT INTO chat VALUES ('".$msg."','".$ping."')");

        put('<script language="JavaScript">');
		put('   parent.chat.location="chat'.$ext.'?id='.$id.'&connexion='.$gconnexionid.'";');
		put('   parent.saisie.location="saisie'.$ext.'?id='.$id.'&connexion='.$gconnexionid.'";');
        put('   self.location="liste'.$ext.'?id='.$id.'&connexion='.$gconnexionid.'";');
        put('</script>');
}
else {
        $ping=time();
        $ancien=$ping-40;
        if (isset($nickname)) {
                $from="GANESHA";
                $from='<font color="#999999">'.date("H:i:s").'....'.$from.' : </font>';
                $debutStyle='<font color="#CC0000">';
                $finStyle='</font>';
                $result=$db->query("SELECT nick FROM connectes WHERE idSession='".$id."'");
                $db->next_record();
                $oldnick=htmlentities(addslashes($db->f(0)));
                $msg=$from.$debutStyle.$oldnick." est maintenant ".htmlentities($nickname).$finStyle;
                $db->query("INSERT INTO chat VALUES ('".$msg."','".$ping."')");
                $db->query("UPDATE connectes SET ping='".$ping."',nick='".$nickname."' WHERE idSession='".$id."'");

                put('<script language="JavaScript">');
				put('   parent.chat.location="chat'.$ext.'?id='.$id.'&connexion='.$gconnexionid.'";');
				put('</script>');
        }
        else {
                $db->query("UPDATE connectes SET ping='".$ping."' WHERE idSession='$id'");
        }
        $db->query("DELETE FROM connectes WHERE ping<'".$ancien."'");
		
		if ( $groupe != '' ) {
			print('['.$ClsGroupe->Name($groupe).']<br />');
		}
        $db->query("SELECT nick FROM connectes");
        while ($db->next_record()) {
                print(htmlentities($db->f(0))."<br>");
        }
}
?>
<!-- </font> -->
</div>
</body>
</html>