<?php 
require('header.php');

$user_det=mysqli_query($conn,"select * from mul_ex_apis where userid='".$_SESSION['userid']."' and type='2'");
$get_info=mysqli_fetch_array($user_det);

?>

    <div class="content">
        <div class="py-4 px-3 px-md-4">
            <div class="card mb-3 mb-md-4">

                <div class="card-body">
                    <!-- Breadcrumb -->
                    <nav class="d-none d-md-block" aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item">
                                <a href="#">Settings</a>
                            </li>
                            <li class="breadcrumb-item active" aria-current="page">OKX API Settings</li>
                        </ol>
                    </nav>
                    <!-- End Breadcrumb -->

                    <div class="mb-3 mb-md-4 d-flex justify-content-between">
                        <div class="h3 mb-0">Update API settings</div>
                    </div>
                     <!-- Form -->
                    <div>
                        <form>
                            <?php
                             if(!empty($_SESSION['success']))
                            {
                                    ?>
                                    <div class="alert alert-success">
                                        <strong>Success!</strong> <?php echo $_SESSION['success'];?>
                                        </div>
                                    <?php 
                                    $_SESSION['success']='';

                            }
                            ?>
                            <div id="dis" class="err"></div>
                            <div class="form-row">
                                <div class="form-group col-12 col-md-12">
                                    <label for="name">API KEY</label>
                                    <input type="text" class="form-control" value="<?php echo $get_info['api_key'];?>" id="api_key" name="api_key" placeholder="API KEY">
                                    <div id="key_err" class="err"></div>
                                </div>
                                <div class="form-group col-12 col-md-12">
                                    <label for="email">API Secret</label>
                                    <input type="text" class="form-control" value="<?php echo $get_info['api_secret'];?>" id="api_secret" name="api_secret" placeholder="API Secret">
                                    <div id="secret_err" class="err"></div>
                                </div>

                                <div class="form-group col-12 col-md-12">
                                    <label for="email">API Password</label>
                                    <input type="text" class="form-control" value="<?php echo $get_info['password'];?>" id="api_pass" name="api_pass" placeholder="API Password">
                                    <div id="pass_err" class="err"></div>
                                </div>

                                <div class="form-group col-12 col-md-12">
                                    <label for="email">IP Address</label>
                                    <input type="text" class="form-control" value="<?php echo $_SERVER['SERVER_ADDR'];?>" id="ip_address" readonly name="ip_address" placeholder="User IP">
                                </div>
                            </div>
                           
                            <button type="button" class="btn btn-primary float-right" onclick="update_okx();">Update</button>
                        </form>
                    </div>
                    <!-- End Form -->
                </div>
            </div>


    
            <script>
                function update_okx()
                {
                    var api_key=$("#api_key").val();
                    var api_secret=$("#api_secret").val();
                    var api_pass=$("#api_pass").val();

                    $("#key_err").html('');
                    $("#secret_err").html('');
                    $("#pass_err").html('');

                    var flag=0;
                    if(api_key=='')
                    {
                        flag=1;
                        $("#key_err").html('Please Enter API KEY');
                    }
                    if(api_secret=='')
                    {
                        flag=1;
                        $("#secret_err").html('Please Enter API Secret');
                    }
                    if(api_pass=='')
                    {
                        flag=1;
                        $("#pass_err").html('Please Enter API Password');
                    }

                    if(flag!='1')
                    {

                        $("#dis").html('Please Wait Data Request Progressing...');
                        $.ajax({
                            type: "POST",
                            url: "okx_verify",
                            data:{api_key:api_key,api_secret:api_secret,api_pass:api_pass},
                            success: function(msg) {
                                var msg = msg.trim();
                                if(msg=='success')
                                {
                                    window.location='okx.php';
                                }
                                else
                                {
                                    $("#dis").html("<div class='alert alert-danger'><strong>Error !</strong>"+ msg +"</div>");
                                }
                            }
                        });

                    }
                }
            </script>
      <?php
      require('footer.php');
      ?>