<?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">
             <div class="col-sm-4">
                 
                 <form action="enviar_email.php" method="post">
                     
                     <div class="form-group">
                         <label for="cliente">Selecione cliente</label>
                          <select required name="cliente" class="form-control">
                              <option></option>
                              <?php buscaCliente(); ?>
                          </select>
                     </div>
                     
                     
                    
                    <div class="form-group">
                        <input type="submit" name="submit" class="btn btn-info btn-block" value="Send Email"/>
                    </div>
                    
                 </form>
                 
             </div>
         </div>
         
         <div class="col-sm-12">
             <table class="table">
                 <thead>
                     <tr>
                         <th>Item</th>
                         <th>Nome</th>
                         <th>B.I</th>
                         <th>Data Nasc</th>
                         <th>Nuit</th>
                         <th>Data</th>
                         <th>Usuario</th>
                         <th>Accao</th>
                     </tr>
                 </thead>
                 
                 <tbody>
                     
                     <?php 
                     $item = 1;
                     
                     $buscar_crc ="SELECT * FROM crc WHERE status='pendente'";
                     $jonas = mysqli_query($con,$buscar_crc);
                     while($row = mysqli_fetch_assoc($jonas)){
                     
                     ?>
                     <tr>
                         <td><?php echo $item++;?></td>
                         <td><?php echo $row['cliente'];?></td>
                         <td><?php echo $row['bi'];?></td>
                         <td><?php echo $row['data_nasc'];?></td>
                         <td><?php echo $row['nuit'];?></td>
                         <td><?php echo $row['data'];?></td>
                         <td><?php echo $row['usuario'];?></td>
                         <td><button type="button" class="btn btn-info btn-sm"><a href="emailForm.php?id=<?php echo $row['id'];?>" 
                         style="text-decoration:none;color:white;"><span>Confirmar</span></a></button></td>
                     </tr>
                     
                     <?php }?>
                     
                 </tbody>
             </table>
             
             <button type="button" class="btn btn-info btn-sm"><span><a href="print_crc.php" style="text-decoration:none; color:white;">Imprimir</a></span></button>
         </div>
	   
	   
        </div>
        
        <?php 
        if(isset($_GET['id']) && !empty($_GET['id'])){
            
            $id = $_GET['id'];
            
            $actualiza = "UPDATE crc SET status='confirmado' WHERE id='$id'";
            $vamos = mysqli_query($con,$actualiza);
            if($vamos){
                
                echo "<script>alert('Crc finalizado com sucesso')</script>";
                echo "<script>window.open('emailForm.php','_self')</script>";
            }else{
                
            echo "<script>alert('Ocorreu um erro')</script>";
             echo "<script>window.open('emailForm.php','_self')</script>";

            }
        }
        
        ?>

     
        

      </div>
      <!-- /.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";?>

  <!-- Bootstrap core JavaScript-->
  <script src="vendor/jquery/jquery.min.js"></script>
  <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

  <!-- Core plugin JavaScript-->
  <script src="vendor/jquery-easing/jquery.easing.min.js"></script>

  <!-- Page level plugin JavaScript-->
  <script src="vendor/chart.js/Chart.min.js"></script>
  <script src="vendor/datatables/jquery.dataTables.js"></script>
  <script src="vendor/datatables/dataTables.bootstrap4.js"></script>

  <!-- Custom scripts for all pages-->
  <script src="js/sb-admin.min.js"></script>

  <!-- Demo scripts for this page-->
  <script src="js/demo/datatables-demo.js"></script>
  <script src="js/demo/chart-area-demo.js"></script>

</body>

</html>
