<?php 
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>
<?php include "includes/header.php";?>
<?php include "includes/navbar.php";?>

  <div id="wrapper">

    <!-- Sidebar -->
   <?php include "includes/sidebar.php";?>

    <div id="content-wrapper">

      <div class="container-fluid">

        <!-- Breadcrumbs-->
        <ol class="breadcrumb">
          <li class="breadcrumb-item">
            <a href="#">Ola</a>
          </li>
          <li class="breadcrumb-item active"><?php echo $_SESSION['nome'];?></li>
        </ol>

        <!-- Icon Cards-->
        <div class="row">
		      <div class="container">

          
             
             <!-- Button trigger modal -->
<button type="button" class="btn btn-warning btn-sm" data-toggle="modal" data-target="#exampleModal">
  <i class="fas fa-fw fa-plus"></i> Nota de cliente
</button>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Cadastrar</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
          <div class="container">
              <div class="col-sm-10">
                  
             
          <form action="" method="post" enctype="multipart/form-data">
              <?php $clientes->historicoChamadas();?>
			<div class="form-group">
			  <label for="nome_cliente">Nome complecto</label>
              <select required name="nome" class="form-control">
                <option></option>
                <?php $clientes->buscaClienteId();?>
              </select>
            </div>
			 
			 <div class="form-group">
			  <label for="motivo">Nota (Historico da chamada)</label>
              <textarea name="nota" class="form-control" row="14px" col="24px"></textarea>
            </div>
			
			 <div class="form-group">
			  <input type="submit" name="submitNota" class="btn btn-primary btn-block" value="Enviar"/>
			 </div>
	
		   </form>
         </div>
          </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
      </div>
    </div>
  </div>
</div>

 <br> <br>
 <div class="container-fluid">

<!-- Breadcrumbs-->

<!-- DataTables Example -->
<div class="card mb-3">
  <div class="card-header">
    <i class="fas fa-table"></i>
    <b>Historico de chamadas de clientes</b></div>
  <div class="card-body">
    <div class="table-responsive">
      <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
        <thead>
          <tr>
            <th>Item</th>
            <th>Cliente</th>
             <th>Mensagem</th>
              <th>Usuario</th>
          </tr>
        </thead>
       
        <tbody>
            
          <?php 
          $item =1;
          $sqlHistorico = $database->query("SELECT hc.*,c.nome_cliente,c.cell1,c.codigo_cliente,c.foto
          FROM historico_chamadas hc INNER JOIN clientes c ON hc.id_cliente=c.id_cliente ORDER BY hc.id DESC");
          while($row = $database->fetch_assoc($sqlHistorico)){
             $id = $row['id'];
            ?>
           <tr>   
            <td><?php echo $item++;?></td>
            <td><?php echo $row['nome_cliente'];?></td>
            
<td class="text-center">

<i
class="fas <?php echo ($row['lida']==0) ? 'fa-envelope text-warning envelope-fechado' : 'fa-envelope-open text-success'; ?>"
style="font-size:24px; cursor:pointer;"
title="Ver Nota"
onclick="marcarLida(<?php echo $id;?>,this)"
data-toggle="modal"
data-target="#modalNota<?php echo $id;?>">
</i>

</td>
<!-- Modal -->
<div class="modal fade" id="modalNota<?php echo $id;?>" tabindex="-1" role="dialog">

<div class="modal-dialog modal-lg" role="document">

<div class="modal-content">

<div class="modal-header bg-primary text-white">

<img
src="img/<?php echo $row['foto'];?>"
class="rounded-circle mr-3"
width="60"
height="60">

<div>

<h5 class="mb-0">
<?php echo $row['nome_cliente'];?>
</h5>

<small>

Código:
<b><?php echo $row['codigo_cliente'];?></b>

</small>

</div>

<button
type="button"
class="close text-white"
data-dismiss="modal">

<span>&times;</span>

</button>

</div>

<div class="modal-body">

<div class="row">

<div class="col-md-6">

<p>

<i class="fas fa-phone text-success"></i>

<b>Contacto</b>

</p>

<?php echo $row['cell1'];?>

</div>

<div class="col-md-6">
<p><i class="far fa-calendar-alt text-primary"></i>
<b>Data</b></p>
<?php echo $row['data'];?>--
<?php echo $row['hora'];?>

</div>

</div>

<hr>

<div class="card">

<div class="card-header bg-light">

<i class="fas fa-sticky-note"></i>

<b>Observação</b>

</div>

<div class="card-body">

<?php echo nl2br($row['nota']);?>

</div>

</div>

</div>

<div class="modal-footer">

<?php

if($row['lida']==0){
echo '<span class="badge badge-warning"><i class="fas fa-envelope"></i>Nova</span>';
}else{
echo '<span class="badge badge-success"><i class="fas fa-check-circle"></i>Lida</span>';

}

?>

<button
class="btn btn-secondary"
data-dismiss="modal">

Fechar

</button>

</div>

</div>

</div>

</div>

     

 <td><?php echo $row['usuario'];?></td>

        </tr>
        
        <?php }
          
          ?>  

         
      
   
               </tbody>
      </table>
    </div>
  </div>
  <div class="card-footer small text-muted">Jonas Dinis Chambela</div>
</div>



</div>

        </div>
      </div>
      <!-- /.container-fluid -->
		  </div>

		 </div>
        
        
        </div>

     
        
<style>
.envelope-fechado{

    animation:piscar 1s infinite;

}

@keyframes piscar{

0%{

opacity:1;

}

50%{

opacity:.3;

}

100%{

opacity:1;

}

}
</style>

<script>

function marcarLida(id,icone){

    fetch("ler_nota.php",{

        method:"POST",

        headers:{
            "Content-Type":"application/x-www-form-urlencoded"
        },

        body:"id="+id

    });

    icone.classList.remove("fa-envelope");
    icone.classList.remove("text-warning");
    icone.classList.remove("envelope-fechado");

    icone.classList.add("fa-envelope-open");
    icone.classList.add("text-success");

}


</script>
      <!-- /.container-fluid -->

      <!-- Sticky Footer -->
      <?php include "includes/footer.php";?>

    </div>
    <!-- /.content-wrapper -->

  </div>
  <!-- /#wrapper -->

  <!-- Scroll to Top Button-->
  <a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
  </a>

  <!-- Logout Modal-->
 <?php include "includes/logout_modal.php";?>
 <?php include "includes/sweatscripFooter.php";?>

