<?
  session_start();
  require('../conectar.php');
  $id= $_SESSION['usuario_id'];  
  $id_cliente=$_POST["idcliente"];
  $folio=$_POST["folio"];
  
  function decrypt($string, $key) {
   $result = '';
   $string = base64_decode($string);
   for($i=0; $i<strlen($string); $i++) {
      $char = substr($string, $i, 1);
      $keychar = substr($key, ($i % strlen($key))-1, 1);
      $char = chr(ord($char));
      $result.=$char;
   }
   return $result;
}
  $sql="SELECT * FROM contadormail WHERE folio='$folio' order by fecha";
  if($folio=="") $sql="SELECT * FROM contadormail as cont INNER JOIN clientes as cl ON cl.email=cont.correo WHERE cl.id_cliente='$id_cliente' order by fecha";
  $re=mysql_query($sql);
  ?>
  <table width="100%" class="datos">
      <tr class="trst"><td align="center" colspan="4">Historial de mails enviados</td></tr>
	  <tr class="trssb"><td align="center" style="width:100px;">Fecha</td><td align="center" style="width:330px;">Remitente</td><td align="center" style="width:330px;">Destino</td><td align="center">Ver correo</td></tr>
  <?
  $x=0;
  while($l=mysql_fetch_array($re)){
     $posible=array('=',"==");
    $corre=str_replace($posible,"+",$l["mail"]);
    $corr = decrypt($corre,"mail");
    $corr =str_replace("¾","",$corr);
    $corr =str_replace(">>",">",$corr);
    $corr =str_replace("<>","",$corr);
	
	$sql="SELECT nombre,a_pat,a_mat FROM empleados WHERE id_empleado='$l[id_emp]'";
	$r=mysql_query($sql);
	$e=mysql_fetch_array($r);
     ?>
	    <tr class="trs"><td class="tdi">&nbsp;&nbsp;&nbsp;&nbsp;<?echo $l["fecha"]?></td><td class="tds">&nbsp;&nbsp;&nbsp;&nbsp;<?echo $e["nombre"]." ".$e["a_pat"]." ".$e["a_mat"]?></td><td class="tds">&nbsp;&nbsp;&nbsp;&nbsp;<?echo $l["correo"]?></td><td class="tds">&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:reloadmail('<?echo $x?>')"><img src="images/zoom.png" width="18" height="18" style="margin-left:-5px;" alt="Ver datos"><a></td></tr>
		<tr id="corr<?echo $x?>" class="oculto" style="background:#585858;">
		     <td colspan="4"><div id="correoenv<?echo $x?>"><?echo $corr?></div></td>
		</tr>
	 <?
	 $x++;
   }
?>
 </table>