
<!--Cabecalho -->
<?php $this->load->view('commons/cabecalho'); ?>
<?php $this->load->view('commons/header'); ?>
<?php $this->load->view('commons/menu'); ?>
<style>
    table-bordered>thead>tr>th, .table-bordered>tbody>tr>th, .table-bordered>tfoot>tr>th, .table-bordered>thead>tr>td, .table-bordered>tbody>tr>td, .table-bordered>tfoot>tr>td {
    border: 1px solid #e0e0e0 !important;
    }
</style>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>Alunos</h1>
    </section>

    <!-- Main content -->
    <section class="content container-fluid">
        <form action="<?= base_url('aluno') ?>" method="GET"  id="form-aluno-pesq">
            <div class="input-group">
                <input type="text" name="nome" class="form-control" placeholder="Digite o nome ou o e-mail do aluno" autofocus="" required="">
                <span class="input-group-btn">
                    <button type="submit" class="btn btn-flat btn-botao"> Pesquisar</button>
                </span>
            </div>
        </form>
        <br>
        <?php echo $this->session->flashdata('erro-dado'); ?>
        <?php echo $this->session->flashdata('sucesso-dados'); ?>
        <?php echo $this->session->flashdata('erro-form'); ?>
        <div class="box">
            <div class="box-body">
                <?php if ($alunos != NULL) { ?>
                    <div class="dataTables_wrapper form-inline dt-bootstrap">
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="row">
                                    <div class="col-sm-4">
                                        <span class="estudou"> <i class="fa fa-square" aria-hidden="true" style="color:  black"></i> ALUNO ANTIGO</span>
                                    </div> 
                                    <div class="col-sm-4">
                                        <span class="estudou"> <i class="fa fa-square" aria-hidden="true" style="color:  #367fa9"></i> ALUNO NOVO</span> 
                                    </div>
                                    <div class="col-sm-4">
                                        <span class="estudou"> <i class="fa fa-square" aria-hidden="true" style="color:  #bdbdbd "></i> ALUNO QUE AINDA NÃO PASSOU VELA VALIDAÇÃO</span> 
                                    </div>
                                </div>
                                <div class="table-responsive">
                                    <table class="table table-bordered table-hover">
                                        <thead>
                                            <tr>
                                                <th>Aluno</th>
                                                <th>Email</th>
                                                <th>Controles</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php foreach ($alunos as $aluno) { ?>
                                                <tr>
                                                    <?php if ($aluno->situacao == 2 || $aluno->situacao == 0 && $aluno->data_vencimento < '2018-08-24') { ?>
                                                        <td class="nome_edit_aluno<?= $aluno->id_aluno ?>"><i class="fa fa-square" aria-hidden="true" style="color:  black"></i> <?php echo $aluno->nome ?></td>
                                                        <td class="nome_edit_aluno_editado<?= $aluno->id_aluno ?>" style="display:none;"><i class="fa fa-square" aria-hidden="true" style="color:  black"></i> </td>

                                                    <?php } else if ($aluno->situacao == 1) { ?>
                                                        <td><i class="fa fa-square" aria-hidden="true" style="color:  #367fa9"></i> <?php echo $aluno->nome ?></td>
                                                    <?php } else if ($aluno->situacao == 0 && $aluno->data_vencimento > '2018-08-24') { ?>
                                                        <td><i class="fa fa-square" aria-hidden="true" style="color:  #bdbdbd"></i> <?php echo $aluno->nome ?></td>
                                                    <?php } ?>
                                                    <td><?php echo $aluno->email ?></td>
                                                    <td>
                                                        <button type="button" class="btn  btn-success btn-mEdit" data-target="#editar<?= $aluno->id_aluno ?>"data-toggle="modal" data-placement="top" title="Dados Cadastrais" style="font-size: 15px;line-height: 10pt;position: relative;top: 2px;">
                                                            <i class="fa fa-pencil-square-o" aria-hidden="true"></i>
                                                            <i class="fa fa-circle-o-notch fa-spin" aria-hidden="true" style="display:none;"></i>
                                                        </button>
                                                        <!-- </span> -->
                                                        <button type="button" class="btn btn-info btn-mAcademic" data-id="<?= $this->criptografia->codifica($aluno->id_aluno); ?>" data-target="#academico<?= $aluno->id_aluno ?>"data-toggle="modal" data-placement="top" title="Acadêmico" style="font-size: 15px;line-height: 10pt;position: relative;top: 2px;">
                                                            <i class="fa fa-graduation-cap" aria-hidden="true"></i>
                                                            <i class="fa fa-circle-o-notch fa-spin" aria-hidden="true" style="display:none;"></i>
                                                        </button>
                                                        <button type="button" class="btn btn-primary btn-mFinanceiro" data-id="<?= $this->criptografia->codifica($aluno->id_aluno); ?>" data-target="#financeiro<?= $aluno->id_aluno ?>"data-toggle="modal" data-placement="top" title="Financeiro" style="font-size: 15px;line-height: 10pt;position: relative;top: 2px;">
                                                            <i class="fa fa-money" aria-hidden="true"></i>
                                                            <i class="fa fa-circle-o-notch fa-spin" aria-hidden="true" style="display:none;"></i>
                                                        </button>

                                                    </td>
                                                </tr>

                                            <?php } ?> 

                                        </tbody>

                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12">
                                <?php echo $pagination ?>

                            </div>

                        </div>
                    </div>
                <?php } else { ?>
                    <span style="font-size: 13pt;">  <i class="fa fa-info-circle" aria-hidden="true"></i> Nenhum registro encontrado</span>
                <?php } ?>
            </div>
        </div>
        <?php if ($alunos != NULL) { ?>
            <?php foreach ($alunos as $aluno) { ?>
                <!-- Modal -->
                <div class="modal fade" id="editar<?= $aluno->id_aluno ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog modal-lg">
                        <div class="modal-content">
                            <!-- Modal Header -->
                            <div class="modal-header" style="background-color: #2ba447; color: white">
                                <button type="button" class="close fechar-modal" 
                                        data-dismiss="modal">
                                    <span aria-hidden="true">&times;</span>
                                    <span class="sr-only">Close</span>
                                </button>
                                <h4 class="modal-title" id="myModalLabel">
                                    Aluno: <?= $aluno->nome ?>
                                    <span class="badge"><?= $aluno->email ?></span>
                                </h4>
                            </div>
                            <!-- Modal Body -->
                            <div class="modal-body">
                                <ul class="nav nav-tabs">
                                    <li class="active"><a data-toggle="tab" href="#dados<?= $aluno->id_aluno ?>">Dados Cadastrais</a></li>
                                    <li><a data-toggle="tab" href="#cpf<?= $aluno->id_aluno ?>">CPF</a></li>
                                </ul>
                                <div class="tab-content">
                                    <div id="dados<?= $aluno->id_aluno ?>" class="tab-pane fade in active">
                                        <form class="form-horizontal" role="form" id="form_aluno_cadastro<?= $aluno->id_aluno ?>">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label" for="nome">Nome:</label>
                                                <?php if ($aluno->situacao == 2 || $aluno->situacao == 0 && $aluno->data_vencimento < '2018-08-24') { ?>
                                                    <div class="col-sm-10">
                                                        <input type="text"  class="form-control" name="nome" value="<?= $aluno->nome ?>"/>
                                                    </div>
                                                <?php } else { ?>
                                                    <div class="col-sm-10">
                                                        <input type="text" readonly="" class="form-control" name="nome"  value="<?= $aluno->nome ?>"/>
                                                    </div>
                                                <?php } ?>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label" for="email" >E-mail:</label>
                                                <div class="col-sm-10">
                                                    <input type="email" class="form-control" name="email" placeholder="Digite o e-mail do aluno" value="<?= $aluno->email ?>" required=""/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <div class="col-md-3">
                                                    <label class="control-label" for="bloqueado" >Bloqueado:</label>

                                                    <select class="form-control" name="bloqueado" id="bloqueado-aluno">
                                                        <?php if ($aluno->bloqueado == 0) { ?>
                                                            <option value="0">NÃO</option>
                                                            <option value="1">SIM</option>
                                                        <?php } else { ?>
                                                            <option value="1">SIM</option>
                                                            <option value="0">NÃO</option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                <?php if ($aluno->ddd != 0) { ?>
                                                    <div class="col-md-2">
                                                        <label class="control-label" for="ddd" >DDD:</label>
                                                        <input type="tel" class="form-control only-number" name="ddd"  placeholder="Digite o ddd do aluno" value="<?= $aluno->ddd ?>" />
                                                    </div>
                                                <?php } else { ?>
                                                    <div class="col-md-2">
                                                        <label class="control-label" for="ddd" >DDD:</label>
                                                        <input type="tel" class="form-control only-number"  name="ddd" placeholder="Digite o ddd do aluno" value=""/>
                                                    </div>
                                                <?php } ?>
                                                <div class="col-md-7">
                                                    <label class="control-label" for="celular" >Celular:</label>
                                                    <input type="tel" class="form-control only-number"  name="celular" placeholder="Digite o celular do aluno" value="<?= $aluno->telefone ?>" />
                                                </div> 
                                            </div>
                                            <div class="form-group">
                                                <div class="col-md-3">
                                                    <label class="control-label" for="cep" >Cep:</label>
                                                    <input type="tel" class="ceps form-control"  name="cep"placeholder="Digite o cep do aluno" value="<?= $aluno->cep ?>" />
                                                </div>
                                                <div class="col-md-9">
                                                    <label class="control-label" for="endereco" >Endereço</label>
                                                    <input type="text" class="form-control" placeholder="Digite o endereço do aluno" name="endereco" value="<?= $aluno->endereco ?>" />
                                                </div> 
                                            </div>
                                            <div class="form-group">

                                                <?php if ($aluno->numero != 0) { ?>
                                                    <div class="col-md-3">
                                                        <label class="control-label" for="numero" >Numero:</label>
                                                        <input type="tel" class="form-control only-number" pattern="[0-9]+$" maxlength="10" name="numero"placeholder="Digite o número do aluno" value="<?= $aluno->numero ?>"/>
                                                    </div>
                                                <?php } else { ?>
                                                    <div class="col-md-3">
                                                        <label class="control-label" for="numero" >Numero:</label>
                                                        <input type="tel" class="form-control only-number" pattern="[0-9]+$" maxlength="10" name="numero"placeholder="Digite o número do aluno" value=""/>
                                                    </div>
                                                <?php } ?>
                                                <div class="col-md-9">
                                                    <label class="control-label" for="complemento" >Complemento</label>
                                                    <input type="text" name="complemento"class="form-control" placeholder="Digite o complemento do aluno" value="<?= $aluno->complemento ?>"/>
                                                </div> 
                                            </div>
                                            <div class="form-group">
                                                <div class="col-md-3">
                                                    <label class="control-label" for="bairro" >Bairro:</label>
                                                    <input type="text" class="form-control" name="bairro" placeholder="Digite o bairro do aluno" value="<?= $aluno->bairro ?>"/>
                                                </div>
                                                <div class="col-md-9">
                                                    <label class="control-label" for="cidade" >Cidade</label>
                                                    <input type="text" class="form-control" name="cidade" placeholder="Digite a cidade do aluno" value="<?= $aluno->cidade ?>"/>
                                                </div> 
                                            </div>
                                            <div class="form-group">
                                                <div class="col-md-12">
                                                    <input type="text" class="form-control" name="estado" placeholder="Digite o estado do aluno" value="<?= $aluno->estado ?>"/>

                                                </div> 
                                            </div>
                                            <input type="hidden" name="id" value="<?= $this->criptografia->codifica($aluno->id_aluno) ?>">
                                            <div class="modal-footer">
                                                <button style="color: black"type="button" class="btn btn-default fechar-modal" data-dismiss="modal">
                                                    Fechar
                                                </button>
                                                <button type="submit" class="btn btn-primary">
                                                    Salvar
                                                </button>
                                            </div>
                                        </form>
                                    </div>
                                    <div id="cpf<?= $aluno->id_aluno ?>" class="tab-pane fade">
                                        <?php $id = $this->criptografia->codifica($aluno->id_aluno); ?>
                                        <div class="box">
                                            <div class="box-body">
                                                <div class="dataTables_wrapper form-inline dt-bootstrap">
                                                    <div class="row">
                                                        <div class="col-sm-12">
                                                            <?php if ($controle->recuperalog($id) != FALSE) { ?>
                                                                <div class="table-responsive">
                                                                    <table class="table table-bordered table-hover">
                                                                        <thead>
                                                                            <tr>
                                                                                <th>CPF</th>
                                                                                <th>Nome Anterior</th>
                                                                                <th>Nome Atual</th>
                                                                                <th>Data da Alteração</th>
                                                                            </tr>
                                                                        </thead>
                                                                        <tbody>
                                                                            <tr>
                                                                                <?php echo $controle->recuperalog($id); ?>
                                                                            </tr>
                                                                        </tbody>
                                                                    </table>
                                                                </div>
                                                            <?php } else { ?>
                                                                <div class="alert alert-warning" role="alert"><i class="fa fa-info-circle"></i> Não há registro de atividade para o aluno informado </div>
                                                            <?php } ?>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Acadêmico -->
                <div class="modal fade" id="academico<?= $aluno->id_aluno ?>"  role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog modal-lg modal-academico">
                        <div class="modal-content">
                            <!-- Modal Header -->
                            <div class="modal-header" style="background-color: #2ba447; color: white">
                                <button type="button" class="close fechar-modal" 
                                        data-dismiss="modal">
                                    <span aria-hidden="true">&times;</span>
                                    <span class="sr-only">Close</span>
                                </button>
                                <h4 class="modal-title" id="myModalLabel">
                                    Aluno: <?= $aluno->nome ?>
                                    <span class="badge"><?= $aluno->email ?></span>
                                </h4>
                            </div>
                            <!-- Modal Body -->
                            <div class="modal-body">
                                <div class="erro"></div>
                                <div class="box">
                                    <div class="box-body">                                    
                                        <span class="estudou"> <i class="fa fa-square" aria-hidden="true"></i> <b>ESTUDOU:</b> Esta coluna apresenta a informação se o aluno acessou ao material de estudo e a quantidade de acesso ao material de estudo</span> <br><br>
                                        <div class="dataTables_wrapper form-inline dt-bootstrap">
                                            <div class="row">
                                                <div class="col-sm-12">
                                                    <div class="table-responsive tabela-historico">
                                                        <p class="td-s"></p> 
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- FIM-->

                <!-- Finânceiro -->
                <div class="modal fade" id="financeiro<?= $aluno->id_aluno ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog modal-lg modal-financeiro">
                        <div class="modal-content">
                            <!-- Modal Header -->
                            <div class="modal-header" style="background-color: #2ba447; color: white">
                                <button type="button" class="close fechar-modal" 
                                        data-dismiss="modal">
                                    <span aria-hidden="true">&times;</span>
                                    <span class="sr-only">Close</span>
                                </button>
                                <h4 class="modal-title" id="myModalLabel">
                                    Aluno: <?= $aluno->nome ?>
                                    <span class="badge"><?= $aluno->email ?></span>
                                </h4>
                            </div>
                            <!-- Modal Body -->
                            <div class="modal-body">
                                <div class="erro"></div>

                                <div class="box">
                                    <div class="box-body">   
                                        <div class="dataTables_wrapper form-inline dt-bootstrap">
                                            <div class="row">
                                                <div class="col-sm-12">
                                                    <div class="table-responsive tabela-financeiro">
                                                    </div>
                                                    <div class="td"></div> 

                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- FIM -->
                <div class="modal fade" id="certificado-log" tabindex="1" role="dialog" aria-labelledby="myModalLabel">
                    <div class="modal-dialog modal-lg" role="document">
                        <div class="modal-content">
                            <div class="modal-header modal-header-primary">
                                <button type="button" class="close fechar-modal" 
                                        data-dismiss="modal">
                                    <span aria-hidden="true">&times;</span>
                                    <span class="sr-only">Close</span>
                                </button>
                                <h4 class="modal-title" id="myModalLabel">ALUNO: <span class="nome-aluno-mAcademic"></span> <span class="email-aluno-mFinanceiro badge"></span></h4>
                            </div>
                            <div class="modal-body">

                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default btn-botao" data-dismiss="modal">Fechar</button>
                            </div>
                        </div>
                    </div>
                </div>
                <script>
                    $(document).ready(function () {
                        $('#form_aluno_cadastro<?= $aluno->id_aluno ?>').submit(function (e) {
                            e.preventDefault();

                            $(".textos").html('<p>Aguarde...O sistema está salvando a edição</p>');
                            $("#aguardeS").css("display", "block");
                            $("#blanketS").css("display", "block");
                            $.ajax({
                                data: $("#form_aluno_cadastro<?= $aluno->id_aluno ?>").serialize(),
                                type: "POST",
                                dataType: 'json',
                                url: 'dados',
                                success: function (data) {
                                    if (data['situacao'] == 'form-erro') {
                                        $("#aguardeS").css("display", "none");
                                        $("#blanketS").css("display", "none");
                                        alertify.set('notifier', 'delay', 5);
                                        alertify.set("notifier", "position", "top-center");
                                        alertify.error(data['erro_form']);
                                    } else if (data['situacao'] == 'sucesso') {
                                        $("#aguardeS").css("display", "none");
                                        $("#blanketS").css("display", "none");
                                        alertify.set('notifier', 'delay', 3);
                                        alertify.set("notifier", "position", "top-center");
                                        alertify.success('<i class="fa fa-check-circle"></i> Dados atualizados com sucesso');
                                        $('#editar<?= $aluno->id_aluno ?>').modal('hide');
                                        $(".nome_edit_aluno<?= $aluno->id_aluno ?>").css("display", "none");
                                        $(".nome_edit_aluno_editado<?= $aluno->id_aluno ?>").html('<i class="fa fa-square" aria-hidden="true" style="color:  black"></i> <span>' + data['nome'] + '</span>');
                                        $(".nome_edit_aluno_editado<?= $aluno->id_aluno ?>").css("display", "block");
                                        
                                    } else if (data['situacao'] == 'erro-email') {
                                        $("#aguardeS").css("display", "none");
                                        $("#blanketS").css("display", "none");
                                        alertify.set('notifier', 'delay', 5);
                                        alertify.set("notifier", "position", "top-center");
                                        alertify.error('O e-mail informado já pertence a um aluno');
                                    }
                                }
                            });
                        });
                    });
                </script>
            <?php } ?>
        <?php } ?>
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->
<?php $this->load->view('commons/rodape'); ?>
