<?php
include("../../packages/require.php");
include("controller/controller_access_detail.php");
$curpage = "access";
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title><?=$title['access'];?></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 Access
                    <small>Adding and editing your role access list</small>
                  </h1>
                  <ol class="breadcrumb">
                        <li><a href="<?=$path['dashboard'];?>"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li><a href="<?=$path['access'];?>">Role Access</a></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-sm-6">
                                <h3 class="box-title">Edit Data ( <?=correctDisplay($data[0]['access_title']);?> ) </h3>
                            </div>
                            <div class="col-sm-6">
                                <div class="text-right">
                                    <a href="#modal-password" data-toggle="modal" data-target="#modal-password" class="btn btn-info">
                                        <i class="fa fa-lock"></i> Change Password
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <form name="form-edit" action="module/access/edit.php?action=edit" enctype="multipart/form-data" method="post" onsubmit="return validateForm();">
                        <div class="box-body">
                            <div class="form-group" style="width: 500px;">
                                <label for="input-title">Title *</label>
                                <input type="text" class="form-control" name="title" id="input-title" placeholder="Title" value="<?=$data[0]['access_title'];?>">
                                <div id="error-title" class="error-text"></div>
                            </div>
                            <div class="form-group" style="width: 500px;">
                                <label for="input-slug">Slug *</label>
                                <input type="text" class="form-control" name="slug" id="input-slug" placeholder="Slug" value="<?=$data[0]['access_slug'];?>">
                                <div id="error-slug" class="error-text"></div>
                            </div>
                            <div class="form-group" style="width: 500px;">
                                <label for="input-module">Module *</label>
                                <select id="input-module" name="module" class="form-control">
                                    <option value="">-Choose Module-</option>
                                    <option value="general" <?php if($data[0]['access_module'] == 'general'){ ?> selected <?php } ?>>General</option>
                                    <option value="dashboard" <?php if($data[0]['access_module'] == 'dashboard'){ ?> selected <?php } ?>>Dashboard</option>
                                    <option value="po">PO</option>
                                    <option value="report" <?php if($data[0]['access_module'] == 'report'){ ?> selected <?php } ?>>Report</option>
                                    <option value="client" <?php if($data[0]['access_module'] == 'client'){ ?> selected <?php } ?>>Client</option>
                                    <option value="region" <?php if($data[0]['access_module'] == 'region'){ ?> selected <?php } ?>>Region</option>
                                    <option value="unit" <?php if($data[0]['access_module'] == 'unit'){ ?> selected <?php } ?>>Unit</option>
                                    <option value="ppn" <?php if($data[0]['access_module'] == 'ppn'){ ?> selected <?php } ?>>PPN</option>
                                    <option value="admin" <?php if($data[0]['access_module'] == 'admin'){ ?> selected <?php } ?>>Admin</option>
                                </select>
                                <div id="error-module" class="error-text"></div>
                            </div>
                        </div>
                        <!-- /.box-body -->
                        <div class="box-footer clearfix">
                            <div class="row">
                                <div class="col-sm-6 col-xs-6">
                                    <div class="text-left">
                                        <div class="btn-group">
                                            <a href="<?=$path['access'];?>" class="btn btn-default">
                                                <i class="fa fa-arrow-left"></i> Back
                                            </a>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-6 col-xs-6">
                                    <div class="text-right">
                                        <div class="btn-group">
                                            <input type="hidden" name="item_id" value="<?=$data[0]['access_id'];?>">
                                            <button type="submit" class="btn btn-success">
                                                <i class="fa fa-save"></i> Save Data
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- /.box-footer-->
                    </form>
                </div>
            </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 validateForm(){
            var title = $("#input-title").val();
            var modules = $("#input-module").val();

            if(title != ""){
                $("#error-title").html("");
                $("#error-title").hide();
                $("#input-title").removeClass("input-error");
            } else {
                $("#error-title").show();
                $("#error-title").html("<i class='fa fa-warning'></i> This field is required.");
                $("#input-title").addClass("input-error");
                $("#input-title").focus();
                return false;
            }
            if(modules != ""){
                $("#error-module").html("");
                $("#error-module").hide();
                $("#input-module").removeClass("input-error");
            } else {
                $("#error-module").show();
                $("#error-module").html("<i class='fa fa-warning'></i> This field is required.");
                $("#input-module").addClass("input-error");
                $("#input-module").focus();
                return false;
            }
        }
        //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>