<?php
include 'header.php';
include 'erpc_local_estoque_toolbar.php';
include_once 'connect.php';
?>
<head>
<script type="text/javascript" src="js/jquery/jquery.min.js"></script>
<style>
.window{
    display:none;
    width:600px;
    height:600px;
    position:absolute;
    left:0;
    top:0;
    background:#FFF;
    z-index:9900;
    padding:10px;
    border-radius:10px;
    background-color:black;
}

#mascara{
    display:none;
    position:absolute;
    left:0;
    top:0;
    z-index:9000;
    background-color:#000;
}

.fechar{display:block; text-align:right;}

.hide-block{
    display: none;
}


</style>
</head>

<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
  <li role="presentation" class="active"><a href="#form1" aria-controls="form1" role="tab" data-toggle="tab">Filtro</a></li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade in active" id="form1">
<form id="printForm" method=POST action="erpc_local_estoque_report_preview.php">
  <input type=text name="html-text" id="html-text" hidden/>
  <div class=block>
    <div class=header>
      <h2>Informe os parametros para o Relatório:</h2>
      <div class="side pull-right"> <button class="btn btn-default btn-clean" onClick="clear_form('#validate_custom');" type=button>Clear form</button>          </div>
    </div>

  <div class="content controls">
  	<div class=form-row>
      <div class=col-md-2>ID:</div>
      <div class=col-md-2><input type=number name="id" value="" class="form-control" /> </div>
    </div>

    <div class=form-row>
      <div class=col-md-2>Descrição:</div>
      <div class=col-md-6><input name="ds_local" value="" class="form-control" /> </div>
    </div>

    <div class="form-row">
      <div class="col-md-2"><label>Tipo de Saída</label></div>
      <div class="col-md-4">
        <div class="input-group">
          <div class="checked inline"><label> <input type=radio class=validate[required] name=st_tipo_saida value="0"/>HTML</label></div>
          <div class="checked inline"><label> <input type=radio class=validate[required] name=st_tipo_saida value="1"/>PDF</label></div>
          <div class="checked inline"><label> <input type=radio class=validate[required] name=st_tipo_saida value="2"/>Excel</label></div>
        </div>
      </div>
    </div>
    </div>

    <div class=footer>
      <div class="side pull-right">
        <div class=btn-group>
		        <button class="btn btn-default" type="button" onClick="window.history.go(-1)" value="voltar">voltar</button>
            <button class="btn btn-success" type="button" value="visualizar" name="visualizar" id="visualizar"
                    data-toggle="modal" data-target="#modal-div">visualizar</button>
			      <!--botao antigo
		          <button class="btn btn-default" type=button onClick="$('#validate_custom').validationEngine('hide');">Hide prompts</button>            <button class="btn btn-success" type=submit>Submit</button>
		        -->
		    </div>
      </div>
     </div>
  </div>
</form>
</div>
</div>

<div id="post-result"   class="window" tabindex="1" hidden>
</div>



<!-- janela de mensagem -->
<div class="modal modal-white fade" id="modal-div" tabindex="-1" role="dialog" aria-labelledby="helper-modal-label" aria-hidden="true">
  <div class="modal-dialog modal-lg">
  <div class="modal-content">
    <!-- Header-->
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal">
        <span aria-hidden="true">&times;</span>
        <span class="sr-only">Close</span>
      </button>
      <h4 class="modal-title" id="myModalLabel">Resultado do Relatório:</h4>
  </div>
    <!-- Body -->
    <div class="modal-body" id="post-mensagem"/>
      Aguarde...&nbsp;
    </div>
    <!-- Footer -->
    <div class="modal-footer">
        <!-- <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>-->
        <button type="button" class="btn btn-primary" class="close" data-dismiss="modal"/>OK</button>
    </div>
  </div>
  </div>
</div>

<?php include 'footer.php'; ?>
<!--
<script type="text/javascript" src="js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="js/js.js"></script> -->
<script>
$(document).ready(function(){
    $("#visualizar").click(function(){
      $('#post-mensagem').empty();

      var p_saida = $('input[name=st_tipo_saida]:checked').val();
      $.post("erpc_local_estoque_report_preview.php",
          $('#printForm').serialize(),
          function(data,status){
            // alert("Data: " + data + "\nStatus: " + status);
            $('#post-mensagem').append(data);

            // Saida para HTML, captura o post do ajax para a DIV
            if(p_saida==0){
              // $('#open-window').show("slow");
              // $('#post-result').fadeIn(1000);
              // $('#post-result').fadeTo("slow", 0.8);

            // Saida para PDF, captura o conteudo
            }else if(p_saida==1){
              var p_html  = $("#post-mensagem").html();
              // seta o valor de um campo texto para o submit
              $("#html-text").val(p_html);
              $("#printForm").attr('action', 'http://192.168.0.200/edival/report/report_pdf.php');
              $("#printForm").submit();

              // var p_link = "http://192.168.0.200/edival/report_pdf.php?html=" + p_html;
              // var p_link = "../report/report_pdf.php?html=" + p_html;
              // window.location = p_link;
            }
          });

      // Saida para Excel, executa o post do form
      if(p_saida==2){
        $("#printForm").attr('action', 'erpc_local_estoque_report_export.php');
        // $("#printForm").submit();

        $.post("erpc_local_estoque_report_export.php",
            $('#printForm').serialize(),
            function(data,status){
              $('#post-mensagem').empty();
              $('#post-mensagem').append(data);
              // $('#modal-div').show("slow");
              // $('#modal-div').fadeIn(1000);
              $('#modal-div').fadeTo("slow", 15);
            });
      }

      });
});

$(document).keyup(function(e) {
     if (e.keyCode == 27) { // escape key maps to keycode `27`
        // <DO YOUR WORK HERE>
        $('#post-result').hide();
        $('#modal-div').hide();
    }
});
</script>
