<?php 
include('protector.php');
include('header.php');
if (file_exists($gbox_path.'share.info'))
{
   $cards = read2array($gbox_path.'share.info');
   unset($cards[count($cards)-1]);
   foreach($cards as $card){
     $elms = explode(' ',$card);
	  $peers[$elms[3]]['domain'] = $elms[3];
   }
}
?>
<style type="text/css">
<!--
.style2 {color: #000000}
-->
</style>
 <blockquote>
  <p align="center" class="style2" style="margin-left: 20">&nbsp;</p>
  <p align="center" class="style2" style="margin-left: 20"><font face="Arial" size="4"><?=$card_avail?></font></p>
  <p style="margin-left: 20">
 <font face="Arial" size="2" color="#000000">  </font></p>

  <table width="396"  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"><form id="form1" name="form1" method="GET" action="cards.php">
        <p align="left"><strong><?=$card_filter?><br />
</strong><br />
          <?=$info_dist?>
          <input name="dist" type="text" 
	<?php if (isset($_GET['filter']))
	{print 'value="'.$_GET['dist'].'"';} 
	else 
	{print 'value="0"';}
	?> size="5" />
        
        <?=$tdomain?> : 
        <select name="peerselect" id="peerselect">
          <option value="all"><?=$filter_all?></option>
          <?php
	 foreach($peers as $peer){
	 if (isset($_GET['filter'])) {
	   if ($peer['domain'] == $_GET['peerselect']) 
	   {print('<option value="'.$peer['domain'].'" selected="selected">'.$peer['domain'].'</option>');}
	   else
   	   print('<option value="'.$peer['domain'].'">'.$peer['domain'].'</option>');
	 }
	 else
	 print('<option value="'.$peer['domain'].'">'.$peer['domain'].'</option>');
	 }
	 ?>
        </select>
        <input name="filter" type="submit" id="filter" value="OK" />
        <br />
        <?=$filter_txt?> </p>
         </form></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>
  <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="8%"><div align="center"><font color="#e2e2e2" size="2" face="Arial"><?=$tcard_n?></font></div></td>
    <td width="8%"><div align="center"><font color="#e2e2e2" size="2" face="Arial"><?=$tcard_id?></font></div></td>
    <td width="8%"><div align="center"><font color="#e2e2e2" size="2" face="Arial"><?=$tprov_id?></font></div></td>
    <td width="10%"><div align="center"><font color="#e2e2e2" size="2" face="Arial"><?=$tcaid?></font></div></td>
    <td width="33%"><div align="center"><font color="#e2e2e2" size="2" face="Arial"><?=$tprov_name?></font></div></td>
    <td width="18%"><div align="center"><font color="#e2e2e2" size="2" face="Arial"><?=$tpeer_name?></font></div></td>
    <td width="12%"><div align="center"><font color="#e2e2e2" size="2" face="Arial"><?=$tlevel?></font></div></td>
    <td width="11%"><div align="center"><font color="#e2e2e2" size="2" face="Arial"><?=$tdistance?></font></div></td>
  </tr>
<?php
if (file_exists($gbox_path.'share.info') && file_exists($gbox_path.'ident.info'))
{
   $cards = read2array($gbox_path.'share.info');
   unset($cards[count($cards)-1]);
   foreach($cards as $card){
     $elms = explode(' ',$card);
	 if (isset($_GET['filter'])) {
	 
	 if (($_GET['dist'] != '0') && ($_GET['peerselect'] == 'all') && ($elms[8] == 'dist:'.$_GET['dist']))
	    {
	  $provs[$elms[1]]['num'] = $elms[1];
	  $provs[$elms[1]]['id'] = $elms[5];
	  $provs[$elms[1]]['peer'] = $elms[3];
	  $provs[$elms[1]]['distance'] = $elms[8];
	  $provs[$elms[1]]['level'] = $elms[7];
	  $provs[$elms[1]]['cardid'] = $elms[9];
	  
	   }
	 else
  	 if (($_GET['dist'] != '0') && ($_GET['peerselect'] != 'all') && ($elms[8] == 'dist:'.$_GET['dist']) && ($elms[3] == $_GET['peerselect']))
	    {
	  $provs[$elms[1]]['num'] = $elms[1];
	  $provs[$elms[1]]['id'] = $elms[5];
	  $provs[$elms[1]]['peer'] = $elms[3];
	  $provs[$elms[1]]['distance'] = $elms[8];
	  $provs[$elms[1]]['level'] = $elms[7];
	  $provs[$elms[1]]['cardid'] = $elms[9];
	   }
	 else
  	 if (($_GET['dist'] == '0') && ($_GET['peerselect'] != 'all') && ($elms[3] == $_GET['peerselect']))
	    {
	  $provs[$elms[1]]['num'] = $elms[1];
	  $provs[$elms[1]]['id'] = $elms[5];
	  $provs[$elms[1]]['peer'] = $elms[3];
	  $provs[$elms[1]]['distance'] = $elms[8];
	  $provs[$elms[1]]['level'] = $elms[7];
	  $provs[$elms[1]]['cardid'] = $elms[9];
	   }
	 else
  	 if (($_GET['dist'] == '0') && ($_GET['peerselect'] == 'all'))
	    {
	  $provs[$elms[1]]['num'] = $elms[1];
	  $provs[$elms[1]]['id'] = $elms[5];
	  $provs[$elms[1]]['peer'] = $elms[3];
	  $provs[$elms[1]]['distance'] = $elms[8];
	  $provs[$elms[1]]['level'] = $elms[7];
	  $provs[$elms[1]]['cardid'] = $elms[9];
	   }
	 
	 }//end submit
	 else
     {
	 $provs[$elms[1]]['num'] = $elms[1];
	 $provs[$elms[1]]['id'] = $elms[5];
	 $provs[$elms[1]]['peer'] = $elms[3];
	 $provs[$elms[1]]['distance'] = $elms[8];
	 $provs[$elms[1]]['level'] = $elms[7];
	  $provs[$elms[1]]['cardid'] = $elms[9];
     }
   }
   $ident = read2array($gbox_path.'ident.info');
   unset($ident[count($ident)-1]);

   foreach ($ident as $id){
     $names = explode(';',$id);
     $ids[$names[0]]['id'] = $names[0];
     $ids[$names[0]]['name'] = $names[1];
   }

   echo "<h4><div align=\"center\">".count($provs).' cartões encontrados.</div></h4>';

   if (empty($provs)){
     echo "<tr><td colspan=7><div align=\"center\">".$no_peers."</div></td></tr>";
   }
   else
   foreach($provs as $prov){
   //print_r($prov);
   echo "<tr>";
    echo "<td><div align=\"center\">".$prov['num']."&nbsp;</div></td>";
    echo "<td><div align=\"center\">".substr($prov['cardid'],3,4)."&nbsp;</div></td>";
    echo "<td><div align=\"center\">".substr($prov['id'],4)."&nbsp;</div></td>";
    echo "<td><div align=\"center\">".substr($prov['id'],0,4)."&nbsp;</div></td>";
    echo "<td><div align=\"center\">".$ids[$prov['id']]['name']."&nbsp;</div></td>";
    echo "<td><div align=\"center\">".$prov['peer']."&nbsp;</div></td>";
    echo "<td><div align=\"center\">".$prov['level']."&nbsp;</div></td>";
    echo "<td><div align=\"center\">".$prov['distance']."&nbsp;</div></td>";
   echo "</tr>";

   }
} 
else   
echo "<tr><td colspan=7><div align=\"center\">".$no_files."</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>
</blockquote>
<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'); 
?>