<?php
include '../../../lib/conn.php';
include '../../../lib/all_function.php';
?>
<?php
    $query = "SELECT * FROM `users`";
    $sql_kul = mysqli_query($conn,$query);	
    $x=1;
    while ($m = mysqli_fetch_assoc($sql_kul)) {
        $ko = $m['id_identitas'];
        $tko = explode(",", $ko);
        $jmko = count($tko);
        
        $sql_akun = mysqli_query($conn,"SELECT `pegawai_id` as id,`pegawai_nama` as nama FROM `pegawai` WHERE pegawai_id = '$m[nama_lengkap]'");
        $g = mysqli_fetch_assoc($sql_akun);
        $nama = $g['nama'];
        
        $sql_menu = "SELECT * FROM tb_group_menu WHERE `kode_group` = '$_SESSION[level_check]' AND id_menu='$_GET[idmx]'";
        $sqqmn = mysqli_query($conn,$sql_menu);	
        $mn = mysqli_fetch_assoc($sqqmn);
        $aksi = 'mod/data_master/user/act_user.php';
?>
<tr>
    <td align="center"><?php echo $x ?></td>
    <td align="center"><?php echo $nama?></td>
    <td align="center"><?php echo $m['username']?></td>                                    
    <td align="center">
        <?php
        for ($i=0; $i < $jmko; $i++) {
            echo nama_toko($tko[$i]). ", ";
        }
        ?>
    </td>
    <td align="center"><?php echo $m['email']?></td>
    <td align="center"><?php echo $m['no_telp']?></td>
    <td align="center"><?php echo group($m['level'])?></td>
    <td align="center">
        <?php 
        if ($m['aktif']=='Ya') {
        ?>
            <span class="lable-table bg-success-subtle text-success rounded border border-success-subtle font-text2 fw-bold">Active<i class="bi bi-check2 ms-2"></i></span>
        <?php
        }else{
        ?>
            <span class="lable-table bg-danger-subtle text-danger rounded border border-danger-subtle font-text2 fw-bold">Inactive<i class="bi bi-x-lg ms-2"></i></span>
        <?php
        }
        ?>
    </td>
    <?php if($mn['update']=="Aktif" OR $mn['view']=="Aktif" OR $mn['delete']=="Aktif"){?>
    <td align="center">
        <div class="btn-group" role="group" aria-label="Aksi">
            <?php if ($mn['update'] == "Aktif") { ?>					
                <a href="med.php?mod=user&act=form&id=<?php echo $m['user_id'] ?>&idmx=<?php echo $mn['id_menu'] ?>" class="btn btn-outline-success btn-sm" title="Edit Data">
                <i class="material-icons-outlined">edit</i>
                </a>
            <?php } ?>

            <?php if ($mn['delete'] == "Aktif") { ?>		
                <button type="button" class="btn btn-outline-danger btn-sm btn-hapus" data-url="<?php echo $aksi; ?>?mod=user&act=hapus&id=<?php echo $m['user_id']; ?>&idmx=<?php echo $mn['id_menu']; ?>" title="Hapus Data"><i class="material-icons-outlined">close</i></button>
            <?php } ?>
        </div>
    </td>
    <?php } ?>
</tr>

<?php
     $x++;
 }
?>
