<?php 
include('protector.php');
include('header.php');
if (file_exists($gbox_path.'share.onl'))
{
   $onl = read2array($gbox_path.'share.onl');
   unset($onl[count($onl)-1]);
   foreach($onl as $peer){
     $elms = explode(' ',$peer);
     $peers[$elms[1]]['domain'] = $elms[1];
   }
}
if (isset($_POST['send_gsms'])) {
   if ($_POST['destination'] == 'all') {$dest = '0.0.0.0';}
   else
   $dest = $_POST['destination'];
   $msg = $dest.' 1 '.$_POST['message'];
   $gsms_file = $gbox_path."gsms.txt";
   $f = fopen($gsms_file, 'w') or die("Error sending GSMS, could not create file.");
   fwrite($f, $msg);
   fclose($f);
}

if (isset($_POST['clean_gsms'])) {
 if (file_exists($gbox_path.'gsms.log'))
 unlink($gbox_path.'gsms.log');
}
if (isset($_POST['clean_log'])) {
 if (file_exists($gbox_path.'gsms.ack'))
 unlink($gbox_path.'gsms.ack');
}
?>

<style type="text/css">
<!--
.style1 {color: #6600CC}
-->
</style>
<style type="text/css">
<!--
.style2 {color: #000000}
-->
</style>

  
&nbsp;
<p>&nbsp;</p>
<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"><p class="style2" align="center"><font face="Arial" size="4">Entrada 
  </font></p>
  <p style="margin-left: 20"><font face="Arial" size="2" color="#000000">
  
  <table width="94%"  border="1" cellpadding="0" cellspacing="0" align="center">
  <tr bgcolor="#2c2f34">
    <td width="17%"><div align="center"><font color="#e2e2e2" size="2" face="Arial">De</font></div></td>
    <td width="16%"><div align="center"><font color="#e2e2e2" size="2" face="Arial">Data</font></div></td>
    <td width="53%"><div align="center"><font color="#e2e2e2" size="2" face="Arial">Menssagem</font></div></td>
    </tr>
<?php
if (file_exists($gbox_path.'gsms.log'))
{
   $sms = read2array($gbox_path.'gsms.log');
   unset($sms[count($sms)-1]);
   $cnt=0;
   
   foreach($sms as $msg){
     $elms = explode(' ',$msg);
	 $messages[$cnt]['from'] = $elms[0];
     $elms = explode(';',$msg);
	 $messages[$cnt]['date'] = $elms[count($elms)-1];
	 $messages[$cnt]['msg'] = substr($elms[count($elms)-2],strlen($messages[$cnt]['from']));
     $cnt=$cnt+1;
   }
   
   if (empty($messages)){
     echo "<tr><td colspan=4><div align=\"center\">Nenhuma menssagem encontrada.</div></td></tr>";
   }

   foreach ($messages as $msg){
   //print_r($prov);
   echo "<tr>";
    echo "<td><div align=\"center\">".$msg['from']."&nbsp;</div></td>";
    echo "<td><div align=\"center\">".$msg['date']."&nbsp;</div></td>";
    echo "<td><div align=\"center\">".str_replace("/","<br />",$msg['msg'])."&nbsp;</div></td>";
   echo "</tr>";

   }
}
else
  echo "<tr><td colspan=4><div align=\"center\">Nenhuma menssagem encontrada.</div></td></tr>";
  ?>
  </table>
    <form id="form2" name="form2" method="post" action="">
    <div align="center"><span class="style1" style="margin-left: 20"><font face="Arial" size="4">
    <input name="clean_gsms" type="submit" id="clean_gsms" value="Limpar" />
    </font></span>
      </p></p>
    </div>
  </form>
  </font></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"><p class="style2" align="center"><font face="Arial" size="4">Enviadas 
      
  </font></p>
  <p style="margin-left: 20">
<table width="94%"  border="1" cellpadding="0" cellspacing="0" align="center">
  <tr bgcolor="#2c2f34">
    <td width="17%"><div align="center"><font color="#e2e2e2" size="2" face="Arial">Data</font></div></td>
    <td width="53%"><div align="center"><font color="#e2e2e2" size="2" face="Arial">Log</font></div></td>
  </tr>

  <p>
    <?php 
 if (file_exists($gbox_path.'gsms.ack')) {
 $report = read2array($gbox_path.'gsms.ack');
 unset($report[count($report)-1]);

 $cnt=0;
 foreach ($report as $rep) {
   $elms = explode(';',$rep);
   $items[$cnt]['to'] = $elms[0];
   $items[$cnt]['date'] = $elms[1];
   $cnt=$cnt+1;
 }
 
 foreach ($items as $item){
   //print_r($prov);
   echo "<tr>";
    echo "<td><div align=\"center\">".$item['date']."&nbsp;</div></td>";
    echo "<td><div align=\"center\">".$item['to']."&nbsp;</div></td>";
   echo "</tr>";

   }
 }
 else   
    echo "<tr><td colspan=2><div align=\"center\">Nenhuma menssagem enviada.&nbsp;</div></td><tr>";
  ?>
</table>
  <form id="form2" name="form2" method="post" action="">
    <div align="center"><span class="style1" style="margin-left: 20"><font face="Arial" size="4">
      <input name="clean_log" type="submit" id="clean_log" value="Limpar" />
    </font></span></div>
  </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>
  <br />
  <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"><p class="style2" align="center"><font face="Arial" size="4">Enviar nova GSMS</font></p>
<form id="send_sms" name="send_sms" method="post" action="">
  <p align="center">Enviar para
      <br />
      <select name="destination" id="destination">
          <option value="all">Todos</option>
          <?php
	 foreach($peers as $peer){
   	   print('<option value="'.$peer['domain'].'">'.$peer['domain'].'</option>');
	 }
	 ?>
    </select>
  </p>
  <p align="center">Menssagem<br />
    <textarea name="message" cols="50" rows="5"></textarea>
  </p>
  <p align="center">
    <input name="send_gsms" type="submit" id="send_gsms" value="Enviar" />
  </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>
<p>&nbsp; </p>
<p class="style1">
<?php 
include('footer.php'); 
?>
</p>
