<?php
/*
 * Copyright (c) 2004-2009 Luiz Otavio O Souza <loos.br@gmail.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/* 
 * $Id: view.php 102 2009-02-05 18:37:40Z loos-br $
 */

    require('mysql.inc.php');
    require('header.inc.php');

    if (!$_REQUEST['sb_id']) die ('no sb_id');

?>

<body bgcolor="#FFFFFF">

<div align=center>
<?php
    if (isset($_REQUEST['back']) && $_REQUEST['back'] == "on") {
	echo "<a href=\"javascript: history.back()\">Voltar</a> | ";
    }
?>
 <a href="javascript: window.close()">Fechar a janela</a><br><br>
</div>
<div align=left>
<?php
    $date = "";;
    $eof = 0;
    while(1) {

	$sql  = "SELECT * from log WHERE sb_id = '".$_REQUEST['sb_id']."' ";
	if ($date) {
	    $sql .= "AND `date` > '$date'";
	}

	$rs = mysql_query($sql, $mysql);
	while($rs && ($row = mysql_fetch_array($rs))) {

	    switch ($row['type']) {
		case "start":
		    $msg = "Abriu a janela";
		    break;
		case "join":
		    $msg = "Respondeu ao convite";
		    break;
		case "stop":
		    $msg = "Fechou a janela";
		    $eof = 1;
		    break;
		default:
		    $msg = "";
	    }
?>
 <table border=0 cellpadding=0 cellspacing=0 bgcolor="#EBEBEB" width=500>
  <tr>
   <td width="20%"><?php echo $row['date'] ?> </td>
   <td width="80%"> <a href="chat.php?email=<?php echo $row['email'] ?>"
	title="<?php echo $row['email'] ?>"><?php echo $row['display_name'] ?>:</a>
	<?php echo $msg ?><?php echo $row['content'] ?><br>
   </td>
  </tr>
</table><br>
<?php
	    flush();
	    $date = $row['date'];
	    if ($eof == 1)
		break;
	}
	if ($eof == 1)
	    break;
	sleep(1);
    }
    mysql_close($mysql);
?>
</div>

</body>
</html>

