<?php
Include("../includes/con_cliente.php");

 require_once('../includes/connection.php');
    session_start();

    if(isset($_SESSION['User']))
    {
        $query="select * from tblogin where nome='".$_SESSION['User']."'";
        $result=mysqli_query($con,$query);
        $resultado = mysqli_fetch_assoc($result);
        $r_resultado = $resultado;
    }
    else
    {
        header("location:index.php");
    }


    $result_alunos = "SELECT * FROM vendedor";
    $resultado_alunos = mysqli_query($con, $result_alunos);


?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
        
      <title>OPME - Cadastro de Vendedores</title>

      <link rel="stylesheet" href="../node_modules/bootstrap/compiler/bootstrap.css">
      <link rel="stylesheet" href="../node_modules/bootstrap/compiler/styler.css">

      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
      <link rel="stylesheet" href="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/build/css/bootstrap-datetimepicker.css" />
      <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.15/jquery.mask.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

      <script src="http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

      <script src="jquery.maskMoney.js" type="text/javascript"></script>
</head>
<body>
    <nav class="navbar navbar-expand-sm navbar-light justify-content-end fixed-top" style="background-color: #008080">
        <a style="color: #FFFAFA">OPME - Aministrativo - Vendedores - <?php echo $resultado["nome"];?></a>
        <a class="btn btn-outline-light ml-auto mr-1" href="../m.php" role="button">Voltar</a>
    </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 Vendedor</h4>
            </div>
            <div class="modal-body">
              <form method="POST" action="../adm/processa_cadastro_vendedor.php" enctype="multipart/form-data">

                <div class="form-group">
                  <label for="recipient-name" style="margin-top: -10px;" class="control-label">Código VIMAN:</label>
                  <input class="form-control " style="margin-top: -10px;" placeholder="Código" required type="number" min="0" step="1"name="codigo" >
                </div>

                <div class="form-group">
                  <label for="recipient-name" style="margin-top: -10px;" class="control-label">Nome do Vendedor:</label>
                  <input class="form-control " style="margin-top: -10px;text-transform: uppercase;" placeholder="Vendedor" required type="text" name="vendedor" onkeypress="return sem_acento(event);" >
                </div>

                <div class="form-group">
                  <label for="recipient-name" style="margin-top: -10px;" class="control-label">E-Mail:</label>
                  <input class="form-control " style="margin-top: -10px;" placeholder="E-Mail" required type="text" name="email" onkeypress="return sem_acento(event);" >
                </div>

                

                <div class="modal-footer">
                  <button type="submit" class="btn btn-warning btn-sm">Cadastrar e Sair</button>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>
      <!-- Fim Modal CADASTRO -->

    <div class="container theme-showcase" role="main" style="margin-top: 3rem;">
        <div class="page-header">
            <h2>Vendedores Cadastrados</h2>
        </div>
        <div class="pull-right">
            <button type="button" class="btn btn-xs btn-success btn-sm" data-toggle="modal" data-target="#myModalcad">Novo</button>
        </div>
    </div>

    <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 style="text-align: center; vertical-align:middle !important">Codigo</th>
                <th style="text-align: center; vertical-align:middle !important">Nome do Vendedor</th>
                <th style="text-align: center; vertical-align:middle !important">E-Mail</th>
                <th style="text-align: center; vertical-align:middle !important">Opções</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 style="text-align: center; vertical-align:middle !important"><?php echo $rows_alunos['Codigo']; ?></td>
                  <td style="text-align: center; vertical-align:middle !important"><?php echo $rows_alunos['Nome']; ?></td>
                  <td style="text-align: center; vertical-align:middle !important"><?php echo $rows_alunos['mail']; ?></td>
                  <td style="text-align: center; vertical-align:middle !important">
                    <button type="button" class="btn btn-warning btn-sm" data-toggle="modal" data-target="#exampleModal" data-whatever="<?php echo $rows_alunos['Nome']; ?>" data-whatevervalidade="<?php echo $rows_alunos['mail']; ?>" data-whateverstatus="<?php echo $rows_alunos['Codigo']; ?>">
                      Editar
                    </button>
                    <a href="../adm/processa_apagar_vendedor.php?Codigo=<?php echo $rows_alunos['Codigo']; ?>"><button type="button" class="btn btn-sm btn-danger">Apagar</button></a>
                  </td>
                </tr>
              <?php } ?>
            </tbody>
           </table>
        </div>
      </div> 

      <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 do Vendedor</h4>
          </div>
          <div class="modal-body">
            <form method="POST" action="http:../adm/alteravendedor.php" enctype="multipart/form-data">
              <div class="form-group">
                <label for="recipient-name" class="control-label">Nome:</label>
                <input name="nome" type="text" class="form-control" id="recipient-name" required type="text"  onkeypress="return sem_acento(event);"  style="margin-top: -10px;text-transform: uppercase;" >
              </div>
              <div class="form-group">
                <label for="recipient-name" class="control-label">E-Mail:</label>
                <input name="email" type="text" class="form-control" id="recipient-validade" required type="text"  onkeypress="return sem_acento(event);"  style="margin-top: -10px;text-transform: uppercase;" >
              </div>
              
              <input name= "matricula" type="hidden" id="recipient-situacao">
              <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">Cancelar</button>
                <button type="submit" class="btn btn-danger">Alterar</button>
              </div>
            </form>
          </div>
          
        </div>
      </div>
    </div> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>

    <script type="text/javascript">

        $('#exampleModal').on('show.bs.modal', function (event) {
          var button = $(event.relatedTarget) // Button that triggered the modal
          var recipient = button.data('whatever')
          var recipientstatus = button.data('whateverstatus')
          var recipientvalidade = button.data('whatevervalidade')
          var recipientmatricula = button.data('whatevermatricula')
          var recipientsenha = button.data('whateversenha')

          var modal = $(this)
          modal.find('.modal-title').text('Médico: ' + recipientstatus)
          modal.find('#recipient-name').val(recipient)
          modal.find('#recipient-situacao').val(recipientstatus)
          modal.find('#recipient-validade').val(recipientvalidade)
          modal.find('#recipient-matricula').val(recipientmatricula)
          modal.find('#recipient-senha').val(recipientsenha)
        })

    </script>
    <script>
                    //FUNÇÃO SEM ACENTO
          function sem_acento(e,args)
          {   
            if (document.all){var evt=event.keyCode;} // caso seja IE
            else{var evt = e.charCode;} // do contrário deve ser Mozilla
            var valid_chars = '0123456789abcdefghijlmnopqrstuvxzwykABCDEFGHIJLMNOPQRSTUVXZWYK-_.,/ '+args;  // criando a lista de teclas permitidas
            var chr= String.fromCharCode(evt);  // pegando a tecla digitada
            if (valid_chars.indexOf(chr)>-1 ){return true;} // se a tecla estiver na lista de permissão permite-a
            // para permitir teclas como <BACKSPACE> adicionamos uma permissão para 
            // códigos de tecla menores que 09 por exemplo (geralmente uso menores que 20)
            if (valid_chars.indexOf(chr)>-1 || evt < 9){return true;} // se a tecla estiver na lista de permissão permite-a
            return false; // do contrário nega
          }
    </script>    

</body>
</html>