<?php

Include("includes/con_cliente.php");

 require_once('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");
    }


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




?>


<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>Sistema SCA - Grupo BRO</title>

        

        <!--<link rel="stylesheet" href="node_modules/bootstrap/compiler/bootstrap.css">
          <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <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 type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
        <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/src/js/bootstrap-datetimepicker.js"></script>
        <script src="js/bootstrap.min.js"></script> -->

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

        <!--<link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.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 type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
        <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/src/js/bootstrap-datetimepicker.js"></script> -->


        <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="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></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 fixed-top navbar-expand-lg navbar-dark" style="background-color: #3333ff;">
      <a class="navbar-brand" href="menu.php">
            <img src="img/logomarca.png" width="50" height="40" class="d-inline-block align-center" alt="">Grupo de Documentos  -  <?php echo $resultado["nomeuser"];?>
            
      </a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
        <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
        </ul>
        <form class="form-inline my-2 my-lg-0">
          <button class="btn btn-primary btn-sm my-2 my-sm-0">
            <a href="gdocumentos.php" style="color:inherit"> Voltar </a></button>
        </form>
      </div>
    </nav>

    <div class="container theme-showcase" role="main" style="margin-top: 5rem;">
      <div class="page-header">
        <h1>Grupo de Documentos</h1>
      </div>
      <div class="pull-right">
        <button type="button" class="btn btn-xs btn-success btn-sm" data-toggle="modal" data-target="#myModalcad">Cadastrar</button>
      </div>

      

      <!-- 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">Grupo de Documento</h4>
            </div>
            <div class="modal-body">
              <form method="POST" action="http://192.168.0.12/sca/processa_cad_tipo.php" enctype="multipart/form-data">
                <div class="form-group">
                  <label for="recipient-name" class="control-label">Nome:</label>
                  <input name="professor" type="text" class="form-control">
                </div>
                <div class="form-group">
                  <label for="message-text" class="control-label">Situação:</label>
                  <!--<input name="situacao" type="text" class="form-control"> -->
                  <select class="form-control" id="situacao" required name="situacao">
                        <option value="Ativo">Ativo</option>
                        <option value="Inativo">Inativo</option>
                  </select>
                </div>
                <div class="form-group">
                  <label for="message-text" class="control-label">Controla Validade ?:</label>
                  <!--<input name="situacao" type="text" class="form-control"> -->
                  <select class="form-control" id="validade" required name="validade">
                        <option value="Ativo">Não</option>
                        <option value="Inativo">Sim</option>
                  </select>
                </div>
                <div class="modal-footer">
                  <button type="submit" class="btn btn-success btn-sm">Cadastrar</button>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>
      <!-- Fim Modal CADASTRO -->
      
      <div class="row">
        <div class="col-md-12">
          <table class="table">
            <thead>
              <tr>
                <th>Id</th>
                <th>Tipo do Documento</th>
                <th>Cont.Validade</th>
                <th>Status</th>
                <th>Ação</th>
              </tr>
            </thead>
            <tbody>
              <?php while($rows_alunos = mysqli_fetch_assoc($resultado_alunos)){ ?>
                <tr>
                  <td><?php echo $rows_alunos['id']; ?></td>
                  <td><?php echo $rows_alunos['tipo']; ?></td>
                  <td><?php echo $rows_alunos['validade']; ?></td>
                  <td><?php echo $rows_alunos['Status']; ?></td>
                  <td>
                    <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal<P><?php echo $rows_alunos['tipo']; ?></P>">Visualizar</button>
                    
                    <button type="button" class="btn btn-warning btn-sm" data-toggle="modal" data-target="#exampleModal" data-whatever="<?php echo $rows_alunos['tipo']; ?>" data-whatevervalidade="<?php echo $rows_alunos['validade']; ?>" data-whateverstatus="<?php echo $rows_alunos['Status']; ?>" data-whatevermatricula="<?php echo $rows_alunos['id']; ?>">
                      Editar
                  </td>
                </tr>
                <!-- Modal VISUALIZA -->
                <div class="modal fade" id="myModal<P><?php echo $rows_alunos['tipo']; ?></P>" 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" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title w-100 text-center" id="myModalLabel"><?php echo $rows_alunos['tipo']; ?></h4>
                      </div>
                      <div class="modal-body">
                        <P>Id: <?php echo $rows_alunos['id']; ?></P>
                        <P>Controle de Validade: <?php echo $rows_alunos['validade']; ?></P>
                        <P>Situação: <?php echo $rows_alunos['Status']; ?></P>
                        <P>Alteração: <?php echo $rows_alunos['controle']; ?></P>
                        <P>Usuário: <?php echo $rows_alunos['usuario']; ?></P>
                      </div>
                    </div>
                  </div>
                </div>
                <!-- FIM Modal VISUALIZA -->
              <?php } ?>
            </tbody>
           </table>
        </div>
      </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">New message</h4>
          </div>
          <div class="modal-body">
            <form method="POST" action="http://192.168.0.12/sca/alteratipo.php" enctype="multipart/form-data">
              <div class="form-group">
                <label for="recipient-name" class="control-label">Documento:</label>
                <input name="professor" type="text" class="form-control" id="recipient-name">
              </div>
              <div class="form-group">
                <label for="message-text" class="control-label">Situação:</label>
                <!--<input name="situacao" type="text" class="form-control" id="recipient-situacao"> -->
                <select class="form-control" id="recipient-situacao" required name="situacao">
                        <option value="Ativo">Ativo</option>
                        <option value="Inativo">Inativo</option>
                  </select>

              </div>
              <div class="form-group">
                <label for="message-text" class="control-label">Controla Validade:</label>
                <!--<input name="situacao" type="text" class="form-control" id="recipient-situacao"> -->
                <select class="form-control" id="recipient-validade" required name="validade">
                        <option value="Sim">Sim</option>
                        <option value="Não">Não</option>
                  </select>

              </div>
              <input name= "matricula" type="hidden" id="recipient-matricula">
              <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 modal = $(this)
      modal.find('.modal-title').text('Id: ' + recipientmatricula)
      modal.find('#recipient-name').val(recipient)
      modal.find('#recipient-situacao').val(recipientstatus)
      modal.find('#recipient-validade').val(recipientvalidade)
      modal.find('#recipient-matricula').val(recipientmatricula)
    })

  </script>


  </body>
</html>

