<section class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1>
                    <?php 
                    //---------------------start check access action TAMBAH-------------------//
                    if(!empty($this->vartambah)){
                        echo "<a href='".base_url()."index.php/$link/add' class='btn btn-outline-info btn-sm'>Tambah Baru</a>";
                    }
                    //---------------------end check access action TAMBAH-------------------//
                    ?>
                </h1>
            </div>
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="<?php echo base_url();?>">Dashboard</a></li>
                    <li class="breadcrumb-item active"><?php echo $title;?></li>
                </ol>
            </div>
        </div>
    </div>
</section>
<!-- Main content -->
<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <div class="card card-default">
                    <div class="card-header">
                        <h3 class="card-title"><?php echo $title;?></h3>
                    </div>
                    <div class="card-body">
                        <?php if($this->session->flashdata('message')){?>
                        <div id="alert" class="alert alert-info alert-dismissable">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            <i class="icon fa fa-check"></i> Alert!
                            <?php echo $this->session->flashdata('message');?>
                        </div>
                        <?php }?>
                        <script> 
                            setTimeout(function() {
                                $('#alert').hide('fast');
                            }, 3000);
                        </script>
                        <table id="example1" class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>No</th>
                                    <th>Tipe User</th>
                                    <th>Status</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    $no=0;
                                    foreach ($ha as $dat) {
                                        $no++;
                                        //---------------------start check access action-------------------//
                                        $editbutton     = "";
                                        $hakaksesbutton = "";
                                        $viewbutton     = "";
                                        $deletebutton   = "";
                                        $disabledbutton = "";
                                        $aktifbutton    = "";
                                        
                                        if(!empty($this->varview)){
                                            $viewbutton="<a href='".base_url()."index.php/$link/view/".$dat->mt_id."' class='btn btn-info btn-xs'><i class='fa fa-eye'></i> <span class='d-none d-md-inline-block'> View</span></a> ";
                                        }
                                        if(!empty($this->varedit)){
                                            $editbutton="<a href='".base_url()."index.php/$link/edit/".$dat->mt_id."' class='btn btn-warning btn-xs'><i class='fa fa-edit'></i> <span class='d-none d-md-inline-block'> Edit</span></a> ";
                                        }
                                        if(!empty($this->varedit)){
                                            $hakaksesbutton="<a href='".base_url()."index.php/$link/edithakakses/".$dat->mt_id."' class='btn btn-success btn-xs'><i class='fa fa-cog'></i> <span class='d-none d-md-inline-block'> Hak Akses</span></a> ";
                                        }
                                        if(!empty($this->vardelete)){
                                            $deletebutton="<a onclick='del(".$dat->mt_id.")' class='btn btn-danger btn-xs'><i class='fa fa-ban'></i> <span class='d-none d-md-inline-block'> Delete</span></a> ";
                                        }
                                        
                                        $setstatus = "<span class='badge bg-teal'> Active</span>";
                                        if($dat->mt_status==0){
                                            $setstatus = "<span class='badge bg-red'> Disabled</span>";
                                            if(!empty($this->varedit)){
                                                $aktifbutton="<a onclick='aktif(".$dat->mt_id.")' class='btn btn-outline-success btn-xs'><i class='fa fa-check'></i> <span class='d-none d-md-inline-block'> On</span></a> ";
                                            }
                                        }else{
                                            if(!empty($this->varedit)){
                                                $disabledbutton="<a onclick='disabled(".$dat->mt_id.")' class='btn btn-outline-danger btn-xs'><i class='fa fa-ban'></i> <span class='d-none d-md-inline-block'> Off</span></a> ";
                                            }
                                        }
                                        
                                        //---------------------end check access action-------------------//
                                        echo("
                                            <tr>
                                                <input type='hidden' id='isi".$dat->mt_id."' value='".$dat->mt_nama."'>
                                                <td>".$no."</td>
                                                <td>".$dat->mt_nama."</td>
                                                <td style='text-align: center;'>".$setstatus."</td>
                                                <td>".$viewbutton.$editbutton.$hakaksesbutton.$disabledbutton.$aktifbutton.$deletebutton."</td>
                                            </tr>
                                        ");
                                    }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<script type="text/javascript">
    var url="<?php echo base_url();?>";
    function disabled(id){
        var isi=document.getElementById('isi'+id).value;
        var r=confirm("Apakah anda ingin Disbaled Tipe User '"+isi+"'?")
        if (r==true)
            window.location = url+"index.php/ps_hakakses/disabled/"+id;
        else
            return false;
    } 
    
    function aktif(id){
        var isi=document.getElementById('isi'+id).value;
        var r=confirm("Apakah anda ingin Aktifkan Tipe User '"+isi+"'?")
        if (r==true)
            window.location = url+"index.php/ps_hakakses/active/"+id;
        else
            return false;
    }
    
    function del(id){
        var isi=document.getElementById('isi'+id).value;
        var r=confirm("Apakah anda ingin Menghapus Tipe User '"+isi+"'?")
        if (r==true)
            window.location = url+"index.php/ps_hakakses/delete/"+id;
        else
            return false;
    }
</script>
