<?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-to.php 116 2009-03-20 17:24:15Z loos-br $
 */

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

    /* ignore user aborts and allow the script to run forever */
    set_time_limit(0);
    ignore_user_abort(TRUE);

?>

<body bgcolor="#FFFFFF">

<div align=center>
 <a href="javascript: history.back()">Voltar</a> |
 <a href="javascript: window.close()">Fechar a janela</a><br><br>
<?php
    $sql  = "SELECT DISTINCT l1.sb_id, l1.date, l1.display_name as dn1, ";
    $sql .= "l1.type as t1, l2.display_name as dn2, l2.type as t2 ";
    $sql .= "FROM log as l1, log as l2 WHERE ";
    $sql .= "(l1.email = '".$_REQUEST['email']."' AND l1.type = 'start' AND ";
    $sql .= "l2.email = '".$_REQUEST['to']."' AND l2.type = 'join' AND ";
    $sql .= "l1.sb_id = l2.sb_id) OR ";
    $sql .= "(l1.email = '".$_REQUEST['email']."' AND l1.type = 'join' AND ";
    $sql .= "l2.email = '".$_REQUEST['to']."' AND l2.type = 'start' AND ";
    $sql .= "l1.sb_id = l2.sb_id) ";
    $sql .= "ORDER BY l1.date";

    $rs = mysql_query($sql, $mysql);
    $rsCount = mysql_num_rows($rs);

    while($rs && ($row = mysql_fetch_array($rs))) {

        $sql  = "SELECT * from log WHERE sb_id = '".$row['sb_id']."'";

        $rsSB = mysql_query($sql, $mysql);
        while($rsSB && ($rowSB = mysql_fetch_array($rsSB))) {

	    if(connection_status() != CONNECTION_NORMAL)
		break;

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

</body>
</html>

