<?php
include("../../packages/require.php");
include("controller/controller_role.php");
$curpage = "role";
$page_name = "module/role/index.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title><?=$title['role'];?></title>
    <?php include($global['root']."packages/head.php");?>
</head>
<body class="<?=$global['body-css'];?>">
    <div class="wrapper">

        <?php include($global['root']."section/header.php");?>
      
        <?php include($global['root']."section/sidebar.php");?>

        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                  <h1>
                    Module Role
                    <small>Adding and editing your admin role</small>
                  </h1>
                  <ol class="breadcrumb">
                        <li><a href="<?=$path['dashboard'];?>"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li class="active">Role</li>
                  </ol>
            </section>

            <!-- Main content -->
            <section class="content">
                <!-- Default box -->
                <div class="box">
                    <div class="box-header with-border">
                        <div class="row">
                            <div class="col-xs-12 col-sm-6"></div>
                            <div class="col-xs-12 col-sm-6">
                                <div class="head-btn text-right">
                                    <a href="<?=$path['role-insert'];?>" class="btn btn-primary">
                                        <i class="fa fa-plus"></i> Add New Data
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="box-body">
                        <div class="body-total text-right" style="margin-bottom: 15px;">
                            <span class="numbadge">
                                Total Data <span class="badge bg-light-blue"><?=$total_data;?></span>
                            </span>
                        </div>
                        <div class="body-content">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-middle">
                                    <tr>
                                        <th class="text-center">#</th>
                                        <th>Title</th>
                                        <th class="text-center">Total Access</th>
                                        <th class="text-center">Create Date</th>
                                        <th class="text-center">Action</th>
                                    </tr>
                                    <?php if(is_array($datas)) { $num=1; foreach($datas as $data){ ?>
                                    <tr>
                                        <td class="text-center"><?=($O_page-1)*10+$num;?>.</td>
                                        <td><?=correctDisplay($data['role_title']);?></td>
                                        <td class="text-center">
                                            <?=$data['total_access'];?>        
                                        </td>
                                        <td class="text-center">
                                            <?=date("d-m-Y H:i", strtotime($data['role_create_date']));?>
                                        </td>
                                        <td class="text-center">
                                            <div class="btn-group">
                                                <a href="<?=$path['role-edit'].$data['role_id'].'/';?>" class="btn btn-info btn-xs btn-flat">
                                                    <i class="fa fa-edit"></i> Edit
                                                </a>
                                                <?php if($data['role_title'] != "Developer" && $data['role_title'] != "Master"){ ?>
                                                <a href="javascript:void(0);" onclick="confirmDelete('<?=$data['role_id'];?>', '<?=correctDisplay($data['role_title']);?>');" class="btn btn-danger btn-xs btn-flat">
                                                    <i class="fa fa-trash"></i> Delete
                                                </a>
                                                <?php } else { ?>
                                                <a href="javascript:void(0);" class="btn btn-danger btn-xs btn-flat disable-state">
                                                    <i class="fa fa-trash"></i> Delete
                                                </a>
                                                <?php } ?>
                                            </div>
                                        </td>
                                    </tr>
                                    <?php $num++; } } else { ?>
                                    <tr class="warning">
                                        <td colspan="5" class="bold" align="center">There is no data right now!</td>
                                    </tr>
                                    <?php } ?>
                                </table>
                            </div>
                        </div>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer clearfix">
                        <div class="row">
                            <div class="col-sm-5">
                                <?php if($total_data > 0){ ?>
                                <div class="dataTables_info">
                                    Showing <?=($O_page-1)*10+1;?> to <?=($O_page-1)*10+$total_show;?> of <?=$total_data;?> entries
                                </div>
                                <?php } ?>
                            </div>
                            <div class="col-sm-7">
                                <?php
                                $batch = getBatch($O_page);
                                if($batch < 1){$batch = 1;}
                                $prevLimit = 1 +(10*($batch-1));
                                $nextLimit = 10 * $batch;

                                if($nextLimit > $total_page){
                                    $nextLimit = $total_page;
                                }
                                ?>
                                <ul class="pagination pagination-sm no-margin pull-right">
                                    <?php if($O_page > 1){?>
                                    <li>
                                        <a href="<?php echo $page_name."?page=".($O_page-1);?>">Previous</a>
                                    </li>
                                    <?php } ?>
                                    <?php for($mon = $prevLimit; $mon <= $nextLimit;$mon++){ ?>
                                    <li class="<?php if($mon == $O_page){echo 'active';}?>">
                                        <a href="<?php echo $page_name."?page=".$mon;?>"><?=$mon;?></a>
                                    </li>
                                    <?php } ?>
                                    <?php if($total_page > 1 && ($O_page < $total_page)){?>
                                    <li>
                                        <a href="<?php echo $page_name."?page=".($O_page+1);?>">Next</a>
                                    </li>
                                    <?php } ?>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.box-footer-->
            </section>
            <!-- /.content -->
        </div>
        <!-- /.content-wrapper -->

        <?php include($global['root']."section/footer.php");?>

    </div>
    <!-- ./wrapper -->

    <?php include($global['root']."packages/footer.php");?>
    <script type="text/javascript">
        $(document).ready(function() {
            <?php if($message != "") { ?>
            //use session here for alert success/failed
            var alertText = "<?=$message;?>";
                <?php if($alert != "success"){ ?>
                errorAlert(alertText);// error alert
                <?php } else { ?>
                successAlert(alertText);// success alert
                <?php } ?>
            <?php } ?>
        });
        //function confirmation delete
        function confirmDelete(num, text){
            swal({
                title: "Are you sure?",
                text: "You will not be able to recover this file!",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "Delete ! ",
                cancelButtonText: "Cancel !",
                closeOnConfirm: false,
                closeOnCancel: true
            },
            function (isConfirm) {
                if (isConfirm) {
                    window.location.href = "index.php?action=delete&id="+num+"&title="+text;
                } else {
                    //nothing
                }
            });
        }
    </script>
</body>
</html>