<?php
//echo '<pre>';var_dump( $this->session->unset_userdata() );
//$this->session->unset_userdata("imazon_nome");
?>
<?php echo doctype('html5'); ?>
<html>

<head>
<style>
    .panel-default {
        border-color: #DDD;
    }
    .panel {
        margin-bottom: 20px;
        background-color: #FFF;
        border: 1px solid transparent;
        border-radius: 4px;
        box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.05);
    }
</style>

<script type="text/javascript" src="https://www.ovumpay.com.br/litebox/js/ovumpay.js"></script>

<script>
class Principal extends Ovumpay {
finalizarPagamento(form) {
var botaoFinalizar = document.getElementById("finalizar");
botaoFinalizar.setAttribute("disabled", "disabled");
var modal = document.getElementById("corpoModal");
var cabecalho = document.getElementById("myModalLabel");
cabecalho.innerHTML = 'Seu pagamento está sendo processado';
modal.innerHTML = '';
var divLoader = document.createElement("div");
divLoader.classList.add('loader');
modal.appendChild(divLoader);
var a = document.createElement("h3");
var botaoFechar = document.getElementById("close");
botaoFechar.setAttribute("disabled", "disabled");
a.classList.add('a');
modal.appendChild(a);
a.innerHTML = "Aguarde...";

$.ajax({
    data: {
        con: "",
        valor: form.valor.value,
        urlRetorno: form.urlRetorno.value,
        id: form.id.value,
        np: form.nomep.value,
        email: form.email.value,
        contato: form.contato.value,
        descricao: form.descricao.value,
        pedido: form.pedido.value,
        dominio: self.location.host,
        parcelamento: form.parcelamento.value,
        numero: form.numero.value,
        validade: form.validade.value,
        n: form.nome.value,
        cvv: form.cvv.value
        },
               type: "POST",
               dataType: 'json',
               url: "<?php echo base_url();?>"+'Site/pagamento_ovumpay',
               success: function (data) {
                   console.log(data);
                  botaoFechar.removeAttribute("disabled");
                  cabecalho.innerHTML = 'Resultado da transação';
                  modal.innerHTML = '';
                  modal.innerHTML = data['mensagem'];

                  if(data['status']==1){
                      setTimeout(function() { window.location='Site/finalizar_compra_saldo';},3000);
                  }
                  else if(data['status']==2){
                      setTimeout(function() { window.location='Site/finalizarPedido';},3000);
                  }

               }
           });

}
};
</script>

<p>Para adicionar mais itens, basta navegar pelo site.</p>

</head>
<body>

<div class="row">
    <div class="col-md-12">

        <?php
        $total = 0;
        $this->table->set_template(array('table_open' => '<table class="table table-condensed">'));
        $this->table->set_heading('Itens', 'Valor');
        foreach ($this->cart->contents() as $c) {
            $bt = '<a href="' . base_url() . 'site/delCarrinho/' . base64_encode($c['rowid']) . '"  onclick="return confirm(\'Deseja realmente excluir o curso ' . $c['name'] . '?\')" type="button" class="btn btn-danger">Remover</button>';
	$this->table->add_row($c['name'], 'R$' . format_number($c['price']));
            $total += $c['price'];
        }

        echo $this->table->generate();
        //echo '<pre>Total: R$' . format_number($this->cart->total()) . '</pre>';
        ?>
    </div>
</div>
	<p>Seu Pagamento será Processado por<a href="https://www.traycheckout.com.br/" target="_blank"> Traycheckout <img src="<?php echo ROOT_URL; ?>imgs/tray.png" width="40"> </a></p>

<div class="col-md-12" id="pedido_i">

<br /><br />
    <div class="form-group">
        <label for="Valor">Escolha a Forma de pagamento</label>

        <div class="radio">
            <span id="test_b" data-toggle="collapse" data-parent="#accordion" href="#boleto" aria-expanded="true" aria-controls="collapseOne" class="btn btn-default mais-carga-horaria">
                <i class="glyphicon glyphicon-barcode"></i>Boleto
            </span><div class="inner-buttons-finalizar"></div>
            <span id="botao" class="collapsed btn btn-warning mais-carga-horaria" role="button" data-toggle="collapse" data-parent="#accordion" href="#cartaox" aria-expanded="false" aria-controls="collapseTwo">
                <i class="glyphicon glyphicon-credit-card"></i>Cartão
            </span><div class="inner-buttons-finalizar"></div>
            <span class="btn btn-info mais-carga-horaria" role="button" data-toggle="collapse" data-parent="#accordion" href="#debito" aria-expanded="false" aria-controls="collapseTwo">
                <i class="glyphicon glyphicon-credit-card"></i>Débito
            </span><div class="inner-buttons-finalizar"></div>
            <span class="btn btn-success mais-carga-horaria" role="button" data-toggle="collapse" data-parent="#accordion" href="#saldo" aria-expanded="false" aria-controls="collapseTwo">
                <i class="glyphicon glyphicon-usd"></i>Saldo
            </span>
        </div>
    </div>
</div>
<?php
        //echo '<pre>';var_dump($this->session->userdata());
    $descricao_cart ='';
    foreach ($cart as $car)
    {
        $descricao_cart .= $car['descricao'].', ';
    }
     //$id_transacao = "IMAC" . substr(md5(microtime()), 0, 10);
//echo '<pre>';var_dump($descricao_cart);//var_dump($this->session->userdata());?>
<input id="valor" hidden value="<?php echo $total;?>">
<input id="id" hidden value="<?php echo $this->session->userdata('imazon_id_fic'); ?>">
<input id="nomep" hidden value="<?php echo $this->session->userdata('imazon_nome');?>">
<input id="email" hidden value="<?php echo $this->session->userdata('imazon_email_aluno'); ?>">
<input id="contato" hidden value="<?php echo $aluno_contato;?>">
<input id="descricao" hidden value="<?php echo $descricao_cart;?>">
<input id="pedido" hidden value="">
<input id="urlRetorno" hidden value="<?php echo $url_retorno;?>">
<!--<button class="button" id="botao" style="margin-top:10vh; margin-left:45vw;">PAGAR</button>-->
<div id="m" class="modal" tabindex="-1" role="dialog"></div>

<script>
Principal = new Principal();
</script>

<script>
var url_base = "<?php echo base_url(); ?>";

$("#botao").click( function(){

        var url_base = "<?php echo base_url();?>";
        var valor = "<?php echo $total;?>";
        var id_aluno = "<?php echo $this->session->userdata('imazon_id_fic'); ?>";
        var cart = <?php echo json_encode($cart); ?>;

        Principal.openModalCriar(this);

//        $.ajax({
//            method: "POST",
//            dataType:"json",
//            url: "<?php echo base_url()."Site/transacaoLightbox" ?>",
//            data:{id_aluno:id_aluno, valor:valor, cart:cart},
//            success:function(response){
//                //$("#pedido").val(response['id_transacao']);
//                Principal.openModalCriar(this);
//            }
//
//          });


});

</script>


<!--<div id="m" class="modal" tabindex="-1" role="dialog"></div>-->

<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
    <div class="panel panel-default">
        <div id="boleto" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
            <div class="panel-body">
                <form action="<?php echo base_url(); ?>gerarPagamento" target="_blank" method="post" id="formulario">
                    <div class="form-group">
                        <label for="Identidade">CPF:</label>
                        <input name="Identidade" id="Identidade" autocomplete="off" maxlength="11" minlength="11" type="tel" class="form-control" required>
                    </div>



                    <input name="Valor" id="Valor" value="<?php echo $total ?>" type="hidden">
                    <input type="hidden" name="Forma" value="6"/>
                    <?php
                    if ($this->session->userdata('aluno_logado_imazon')) {
                        echo '<input type="submit" class="btn btn-success mais-carga-horaria" value="Finalizar">';
                    } else {
                        echo '<input type="submit" class="btn btn-success mais-carga-horaria" value="Finalizar">';
                    }
                    ?>
                </form>
            </div>
        </div>
    </div>

    <div class="panel panel-default">
        <div id="debito" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
            <div class="panel-body">
                <form action="<?php echo base_url(); ?>gerarPagamento" target="_blank" method="post" id="formulario">
                    <div class="container-fluid">
                        <div class="row">
                                <label for="fdebito">Escolha o Banco: </label><br>
                                <label class="radio-inline">
                          <input name="Forma" id="Forma" value="22" required="" type="radio">
                          <img src="<?php echo ROOT_URL; ?>imgs/ico-bradesco.jpg">
								</label>
                        <label class="radio-inline">
                           <input name="Forma" id="Forma" value="23" required="" type="radio">
                           <img src="<?php echo ROOT_URL; ?>imgs/ico-bb.jpg">
                        </label>
                        <label class="radio-inline">
                          <input name="Forma" id="Forma" value="7" required="" type="radio">
                          <img src="<?php echo ROOT_URL; ?>imgs/ico-itau.jpg">
                        </label>
                        <label class="radio-inline">
                          <input name="Forma" id="Forma" value="21" required="" type="radio">
                          <img src="<?php echo ROOT_URL; ?>imgs/ico-hsbc.jpg">
                        </label>
                        <label class="radio-inline">
                          <input name="Forma" id="Forma" value="14" required="" type="radio">
                          <img src="<?php echo ROOT_URL; ?>imgs/ico-peela.jpg">
                        </label>

                            </div>
                    </div>

                    <div class="form-group">
                        <label for="Identidade">CPF:</label>
                        <input name="Identidade" id="Identidade"  autocomplete="off" maxlength="11" minlength="11" type="tel" class="form-control" required>           </div>

                    <input name="Valor" id="Valor" value="<?php echo $total ?>" type="hidden">

                    <?php
                    if ($this->session->userdata('aluno_logado_imazon')) {
                        echo '<input type="submit" class="btn btn-success mais-carga-horaria" value="Finalizar">';
                    } else {
                        echo '<input type="submit" class="btn btn-success mais-carga-horaria" value="Finalizar">';
                    }
                    ?>
                </form>
            </div>
        </div>
    </div>


    <div class="panel panel-default">
        <div id="cartao" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
            <div class="panel-body">

                <form action="<?php echo base_url(); ?>gerarPagamento" target="_blank" method="post" id="formulario">

                    <div class="form-group">
                        <label for="cartao">Escolha a Bandeira do Cart&atilde;o: <br> <br> </label>
                        <br>
                        <label class="radio-inline">
                            <input name="Forma" id="Forma" value="3" required="" type="radio">
                            <img src="<?php echo ROOT_URL; ?>imgs/ico-visa.jpg">
                        </label>

                        <label class="radio-inline">
                            <input name="Forma" id="Forma" value="4" required="" type="radio">
                            <img src="<?php echo ROOT_URL; ?>imgs/ico-m.jpg">
                        </label>
                        <label class="radio-inline">
                            <input name="Forma" id="Forma" value="5" required="" type="radio">
                            <img src="<?php echo ROOT_URL; ?>imgs/ico-a.jpg">
                        </label>
                        <label class="radio-inline">
                            <input name="Forma" id="Forma" value="2" required="" type="radio">
                            <img src="<?php echo ROOT_URL; ?>imgs/ico-dinners.jpg">
                        </label>
                        <label class="radio-inline">
                            <input name="Forma" id="Forma" value="20" required="" type="radio">
                            <img src="<?php echo ROOT_URL; ?>imgs/ico-hipercard.jpg">
                        </label>
                        <label class="radio-inline">
                            <input name="Forma" id="Forma" value="16" required="" type="radio">
                            <img src="<?php echo ROOT_URL; ?>imgs/ico-elo.jpg">
                        </label>
                        <label class="radio-inline">
                            <input name="Forma" id="Forma" value="18" required="" type="radio">
                            <img src="<?php echo ROOT_URL; ?>imgs/ico-aura.jpg">
                        </label>

                         <label class="radio-inline">
                            <input name="Forma" id="Forma" value="19" required="" type="radio">
                            <img src="<?php echo ROOT_URL; ?>imgs/ico-jcb.jpg">
						 </label>

                         <label class="radio-inline">
                            <input name="Forma" id="Forma" value="15" required="" type="radio">
                            <img src="<?php echo ROOT_URL; ?>imgs/ico_discovery.jpg">
						 </label>

                    </div>

            </div>

            <div class="form-group">
                <label for="CartaoNumero">Número do Cartão:</label>
                <input name="CartaoNumero" autocomplete="off"  id="CartaoNumero" minlength="14" maxlength="22" type="text" class="form-control" required>
            </div>

            <div class="form-group">
                <label for="NomePortador">Nome do Portador (Igual ao do Cartão):</label>
                <input name="NomePortador" id="NomePortador" autocomplete="off" type="text" class="form-control" required>
            </div>


            <div class="form-group">
                <label for="Expiracao">Validade (Ex: 08/<?php echo date("y") + 1 ?>):</label>
                <input name="Expiracao" id="Expiracao"  onKeyPress="formataCampo(Expiracao, '99/99', event);"  autocomplete="off" maxlength="5" type="text" class="form-control" required>
            </div>

            <div class="form-group">
                <label for="CodigoSeguranca">Código de Segurança (Geralmente impresso no verso do Cartão. Ex:495):</label>
                <input name="CodigoSeguranca" id="CodigoSeguranca" autocomplete="off" maxlength="4" type="text" class="form-control" required>
            </div>
                  <div class="form-group">
                <label for="Identidade">CPF:</label>
                <input name="Identidade" id="Identidade" autocomplete="off" minlength="11" maxlength="11" type="tel" class="form-control" required>
            </div>

            <input name="TipoCartao" id="TipoCartao" type="hidden" value="Parcelado">
            <input name="Valor" id="Valor" value="<?php echo $total ?>" type="hidden">
            <?php
            if ($this->session->userdata('aluno_logado_imazon')) {
                echo '<input type="submit" class="btn btn-success mais-carga-horaria" value="Finalizar">';
            } else {
                echo '<input type="submit" class="btn btn-success mais-carga-horaria" value="Finalizar">';
            }
            ?>
            </form>

        </div>
    </div>

    <div class="panel panel-default">
        <div id="saldo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
            <div class="panel-body">
                <label>Seu Saldo é de: <strong>R$ <?php echo number_format($saldo, 2, ',', ' ') ?> </strong></label>
                <div id="container_saldo" style="display: none;">
                <div id="form_saldo" id="formulario">

                    <div class="alert alert-success" role="alert"><strong>Muito bom! </strong>Saldo suficiente para a realização desta compra. Ao concluir esta compra Seu saldo será de <strong>R$ <?php $novo_saldo = $saldo-$preco; echo $saldo_formatado = number_format($novo_saldo, 2, ',', ' ')?></strong></div>

                    <div class="form-group">
                        <?php

                        if($saldo >=$preco)
                        {
                            echo '<input id="idq_u" type="hidden" value="'.$id_fic.'">';
                            echo '<input id="idq_p" type="hidden" value="'. $preco_codificado.'">';
                        }
                        ?>
                    </div>

                    <input name="Valor" id="Valor" value="<?php echo $total ?>" type="hidden">
                    <input type="hidden" name="Forma" value="6"/>
                    <?php
                    if ($this->session->userdata('aluno_logado_imazon')) {
                        echo '<input id="finalizar_saldo" type="submit" class="btn btn-success mais-carga-horaria" value="Finalizar">';
                        echo '<div id="loading"></div>';
                    } else {
                        echo '<input id="finalizar_saldo" type="submit" class="btn btn-success mais-carga-horaria" value="Finalizar">';
                        echo '<div id="loading"></div>';
                    }
                    ?>
                </div>
                </div>
                <div id="warning_saldo" style="display: none">
                    <div class="alert alert-warning" role="alert"><strong>Infelizmente seu Saldo é Insuficiente para a realização desta compra.</strong></div>
                </div>
            </div>
        </div>
    </div>

</div>
<br /><br /><br /><br /><br />
</div>

<div class="modal fade preloader-modal" tabindex="-1" role="dialog">

  <div class="modal-dialog">

    <div class="modal-content">

      <div class="modal-body">

      </div>

    </div><!-- /.modal-content -->

  </div><!-- /.modal-dialog -->

</div><!-- /.modal -->

</body>

</html>
<script>
    //$(document).ready(function () {
  //$('span[href*=#]').on('click', function(e) {
  $('.mais-carga-horaria').on('click', function(e) {
    window.location.href ="#pedido_i";
    //e.preventDefault();
    //$('html, body').animate({ scrollTop: $( $(this).attr('href') ).offset().top}, 500, 'linear');
  });
  //});
</script>
<script>
//  $("#button_saldo").click( function(){

    var saldo = <?php echo $saldo;?>;
    var preco = <?php echo $preco;?>;
    var cart = <?php echo json_encode($cart); ?>;

    var base_url = "<?php echo base_url(); ?>";

//    /<div class="alert alert-warning" role="alert">...</div>
    if(saldo >=preco)
    {
        $("#container_saldo").show("slow");

        $("input#finalizar_saldo").click( function(){
            $("#finalizar_saldo").remove();
             $("#loading").html("<button  class='btn btn-success loading'>Aguarde <i class='fa fa-spinner fa-spin'></i></button>");
            $('.loading').prop('disabled', true);
            var idq_u = $("#idq_u").val();
            var idq_p = $("#idq_p").val();

            $.ajax({
                    method: "POST",
                    url: base_url+"api/auth",
                    data: { idq_u: idq_u, idq_p: idq_p, cart: cart },
                    success: function(response) {

                        if(response==='sucesso')
                        {
                            window.location.href = base_url+'site/finalizar_compra_saldo';
                        }
                        else if(response==='saldo_insuficiente')
                        {
                             $(".loading").remove();
                             $("#loading").html("<button  class='btn btn-warning'>Saldo Insuficiente <i class='fa fa-frown-o'></i></button>");
                             setTimeout(function() { window.location=window.location;},5000);
                        }
                        else if(response==='falha')
                        {
                            $(".loading").remove();
                            $("#loading").html("<button  class='btn btn-danger'>Falha na Operação <i class='fa fa-thumbs-down'></i></button>");

                            setTimeout(function() { window.location=window.location;},3000);
                        }
                        else if(response==='client_inexistente')
                        {
                            $(".loading").remove();
                            $("#loading").html("<button  class='btn btn-danger'>Cliente não existe <i class='fa fa-exclamation-triangle'></i></button>");
                            location.reload();
                        }

                    }
                  });


        } );
    }
    else
    {
        $("#warning_saldo").show("slow");
    }

//} );
</script>
<script>
     $("form").submit(function(){

        $(".modal-footer").remove();

        $(".btn-fechar-modal").remove();

        $(".preloader-modal").modal('show');

        $(".modal-body").html('<div class="progress"><div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%; color: #fff; font-weight: bold;">Aguarde, sua transa&ccedil;&atilde;o est&aacute; sendo processada...</div></div>');

        setTimeout(function(){
            window.location.href = "cursos";
        }, 2000);

    });
</script>
