<?
$result = mysql_query("SELECT 
					  crm_chamado.`idChamado`,
					  crm_chamado.`id_cliente`,
					  crm_chamado.`id_usuario`,
					  crm_chamado.`titulo`,
					  crm_chamado.`dataHoraCriacao`,
					  crm_statusChamado.`titulo` 
					FROM
					  crm_chamado 
					  JOIN crm_statusChamado 
					    ON crm_chamado.`statusChamado` = crm_statusChamado.`idStatusChamado` 
					WHERE crm_chamado.`id_cliente` = '".$_SESSION['idUser']."' 
					ORDER BY crm_chamado.`dataHoraCriacao`") or die (mysql_error());

$rescli=mysql_query("select empresa from crm_cliente where id = '".$_SESSION['idUser']."'") or die (mysql_error());

$aempre=mysql_fetch_array($rescli);
?>
 <table width="700" border="0" align="center" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF">
<form name="form2" id="form2" method="post" action="miolo.php?miolo=insertChamado" enctype="multipart/form-data">
	<tr>
      <td height="25" colspan="2" align="left" valign="middle"><span class="style1">Chamado  da Empresa: <?Php echo utf8_encode($aempre[0]); ?></span></td>
    </tr>
    <tr>
      <td height="30"><span class="style1">Enviar para:</span></td>
      <td height="30"><label>
        <select name="destinatario" id="destinatario">
        	<?php 
        	$selectContato = mysql_query("SELECT nomeUser, id FROM usuarios WHERE nivelUser = 3 AND statusUser = 1");
        	while($linhaContato = mysql_fetch_array($selectContato)){
        		?>
        		<option value="<?php echo $linhaContato[1]; ?>"><?php echo $linhaContato[0]; ?></option>
        		<?
        	}
        	?>
        </select>
      </label></td>
    </tr>
    <tr>
      <td width="93" height="30"><span class="style1">T&iacute;tulo:</span></td>
      <td width="607" height="30"><input name="titulo" type="text" id="titulo" size="78" value="<? echo $titulo; ?>"></td>
    </tr>

    <tr>
      <td height="95"><span class="style1">Chamado:</span></td>
      <td width="607" height="95"><textarea name="lembrete" cols="60" rows="5" id="lembrete"></textarea></td>
    </tr>
	    <tr>
      <td height="39" colspan="2" align="center" valign="middle"><input name="enviar" type="submit"  onclick="return agoravai();" id="enviar" value="Enviar" />
      <input type="reset" name="Reset" value="Limpar" />
    </form></td>
    </tr>
    <tr>
	
      <td colspan="2"><hr /></td></tr>
	  <tr>
      <td height="25" colspan="2"><span class="style2">Lista de Chamados:</span></td>
	  </tr>

<?Php
		require 'auxiliares/formata-data.php';
		while ($linha = mysql_fetch_array($result)){
		list($cod, $codcli, $coduser, $titulo, $dh_iniciado, $statusChamado) = $linha;
		
		?>	
		<tr>
			<td><span class='style2'>Iniciado em:</span></td>
			<td><span class='style2'><?php echo dataPTBRTime($dh_iniciado); ?></span></td>
		</tr>
	  	<tr>
	  		<td><span class='style2'>Chamado:</span></td>
	  		<td><span class='style2'><b><?php echo $titulo; ?></b></span></td>
	  	</tr>
	 	<tr>
	 		<td><span class='style2'>Status: </span></td>
	 		<td><span class='style2'><b><?php echo $statusChamado ?></b></span></td>
	 	</tr>
		<tr>
	 		<td colspan="2"><a href="miolo.php?miolo=gerenciarLembrete&cod=<?php echo $cod; ?>">Gerenciar</a></td>
	 	</tr>
	 	<tr><td colspan='2'><hr /></td></tr>
	<?
		}
	
?>
</table>