<!DOCTYPE html>
<html lang="en">
<?php
Include("../includes/con_cliente.php");
 require_once('../includes/connection.php');
    session_start();
    if(isset($_SESSION['User']))
    {
        $query="select * from tbusuario where nomeuser='".$_SESSION['User']."'";
        $result=mysqli_query($con,$query);
        $resultado = mysqli_fetch_assoc($result);
        $r_resultado = $resultado;
    }
    else
    {
        header("location:../index.php");
    }

    

    $P_idcobranca=$_GET['id'];

    
    
    $result_cobranca = "SELECT * FROM crm_processo_fatura WHERE id = '".$P_idcobranca."'";
    $resultado_cobranca = mysqli_query($con,$result_cobranca);
    $row_cobranca = mysqli_fetch_assoc($resultado_cobranca);



    $result_alunos = "SELECT * FROM crm_processo_fatura_contato WHERE id = '".$P_idcobranca."'";
    $resultado_alunos = mysqli_query($con, $result_alunos);





 ?>


<head>
    <title>SCA - Módulo CRM</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900" rel="stylesheet">
    
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="css/style.css">
  </head>
  <body>
    
    <div class="wrapper d-flex align-items-stretch">
      <nav id="sidebar" class="active">
        <h1><a href="index.html" class="logo">CRM</a></h1>
        <ul class="list-unstyled components mb-5">
          <li class="active">
           <a href="#" data-toggle="modal" data-target="#myModalcad"><span class="fa fa-child"></span> Novo Contato</a> 

           <!-- <button type="button" class="btn btn-xs btn-success btn-sm" data-toggle="modal" data-target="#myModalcad">Novo</button>-->

          </li>
         <!-- <li>
              <a href="#"><span class="fa fa-briefcase"></span> Vales</a>
          </li>
          <li>
            <a href="#"><span class="fa fa-legal"></span> Administração</a>
          </li>
          <li>
            <a href="#"><span class="fa fa-line-chart"></span> Dashboard</a>
          </li> -->
          <li>
            <a href="fatura01.php"><span class="fa fa-reply-all"></span> Voltar</a>
          </li>
        </ul>

        <div class="footer">
          <p>
            Copyright &copy;<script>document.write(new Date().getFullYear());</script> All rights reserved - Fábio Freitas <a href="https://colorlib.com" target="_blank">Colorlib.com</a>
          </p>
        </div>
      </nav>


       <!-- Inicio Modal CADASTRO -->
      <div class="modal fade" id="myModalcad" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close btn-sm" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title w-100 text-center" id="myModalLabel">Novo Contato</h4>
            </div>
            <div class="modal-body">
              <form method="POST" action="../crm/processa_cadastro_contatos.php" enctype="multipart/form-data">
                <div class="form-group">
                  <label for="message-text" class="control-label">Tipo do Contato:</label>
                  <select class="form-control" style="margin-top: -10px;" id="tipo" required name="tipo">
                    <option value="Telefone Fixo">Telefone Fixo</option>
                    <option value="Telefone Celular">Celular</option>
                    <option value="E-mail">E-Mail</option>
                    <option value="Endereço">Endereço</option>
                  </select>
                </div>
                <div class="form-group">
                  <label for="recipient-name" style="margin-top: -10px;" class="control-label">Endereço / Número:</label>
                  <input class="form-control " placeholder="Descrição" required type="text" name="endereco" onkeypress="return sem_acento(event);" >
                </div>
                <div class="form-group">
                  <label for="recipient-name" style="margin-top: -10px;" class="control-label">Contato:</label>
                  <input class="form-control" placeholder="Contato" required type="text" name="contato" >
                </div>
                <div class="form-group">
                  <label for="recipient-name" style="margin-top: -10px;" class="control-label">Observações:</label>
                  <input class="form-control" placeholder="Observações" required type="text" name="obs" >
                </div>
                <div class="form-group">
                  <label for="message-text" class="control-label">Situação:</label>
                  <select class="form-control" style="margin-top: -10px;" id="tipo" required name="status">
                        <option value="Ativo">Ativo</option>
                    <option value="Inativo">Inativo</option>
                  </select>
                </div>
                
                <input name= "idcliente" type="hidden" id="recipient-id" value="<?php echo $row_cobranca['id']; ?>">
                
                <div class="modal-footer">
                  <button type="submit" class="btn btn-outline-primary btn-sm">Cadastrar e Sair</button>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>
      <!-- Fim Modal CADASTRO -->

     
        <!-- Page Content  -->
      <div id="content" class="p-4 p-md-5">

      <!--  <nav class="navbar navbar-expand-lg navbar-light bg-light">
          <div class="container-fluid">

            <button type="button" id="sidebarCollapse" class="btn btn-primary">
              <i class="fa fa-bars"></i>
              <span class="sr-only">Toggle Menu</span>
            </button>
            

            
          </div>
        </nav> -->

        <h2 class="mb-4">Contatos da Cobrança <?php echo $row_cobranca['cliente']; ?></h2>

        <div class="container">
          <div class="table-responsive-xl">
            <!--<table class="table table-sm"> -->
            <table style="overflow: auto;" class="table table-striped table-responsive-md btn-table table-hover table-bordered">
              <thead>
                <tr class="info">
                  <th>Tipo</th>
                  <th>Descrição</th>
                  <th>Contato</th>
                  <th>Observação</th>
                  
                </tr>
              </thead>
              <tbody>
                <?php while($rows_alunos = mysqli_fetch_assoc($resultado_alunos)){ ?>
                  <!--<tr onclick="location.href = 'detalheprocesso.php?id=<?php echo $rows_alunos['id']; ?>'" style="cursor: hand;"> -->
                  <tr>
                    <td><?php echo $rows_alunos['tipo']; ?></td>
                    <td><?php echo $rows_alunos['nome']; ?></td>
                    <td><?php echo $rows_alunos['contato']; ?></td>
                    <td><?php echo $rows_alunos['obs']; ?></td>
                    <td></td>
                    <td></td>
                  
                    <td>
                      <button type="button" class="btn btn-outline-info btn-sm btn-block" data-toggle="modal" data-target="#exampleModal" data-wtipo="<?php echo $rows_alunos['tipo']; ?>" data-wnome="<?php echo $rows_alunos['nome']; ?>" data-wcontato="<?php echo $rows_alunos['contato']; ?>"data-wobs="<?php echo $rows_alunos['obs']; ?>" data-wid="<?php echo $rows_alunos['id']; ?>" data-wstatus="<?php echo $rows_alunos['status']; ?>" data-widcontato="<?php echo $rows_alunos['idcontato']; ?>">
                        Editar
                      </button>
                    </td>
                    
                  </tr>
                <?php } ?>
              </tbody>
             </table>
          </div>
      </div> 
        
      </div>
    </div>

    <!-- Modal para alteração do contrato -->

    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title w-100 text-center" id="exampleModalLabel">Alteração da Descrição</h4>
          </div>
          <div class="modal-body">
            <form method="POST" action="../crm/alteracontato.php" enctype="multipart/form-data">
              <div class="form-group">
                  <label for="message-text" class="control-label">Tipo do Contato:</label>
                  <select class="form-control" style="margin-top: -10px;" id="recipient-tipo" required name="tipo">
                    <option value="Telefone Fixo">Telefone Fixo</option>
                    <option value="Telefone Celular">Celular</option>
                    <option value="E-mail">E-Mail</option>
                    <option value="Endereço">Endereço</option>
                  </select>
                </div>
              <div class="form-group">
                  <label for="recipient-name" style="margin-top: -10px;" class="control-label">Endereço / Número:</label>
                  <input class="form-control " placeholder="Descrição" required type="text" name="endereco" id="recipient-nome" >
                </div>
                <div class="form-group">
                  <label for="recipient-name" style="margin-top: -10px;" class="control-label">Contato:</label>
                  <input class="form-control" placeholder="Contato" required type="text" name="contato" id="recipient-contato" >
                </div>
                <div class="form-group">
                  <label for="recipient-name" style="margin-top: -10px;" class="control-label">Observações:</label>
                  <input class="form-control" placeholder="Observações" required type="text" name="obs" id="recipient-obs" >
                </div>
                <div class="form-group">
                  <label for="message-text" class="control-label">Situação:</label>
                  <select class="form-control" style="margin-top: -10px;" id="recipient-status" required name="status">
                        <option value="Ativo">Ativo</option>
                    <option value="Inativo">Inativo</option>
                  </select>
                </div>
                
                <input name= "idcliente" type="hidden" id="recipient-id" value="<?php echo $row_cobranca['id']; ?>">
                <input name= "id" type="hidden" id="recipient-idcontato">
                <div class="modal-footer">
                 <button type="button" class="btn btn-outline-danger" data-dismiss="modal">Cancelar</button>
                  <button type="submit" class="btn btn-outline-primary">Alterar</button>
                </div>
            </form>
          </div>
        </div>
      </div>
    </div> 

    <!-- Fim Modal Altera contratos -->

    <script src="js/jquery.min.js"></script>
    <script src="js/popper.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/main.js"></script>
    <script type="text/javascript">

        $('#exampleModal').on('show.bs.modal', function (event) {
          var button = $(event.relatedTarget) // Button that triggered the modal
          var recipienttipo = button.data('wtipo')
          var recipientnome = button.data('wnome')
          var recipientcontato = button.data('wcontato')
          var recipientobs = button.data('wobs')
          var recipientstatus = button.data('wstatus')
          var recipientid = button.data('wid')
          var recipientidcontato = button.data('widcontato')

          var modal = $(this)
          modal.find('.modal-title').text('Contato ID: ' + recipientidcontato)
          modal.find('#recipient-tipo').val(recipienttipo)
          modal.find('#recipient-nome').val(recipientnome)
          modal.find('#recipient-contato').val(recipientcontato)
          modal.find('#recipient-obs').val(recipientobs)
          modal.find('#recipient-status').val(recipientstatus)
          modal.find('#recipient-id').val(recipientid)
          modal.find('#recipient-idcontato').val(recipientidcontato)
        })

        
    </script>


  </body>
</html>
