<?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="" method="post">
	             <?php
	             if(isset($_POST['submit'])){
	                 $nome_avalista = $_POST['nome_avalista'];
	                 $estado_civil_avalista = $_POST['estado_civil_avalista'];
	                 $bi_avalista = $_POST['bi_avalista'];
	                 $aic_avalista = $_POST['aic_avalista'];
	                 $data_emissao_avalista = $_POST['data_emissao_avalista'];
	                 $pai_avalista = $_POST['pai_avalista'];
	                 $mae_avalista = $_POST['mae_avalista'];
	                 $bairro_avalista = $_POST['bairro_avalista'];
	                    $pessoa_avalista = $_POST['pessoa_avalista'];
	                       $morada_pessoa_avalista = $_POST['morada_pessoa_avalista'];
	                          $telefone_pessoa_avalista = $_POST['telefone_pessoa_avalista'];
	                 $email_pessoa_avalista = $_POST['email_pessoa_avalista'];
	                          $cliente = $_POST['cliente'];
	                          
	               $query = mysqli_query($con,"INSERT INTO avalista(nome_avalista,estado_civil_avalista,bi_avalista,aic_avalista,data_emissao_avalista,pai_avalista,mae_avalista,bairro_avalista,pessoa_avalista,morada_pessoa_avalista,telefone_pessoa_avalista,email_pessoa_avalista,cliente)
	               VALUES('$nome_avalista','$estado_civil_avalista','$bi_avalista','$aic_avalista','$data_emissao_avalista','$pai_avalista','$mae_avalista','$bairro_avalista','$pessoa_avalista','$morada_pessoa_avalista','$telefone_pessoa_avalista','$email_pessoa_avalista','$cliente')");
	               
	               if($query){
	                   echo "<script>alert('Avalista do cliente $cliente cadastrado com sucesso')</script>";
	                   echo "<script>window.open('avalista.php','_self')</script>";
	               }else{
	                    echo "<script>alert('OCORREU UM ERRO')</script>";
	                   echo "<script>window.open('avalista.php','_self')</script>";
	               }
	               
	                 
	             }
	             
	             ?>
	               <div class="form-group">
	                   <label for="nome_avalista">Nome do avalista</label>
	                   <input type="text" name="nome_avalista" class="form-control" autocomplete="off" required/>
	               </div>
	               
	               <div class="form-group">
	                   <label for="estado_civil_avalista">Estado civil</label>
	                   <select required name="estado_civil_avalista" class="form-control">
	                       <option></option>
	                       <option>Solteiro(a)</option>
	                       <option>Casado(a)</option>
	                       <option>Divoriciado(a)</option>
	                       <option>Viuvo(a)</option>
	                   </select>
	               </div>
	               
	               <div class="form-group">
	                   <label for="bi_avalista">Numero de b.i</label>
	                   <input type="text" name="bi_avalista" class="form-control" autocomplete="off" required/>
	               </div>
	               
	               <div class="form-group">
	                   <label for="aic_avalista">Arquivo I.C</label>
	                   <input type="text" name="aic_avalista" class="form-control" autocomplete="off" required/>
	               </div>
	               
	               <div class="form-group">
	                   <label for="data_emissao_avalista">Data emissao</label>
	                   <input type="date" name="data_emissao_avalista" class="form-control" autocomplete="off" required/>
	               </div>
	               
	               <div class="form-group">
	                   <label for="pai_avalista">Nome do pai</label>
	                   <input type="text" name="pai_avalista" class="form-control" autocomplete="off" required/>
	               </div>
	               
	               <div class="form-group">
	                   <label for="mae_avalista">Nome da mae</label>
	                   <input type="text" name="mae_avalista" class="form-control" autocomplete="off" required/>
	               </div>
	               
	               <div class="form-group">
	                   <label for="nome_avalista">Bairro</label>
	                   <input type="text" name="bairro_avalista" class="form-control" autocomplete="off" required/>
	               </div>
	               
	               <div class="form-group">
	                   <label for="pessoa_avalista">Pessoa de contacto</label>
	                   <input type="text" name="pessoa_avalista" class="form-control" autocomplete="off" required/>
	               </div>
	               
	               <div class="form-group">
	                   <label for="morada_pessoa_avalista">Morada</label>
	                   <input type="text" name="morada_pessoa_avalista" class="form-control" autocomplete="off" required/>
	               </div>
	               
	               <div class="form-group">
	                   <label for="nome_avalista">Telefone</label>
	                   <input type="text" name="telefone_pessoa_avalista" class="form-control" autocomplete="off" required/>
	               </div>
	               
	               <div class="form-group">
	                   <label for="nome_avalista">Email</label>
	                   <input type="email" name="email_pessoa_avalista" class="form-control" autocomplete="off" required/>
	               </div>
	               
	               <div class="form-group">
	                   <label for="nome_cliente">Nome do cliente</label>
	                   <select required name="cliente" class="form-control">
	                       <option></option>
	                       <?php echo busca_cliente();?>
	                   </select>
	               </div>
	               
	               <div class="form-group">
	                   <input type="submit" name="submit" class="btn btn-info btn-sm" value="Submit"/>
	               </div>
	               
	           </form>
	           
	       </div>
	   </div>
        
        
        </div>

     <div class="absolute">
        
         <table class="table">
             <thead>
                 <tr>
                     <th>Item</th>
                     <th>Cliente</th>
                     <th>Avalista</th>
                 </tr>
             </thead>
             <tbody>
                 <?php
                 $item =1;
                 $sel = mysqli_query($con,"SELECT * FROM avalista");
                 while($row = mysqli_fetch_assoc($sel)){
                 ?>
                 <tr>
                     <td><?php echo $item++;?></td>
                     <td><?php echo $row['cliente'];?></td>
                     <td><?php echo $row['nome_avalista']?></td>
                 </tr>
                 <?php }?>
             </tbody>
         </table>
     </div>
        

      </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>
