<?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-file-o"></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('documents') ?></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-file-o"></i> <?php echo lang('documents') ?></h3>
        <div class="box-tools pull-right">
            <?php if(check_user_role(119)==1): ?>
            <a href="<?php echo site_url('admin/documents/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>Nome</th>
                    <th style="width:90px">Tipo</th>
                    <th>Processo Vinculado</th>
                    <th style="width:140px">Ações</th>
                </tr>
            </thead>
            <tbody>
            <?php if(isset($documents)): $i=1; foreach($documents as $new): ?>
            <?php
            if(!empty($new->c_id)) {
                $link = '<a href="'.site_url('admin/cases/view_case/'.$new->c_id).'">#'.$new->case_no.' '.htmlspecialchars($new->case_title).'</a>';
            } else {
                $link = '<span class="text-muted">—</span>';
            }
            ?>
            <tr>
                <td><?php echo $i++ ?></td>
                <td style="vertical-align:middle">
                    <i class="fa fa-file-text-o text-muted" style="margin-right:7px"></i>
                    <strong><?php echo htmlspecialchars($new->title) ?></strong>
                </td>
                <td style="vertical-align:middle">
                    <?php if($new->is_case == 1): ?>
                    <span class="label label-info"><?php echo lang('case') ?></span>
                    <?php else: ?>
                    <span class="label label-default"><?php echo lang('other') ?></span>
                    <?php endif; ?>
                </td>
                <td style="vertical-align:middle"><small><?php echo $link ?></small></td>
                <td style="vertical-align:middle;white-space:nowrap">
                    <?php if(check_user_role(122)==1): ?>
                    <a href="<?php echo site_url('admin/documents/manage/'.$new->id) ?>" class="btn btn-xs btn-primary" title="Gerenciar"><i class="fa fa-chain"></i></a>
                    <?php endif; ?>
                    <?php if(check_user_role(120)==1): ?>
                    <a href="<?php echo site_url('admin/documents/edit/'.$new->id) ?>" class="btn btn-xs btn-warning" title="Editar"><i class="fa fa-pencil"></i></a>
                    <a href="<?php echo site_url('admin/documents/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: [[1,'asc']],
        pageLength: 25,
        language: { url: '//cdn.datatables.net/plug-ins/1.10.21/i18n/Portuguese-Brasil.json' }
    });
});
</script>
