<link href="http://www.google.com/fonts#UsePlace:use/Collection:Open+Sans:300" rel="stylesheet" />
<link rel="stylesheet" href="<?php echo base_url();?>assets/css/cust_paginition.css" type="text/css" />
<!--Left section start here-->



<div id="content">
    <div id="right">
        <div class="box">
            <div class="modal-header">
                <h3 class="modal-title" align="center">Manage Access Roles</h3>
            </div>
            <form name="permission_form" id="permission_form" method="post" action="">
                <br />
                <label  class="col-sm-2 control-label text-center">Select User Level:</label>
                <select class="cust_select" name="role_id" id="role_id">
                    <option value="">--Select--</option>
                    <?php foreach($users as $role) {?>
                        <option value="<?php echo $role['id'];?>"
                                <?php if ($selected_id == $role['id']){ ?>selected = "selected" <?php }?>><?php echo ucwords($role['name']);?></option>
                    <?php } ?>
                </select>

                <br>
                <?php $this->load->view('admin/flashdata_admin'); ?>
                <table class="table table-white table-vertical-center margin-none table-striped footable">
                    <thead>
                    <tr>
                        <th class="text-left strong">Sr. No.</th>
                        <th class="text-left strong">Module Name</th>
                        <th class="text-left strong">Permissions</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php
                    if(!empty($arr_modules))
                    {
                        $intCounter = 1;
                        foreach($arr_modules as $module)
                        {
                            ?>
                            <tr>
                                <td align="left" style="line-height: 3px !important;vertical-align: top"><?php echo $intCounter++; ?></td>
                                <td align="left" style="line-height: 3px !important;vertical-align: top"><?php echo ucwords(trim(str_replace('_',' ',$module['module_name']))); ?></td>
                                <td align="justify" style="line-height: 3em !important;vertical-align: top">
                                    <?php
                                    //echo $module['methods'];
                                    $arr_methods = explode(',', $module['methods']);
                                    $arr_permissions = explode(',', $module['permissions']);
                                    $arr_permission_id = explode(',', $module['permission_id']);
                                    if(!empty($arr_methods))
                                    {
                                        $i = 0;
                                        foreach($arr_methods as $key=>$val)
                                        {
                                            $checked = '';

                                            $strFinalVal =  ucwords(trim(str_replace('_',' ',$val)));
                                            if($arr_permissions[$i])
                                                $checked = 'checked="checked"';


                                            echo "<lable style='border: 1px solid #CCCCCC;padding: 5px 14px;'><input type='checkbox' name='permission[]' id='permission".$i."' value='".$arr_permission_id[$i]."' ".$checked.">&nbsp;$strFinalVal</lable>&nbsp;&nbsp;";
                                            $i++;

                                        }
                                    }
                                    ?>
                                </td>

                            </tr>
                        <?php
                        }
                        ?>
                        <tr>

                            <td colspan="3">
                                <button type="submit" class="btn btn-primary">Save</button>

                            </td>
                        </tr>
                    <?php
                    }
                    else
                    {
                        ?>
                        <tr>
                            <td align="center" colspan="3">No record found.</td>
                        </tr>

                    <?php
                    }
                    ?>
                    </tbody>
                </table>
                <?php //echo $pagination; ?>
            </form>
        </div><!--class table ends-->


    </div>
</div>
<script src="<?php echo base_url();?>assets/js/main.js" type="text/javascript"></script>
<script>
    $(document).ready(function() {

        $('#role_id').change(function(){
            window.location = "<?php echo base_url();?>"+'index.php/manage/permission/'+$(this).val();
        });


    });

    function printDiv() {

        w = window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=850,height=750');
        w.document.write($('#PrintDiv').html());
        w.print();
        w.close();

        /* var printContents = document.getElementById('PrintDiv').innerHTML;
         var originalContents = document.body.innerHTML;

         document.body.innerHTML = printContents;

         window.print();

         document.body.innerHTML = originalContents;*/
    }
</script>