<?php 
include('protector.php');
include('header.php');
?>
<style type="text/css">
<!--
.style1 {color: #000000}
-->
</style>

<blockquote>
  <p align="left" class="style1" style="margin-left: 20">&nbsp;</p>
  <p align="center" class="style1" style="margin-left: 20"><font face="Arial" size="4">Lista de Grupos</font></p>
  <p align="center" class="style1" style="margin-left: 20">&nbsp;</p>
  <p style="margin-left: 20"><font face="Arial" size="2" color="#000000">
  

  </font></p>
</blockquote>
<table width="919"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="16"><img src="images/top_lef.gif" alt="f" width="16" height="16" /></td>
    <td height="16" background="images/top_mid.gif"><img src="images/top_mid.gif" alt="g" width="16" height="16" /></td>
    <td width="24"><img src="images/top_rig.gif" alt="h" width="24" height="16" /></td>
  </tr>
  <tr>
    <td width="16" background="images/cen_lef.gif"><img src="images/cen_lef.gif" alt="d" width="16" height="11" /></td>
    <td align="center" valign="middle" bgcolor="#FFFFFF"><table width="95%"  border="1" cellpadding="0" cellspacing="0" align="center">
  <tr bgcolor="#2c2f34">
    <td width="9%"><div align="center"><font color="#e2e2e2" size="2" face="Arial">Gbox ID </font></div></td>
    <td width="9%"><div align="center"><font color="#e2e2e2" size="2" face="Arial">Versão</font></div></td>
    <td width="31%"><div align="center"><font color="#e2e2e2" size="2" face="Arial">Dominio</font></div></td>
    <td width="23%"><div align="center"><font color="#e2e2e2" size="2" face="Arial">IP</font></div></td>
    <td width="19%"><div align="center"><font color="#e2e2e2" size="2" face="Arial">Estado</font></div></td>
    <td width="9%"><div align="center"><font color="#e2e2e2" size="2" face="Arial">Cartões</font></div></td>
    </tr>
<?php
if (file_exists($gbox_path.'share.info') && file_exists($gbox_path.'share.onl'))
{
   $cards = read2array($gbox_path.'share.info');
   unset($cards[count($cards)-1]);

   foreach($cards as $card){
     $elms = explode(' ',$card);
	 $cid=$elms[3];
	 $provs[$cid] = $provs[$cid]+1;
	 $dists[$cid][$elms[8]] = $dists[$cid][$elms[8]]+1;
   }
   $peer_list = read2array($gbox_path.'share.onl');
   unset($peer_list[count($peer_list)-1]);

   echo "<h4><div align=\"center\">".count($peer_list).' grupos na lista.<br>';
   echo count($cards).' cartões <font color="green">online</font>.</div></h4>';
   foreach($peer_list as $peer){
     $p = explode(' ',$peer);
	 $peers[$p[3]]['id'] = $p[3];
	 $peers[$p[3]]['version'] = $p[4];
	 $peers[$p[3]]['domain'] = $p[1];
	 $peers[$p[3]]['status'] = $p[0];
	 $peers[$p[3]]['ip'] = $p[2];
	 $peers[$p[3]]['cards'] = $provs[$p[1]];
   }
   if (empty($peers)){
     echo "<tr><td colspan=6><div align=\"center\">Nenhum grupo encontrado.</div></td></tr>";
   }

   foreach ($peers as $peer){
   if (($peer['status'] == '0') && (!isset($peer['cards'])))
   {$status = 'OFF'; $color='#FF0000';} else {$status = 'Online'; $color='#30e805';}

	if (isset($dists[$peer['domain']]['dist:1'])){
    $color = '#66FF00';
	} else 
	{
	if (isset($dists[$peer['domain']]['dist:2'])){
    $color = '#2080ff';}
	}
	if (!isset($peer['cards']) && $peer['status'] == '1') {$color='#FFFF00';}
    echo "<tr>";
    echo "<td><div align=\"center\">".$peer['id']."&nbsp;</div></td>";
    echo "<td><div align=\"center\">".$peer['version']."&nbsp;</div></td>";
    echo "<td><div align=\"center\"><a href=\"cards.php?dist=0&peerselect=".$peer['domain']."&filter=OK\">".$peer['domain']."</a>&nbsp;</div></td>";
    echo "<td><div align=\"center\">".$peer['ip']."&nbsp;</div></td>";
    echo "<td bgcolor=\"".$color."\"><div align=\"center\">".$status."&nbsp;</div></td>";
	if (isset($peer['cards'])) 
    echo "<td><div align=\"center\"><a href=\"cards.php?dist=0&peerselect=".$peer['domain']."&filter=OK\">".$peer['cards']."&nbsp;</div></td>";
	else 
    echo "<td><div align=\"center\">&nbsp;</td>";
   echo "</tr>";

   }
}
else   
echo "<tr><td colspan=6><div align=\"center\">Os ficheiros 'share.info' e/ou 'share.onl' não encontrados.</div></td></tr>";
  ?>
  </table>
      <br />
    </p></td>
    <td width="24" background="images/cen_rig.gif"><img src="images/cen_rig.gif" alt="e" width="24" height="11" /></td>
  </tr>
  <tr>
    <td width="16" height="16"><img src="images/bot_lef.gif" alt="a" width="16" height="16" /></td>
    <td height="16" background="images/bot_mid.gif"><img src="images/bot_mid.gif" alt="b" width="16" height="16" /></td>
    <td width="24" height="16"><img src="images/bot_rig.gif" alt="c" width="24" height="16" /></td>
  </tr>
</table>
<p>&nbsp;</p>
      <p><font face="Arial" size="2" color="#000000">&nbsp;</font></p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p><font face="Arial" size="2" color="#000000">&nbsp;&nbsp;</font></p>
      <p><font face="Arial" size="2" color="#000000">&nbsp;</font></p>
      
<?php 
include('footer.php'); 
?>