<?php
include("../../packages/require.php");
include("controller/controller_role.php");
$curpage = "role";
?>
<!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 role list</small>
                  </h1>
                  <ol class="breadcrumb">
                        <li><a href="<?=$path['dashboard'];?>"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li><a href="<?=$path['role'];?>"> Role</a></li>
                  </ol>
            </section>

            <!-- Main content -->
            <section class="content">
                <!-- Default box -->
                <div class="box">
                    <div class="box-header with-border">
                        <h3 class="box-title">Add New Data</h3>
                    </div>
                    <form name="form-insert" action="<?=$path['role'];?>insert.php?action=add" enctype="multipart/form-data" method="post" onsubmit="return validateForm();">
                        <div class="box-body">
                            <div class="form-group" style="width: 500px;">
                                <label for="input-title">Role Title *</label>
                                <input type="text" class="form-control" name="title" id="input-title" placeholder="Title Address">
                                <div id="error-title" class="error-text"></div>
                            </div>
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered check_access">
                                    <thead>
                                        <tr>
                                            <th class="text-center">General</th>
                                            <th class="text-center">Dashboard</th>
                                            <th class="text-center">Admin</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>
                                                <?php if(is_array($data_general)){ foreach($data_general as $general){ ?>
                                                <div class="checkbox">
                                                    <label>
                                                        <input type="checkbox" name="access[]" value="<?=$general['access_id'];?>" data-slug="<?=$general['access_slug'];?>"> <?=$general['access_title'];?>
                                                    </label>
                                                </div>
                                                <?php } } ?>
                                            </td>
                                            <td>
                                                <?php if(is_array($data_dashboard)){ foreach($data_dashboard as $dashboard){ ?>
                                                <div class="checkbox">
                                                    <label>
                                                        <input type="checkbox" name="access[]" value="<?=$dashboard['access_id'];?>" data-slug="<?=$dashboard['access_slug'];?>"> <?=$dashboard['access_title'];?>
                                                    </label>
                                                </div>
                                                <?php } } ?>
                                            </td>
                                            <td>
                                                <?php if(is_array($data_admin)){ foreach($data_admin as $admins){ ?>
                                                <div class="checkbox">
                                                    <label>
                                                        <input type="checkbox" name="access[]" value="<?=$admins['access_id'];?>" data-slug="<?=$admins['access_slug'];?>"> <?=$admins['access_title'];?>
                                                    </label>
                                                </div>
                                                <?php } } ?>
                                            </td>
                                        </tr>
                                    </tbody>
                                    <thead>
                                        <tr>
                                            <th class="text-center">Purchase Order</th>
                                            <th class="text-center">Report</th>
                                            <th class="text-center">Client</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>
                                                <?php if(is_array($data_po)){ foreach($data_po as $po){ ?>
                                                <div class="checkbox">
                                                    <label>
                                                        <input type="checkbox" name="access[]" value="<?=$po['access_id'];?>" data-slug="<?=$po['access_slug'];?>"> <?=$po['access_title'];?>
                                                    </label>
                                                </div>
                                                <?php } } ?>
                                            </td>
                                            <td>
                                                <?php if(is_array($data_report)){ foreach($data_report as $report){ ?>
                                                <div class="checkbox">
                                                    <label>
                                                        <input type="checkbox" name="access[]" value="<?=$report['access_id'];?>" data-slug="<?=$report['access_slug'];?>"> <?=$report['access_title'];?>
                                                    </label>
                                                </div>
                                                <?php } } ?>
                                            </td>
                                            <td>
                                                <?php if(is_array($data_client)){ foreach($data_client as $client){ ?>
                                                <div class="checkbox">
                                                    <label>
                                                        <input type="checkbox" name="access[]" value="<?=$client['access_id'];?>" data-slug="<?=$client['access_slug'];?>"> <?=$client['access_title'];?>
                                                    </label>
                                                </div>
                                                <?php } } ?>
                                            </td>
                                        </tr>
                                    </tbody>
                                    <thead>
                                        <tr>
                                            <th class="text-center">Region</th>
                                            <th class="text-center">Unit</th>
                                            <th class="text-center">PPN</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>
                                                <?php if(is_array($data_region)){ foreach($data_region as $region){ ?>
                                                <div class="checkbox">
                                                    <label>
                                                        <input type="checkbox" name="access[]" value="<?=$region['access_id'];?>" data-slug="<?=$region['access_slug'];?>"> <?=$region['access_title'];?>
                                                    </label>
                                                </div>
                                                <?php } } ?>
                                            </td>
                                            <td>
                                                <?php if(is_array($data_unit)){ foreach($data_unit as $unit){ ?>
                                                <div class="checkbox">
                                                    <label>
                                                        <input type="checkbox" name="access[]" value="<?=$unit['access_id'];?>" data-slug="<?=$unit['access_slug'];?>"> <?=$unit['access_title'];?>
                                                    </label>
                                                </div>
                                                <?php } } ?>
                                            </td>
                                            <td>
                                                <?php if(is_array($data_ppn)){ foreach($data_ppn as $ppn){ ?>
                                                <div class="checkbox">
                                                    <label>
                                                        <input type="checkbox" name="access[]" value="<?=$ppn['access_id'];?>" data-slug="<?=$ppn['access_slug'];?>"> <?=$ppn['access_title'];?>
                                                    </label>
                                                </div>
                                                <?php } } ?>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <!-- /.box-body -->
                        <div class="box-footer clearfix">
                            <div class="row">
                                <div class="col-sm-6 col-xs-6">
                                    <div class="text-left">
                                        <a href="<?=$path['role'];?>" class="btn btn-default">
                                            <i class="fa fa-arrow-left"></i> Back
                                        </a>
                                    </div>
                                </div>
                                <div class="col-sm-6 col-xs-6">
                                    <div class="text-right">
                                        <div class="btn-group">
                                            <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">
        function validateForm(){
            var title = $("#input-title").val();
            var res_check = $(".check_access").find('input[type="checkbox"]:checked').length;
            //console.log(res_check);
            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(res_check > 0){
                //nothing
            } else {
                errorAlert("Atleast Select 1 Role Access");
                return false;
            }
            return true;
        }
    </script>
</body>
</html>