<link rel="stylesheet" href="<?php echo base_url();?>assets/css/cust_paginition.css" type="text/css" />
<script src="<?php echo base_url(); ?>assets/library/jquery/jquery.min.js"></script>
<div class="layout-app">
    <div class="container"><div class="row row-app">
            <div class="col-md-12">
                <div class="col-separator col-separator-first col-unscrollable bg-none">
                    <div class="col-table">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="widget">
                                    <?php $this->load->view('admin/flashdata_admin'); ?>
                                    <div class="widget-head">
                                        <a href="#addMagazine" class="btn btn-inverse pull-right mar" data-toggle="modal" onclick="return add_Access()"><i class="fa fa-fw fa-plus"></i>Add New</a>
                                        <h4 class="heading">Access Management</h4>

                                    </div>
                                    <div class = "form-group mmar" id="suceess_msgs" style="text-align: center"></div>
                                    <div class="widget-body">
                                        <form action="" method="GET" >
                                            <div class="col-md-12 selectBox">
                                                <div class="col-xs-4 col-md-2 bot-mar">
                                                    <label class="col-xs-12">Access Role</label>
                                                    <select class="cust_select col-xs-12" name = "sel_role">
                                                        <option value = "">--All--</option>
                                                        <?php foreach ($all_access as $role) {?>
                                                            <option value = "<?php echo $role['id']?>"
                                                                <?php if($selected_roles == $role['id']) {?> selected
                                                                <?php } ?>><?php echo $role['name']?></option>
                                                        <?php } ?>

                                                    </select>
                                                </div>

                                                <div class="col-xs-4 col-md-2 bot-mar">
                                                    <label class="col-xs-12">&nbsp;</label>
                                                    <div>
                                                        <button type="submit" class="btn btn-primary">Search</button>
                                                    </div>
                                                </div>
                                        </form>
                                        <div class="clearfix"></div>
                                    </div>
                                    <div class="widget-body">
                                        <table class="table table-white table-vertical-center margin-none table-striped footable">
                                            <thead>
                                            <tr>
                                                <th data-class="highlight" class="text-center">Access Roles</th>
                                                <th class="text-center">Edit</th>
                                                <th class="text-center">Delete</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <?php if(count($roles) > 0) {
                                            $intRowId = 1;
                                            foreach ($roles as $role){ ?>
                                                <tr id="Row<?php echo $intRowId;?>">
                                                    <td class="text-center"><?php echo ucfirst($role['name']);?></td>
                                                    <?php $intEncodedId =  base64_encode($role['id']);
                                                        $strRowId = 'Row'.$intRowId;?>
                                                    <td class="text-center"><a href="#editMagazine" data-toggle="modal" onclick="return edit_Access('<?php echo $intEncodedId; ?>')"><i class="fa fa-pencil"></i></a></td>
                                                    <td class="text-center"><a href="#editMagazine" onclick="return fnDelete('<?php echo $intEncodedId; ?>', '<?php echo $strRowId; ?>')"><i class="fa fa-trash-o"></i></a></td>
                                                </tr>
                                            <?php $intRowId++; }?>
                                            </tbody>
                                        </table>
                                        <div class="text-center innerAll border-top pagination">
                                            <?php echo $pagination; ?>
                                        </div>
                                        <?php } else { ?>
                                            <tr>
                                                <td class="text-center" colspan = "5" align = "center">Sorry, Access found</td>
                                            </tr>
                                            </tbody>
                                            </table>
                                        <?php }?>


                                    </div>
                                    <!-- // END TRENDS -->
                                </div>


                            </div>

                        </div>
                        <div class="col-separator-h"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<input type="hidden" id="system_base_url" value="<?php echo base_url();?>">
<div class="modal fade" id="addMagazine" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content" id="tran_preview">

        </div>
    </div>
</div>
<div class="modal fade" id="editMagazine" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content" id="edit_promo">

        </div>
    </div>
</div>
<script src="<?php echo base_url(); ?>assets/library/jquery/jquery.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/subscriber.js"></script>
<script type="application/javascript">
    function add_Access()
    {
        var system_base_url = $("#system_base_url").val();
        $.ajax({
            url:system_base_url + "index.php/users/fnAddAccess",
            'type' : 'GET',
            success:function(result){
                $("#tran_preview").html(result);
                //alert(result);
            }
        });
    }

    function edit_Access(intAccessId)
    {
        var system_base_url = $("#system_base_url").val();
        $.ajax({
            url:system_base_url + "index.php/users/fnEditAccess",
            'data' : {
                'id' :intAccessId
            },
            'type' : 'GET',
            success:function(result){
                $("#edit_promo").html(result);
            }
        });
    }

    function fnDelete(intAccessId, rowId)
    {
        var system_base_url = $("#system_base_url").val();
        $.ajax({
            url:system_base_url + "index.php/users/fnDeleteAccess",
            'data' : {
                'id' :intAccessId
            },
            'type' : 'GET',
            success:function(result){
                $("#suceess_msgs").html("<b>Access level has been deleted successfully</b>")
                $("#"+rowId).hide();
            }
        });
    }
</script>