<?php setcookie("login", $_COOKIE["login"] , time()+3600, "/", "deim.etse.urv.es", 1 ); ?>
<?php setcookie("sessio", $_COOKIE["sessio"] , time()+3600, "/", "deim.etse.urv.es", 1 ); ?>
<html>
  <head>
    <link rel="stylesheet" href="../estils/hoja.css" type="text/css" />
    <title>Log webmail</title>
  </head>

  <body leftmargin="0" topmargin="0" bgcolor="#8F0000">
    <table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0">
      <tr>
        <!-- Menú dret -->
        <td align="left" valign="top" width="100" bgcolor="#4F0000">
          <?php include("../menu.inc") ?>
        </td>

        <!-- Capçalera -->
        <td align="left" valign="top" width="100%" class="centered">
        <h2>Departament d'Enginyeria Informàtica i Matemàtiques</h2>
        <img src="images/separador.gif">
        <br><br>
        <div align="left"><blockquote>
        <h2>Administració Webmail: Log</h2>
        <!-- Començament del cos -->
        <?php require("../private/connect.inc");
              require("../private/ident.inc");
              ident();
              // Nomes deixar visualitzar a l'administrador
              if ($_COOKIE["login"] != "admin") {
                echo "No esta autoritzat!";
                die;
              }
              $link=ConectarWebmail();
              $result=mysql_query("SELECT username,ip,connect_date,connect_time,successful FROM tblLoggedUsers ORDER BY connect_date
              DESC,connect_time DESC", $link);
              echo("<table border=\"0\" width=\"90%\" align=\"left\">");
              echo("<tr bgcolor=\"#4f0000\"><td><b>Usuari</b></td><td>Data</td><td>Hora</td><td>Conexió
              exitosa</td><td>Adreça IP</td></tr>");
              
              // Saltem fins a la noticia indicada
              $bucle=0;
              while ($bucle<$_GET["pag"]) {
                $row = mysql_fetch_array($result);
                $bucle++;
              }
              // Mostrem 10 noticies des de la indicada
              $bucle=0;
              while (($row = mysql_fetch_array($result))&&($bucle<50)) {
                  echo("<tr><td align=\"left\"> <div align=\"left\">" .
                  htmlspecialchars($row["username"]) . "</td>" );
                  echo("<td>". $row["connect_date"] . "</td>");
                  echo("<td>". $row["connect_time"] . "</td>");
                  echo("<td> ". $row["successful"] . "</td>");
                  echo("<td>". $row["ip"] . "</td></tr>");
                  $bucle++;
              }

              // Si $row no era null es que encara queden noticies, per tant mostrem link.
              if ($row != null) {
                echo "<tr><td colspan=\"2\" align=\"center\"><br><a href=\"viewmaillog.php?pag=";
                echo $_GET["pag"]+50;
                echo "\">Següents</a></td></tr>";
              }
              mysql_free_result($result);
        ?>
        <td><br><input type="image" onClick="history.go(-1)" src="images/tornar.jpg"></td>
        </table>
        </blockquote></div>
        </td>
        <td align="left" valign="top" width="100">
          <br />
          <br />
          <br />
          <br />
          <a href="../desconectar.php" class="link2"><img src="images/tancar.jpg" border="0"></a>
        </td>
      </tr>
    </table>
  </body>
</html>

