<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"><?php echo $parent;?></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-success 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>Nama</th>
                                    <th>Kode</th>
                                    <th>Quota</th>
                                    <th>Pelayanan</th>
                                    <th>Pembayaran</th>
                                    <th>Online</th>
                                    <th>Status</th>
                                    <th width="15%">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    $no=0;
                                    foreach ($lkrj as $dat) {
                                        $no++;
                                        //---------------------start check access action-------------------//
                                        $editbutton     = "";
                                        $viewbutton     = "";
                                        $deletebutton   = "";
                                        $disabledbutton = "";
                                        $aktifbutton    = "";
                                        
                                        if(!empty($this->varview)){
                                            $viewbutton="<a href='".base_url()."index.php/$link/view/".$dat->mlrj_id."' class='btn btn-info btn-xs'><i class='fa fa-eye'></i></a> ";
                                        }
                                        if(!empty($this->varedit)){
                                            $editbutton="<a href='".base_url()."index.php/$link/edit/".$dat->mlrj_id."' class='btn btn-warning btn-xs'><i class='fa fa-edit'></i></a> ";
                                        }
                                        if(!empty($this->vardelete)){
                                            $deletebutton="<a onclick='del(".$dat->mlrj_id.")' class='btn btn-danger btn-xs'><i class='fa fa-times'></i></a> ";
                                        }
                                        
                                        $setstatus = "<span class='badge bg-teal'> Active</span>";
                                        if($dat->mlrj_status==0){
                                            $setstatus = "<span class='badge bg-red'> Disabled</span>";
                                            if(!empty($this->varedit)){
                                                $aktifbutton="<a onclick='aktif(".$dat->mlrj_id.")' class='btn btn-outline-success btn-xs'><i class='fa fa-check'></i></a> ";
                                            }
                                        }else{
                                            if(!empty($this->varedit)){
                                                $disabledbutton="<a onclick='disabled(".$dat->mlrj_id.")' class='btn btn-outline-danger btn-xs'><i class='fa fa-ban'></i></a> ";
                                            }
                                        }
                                        
                                        //---------------------end check access action-------------------//
                                        //----------start pelayanan-------------//
                                        $pecahpel   = explode("|",$dat->mlrj_pelayanan);
                                        $jumpel     = (count($pecahpel));
                                        $infoklinik = "";
                                        for($x=0;$x<=$jumpel;$x++){
                                            if(isset($pecahpel[$x])){
                                                foreach ($kl as $datkli){
                                                    if($pecahpel[$x]==$datkli->mk_id){
                                                        $infoklinik=$infoklinik."<small class='badge badge-success'>".$datkli->mk_nama."</small> ";
                                                    }
                                                }
                                            }
                                        }
                                        //------------end pelayanan-------------//
                                        
                                        //----------start pembayaran------------//
                                        $pecahpem   = explode("|",$dat->mlrj_pembayaran);
                                        $jumpem     = (count($pecahpem));
                                        $infopem    = "";
                                        for($y=0;$y<=$jumpem;$y++){
                                            if(isset($pecahpem[$y])){
                                                foreach ($pm as $datpem){
                                                    if($pecahpem[$y]==$datpem->mp_id){
                                                        $infopem=$infopem."<small class='badge badge-warning'>".$datpem->mp_nama."</small> ";
                                                    }
                                                }
                                            }
                                        }
                                        //------------end pembayaran------------//
                                        //------------start online--------------//
                                        if($dat->mlrj_online==1){
                                            $infoonl="<small class='badge badge-primary'>Online</small> ";
                                        }elseif($dat->mlrj_online==2){
                                            $infoonl="<small class='badge badge-secondary'>Offline</small> ";
                                        }elseif($dat->mlrj_online==3){
                                            $infoonl="<small class='badge badge-info'>Semua</small> ";
                                        }
                                        
                                        //--------------end online--------------//
                                        
                                        echo("
                                            <tr>
                                                <input type='hidden' id='isi".$dat->mlrj_id."' value='".$dat->mlrj_nama."'>
                                                <td>".$no."</td>
                                                <td>".$dat->mlrj_nama."</td>
                                                <td>".$dat->mlrj_kode."</td>
                                                <td>".$dat->mlrj_quotabangku."</td>
                                                <td>".$infoklinik."</td>
                                                <td>".$infopem."</td>
                                                <td>".$infoonl."</td>
                                                <td style='text-align: center;'>".$setstatus."</td>
                                                <td>".$viewbutton.$editbutton.$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 Loket Rajal '"+isi+"'?")
        if (r==true)
            window.location = url+"index.php/ps_loket_rajal/disabled/"+id;
        else
            return false;
    } 
    
    function aktif(id){
        var isi=document.getElementById('isi'+id).value;
        var r=confirm("Apakah anda ingin Aktifkan Loket Rajal '"+isi+"'?")
        if (r==true)
            window.location = url+"index.php/ps_loket_rajal/active/"+id;
        else
            return false;
    }
    
    function del(id){
        var isi=document.getElementById('isi'+id).value;
        var r=confirm("Apakah anda ingin Menghapus Loket Rajal '"+isi+"'?")
        if (r==true)
            window.location = url+"index.php/ps_loket_rajal/delete/"+id;
        else
            return false;
    }
</script>
