<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
   <section class="content-header">
      <div class="container-fluid">
         <div class="row mb-2">
            <div class="col-sm-6">
               <h4>Role Permission</h4>
            </div>
            <div class="col-sm-6">
               <ol class="breadcrumb float-sm-right">
                  <li class="breadcrumb-item"><a href="#">Home</a></li>
                  <li class="breadcrumb-item active">Role Permission</li>
               </ol>
            </div>
         </div>
      </div>
      <!-- /.container-fluid -->
   </section>

   <section class="content">
      <div class="container">
         <div class="row"> 
            <div class="col-md-6 col-lg-6">
               <div class="container-fluid">
                  <?php echo form_open_multipart('admin/user/add_new_role'); ?>
                  <div class="card card-default">
                     <div class="card-header">
                     <h3 class="card-title">Add Role</h3>
                  </div>
                     <div class="card-body">
                        <div class="tab-content">
                           <!--Application Details-->
                           <div class="tab-pane active" id="general_setting">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Role Name</label>
                                 <div class="col-sm-12">
                                    <input type="text" name="role_name" class="form-control" id="inputName" placeholder="Enter Role Name" required="required">
                                 </div>
                              </div>
                              <div class="form-group row d-none">
                                 <label for="inputEmail" class="col-sm-12 col-form-label">Select Permission</label>
                                 <div class="col-sm-12">
                                    <table>
                                       <tr>
                                          <div class="selectgroup selectgroup-pills">
                                            <?php 
                                           
                                            foreach ($tables as $table){ 
                                             if($table != 'is_emp'): ?>
                                             
                                               <label class="selectgroup-item" >
                                                 <input type="checkbox" name="<?php echo $table ?>" value="1" class="selectgroup-input">
                                                 <span class="selectgroup-button" style="display: <?php if($table == 'id' || $table == 'role_name'){echo 'none';} ?>;"><?php echo ucwords(str_replace("_", " ", $table)); ?></span>
                                               </label>

                                            <?php endif; } ?>
                                          </div>
                                       </tr>
                                    </table>
                                 </div>
                              </div>
                              <div class="form-group row">
                                 <div class="offset-sm-2 col-sm-10">
                                    <button style="float: right;" type="submit" class="btn btn-success setting-submit" name="submit">Save</button>
                                 </div>
                              </div>
                           </div>
                        </div>
                     </div>
                     
                     <?php echo form_close(); ?>
                  </div>
               </div>
            </div>
          
            <div class="col-md-6 col-lg-6">
               <div class="card">
                  <div class="card-header">
                     <h3 class="card-title">All Role Permission Details</h3>
                  </div>
                  <!-- /.card-header -->
                  <div class="card-body">
                     <table width="100%" id="example1" class="table table-bordered table-striped">
                        <thead>
                           <tr>
                              <th>Role Name</th>
                              <th class="d-none">Permission Details</th>
                              <th></th>
                           </tr>
                        </thead>
                        <tbody>
                           <?php foreach ($role_permission as $key => $permission):
                              if($permission->role_name != 'Admin'):
                              ?>
                                 <tr>
                                    <td><?php echo $permission->role_name ?></td>
                                    <td class="d-none">
                                      <div class="selectgroup selectgroup-pills">
                                          <?php 
                                          
                                          foreach ($tables as $table){ ?>
                                          <?php if($permission->$table == 1): ?>
                                          <label class="selectgroup-item">
                                          <input type="checkbox" checked disabled class="selectgroup-input">
                                          <span class="selectgroup-button" style="display: <?php if($table == 'id' || $table == 'role_name' || $table == 'show' || $table == 'is_emp'){echo 'none';} ?>;"><?php echo ucwords(str_replace("_", " ", $table)); ?></span>
                                          </label>
                                          <?php endif ?>
                                          <?php } ?>
                                      </div>
                                    </td>
                                    <td>
                                      <?php ?>
                                       <div class="input-group-prepend">
                                         <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                           Action
                                         </button>
                                         <div class="dropdown-menu" style="">
                                          <a class="dropdown-item" href="<?php echo base_url() ?>/admin/user/edit_permission/<?php echo $permission->id ?>"><i class="fa fa-edit option-icon"></i>&nbsp;Edit</a>
                                          <?php if($permission->role_name != 'Teacher'): ?>
                                          <div class="dropdown-divider"></div>
                                          
                                             <a class="dropdown-item" onclick="return confirm('Are you sure?')" href="<?php echo base_url() ?>/admin/user/delete_role_permission/<?php echo $permission->id ?>"><i class="fa fa-trash" aria-hidden="true"></i>
                                             &nbsp;Delete</a>
                                          <?php endif;?>
                                         </div>
                                       </div>
                                    </td>
                                 </tr>
                               <?php endif;
                           endforeach; ?>
                        </tbody>
                     </table>
                  </div>
                  <!-- /.card-body -->
               </div>
               <!-- /.card -->
            </div>
         </div>
      </div>
   </div>
   
</section>
</div>
<!-- /.content-wrapper -->
<style type="text/css">
  .selectgroup-pills .selectgroup-item {
    margin-right: .5rem;
    -ms-flex-positive: 0;
    flex-grow: 0;
}
.selectgroup-item {
    -ms-flex-positive: 1;
    flex-grow: 1;
    position: relative;
    font-weight: 400!important;
}
.selectgroup-input {
    opacity: 0;
    position: absolute;
    z-index: -1;
    top: 0;
    left: 0;
}
.selectgroup-item:not(:last-child) .selectgroup-button {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.selectgroup-item:not(:first-child) .selectgroup-button {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}
body[data-background-color=dark] .selectgroup-button {
    border: 1px solid #2f374b;
}
.selectgroup-pills .selectgroup-button {
    border-radius: 50px!important;
}
.selectgroup-button {
    display: block;
    border: 1px solid rgba(0,40,100,.12);
    text-align: center;
    padding: .375rem 1rem;
    position: relative;
    cursor: pointer;
    border-radius: 3px;
    color: #9aa0ac;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    font-size: 14px;
    line-height: 1.5rem;
    min-width: 2.375rem;
}
.selectgroup-input:checked+.selectgroup-button {
    border-color: #1572e8;
    z-index: 1;
    color: #1572e8;
    background: rgba(21,114,232,.15);
}
</style>