<section class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1>
                    
                </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"><a href="<?php echo base_url()."index.php/".$link;?>"><?php echo $titlebefore;?></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">
                    <?php 
                        $setdisabled= "";
                        $setid      = "";
                        $setnama    = "";
                        $setstatus  = 1;
                        if ($actionform=="prosesview"){
                            $setdisabled="disabled=''";
                        }
                        if ($actionform!="prosesadd"){
//                            $setid      = $ha->row('mt_id');
//                            $setnama    = $ha->row('mt_nama');
//                            $setstatus  = $ha->row('mt_status');
                        }
                    ?>
                    <form action="<?php echo(base_url()); ?>index.php/<?php echo $link;?>/<?php echo $actionform; ?>" method="post" autocomplete="off">
                        <div class="card-header">
                            <h3 class="card-title"><?php echo $title." - <b> ".$tu->row("mt_nama")."</b>"; ?> </h3>
                        </div>
                        <?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 class="table table-hover text-nowrap">
                            <input id="id" name="id" hidden="" value="<?php echo $id;?>" />
                            <thead>
                                <tr>
                                    <th>No</th>
                                    <th>Menu</th>
                                    <th>Access</th>
                                    <th>View</th>
                                    <th>Add</th>
                                    <th>Edit</th>
                                    <th>Delete</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    $no=0;
                                    //$id_input="";
                                    foreach ($mn as $menu) {
                                        $parentmenu="";
                                        //----cek parent menu----------------------------//
                                        $this->db->where('mm_id', $menu->mm_parent);
                                        $cekParent = $this->db->get('m_menu');
                                        foreach ($cekParent->result() as $par)
                                            {
                                                $parentmenu="<code>".$par->mm_nama." /</code> ";
                                            }
                                        //----cek parent menu----------------------------//
                                            
                                        $no++;
                                        echo("
                                            <tr>
                                                <td>".$no."</td>
                                                <td><input type='hidden' name='id_menu' value='".$menu->mm_id."'>".$parentmenu.$menu->mm_nama."</td>
                                                ");
                                                $cekakses   = ""; 
                                                $cekview    = "";
                                                $cektambah  = "";
                                                $cekedit    = "";
                                                $cekdelete  = ""; 
                                                $idusermenu = "";
                                                $setdisabled= "";
                                                foreach($um as $usermenu){
                                                    if($usermenu->mh_menu_id==$menu->mm_id){
                                                        $cekakses="checked";
                                                        
                                                        $this->db->where('mh_id', $usermenu->mh_id);
                                                        $query1 = $this->db->get('m_hakakses');
                                                        foreach ($query1->result() as $row1)
                                                        {
                                                            if($row1->mh_view==1){
                                                                $cekview="checked";
                                                            }
                                                            if($row1->mh_add==1){
                                                                $cektambah="checked";
                                                            }
                                                            if($row1->mh_edit==1){
                                                                $cekedit="checked";
                                                            }
                                                            if($row1->mh_delete==1){
                                                                $cekdelete="checked";
                                                            }
                                                        }
                                                    }
                                                }
                                                if ($actionform=="prosesview"){
                                                    $setdisabled="disabled=''";
                                                }
                                                if($menu->mm_action==1){
                                                    echo ("
                                                            <td><input type='checkbox'".$setdisabled." id='action".$no."'   name='akses[]'  ".$cekakses."   value='".$tu->row('mt_id')."-".$menu->mm_id."'></td>
                                                            <td><input type='checkbox'".$setdisabled." id='view".$no."'     name='view[]'   ".$cekview."    value='".$menu->mm_id."' ></td>
                                                            <td><input type='checkbox'".$setdisabled." id='tambah".$no."'   name='tambah[]' ".$cektambah."  value='".$menu->mm_id."' ></td>
                                                            <td><input type='checkbox'".$setdisabled." id='edit".$no."'     name='edit[]'   ".$cekedit."    value='".$menu->mm_id."'></td>
                                                            <td><input type='checkbox'".$setdisabled." id='delete".$no."'   name='delete[]' ".$cekdelete."  value='".$menu->mm_id."'></td>                                                                                                                                                                        
                                                        </tr>
                                                    ");
                                                    
                                                }else{
                                                    echo ("
                                                            <td><input type='checkbox'".$setdisabled." id='action".$no."'   name='akses[]'  class='flat-red'".$cekakses."   value='".$tu->row('mt_id')."-".$menu->mm_id."'></td>
                                                            <td></td>
                                                            <td></td>
                                                            <td></td>
                                                            <td></td>                                                                                                                                                                        
                                                        </tr>
                                                    ");
                                                }
                                            }
                                ?>      
                            </tbody>
                        </table>
                        <div class="card-footer">
                            <?php if ($actionform!="prosesview"){ ?>
                                <button type="submit" class="btn btn-info">Simpan</button>
                            <?php } ?>
                            <a href="<?php echo base_url()."index.php/".$link;?>" class="btn btn-default float-right">Cancel</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>
