<?php
$comp_model = new SharedController;
$page_element_id = "list-page-" . random_str();
$current_page = $this->set_current_page_link();
$csrf_token = Csrf::$token;
//Page Data From Controller
$view_data = $this->view_data;
$records = $view_data->records;
$record_count = $view_data->record_count;
$total_records = $view_data->total_records;
$field_name = $this->route->field_name;
$field_value = $this->route->field_value;
$view_title = $this->view_title;
$show_header = $this->show_header;
$show_footer = $this->show_footer;
$show_pagination = $this->show_pagination;
?>
<section class="page ajax-page" id="<?php echo $page_element_id; ?>" data-page-type="list"  data-display-type="table" data-page-url="<?php print_link($current_page); ?>">
    <?php
    if( $show_header == true ){
    ?>
    <div  class="bg-light p-3 mb-3">
        <div class="container-fluid">
            <div class="row ">
                <div class="col ">
                    <h4 class="record-title">Data Generus</h4>
                </div>
                <div class="col-sm-3 ">
                    <?php $modal_id = "modal-" . random_str(); ?>
                    <button data-toggle="modal" data-target="#<?php  echo $modal_id ?>"  class="btn btn btn-primary my-1">
                        <i class="fa fa-plus"></i>                                  
                        Tambah Data Generus 
                    </button>
                    <div data-backdrop="true" id="<?php  echo $modal_id ?>" class="modal fade"  role="dialog" aria-labelledby="<?php  echo $modal_id ?>" aria-hidden="true">
                        <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
                            <div class="modal-content">
                                <div class="modal-body p-0 reset-grids">
                                    <div class=" ">
                                        <?php  
                                        $this->render_page("data_generus/add"); 
                                        ?>
                                    </div>
                                </div>
                                <div style="top: 5px; right:5px; z-index: 999;" class="position-absolute">
                                    <button type="button" class="btn btn-sm btn-danger" data-dismiss="modal">&times;</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-4 ">
                </div>
                <div class="col-md-12 comp-grid">
                    <div class="">
                        <!-- Page bread crumbs components-->
                        <?php
                        if(!empty($field_name) || !empty($_GET['search'])){
                        ?>
                        <hr class="sm d-block d-sm-none" />
                        <nav class="page-header-breadcrumbs mt-2" aria-label="breadcrumb">
                            <ul class="breadcrumb m-0 p-1">
                                <?php
                                if(!empty($field_name)){
                                ?>
                                <li class="breadcrumb-item">
                                    <a class="text-decoration-none" href="<?php print_link('data_generus'); ?>">
                                        <i class="fa fa-angle-left"></i>
                                    </a>
                                </li>
                                <li class="breadcrumb-item">
                                    <?php echo (get_value("tag") ? get_value("tag")  :  make_readable($field_name)); ?>
                                </li>
                                <li  class="breadcrumb-item active text-capitalize font-weight-bold">
                                    <?php echo (get_value("label") ? get_value("label")  :  make_readable(urldecode($field_value))); ?>
                                </li>
                                <?php 
                                }   
                                ?>
                                <?php
                                if(get_value("search")){
                                ?>
                                <li class="breadcrumb-item">
                                    <a class="text-decoration-none" href="<?php print_link('data_generus'); ?>">
                                        <i class="fa fa-angle-left"></i>
                                    </a>
                                </li>
                                <li class="breadcrumb-item text-capitalize">
                                    Search
                                </li>
                                <li  class="breadcrumb-item active text-capitalize font-weight-bold"><?php echo get_value("search"); ?></li>
                                <?php
                                }
                                ?>
                            </ul>
                        </nav>
                        <!--End of Page bread crumbs components-->
                        <?php
                        }
                        ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php
    }
    ?>
    <div  class="">
        <div class="container">
            <div class="row ">
                <div class="col-sm-6 comp-grid">
                    <?php $menu_id = "menu-" . random_str(); ?>
                    <div class="card mb-3 ">
                        <nav class="navbar navbar-expand-lg navbar-light">
                            <span class="navbar-brand mb-0 h4"><b><i class="text-white badge badge-primary">Zona 1</i></b></span>
                            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#<?php echo $menu_id ?>" aria-expanded="false">
                                <span class="navbar-toggler-icon"></span>
                            </button>
                        </nav>  
                        <div class="collapse collapse-lg " id="<?php echo $menu_id ?>">
                            <?php 
                            $arr_menu = array();
                            $menus = $comp_model->data_generuskelompok_list(); // Get menu items from database
                            if(!empty($menus)){
                            //build menu items into arrays
                            foreach($menus as $menu){
                            $arr_menu[] = array(
                            "path"=>"data_generus/list/data_generus.kelompok/$menu[kelompok]?label=$menu[kelompok]&tag=Data Generus Kelompok", 
                            "label"=>"$menu[kelompok] <span class='badge badge-primary float-right'>$menu[num]</span>", 
                            "icon"=>''
                            );
                            }
                            //call menu render helper.
                            Html :: render_menu($arr_menu , "nav nav-tabs flex-column");
                            }
                            ?>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6 comp-grid">
                    <?php $menu_id = "menu-" . random_str(); ?>
                    <div class="card mb-3 ">
                        <nav class="navbar navbar-expand-lg navbar-light">
                            <span class="navbar-brand mb-0 h4"><b><i class="text-white badge badge-primary">Zona 2</i></b></span>
                            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#<?php echo $menu_id ?>" aria-expanded="false">
                                <span class="navbar-toggler-icon"></span>
                            </button>
                        </nav>  
                        <div class="collapse collapse-lg " id="<?php echo $menu_id ?>">
                            <?php 
                            $arr_menu = array();
                            $menus = $comp_model->data_generuskelompok_list_2(); // Get menu items from database
                            if(!empty($menus)){
                            //build menu items into arrays
                            foreach($menus as $menu){
                            $arr_menu[] = array(
                            "path"=>"data_generus/list/data_generus.kelompok/$menu[kelompok]?label=$menu[kelompok]&tag=Data Generus Kelompok", 
                            "label"=>"$menu[kelompok] <span class='badge badge-primary float-right'>$menu[num]</span>", 
                            "icon"=>''
                            );
                            }
                            //call menu render helper.
                            Html :: render_menu($arr_menu , "nav nav-tabs flex-column");
                            }
                            ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div  class="">
        <div class="container-fluid">
            <div class="row ">
                <div class="col-md-12 comp-grid">
                    <?php $this :: display_page_errors(); ?>
                    <div  class=" animated fadeIn page-content">
                        <div id="data_generus-list-records">
                            <div id="page-report-body" class="table-responsive">
                                <?php Html::ajaxpage_spinner(); ?>
                                <table class="table table-hover table-striped table-sm text-left table-bordered">
                                    <thead class="table-header bg-light text-dark">
                                        <tr>
                                            <th class="td-sno">#</th>
                                            <th  class="td-nama_lengkap"> Nama Lengkap</th>
                                            <th  class="td-jenis_kelamin"> Jenis Kelamin</th>
                                            <th  class="td-kelompok"> Kelompok</th>
                                            <th  class="td-rombel"> Rombel</th>
                                            <th  class="td-keterangan"> Keterangan</th>
                                            <th class="td-btn"></th>
                                        </tr>
                                    </thead>
                                    <?php
                                    if(!empty($records)){
                                    ?>
                                    <tbody class="page-data" id="page-data-<?php echo $page_element_id; ?>">
                                        <!--record-->
                                        <?php
                                        $counter = 0;
                                        foreach($records as $data){
                                        $rec_id = (!empty($data['id']) ? urlencode($data['id']) : null);
                                        $counter++;
                                        ?>
                                        <tr>
                                            <th class="td-sno"><?php echo $counter; ?></th>
                                            <td class="td-nama_lengkap"> <?php echo $data['nama_lengkap']; ?></td>
                                            <td class="td-jenis_kelamin"> <?php echo $data['jenis_kelamin']; ?></td>
                                            <td class="td-kelompok"> <?php echo $data['kelompok']; ?></td>
                                            <td class="td-rombel"> <?php echo $data['rombel']; ?></td>
                                            <td class="td-keterangan"> <?php echo $data['keterangan']; ?></td>
                                            <td class="page-list-action td-btn">
                                                <div class="dropdown" >
                                                    <button data-toggle="dropdown" class="dropdown-toggle btn btn-primary btn-sm">
                                                        <i class="fa fa-bars"></i> 
                                                    </button>
                                                    <ul class="dropdown-menu">
                                                        <a class="dropdown-item page-modal" href="<?php print_link("data_generus/view/$rec_id"); ?>">
                                                            <i class="fa fa-eye"></i> Lihat 
                                                        </a>
                                                        <a class="dropdown-item page-modal" href="<?php print_link("data_generus/edit/$rec_id"); ?>">
                                                            <i class="fa fa-edit"></i> Ubah
                                                        </a>
                                                        <a  class="dropdown-item record-delete-btn" href="<?php print_link("data_generus/delete/$rec_id/?csrf_token=$csrf_token&redirect=$current_page"); ?>" data-prompt-msg="Apakah yakin menghapus data?" data-display-style="modal">
                                                            <i class="fa fa-times"></i> Hapus 
                                                        </a>
                                                    </ul>
                                                </div>
                                            </td>
                                        </tr>
                                        <?php 
                                        }
                                        ?>
                                        <!--endrecord-->
                                    </tbody>
                                    <tbody class="search-data" id="search-data-<?php echo $page_element_id; ?>"></tbody>
                                    <?php
                                    }
                                    ?>
                                </table>
                                <?php 
                                if(empty($records)){
                                ?>
                                <h4 class="bg-light text-center border-top text-muted animated bounce  p-3">
                                    <i class="fa fa-ban"></i> data tidak ditemukan
                                </h4>
                                <?php
                                }
                                ?>
                            </div>
                            <?php
                            if( $show_footer && !empty($records)){
                            ?>
                            <div class=" border-top mt-2">
                                <div class="row justify-content-center">    
                                    <div class="col-md-auto justify-content-center">    
                                        <div class="p-3 d-flex justify-content-between">    
                                            <button data-prompt-msg="Are you sure you want to delete these records?" data-display-style="modal" data-url="<?php print_link("data_generus/delete/{sel_ids}/?csrf_token=$csrf_token&redirect=$current_page"); ?>" class="btn btn-sm btn-danger btn-delete-selected d-none">
                                                <i class="fa fa-times"></i> Delete Selected
                                            </button>
                                            <div class="dropup export-btn-holder mx-1">
                                                <button class="btn btn-sm btn-primary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                    <i class="fa fa-save"></i> Download
                                                </button>
                                                <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                                    <?php $export_print_link = $this->set_current_page_link(array('format' => 'print')); ?>
                                                    <a class="dropdown-item export-link-btn" data-format="print" href="<?php print_link($export_print_link); ?>" target="_blank">
                                                        <img src="<?php print_link('assets/images/print.png') ?>" class="mr-2" /> PRINT
                                                        </a>
                                                        <?php $export_pdf_link = $this->set_current_page_link(array('format' => 'pdf')); ?>
                                                        <a class="dropdown-item export-link-btn" data-format="pdf" href="<?php print_link($export_pdf_link); ?>" target="_blank">
                                                            <img src="<?php print_link('assets/images/pdf.png') ?>" class="mr-2" /> PDF
                                                            </a>
                                                            <?php $export_word_link = $this->set_current_page_link(array('format' => 'word')); ?>
                                                            <a class="dropdown-item export-link-btn" data-format="word" href="<?php print_link($export_word_link); ?>" target="_blank">
                                                                <img src="<?php print_link('assets/images/doc.png') ?>" class="mr-2" /> WORD
                                                                </a>
                                                                <?php $export_csv_link = $this->set_current_page_link(array('format' => 'csv')); ?>
                                                                <a class="dropdown-item export-link-btn" data-format="csv" href="<?php print_link($export_csv_link); ?>" target="_blank">
                                                                    <img src="<?php print_link('assets/images/csv.png') ?>" class="mr-2" /> CSV
                                                                    </a>
                                                                    <?php $export_excel_link = $this->set_current_page_link(array('format' => 'excel')); ?>
                                                                    <a class="dropdown-item export-link-btn" data-format="excel" href="<?php print_link($export_excel_link); ?>" target="_blank">
                                                                        <img src="<?php print_link('assets/images/xsl.png') ?>" class="mr-2" /> EXCEL
                                                                        </a>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col">   
                                                            <?php
                                                            if($show_pagination == true){
                                                            $pager = new Pagination($total_records, $record_count);
                                                            $pager->route = $this->route;
                                                            $pager->show_page_count = false;
                                                            $pager->show_record_count = true;
                                                            $pager->show_page_limit =false;
                                                            $pager->limit_count = $this->limit_count;
                                                            $pager->show_page_number_list = true;
                                                            $pager->pager_link_range=5;
                                                            $pager->ajax_page = true;
                                                            $pager->render();
                                                            }
                                                            ?>
                                                        </div>
                                                    </div>
                                                </div>
                                                <?php
                                                }
                                                ?>
                                            </div>
                                        </div>
                                        <div class=""><div>
                                            <style>
                                                .table td{
                                                font-size:12px;
                                                }
                                                .table th{
                                                font-size:12px;
                                                .table thead{
                                                font-size:12px;
                                                }
                                            </style>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>
