<!--Cabecalho -->
<?php $this->load->view('commons/cabecalho'); ?>
<!--Header -->
<?php $this->load->view('commons/header');
?>
<!--Opcao -->



<?php if ($this->cart->total_items() < 0) { ?>
    <?php $this->cart->destroy(); ?>
<?php } ?>
<br>
<div class="row">


    <div class="col">
        <?php echo $this->session->flashdata('erro-matricula'); ?>
        <?php echo $this->session->flashdata('sucesso-transacao'); ?>
        <?php echo $this->session->flashdata('sucesso-saldo'); ?>
        <?php echo $this->session->flashdata('erro-acesso'); ?>
    </div>        
    <div class="tentativa">

    </div>
    <h4 style="margin-left: 0%; font-size: 25pt;"><b>Cursos Matriculados</b></h4>


    <div class="collection opcao-d">
        <table>
            <thead>
                <tr>

                    <th>Curso</th>
                    <th>Carga Horária</th>
                    <th>Data da Matrícula</th>
                    <th>Data de Conclusão</th>
                    <th>Nota</th>
                    <th>Pagamento</th

                    <th></th>
                </tr>
            </thead>

            <tbody>

                <?php if ($cursos != NULL) { ?>
                    <?php foreach ($cursos as $value) { ?>
                        <?php
                        $situacao_transacao = '';

                        $this->db->select('transacao');
                        $this->db->where('historico', $value->id_historico);
                        $trans = $this->db->get('itens_transacao')->row_array();

                        if (!empty($trans)) {

                            $this->db->select('situacao');
                            $this->db->where('id_transacao', $trans['transacao']);
                            $sit_trans = $this->db->get('transacao')->row_array()['situacao'];


                            if ($sit_trans == 1 || $sit_trans == 4) {
                                $situacao_transacao = 'PAGO';
                            } else if ($sit_trans == 2 || $sit_trans == 3 || $sit_trans == 5 || $sit_trans == 6 || $sit_trans == 8 || $sit_trans == 0) {
                                $situacao_transacao = 'PENDENTE';
                            } else if ($sit_trans == 7) {
                                $situacao_transacao = 'ESTORNADO';
                            } else if ($sit_trans == 9) {
                                $situacao_transacao = 'REEMBOLSADO';
                            }
                        }
                        ?>
                        <?php if ($value->concluido != 2) { ?>
                            <tr class="<?php echo $this->criptografia->codifica($value->id_historico) ?> ">
                                <td> <?php echo $value->nome ?></td>                       
                                <td>
                                    <?php $transacao_historico = $controle->verificatransacaohistorico($value->id_historico); ?>
                                    <?php if ($transacao_historico == NULL) { ?>
                                        <select required aria-required="true" name="carga_horaria" class="ch browser-default" > 
                                            <option curso="<?php echo $value->id_curso ?>" style="background: #8c9eff !important;"duracao="<?php echo $value->carga_horaria ?>" value="<?php echo $value->carga_horaria ?>"><?php echo $value->carga_horaria ?> Horas</option>
                                            <?php
                                            $i = 10;
                                            $aux = 0;
                                            while ($i <= 360) {
                                                if ($i == 10) {
                                                    $aux = $i + 5;
                                                }
                                                ?>
                                                <?php if ($i != $value->carga_horaria && $aux != $value->carga_horaria) { ?>
                                                    <option curso="<?php echo $value->id_curso ?>" historico="<?php echo $this->criptografia->codifica($value->id_historico) ?>" duracao="<?php echo ($aux > 0) ? $aux : $i; ?>" value="<?php echo ($aux > 0) ? $aux : $i; ?>"><?php echo ($aux > 0) ? $aux : $i; ?> Horas</option>
                                                <?php } ?>
                                                <?php
                                                $i = $i + 10;
                                                $aux = 0;
                                                ?>


                                            <?php } ?>
                                        </select>

                                    <?php } else { ?>
                                        <?php echo $value->carga_horaria ?> Horas
                                    <?php } ?>
                                </td>

                                <td><?php echo date("d/m/Y", strtotime($value->primeiro_dia)) ?></td>
                         <?php if ($value->concluido == 0 && $value->certificado <> 1) { ?>
                            <form name="historico" id="historico"> 
                                <input type="hidden" name="datadematricula" id="datadematricula_ini_<?= $value->id_historico ?>" value="<?php echo date('d/m/Y', strtotime('+' . ceil($value->carga_horaria / 8) . ' days', strtotime(date("d-m-Y", strtotime($value->primeiro_dia))))) ?>" />
                                <input type="hidden" name="datadematricula1" id="datadematricula_fim_<?= $value->id_historico ?>" value="<?php echo date('d/m/Y', strtotime('+90 days', strtotime(date("d-m-Y", strtotime($value->primeiro_dia))))) ?>" />
                                <input type="hidden" name="id_historico" id="id_historico_<?= $value->id_historico ?>" value="<?= $value->id_historico ?>" />                    
                                <td>
                                    
                                    <i class="fa fa-info-circle" title="Clicando no campo data você pode escolher a data da conclusão do seu curso."></i> <input type="text"  style=" width: 70px;" name="data_pagamento_<?= $value->id_historico ?>" id="data_pagamento_<?= $value->id_historico ?>" value="<?=date("d-m-Y", strtotime($value->ultimo_dia))?>" /></td>
                           
                            </form>

                            <script>
                                $(function () {

                                    var minDate = $("#datadematricula_ini_<?= $value->id_historico ?>").val();
                                    var maxDate = $("#datadematricula_fim_<?= $value->id_historico ?>").val();
                                    var id_historico = $("#id_historico_<?= $value->id_historico ?>").val();
                                   

                                    $('input[name="data_pagamento_<?= $value->id_historico ?>"]').daterangepicker({

                                        "autoApply": true,
                                        "singleDatePicker": true,
                                        "minDate": minDate,
                                        "maxDate": maxDate,
                                        
                                        locale: {
                                            "format": 'DD/MM/YYYY',
                                            "customRangeLabel": "Custom",
                                            "daysOfWeek": [
                                                "Dom",
                                                "Seg",
                                                "Ter",
                                                "Qua",
                                                "Qui",
                                                "Sex",
                                                "Sáb"
                                            ],
                                            "monthNames": [
                                                "Janeiro",
                                                "Fevereiro",
                                                "Março",
                                                "Abril",
                                                "Maio",
                                                "Junho",
                                                "Julho",
                                                "Agosto",
                                                "Setembro",
                                                "Outubro",
                                                "Novembro",
                                                "Dezembro"
                                            ],
                                            "firstDay": 0,
                                            
                                        }

                                    },
                                            
                                            function (start, end, label) {
                                                var id_historico = $("#id_historico_<?= $value->id_historico ?>").val();
                                                 var data_conclusao=start.format('YYYY-MM-DD');
                                               
                                            $.ajax({
                                            method: "POST",
                                            url: "cursodataconclusao",
                                            data: {id_historico:id_historico,data_conclusao:data_conclusao},
                                            
                                           success: function (data) {
                                               window.location = 'cursosmatriculados';
                                           }
                                             
                                            });
                                            

                                            });
                                });
                            </script>

                        <?php } else { ?>
                            <td><?php if(!empty($value->ultimo_dia)){ echo date("d/m/Y", strtotime($value->ultimo_dia));}?></td>
                            <?php
                        }
                        ?>
                        <?php if ($value->nota == NULL) { ?>
                            <td>Falta Avaliar</td>
                        <?php } else { ?>
                            <td><?php echo $value->nota ?></td>
                        <?php } ?>
                        <?php if ($value->certificado == 1) { ?>
                            <td>PAGO</td>
                            <? }?>

                            <?php if ($value->certificado <> 1) { ?>
                                <td>PENDENTE</td>
                                <? }?>

                                <?php if ($value->concluido == 0) { ?>
                                    <?php $url = $this->url->urlamigavel($value->nome); ?>
                                    <td><a href="<?php echo base_url('acessar/' . $this->criptografia->codifica($value->id_historico)) ?>"  class="waves-effect waves-light btn btn-curso btn-matricular-curso" style="width: 100%;">&nbsp;Acessar&nbsp;</a></td>

                                <?php } ?>
                                <?php if ($value->certificado == 0) { ?> 
                                    <td><a href="<?php echo base_url('detalhescertificados/' . $this->criptografia->codifica($value->id_historico)); ?>" class="btn btn-primary"  style="padding-right: 30px; background-color: #007bff;">Certificado</a></td>
                                <?php } else { ?>
                                    <?php if ($cpf == false) { ?>
                                        <td><a href="" data-target="cpf" class=" modal-trigger waves-effect waves-light btn btn-curso btn-matricular-curso teal lighten-2" style="width: 120%; background-color: #2ba447;">&nbsp;Certificado&nbsp;</a></td>
                                    <?php } else { ?>
                                        <td><a href="<?php echo base_url('certificado/' . $this->criptografia->codifica($value->id_historico)); ?>" target="_blanck" class="btn btn-success" style="width: 100%; background-color: #2BA447">&nbsp;Certificado</a></td>
                                         <?php if($value->concluido <> 3){?><td><a target="_blank" href="<?= ($value->concluido == 1) ? 'declaracao_curso/' : 'declaracao_matricula/' ?><?= $this->criptografia->codifica($value->id_historico) ?>"  class="btn btn-success" style="width: 100%; background-color: #2BA447;">&nbsp;Declaração&nbsp;</a></td><?php }?>
                                        <?php if($value->concluido <> 3){?><td> <a target="_blank" href="<?= ($value->concluido == 1) ? 'declaracao_curso/' : 'declaracao_matricula_ead/' ?><?= $this->criptografia->codifica($value->id_historico) ?>"  class="btn btn-success" style="width: 160px; background-color: #2BA447;">Decla. EAD</a></td><?php }?>
                                        <?php if($value->concluido <> 3){?><td><a class="btn "target="_blank" style="background-color: #2ba447!important" href="<?= base_url('declaracao_autenticidade/' . $this->criptografia->codifica($value->id_historico)) ?>">AUTENTICAR</a></td><?php }?>
                                        <?php
                                    }
                                }
                                ?>
                                <!--DECLARAÇÃO DE MATRÍCULA -->                            
                                <?php if ($value->concluido == 0 && $value->certificado == 0) { ?> 
                                    <td><button class=" cancela waves-effect waves-light btn btn-botao" data-id="<?php echo $this->criptografia->codifica($value->id_historico) ?>" style="width: 50%; background-color: #d9534f">&nbsp;&nbsp;X&nbsp;&nbsp;</button></td>
                                <?php } else { ?>
                                    <td></td>
                                <?php } ?>    

                                </tr>
                            <?php } ?>
                        <?php } ?>      
                    <?php } else { ?>
                        <tr><td><i class="fa fa-info-circle"></i> Não encotramos nenhum resultado. <a href="<?php echo base_url('cursos'); ?>"><b>Matricule-se agora!</b></a></td></tr>
                    <?php } ?>    
                    </tbody> 
                </table>
            </div>
        </div>
        <!-- VERSÃO MOBILE -->
        <?php if ($cursos != NULL) { ?>
            <?php foreach ($cursos as $value) { ?>
                <?php if ($value->concluido != 2) { ?>
                    <div class="<?php echo $this->criptografia->codifica($value->id_historico) ?>">

                        <div class="collection opcao-m" style=" margin-bottom: 30px;">

                            <div class="collection-item txt-centro">
                                <b style=" font-size: 16px;"> <?php echo $value->nome ?></b> <br>
                                <?php $transacao_historico = $controle->verificatransacaohistorico($value->id_historico); ?>
                                <?php if ($transacao_historico == NULL) { ?>

                                    <select required aria-required="true" name="carga_horaria" class="ch browser-default" > 
                                        <option curso="<?php echo $value->id_curso ?>" style="background: #8c9eff !important; text-align: center"duracao="<?php echo $value->carga_horaria ?>" value="<?php echo $value->carga_horaria ?>"><?php echo $value->carga_horaria ?> Horas</option>
                                        <?php
                                        $i = 10;
                                        $aux = 0;
                                        while ($i <= 360) {
                                            if ($i == 10) {
                                                $aux = $i + 5;
                                            }
                                            ?>
                                            <?php if ($i != $value->carga_horaria && $aux != $value->carga_horaria) { ?>
                                                <option curso="<?php echo $value->id_curso ?>" style="text-align:center" historico="<?php echo $this->criptografia->codifica($value->id_historico) ?>" duracao="<?php echo ($aux > 0) ? $aux : $i; ?>" value="<?php echo ($aux > 0) ? $aux : $i; ?>"><?php echo ($aux > 0) ? $aux : $i; ?> Horas</option>
                                            <?php } ?>
                                            <?php
                                            $i = $i + 10;
                                            $aux = 0;
                                            ?>


                                        <?php } ?>
                                    </select> 

                                <?php } else { ?>
                                    <p><b>Carga Horária:</b> <?php echo $value->carga_horaria ?> Horas </p>
                                <?php } ?>
                                <p><b>Início:</b> <?php echo date("d/m/Y", strtotime($value->primeiro_dia)) ?></p>
                                <?php if ($value->concluido == 0 && $value->certificado <> 1) { ?>
                            <form name="historico" id="historico"> 
                                <input type="hidden" name="datadematricula" id="datadematricula_ini_<?= $value->id_historico ?>" value="<?php echo date('d/m/Y', strtotime('+' . ceil($value->carga_horaria / 8) . ' days', strtotime(date("d-m-Y", strtotime($value->primeiro_dia))))) ?>" />
                                <input type="hidden" name="datadematricula1" id="datadematricula_fim_<?= $value->id_historico ?>" value="<?php echo date('d/m/Y', strtotime('+90 days', strtotime(date("d-m-Y", strtotime($value->primeiro_dia))))) ?>" />
                                <input type="hidden" name="id_historico" id="id_historico_<?= $value->id_historico ?>" value="<?= $value->id_historico ?>" />                    
                                <p style=" text-align: center;"><b>Data Conclusão: </b><?php if(!empty($value->ultimo_dia)){ echo date("d/m/Y", strtotime($value->ultimo_dia));} ?> <a class="<?= 'edit'.$value->id_historico ?>"><i class="fa fa-calendar-plus-o"></i>Editar Data</a> </p>
                           
                            </form>

                            <script>
                                $(function () {

                                    var minDate = $("#datadematricula_ini_<?= $value->id_historico ?>").val();
                                    var maxDate = $("#datadematricula_fim_<?= $value->id_historico ?>").val();
                                    var id_historico = $("#id_historico_<?= $value->id_historico ?>").val();
                                   

                                    $('.edit<?= $value->id_historico ?>').daterangepicker({

                                        "autoApply": true,
                                        "singleDatePicker": true,
                                        "minDate": minDate,
                                        "maxDate": maxDate,
                                        
                                        locale: {
                                            "format": 'DD/MM/YYYY',
                                            "customRangeLabel": "Custom",
                                            "daysOfWeek": [
                                                "Dom",
                                                "Seg",
                                                "Ter",
                                                "Qua",
                                                "Qui",
                                                "Sex",
                                                "Sáb"
                                            ],
                                            "monthNames": [
                                                "Janeiro",
                                                "Fevereiro",
                                                "Março",
                                                "Abril",
                                                "Maio",
                                                "Junho",
                                                "Julho",
                                                "Agosto",
                                                "Setembro",
                                                "Outubro",
                                                "Novembro",
                                                "Dezembro"
                                            ],
                                            "firstDay": 0,
                                            
                                        }

                                    },
                                            
                                            function (start, end, label) {
                                                var id_historico = $("#id_historico_<?= $value->id_historico ?>").val();
                                                 var data_conclusao=start.format('YYYY-MM-DD');
                                               
                                            $.ajax({
                                            method: "POST",
                                            url: "cursodataconclusao",
                                            data: {id_historico:id_historico,data_conclusao:data_conclusao},
                                            
                                           success: function (data) {
                                               window.location = 'cursosmatriculados';
                                           }
                                             
                                            });

                                            });
                                });
                            </script>

                        <?php } else { ?>
                            <p><?php if(!empty($value->ultimo_dia)){ echo date("d/m/Y", strtotime($value->ultimo_dia));}?><p>
                            <?php
                        }
                        ?>
                                    
                                    <?php
                                if ($value->nota == NULL) {

                                    $ch = ceil($value->carga_horaria / 8);
                                    $acres = '+ ' . $ch . ' days';
                                    $datafutura = date('d/m/Y', strtotime($value->primeiro_dia . $acres));
                                    ?>
                                    <p><b>Avaliação:</b> <?= $datafutura ?></p>
                                <?php } else { ?>
                                    <p><b>Nota:</b> <?php echo $value->nota ?></p>
                                <?php } ?>
                                <?php if ($value->concluido == 0) { ?>
                                    <a href="<?php echo base_url('acessar/' . $this->criptografia->codifica($value->id_historico)) ?>"  class="waves-effect waves-light btn btn-curso btn-matricular-curso" style="width: 100%;">&nbsp;Acessar&nbsp;</a><br><br>
                                <?php } ?>

                                <?php if ($value->certificado == 0) { ?>
                                    <a href="<?php echo base_url('detalhescertificados/' . $this->criptografia->codifica($value->id_historico)); ?>" class="btn btn-primary"  style="padding-right: 30px; background-color: #007bff; width: 100%">&nbsp;Certificado&nbsp;</a>
                                <?php } else { ?>
                                    <?php if ($cpf == false) { ?>
                                        <a href="" data-target="cpf" class=" modal-trigger waves-effect waves-light btn btn-curso btn-matricular-curso teal lighten-2" style="width: 100%;">&nbsp;Certificado&nbsp;</a>
                                    <?php } else { ?>
                                        <a href="<?php echo base_url('certificado/' . $this->criptografia->codifica($value->id_historico)); ?>" target="_blanck" class="btn btn-success" style="width: 100%; background-color: #2BA447; margin-bottom: 20px;">&nbsp;Certificado&nbsp;</a>
                                        <?php if($value->concluido <> 3){?><a target="_blank" href="declaracao_curso/<?= $this->criptografia->codifica($value->id_historico) ?>" class="btn btn-success" style="width: 100%; background-color: #2BA447;margin-bottom: 20px;">&nbsp;Declaração&nbsp;</a>   <?php }?>     
                                         <?php if($value->concluido <> 3){?><a target="_blank" href="<?= ($value->concluido == 1) ? 'declaracao_curso/' : 'declaracao_matricula_ead/' ?><?= $this->criptografia->codifica($value->id_historico) ?>"  class="btn btn-success" style="width: 100%; background-color: #2BA447;">Decla. EAD</a><?php }?>
                                            <?php
                                    }
                                }
                                ?>


                                <?php if ($value->concluido == 0 && $value->certificado == 0) { ?> 
                                    <br><br><button class=" cancela waves-effect waves-light btn btn-botao" data-id="<?php echo $this->criptografia->codifica($value->id_historico) ?>" style="width: 100%; background-color: #d9534f">CANCELAR MATRÍCULA</button>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                <?php }
                ?>
            <?php } ?>
        <?php } else { ?>
            <p class="hide-on-large-only" style="margin-left: 8%;"><i class="fa fa-info-circle "></i> Não encotramos nenhum resultado. <a href="<?php echo base_url('cursos'); ?>"><b>Matricule-se agora!</b></a></p>
        <?php } ?>  
        <nav  style="width: 100%; background-color: #f2f2f2; color: black;">&nbsp;&nbsp;<i class="fa fa-info-circle"></i> A nota mínima para aprovação é 50,0 </nav>
        </div>
        <br>




        <script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
        <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
        <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />








        <br><br><br>
        <?php $this->load->view('commons/rodape'); ?>
