<?

if($_SESSION['nivel'] == '1'){

if(count($_GET)>0){
  while (list($variavelNOME,$variavelGET) = each($_GET)) {
    $$variavelNOME= $variavelGET;
  }
}
if(count($_POST)>0){
  while (list($variavelNOME,$variavelPOST) = each($_POST)) {
    $$variavelNOME= $variavelPOST;
  }
}

$result=mysql_query("select * from crm_agenda where codcli='$cod' order by id desc");
$rescli=mysql_query("select empresa, email, email01, email02, email03, login, senha from crm_cliente where id='$cod'");
$aempre=mysql_fetch_array($rescli);
$empresa=$aempre['empresa'];
$email=$aempre['email'];
$email01=$aempre['email01'];
$email02=$aempre['email02'];
$email03=$aempre['email03'];
$login=$aempre['login'];
$senha=$aempre['senha'];

?>
<body onLoad="javascript:document.form1.compromisso.focus();">
  <table width="600" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <form id="form1" name="form1" method="post" action="miolo.php?miolo=agenda&acao=insert" enctype="multipart/form-data">
<input type="hidden" name="codcli" value="<? echo $cod; ?>">
<input type="hidden" name="email" value="<? echo $email; ?>">
<input name="email01" value="<? echo $email01; ?>" type="hidden">
<input name="email02" value="<? echo $email02; ?>" type="hidden">
<input name="email03" value="<? echo $email03; ?>" type="hidden">
<input name="login" value="<? echo $login; ?>" type="hidden">
<input name="senha" value="<? echo $senha; ?>" type="hidden">
    <tr>
      <td height="25" colspan="2"><table width="700" height="26" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="507" height="26"><strong><font size="2" face="Arial, Helvetica, sans-serif">Agenda da empresa: <? echo $empresa; ?> </font></strong></td>
          <td width="193"><div align="center"><a href="miolo.php?miolo=clientes&acao=gerenciar" class="style1">voltar</a></div></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td height="25"><strong><font size="2" face="Arial, Helvetica, sans-serif">Compromisso: </font></strong></td>
      <td height="25"><input name="compromisso" type="text" size="40"></td>
    </tr>
    <tr>
      <td height="25"><strong><font size="2" face="Arial, Helvetica, sans-serif">Data de vencimento: </font></strong></td>
      <td height="25"><input name="dtcomp" type="text" id="dtcomp" class="data" size="10" maxlength="10">
      <strong><font color="#999999" size="1" face="Arial, Helvetica, sans-serif">99/99/9999</font></strong></td>
    </tr>
<tr>
      <td height="25"><strong><font size="2" face="Arial, Helvetica, sans-serif">Arquivo: </font></strong></td>
      <td height="25"><input name="nomearquivo" type="file" id="nomearquivo" >
      </td>
    </tr>
    <tr>
      <td height="44" colspan="2" align="center" valign="middle"><input name="enviar" type="submit" id="enviar" value="Enviar">
      <input type="reset" name="Reset" value="Limpar"></form><tr><td height="25" colspan="2"><hr /></td></tr>
	<tr><td height="25" colspan="2"><strong><font size="2" face="Arial, Helvetica, sans-serif">Lista de compromissos para cumprir</font></strong></td></tr>

<?

while ($linha=mysql_fetch_array($result)){
list($cod, $codcli, $compromisso, $dtcomp, $data, $hora, $arquivo, $down, $nomedoarquivo)=$linha;
list($ano, $mes, $dia)=explode("-",$data);
$data="$dia/$mes/$ano";
list($ano, $mes, $dia)=explode("-",$dtcomp);
$dtcomp="$dia/$mes/$ano";
//$quantidade=(strlen($arquivo));
//$resultado=($quantidade-9);
//$menorarquivo=substr($arquivo, -$quantidade);

if ($nomedoarquivo==""){
$nomedoarquivo=$arquivo;
}

echo "<tr><td><font size='2' face='arial'><strong>Data/Hora do Compromisso:</strong></font></td><td><font size='2' face='arial'>$dtcomp -$hora <a href='miolo.php?miolo=agenda&acao=excluir&cod=$cod&codcli=$codcli'><strong>Excluir Compromisso</a></strong></font></td></tr>
	  <tr><td><font size='2' face='arial'><strong>Data de vencimento do compromisso:</strong></font></td><td><font size='2' face='arial'>$data</font></td></tr>
	  <tr><td><font size='2' face='arial'><strong>Compromisso:</strong></font></td><td><font size='2' face='arial'>$compromisso</font></td></tr>
	  <tr><td class='style1'><font size='2' face='arial'><strong>Baixar Guia:</strong></font></td><td><span class='style6'><a href='arquivos/crm/$arquivo' target='_blank'> $nomedoarquivo</a>- 	  <a href='protocoloagenda.php?cod=$cod&codemp=$codemp' target='_blank'><img src='images/icone_pdf.jpg' border='0' width='20' height='20' align='bottom'>Gerar Protocolo</a> </span></td></tr>
      <tr><td colspan='2'><hr /></td></tr>";
}


?>
</table>

<?php 
  }
?>