<?php
include("../../packages/require.php");
include("controller/controller_admin.php");
$curpage = "admin";
$page_name = "module/admin/index.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title><?=$title['admin'];?></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 Admin
                    <small>Adding and editing your admin list</small>
                  </h1>
                  <ol class="breadcrumb">
                        <li><a href="<?=$path['dashboard'];?>"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li class="active">Admin</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">
                                <?php if($acsa_create_admin == 1){ ?>
                                <div class="head-btn text-right">
                                    <a href="<?=$path['admin-insert'];?>" class="btn btn-primary">
                                        <i class="fa fa-plus"></i> Add New Data
                                    </a>
                                </div>
                                <?php } ?>
                            </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>E-Mail</th>
                                        <th>Username</th>
                                        <th class="text-center">Role</th>
                                        <th class="text-center">PIC</th>
                                        <th class="text-center">Region</th>
                                        <th class="text-center">Image</th>
                                        <th class="text-center">Action</th>
                                    </tr>
                                    <?php 
                                        if(is_array($datas)) { $num=1; foreach($datas as $data){ 
                                    ?>
                                    <tr <?php if($data['admin_active'] == "inactive" && $data['admin_password'] == ""){ ?>class="danger"<?php } else if ($data['admin_active'] == "inactive" && $data['admin_password'] != ""){ ?>class="warning"<?php } ?>>
                                        <td class="text-center"><?=($O_page-1)*10+$num;?>.</td>
                                        <td><?=correctDisplay($data['admin_email']);?></td>
                                        <td><?=correctDisplay($data['admin_name']);?></td>
                                        <td class="text-center"><?=correctDisplay($data['role_title']);?></td>
                                        <?php if($data['admin_pic'] == 'yes'){ ?>
                                        <td class="text-center"><span class="label label-success">Yes</span></td>
                                        <?php } else { ?>
                                        <td class="text-center"><span class="label label-warning">No</span></td>
                                        <?php } ?>
                                        <td class="text-center"><?=correctDisplay($data['region_title']);?></td>
                                        <td class="text-center">
                                            <?php if($data['admin_img'] != ""){ ?>
                                            <a href="<?=$global['absolute-url'].$data['admin_img'];?>" title="<?=correctDisplay($data['admin_name']);?>" class="image-link fancybox">
                                                <div class="img-bg" style="background-image: url('<?=$global['absolute-url'].$data['admin_img'];?>');"></div>
                                            </a>
                                            <?php } else { ?>
                                            <a href="<?=$global['absolute-url'].'img/dummy.jpg';?>" title="<?=correctDisplay($data['admin_name']);?>" class="image-link fancybox">
                                                <div class="img-bg" style="background-image: url('<?=$global['absolute-url'].'img/dummy.jpg';?>');"></div>
                                            </a>
                                            <?php } ?>
                                        </td>
                                        <td class="text-center">
                                            <div class="btn-group">
                                                <?php if($acsa_edit_admin == 1){ ?>
                                                <?php if($data['role_title'] == 'Developer' && $_SESSION['admin_role_name'] != 'Developer'){ ?>
                                                    <a href="javascript:void(0);" class="btn btn-info btn-xs btn-flat disable-state">
                                                        <i class="fa fa-edit"></i> Edit
                                                    </a>
                                                <?php } else { ?>
                                                    <a href="<?=$path['admin-edit'].$data['admin_id'].'/';?>" class="btn btn-info btn-xs btn-flat">
                                                        <i class="fa fa-edit"></i> Edit
                                                    </a>
                                                <?php } ?>
                                                <?php } else { ?>
                                                <?php if($_SESSION['admin_id'] != $data['admin_id']){ ?>
                                                <a href="javascript:void(0);" class="btn btn-info btn-xs btn-flat disable-state">
                                                    <i class="fa fa-edit"></i> Edit
                                                </a>
                                                <?php } else { ?>
                                                <a href="<?=$path['admin-edit'].$data['admin_id'].'/';?>" class="btn btn-info btn-xs btn-flat">
                                                    <i class="fa fa-edit"></i> Edit
                                                </a>
                                                <?php } ?>
                                                <?php } ?>

                                                <?php if($_SESSION['admin_id'] != $data['admin_id']){ ?>
                                                <?php if($acsa_activate_admin == 1){ ?>
                                                    <?php if($data['admin_active'] == "active" && $data['admin_password'] != ""){ ?>
                                                        <?php if($data['role_title'] == 'Developer' && $_SESSION['admin_role_name'] != 'Developer'){ ?>
                                                        <a href="javascript:void(0);" class="btn btn-danger btn-xs btn-flat disable-state">
                                                            <i class="fa fa-trash"></i> Deactive
                                                        </a>
                                                        <?php } else { ?>
                                                        <a href="javascript:void(0);" onclick="confirmDeactive('<?=$data['admin_id'];?>', '<?=correctDisplay($data['admin_name']);?>');" class="btn btn-danger btn-xs btn-flat">
                                                            <i class="fa fa-trash"></i> Deactive
                                                        </a>
                                                        <?php }?>
                                                    <?php } else if($data['admin_active'] == "inactive" && $data['admin_password'] != ""){ ?>
                                                        <?php if($data['role_title'] == 'Developer' && $_SESSION['admin_role_name'] != 'Developer'){ ?>
                                                        <a href="javascript:void(0);" class="btn btn-success btn-xs btn-flat disable-state">
                                                            <i class="fa fa-check"></i> Activate
                                                        </a>
                                                        <?php } else { ?>
                                                        <a href="javascript:void(0);" onclick="confirmActive('<?=$data['admin_id'];?>', '<?=correctDisplay($data['admin_name']);?>');" class="btn btn-success btn-xs btn-flat">
                                                            <i class="fa fa-check"></i> Activate
                                                        </a>
                                                        <?php } ?>
                                                    <?php } else if($data['admin_active'] == "inactive" && $data['admin_password'] == ""){ ?>
                                                        <?php if($data['role_title'] == 'Developer' && $_SESSION['admin_role_name'] != 'Developer'){ ?>
                                                        <a href="javascript:void(0);" class="btn bg-maroon btn-xs btn-flat disable-state">
                                                            <i class="fa fa-envelope"></i> Resend Mail
                                                        </a>
                                                        <?php } else { ?>
                                                        <a href="javascript:void(0);" onclick="confirmResend('<?=$data['admin_id'];?>', '<?=correctDisplay($data['admin_name']);?>');" class="btn bg-maroon btn-xs btn-flat">
                                                            <i class="fa fa-envelope"></i> Resend Mail
                                                        </a>
                                                        <?php } ?>
                                                    
                                                    <?php } ?>
                                                <?php } else { ?>
                                                    <?php if($data['admin_active'] == "active" && $data['admin_password'] != ""){ ?>
                                                    <a href="javascript:void(0);" class="btn btn-danger btn-xs btn-flat disable-state">
                                                        <i class="fa fa-trash"></i> Deactive
                                                    </a>
                                                    <?php } else if($data['admin_active'] == "inactive" && $data['admin_password'] != ""){ ?>
                                                    <a href="javascript:void(0);" class="btn btn-success btn-xs btn-flat disable-state">
                                                        <i class="fa fa-check"></i> Activate
                                                    </a>
                                                    <?php } ?>
                                                <?php } ?>
                                                <?php } else { ?>
                                                    <?php if($data['admin_active'] == "active" && $data['admin_password'] != ""){ ?>
                                                    <a href="javascript:void(0);" class="btn btn-danger btn-xs btn-flat disable-state">
                                                        <i class="fa fa-trash"></i> Deactive
                                                    </a>
                                                    <?php } else if($data['admin_active'] == "inactive" && $data['admin_password'] != ""){ ?>
                                                    <a href="javascript:void(0);" class="btn btn-success btn-xs btn-flat disable-state">
                                                        <i class="fa fa-check"></i> Activate
                                                    </a>
                                                    <?php } ?>
                                                <?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 confirmDeactive(num, text){
            swal({
                title: "Are you sure Deactive this account?",
                text: "You will able activate this account later!",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "Deactive ! ",
                cancelButtonText: "Cancel !",
                closeOnConfirm: false,
                closeOnCancel: true
            },
            function (isConfirm) {
                if (isConfirm) {
                    window.location.href = "<?=$path['admin'];?>index.php?action=deactive&id="+num+"&title="+text;
                } else {
                    //nothing
                }
            });
        }
        function confirmActive(num, text){
            swal({
                title: "Are you sure Activate this account?",
                text: "",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#00a65a",
                confirmButtonText: "Activate ! ",
                cancelButtonText: "Cancel !",
                closeOnConfirm: false,
                closeOnCancel: true
            },
            function (isConfirm) {
                if (isConfirm) {
                    window.location.href = "<?=$path['admin'];?>index.php?action=active&id="+num+"&title="+text;
                } else {
                    //nothing
                }
            });
        }
        function confirmResend(num, text){
            swal({
                title: "Resend Mail Activation to This Account?",
                text: "",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#00a65a",
                confirmButtonText: "Resend ! ",
                cancelButtonText: "Cancel !",
                closeOnConfirm: false,
                closeOnCancel: true
            },
            function (isConfirm) {
                if (isConfirm) {
                    window.location.href = "<?=$path['admin'];?>index.php?action=resend&id="+num+"&title="+text;
                } else {
                    //nothing
                }
            });
        }
    </script>
</body>
</html>