<?php
$getPage = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT);
$Pager = new Pager('painel.php?exe=periodo/index&page=');
$Pager->ExePager($getPage, 20);
?>
<ul class="page-breadcrumb breadcrumb">
    <li>
        <span>Periodo</span>
        <i class="fa fa-circle"></i>
    </li>
    <li>
        <span>Listar</span>
    </li>
</ul>
<?php
$empty = filter_input(INPUT_GET, 'create', FILTER_VALIDATE_BOOLEAN);
if ($empty):
    WSErro("<b>Sucesso:</b> A periodo foi cadastrado no sistema", WS_ACCEPT);
endif;

$delUser = filter_input(INPUT_GET, 'delete', FILTER_VALIDATE_INT);
if ($delUser):
    $deletar = new Delete;
    $deletar->ExeDelete("tp_periodos", "WHERE periodo_id = :id", "id={$delUser}");

    if ($deletar->getResult()):
        WSErro("Periodo excluido com sucesso", WS_ACCEPT);
    else:
        WSErro("Periodo não pode ser excluida", WS_ALERT);
    endif;

endif;
?>
<div class="portlet">
    <div class="portlet-title">
        <div class="caption">
            <span class="caption-subject font-dark bold uppercase">Lista de períodos</span>
        </div>
        <div class="actions">
            <a href="painel.php?exe=sistema/periodo_create" class="btn btn-xs blue" alt="Add Novo" title="Add Novo"><i class="fa fa-plus"></i> <span> Novo</span></a>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="portlet light bordered">
                <!--                <div class="portlet-title">
                                    <form class="form-inline pull-right" action="#">
                                        <div class="input-group input-medium">
                                            <input type="text" class="form-control" placeholder="Buscar" id="campo_busca" name="campo_busca">
                                            <span class="input-group-btn">
                                                <button type="button" class="btn green" onclick="javascript:busca_orcamento(1);">
                                                    <i class="fa fa-search"></i>
                                                </button>
                                            </span>
                                        </div>
                                    </form>
                                </div>-->
                <div class="portlet-body">
                    <table class="table table-striped table-bordered table-hover table-checkable order-column" id="sample_1">
                        <thead>
                            <tr>
<!--                                <th>
                                    <label class="mt-checkbox mt-checkbox-single mt-checkbox-outline">
                                        <input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes">
                                        <span></span>
                                    </label>
                                </th>-->
                                <th> Periodo </th>
                                <th> Meses </th>
                                <th>  </th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $Read = new Read;
                            $Read->ExeRead("tp_periodos", "LIMIT :limit OFFSET :offset", "limit={$Pager->getLimit()}&offset={$Pager->getOffset()}");
                            if (!$Read->getResult()):
                                ?>
                                <tr class="odd gradeX">
                                    <td class="text-center" colspan="6">
                                        Sem resultados!
                                    </td>
                                </tr>
                                <?php
                            else:
                                foreach ($Read->getResult() as $periodos):
                                    extract($periodos);
                                    ?>
                                    <tr>                                        
                                        <td><?= $periodo_nome ?></td>
                                        <td><?= $periodo_meses ?></td>
                                        <td>
                                            <a href="painel.php?exe=sistema/periodo_update&perid=<?= $periodo_id ?>" class="btn btn-xs blue"><i class="fa fa-edit"></i></a>
                                            <a href="javascript:excluir(<?= $periodo_id ?>);" class="btn btn-xs red"><i class="fa fa-times"></i></a>
                                            <!--<a href="painel.php?exe=periodo/index&delete=<?= $periodo_id ?>" class="btn btn-xs red"><i class="fa fa-times"></i></a>-->
                                        </td>
                                    </tr>
                                    <?php
                                endforeach;
                            endif;
                            ?>
                        </tbody>
                    </table>
                </div>
                <div class="inbox-footer">
                    <div class="row">
                        <div class="col-md-5">
                        </div>
                        <div class="col-md-7">
                            <?php
                            $Pager->ExePaginator("tp_periodos");
                            echo $Pager->getPaginator();
                            ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>

<div class="modal fade bs-modal-sm" id="excluir" tabindex="-1" role="dialog" aria-hidden="true" style="display: none;">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                <h4 class="modal-title">ATENÇÃO</h4>
            </div>
            <div class="modal-body"> Tem certeza que deseja excluir? </div>
            <div class="modal-footer">
                <a href="" id="yes" class="btn green">Sim</a>
                <button type="button" class="btn dark btn-outline" data-dismiss="modal">Não</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>

<script>
    function excluir(id) {
        console.log(id);
        $('#excluir').modal('show');

        $("#yes").attr('href', 'painel.php?exe=sistema/periodo_lista&delete=' + id);
    }
</script>