<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<link href="<?php echo base_url('assets/css/datatables/dataTables.bootstrap.css') ?>" rel="stylesheet">

<section class="content-header">
    <h1><i class="fa fa-bullhorn"></i> <?php echo $page_title ?> <small><?php echo lang('list') ?></small></h1>
    <ol class="breadcrumb">
        <li><a href="<?php echo site_url('admin') ?>"><i class="fa fa-dashboard"></i> Dashboard</a></li>
        <li class="active"><?php echo lang('notice') ?></li>
    </ol>
</section>

<section class="content">

<div class="box box-primary">
    <div class="box-header with-border">
        <h3 class="box-title"><i class="fa fa-bullhorn"></i> <?php echo lang('notice') ?></h3>
        <div class="box-tools pull-right">
            <?php if(check_user_role(147)==1): ?>
            <a href="<?php echo site_url('admin/notice/add') ?>" class="btn btn-primary btn-sm">
                <i class="fa fa-plus"></i> <?php echo lang('add_new') ?>
            </a>
            <?php endif; ?>
        </div>
    </div>
    <div class="box-body no-padding">
        <table id="example1" class="table table-hover" style="margin:0">
            <thead>
                <tr>
                    <th style="width:36px">#</th>
                    <th>Título</th>
                    <th style="width:160px">Data / Hora</th>
                    <th style="width:120px">Ações</th>
                </tr>
            </thead>
            <tbody>
            <?php if(isset($notice)): $i=1; foreach($notice as $new):
                $dt = strtotime($new->date_time);
                $hoje = date('Y-m-d') === date('Y-m-d', $dt);
            ?>
            <tr class="<?php echo $hoje ? 'success' : '' ?>">
                <td><?php echo $i++ ?></td>
                <td style="vertical-align:middle">
                    <i class="fa fa-bullhorn text-muted" style="margin-right:7px"></i>
                    <strong><?php echo htmlspecialchars($new->title) ?></strong>
                    <?php if($hoje): ?>
                    <span class="label label-success" style="margin-left:6px;font-size:10px">Hoje</span>
                    <?php endif; ?>
                </td>
                <td style="vertical-align:middle">
                    <i class="fa fa-clock-o text-muted" style="margin-right:5px"></i>
                    <small><?php echo date_time_convert($new->date_time) ?></small>
                </td>
                <td style="vertical-align:middle;white-space:nowrap">
                    <?php if(check_user_role(150)==1): ?>
                    <a href="<?php echo site_url('admin/notice/view/'.$new->id) ?>" class="btn btn-xs btn-default" title="Ver"><i class="fa fa-eye"></i></a>
                    <?php endif; ?>
                    <?php if(check_user_role(148)==1): ?>
                    <a href="<?php echo site_url('admin/notice/edit/'.$new->id) ?>" class="btn btn-xs btn-warning" title="Editar"><i class="fa fa-pencil"></i></a>
                    <?php endif; ?>
                    <?php if(check_user_role(149)==1): ?>
                    <a href="<?php echo site_url('admin/notice/delete/'.$new->id) ?>" class="btn btn-xs btn-danger" onclick="return confirm('<?php echo lang('are_you_sure') ?>')" title="Excluir"><i class="fa fa-trash"></i></a>
                    <?php endif; ?>
                </td>
            </tr>
            <?php endforeach; endif; ?>
            </tbody>
        </table>
    </div>
</div>

</section>

<script src="<?php echo base_url('assets/js/plugins/datatables/jquery.dataTables.js') ?>"></script>
<script src="<?php echo base_url('assets/js/plugins/datatables/dataTables.bootstrap.js') ?>"></script>
<script>
$(function() {
    $('#example1').dataTable({
        order: [[2,'desc']],
        pageLength: 25,
        language: { url: '//cdn.datatables.net/plug-ins/1.10.21/i18n/Portuguese-Brasil.json' }
    });
});
</script>
