<?php 
//check if current user role is allowed access to the pages
$can_add = ACL::is_allowed("role_permissions/add");
$can_edit = ACL::is_allowed("role_permissions/edit");
$can_view = ACL::is_allowed("role_permissions/view");
$can_delete = ACL::is_allowed("role_permissions/delete");
?>
<?php
$current_page = $this->set_current_page_link();
$csrf_token = Csrf::$token;
$field_name = $this->route->field_name;
$field_value = $this->route->field_value;
$view_data = $this->view_data;
$records = $view_data->records;
$record_count = $view_data->record_count;
$total_records = $view_data->total_records;
if (!empty($records)) {
?>
<!--record-->
<?php
$counter = 0;
foreach($records as $data){
$rec_id = (!empty($data['permission_id']) ? urlencode($data['permission_id']) : null);
$counter++;
?>
<tr>
    <?php if($can_delete){ ?>
    <th class=" td-checkbox">
        <label class="custom-control custom-checkbox custom-control-inline">
            <input class="optioncheck custom-control-input" name="optioncheck[]" value="<?php echo $data['permission_id'] ?>" type="checkbox" />
                <span class="custom-control-label"></span>
            </label>
        </th>
        <?php } ?>
        <th class="td-sno"><?php echo $counter; ?></th>
        <td class="page-list-action td-btn">
            <div class="dropdown" >
                <button data-toggle="dropdown" class="dropdown-toggle btn btn-primary btn-sm">
                    <i class="icon dripicons-menu"></i> 
                </button>
                <ul class="dropdown-menu">
                    <?php if($can_view){ ?>
                    <a class="dropdown-item" href="<?php print_link("role_permissions/view/$rec_id"); ?>">
                        <i class="icon dripicons-preview"></i> Visão 
                    </a>
                    <?php } ?>
                    <?php if($can_edit){ ?>
                    <a class="dropdown-item" href="<?php print_link("role_permissions/edit/$rec_id"); ?>">
                        <i class="icon dripicons-document-edit"></i> Editar
                    </a>
                    <?php } ?>
                    <?php if($can_delete){ ?>
                    <a  class="dropdown-item record-delete-btn" href="<?php print_link("role_permissions/delete/$rec_id/?csrf_token=$csrf_token&redirect=$current_page"); ?>" data-prompt-msg="Apagar?" data-display-style="modal">
                        <i class="icon dripicons-cross"></i> Apagar 
                    </a>
                    <?php } ?>
                </ul>
            </div>
        </td>
        <td class="td-page_name">
            <span <?php if($can_edit){ ?> data-value="<?php echo $data['page_name']; ?>" 
                data-pk="<?php echo $data['permission_id'] ?>" 
                data-url="<?php print_link("role_permissions/editfield/" . urlencode($data['permission_id'])); ?>" 
                data-name="page_name" 
                data-title="Entrar  Page Name" 
                data-placement="left" 
                data-toggle="click" 
                data-type="text" 
                data-mode="popover" 
                data-showbuttons="left" 
                class="is-editable" <?php } ?>>
                <?php echo $data['page_name']; ?> 
            </span>
        </td>
        <td class="td-action_name">
            <span <?php if($can_edit){ ?> data-value="<?php echo $data['action_name']; ?>" 
                data-pk="<?php echo $data['permission_id'] ?>" 
                data-url="<?php print_link("role_permissions/editfield/" . urlencode($data['permission_id'])); ?>" 
                data-name="action_name" 
                data-title="Entrar  Action Name" 
                data-placement="left" 
                data-toggle="click" 
                data-type="text" 
                data-mode="popover" 
                data-showbuttons="left" 
                class="is-editable" <?php } ?>>
                <?php echo $data['action_name']; ?> 
            </span>
        </td>
        <td class="td-permission_id"><a href="<?php print_link("role_permissions/view/$data[permission_id]") ?>"><?php echo $data['permission_id']; ?></a></td>
        <td class="td-role_id">
            <span <?php if($can_edit){ ?> data-value="<?php echo $data['role_id']; ?>" 
                data-pk="<?php echo $data['permission_id'] ?>" 
                data-url="<?php print_link("role_permissions/editfield/" . urlencode($data['permission_id'])); ?>" 
                data-name="role_id" 
                data-title="Entrar  Role Id" 
                data-placement="left" 
                data-toggle="click" 
                data-type="number" 
                data-mode="popover" 
                data-showbuttons="left" 
                class="is-editable" <?php } ?>>
                <?php echo $data['role_id']; ?> 
            </span>
        </td>
    </tr>
    <?php 
    }
    ?>
    <?php
    } else {
    ?>
    <td class="no-record-found col-12" colspan="100">
        <h4 class="text-muted text-center ">
            Nenhum Registro Encontrado
        </h4>
    </td>
    <?php
    }
    ?>
    