<?php
include("../../packages/require.php");
include("controller/controller_ppn.php");
$curpage = "ppn";
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title><?=$title['ppn'];?></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 PPN
                    <small>Editing your PPN</small>
                  </h1>
                  <ol class="breadcrumb">
                        <li><a href="<?=$path['dashboard'];?>"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li><a href="<?=$path['ppn'];?>"> PPN</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">Detail PPN</h3>
                            </div>
                            <div class="col-sm-6"></div>
                        </div>
                    </div>
                    <form name="form-edit" action="<?=$path['ppn'];?>?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-token">PPN *</label>
                                <?php if($acsp_edit == 1){ ?>
                                <div class="input-group">
                                    <input type="text" id="input-ppn" name="ppn" class="form-control" value="<?=$data[0]['ppn_value'];?>">
                                    <span class="input-group-addon">%</span>
                                </div>
                                <?php } else { ?>
                                <div class="input-group">
                                    <input type="text" id="input-ppn" name="ppn" class="form-control disable-input" value="<?=$data[0]['ppn_value'];?>">
                                    <span class="input-group-addon">%</span>
                                </div>
                                <?php } ?>
                                <div id="error-ppn" class="error-text"></div>
                            </div>
                        </div>
                        <!-- /.box-body -->
                        <div class="box-footer clearfix">
                            <div class="row">
                                <div class="col-sm-6 col-xs-12"></div>
                                <div class="col-sm-6 col-xs-12">
                                    <div class="text-right">
                                        <div class="btn-group">
                                            <?php if($acsp_edit == 1){ ?>
                                            <input type="hidden" value="<?=$data[0]['ppn_id'];?>" name="item_id">
                                            <button type="submit" class="btn btn-success">
                                                <i class="fa fa-save"></i> Save Data
                                            </button>
                                            <?php } ?>
                                        </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 } ?>
        });
        $("#btn-generate").click(function(){
            var new_code = makeid('25');
            $("#btn-generate").html("Loading...");
            $("#btn-generate").addClass("disable-state");
            setTimeout(function() {
            $("#input-token").val(new_code);
            $("#btn-generate").html("Generate Code");
            $("#btn-generate").removeClass("disable-state");
            }, 1000);
        });
        $("#btn-copy").click(function(){
            var copyText = document.getElementById("input-token");
            copyText.select();
            copyText.setSelectionRange(0, 99999)
            document.execCommand("copy");
            var alertText = "Success Copy API Token";
            successAlert(alertText);
        });
        function makeid(length) {
           var result           = '';
           var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
           var charactersLength = characters.length;
           for ( var i = 0; i < length; i++ ) {
              result += characters.charAt(Math.floor(Math.random() * charactersLength));
           }
           return result;
        }
        function validateForm(){
            var ppn = $("#input-ppn").val();
            var numFormat = /^\+?[\d+ ]*$/;
            
            if(ppn != ""){
                if(ppn.match(numFormat)){
                    $("#error-ppn").html("");
                    $("#error-ppn").hide();
                    $("#input-ppn").removeClass("input-error");
                } else {
                    $("#error-ppn").show();
                    $("#error-ppn").html("<i class='fa fa-warning'></i> Please input number only.");
                    $("#input-ppn").addClass("input-error");
                    $("#input-ppn").focus();
                    return false;
                }
            } else {
                $("#error-ppn").show();
                $("#error-ppn").html("<i class='fa fa-warning'></i> This field is required.");
                $("#input-ppn").addClass("input-error");
                $("#input-ppn").focus();
                return false;
            }
            return true;
        }
    </script>

</body>
</html>