<?= $this->extend('Modules\Admin\Views\index'); ?>
<?= $this->section('content');?>
<div class="container-fluid">
<div class="row mb-md-3">
	<div class="col">
		<h4>All User</h4>
		<!-- Breadcrumb !-->
		<nav aria-label="breadcrumb"><small>
			<ol class="breadcrumb mb-0">
				<li class="breadcrumb-item"><a href="<?= base_url('administrator') ?> ">Home</a></li>
				<li class="breadcrumb-item active" aria-current="page"><?= esc($bcrumb) ?> </li>
			</ol></small>
		</nav>
		<!-- End Breadcrumb !-->
	</div>
</div>
<!-- print success message !-->
<div class="row">
    <div class="col">
		<!-- print success message !-->
		<?php if(session()->getTempdata('success')): ?>
			<div class="alert alert-success" role="alert"><?= session()->getTempdata('success');?></div>
		<?php endif;?>
		<!-- print failure message !-->
		<?php if(session()->getTempdata('error')): ?>
			<div class="alert alert-danger" role="alert"><?= session()->getTempdata('error');?></div>
		<?php endif;?>
        <?php if(isset($validation)): ?>
			<div class="alert alert-danger">
		<?= $validation->listErrors()?>
		</div>
        <?php endif;?>
        <div id="showMsg"></div>
</div></div>
<!-- END print success message !-->
<div class="row">
	<div class="col-lg-10 col-md-10 col-sm-12">
	<div class="card card-body">
		<div><h6>.. <a href="<?= base_url('administrator/users/add') ?>" class="btn btn-sm btn-primary float-md-end">Add User</a></span></h6></div>
		<div class="table-responsive">
            <table id="users-list" class="table table-hover expandable-table" >
                <thead><tr>
                  <th>Name</th>
                  <th>Email</th>
                  <th>Group</th>
                  <th>Status</th>
                  <th width="10%">Action</th>
                </tr></thead>
                <tbody>
                 <?php foreach($users as $us):?>
                  <?php if($us->group_id != 1):?>
                  <tr>
                    <td><a href="<?= base_url('administrator/settings/admin/edit/').$us->id ?>"> <strong><?= $us->first_name.' '.$us->last_name; ?></strong></a></td>
                    <td><?= $us->email; ?></td>
                    <td><?= $us->group; ?></td>
                    <td>
                      <?php if($us->status == "active"):?>
                        <span class="badge bg-success"><?= $us->status; ?></span>
                      <?php else:?>
                        <span class="badge bg-secondary"><?= $us->status; ?></span>
                      <?php endif;?>
                    </td>
                    <td>
                    <div class="btn-group" role="group" aria-label="users">
                      <a href="<?= base_url('administrator/users/edit/').$us->id ?>" class="btn btn-primary btn-sm" title="Edit"> 
                        <i class="bi bi-pencil-square" aria-hidden="true" ></i>
                      </a>
                      <?php $name = $us->first_name.' '.$us->last_name;?>
                      <a class="btn btn-warning btn-sm" title="Password" onclick="change_pwd(<?= $us->id; ?>, '<?= $name; ?>')"> 
                        <i class="bi bi-lock" aria-hidden="true"></i>
                      </a>
                      <a class="btn btn-info btn-sm" title="Group" onclick="change_group(<?= $us->id; ?>, '<?= $us->group; ?>', '<?= $name; ?>')"> 
                        <i class="bi bi-people" aria-hidden="true"></i>
                      </a>
                      <?php if($userdata->group_id == 1):?>
                      <a class="btn btn-danger btn-sm" title="Delete" onclick="delete_user('<?= $us->id; ?>', '<?= $us->first_name; ?>')">
                        <i class="bi bi-trash" aria-hidden="true"></i>
                      </a>
                      <?php endif;?>
                    </div>
                    </td>
                  </tr>
                  <?php endif;?>
                <?php endforeach;?>
                </tbody>
            </table>
        </div><!-- Table responsive !-->
	</div><!-- card !-->
	</div><!-- Col !-->
</div><!-- Row !-->

<!---- Modals --->
<?= view('Modules\Admin\Views\users\\modals\change_userPassword'); ?>
<?= view('Modules\Admin\Views\users\\modals\change_groupModal'); ?>
<!---- JS --->
<script type="text/javascript">
    $(document).ready(function () {
    $('#admins-list').DataTable({
        pageLength: 10,
        order: [[0, "Desc"]],
    });
    });
</script>            
<script src="<?= base_url();?>/assets/js/modules/admin_settings.js"></script>   
<?= $this->endSection();?>
