<?php
    include("headfile.php");
?>
<!DOCTYPE html>
<html lang="zxx" class="js">

<head>
    <meta charset="utf-8">
    <meta name="author" content="Eagle Winks">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="@@page-discription">
    <!-- Fav Icon  -->
    <link rel="shortcut icon" href="images/favicon.png">
    <!-- Page Title  -->
    <title>My Profile | Eagle Winks Cash Flow</title>
    <!-- StyleSheets  -->
    <link rel="stylesheet" href="css/dashlite.css?ver=1.4.0">
    <link id="skin-default" rel="stylesheet" href="css/theme.css?ver=1.4.0">
</head>

<body class="nk-body npc-crypto has-sidebar has-sidebar-fat ui-clean ">
    <div class="nk-app-root">
        <!-- main @s -->
        <div class="nk-main ">
            <!-- sidebar @s -->
            <?php 
            include("nav.php");
            ?>
            <!-- sidebar @e -->
            <!-- wrap @s -->
            <div class="nk-wrap ">
                <!-- main header @s -->
                 <?php 
            include("header.php");
            ?>
                <!-- main header @e -->
                <!-- content @s -->
                <div class="nk-content nk-content-fluid">
                    <div class="container-xl wide-lg">
                        <div class="nk-content-body">
                            <div class="nk-block-head">
                                <div class="nk-block-head-content">
                                    <div class="nk-block-head-sub"><span>Account Setting</span></div>
                                    <h2 class="nk-block-title fw-normal">My Profile</h2>
                                    <div class="nk-block-des">
                                        <p>You have full control to manage your own account setting. <p>
                                    </div>
                                </div>
                            </div><!-- .nk-block-head -->
                            <ul class="nk-nav nav nav-tabs">
                                <li class="nav-item">
                                    <a class="nav-link" href="#">Personal Details</a>
                                </li>
                               
                            </ul><!-- .nk-menu -->
                            <!-- NK-Block @s -->
                            <div class="nk-block">
                             <!--   <div class="alert alert-warning">
                                    <div class="alert-cta flex-wrap flex-md-nowrap">
                                        <div class="alert-text">
                                            <p>Activate Your Eagle Winks Cash Flow Account To Earn Unlimited Referral Bonus.</p>
                                        </div>
                                        <ul class="alert-actions gx-3 mt-3 mb-1 my-md-0">
                                           
                                            <li>
                                                <a href="../about" class="link link-primary">Learn More</a>
                                            </li>
                                        </ul>
                                    </div>
                                </div><!-- .alert -->
                                <div class="nk-block-head">
                                    <div class="nk-block-head-content">
                                        <h5 class="nk-block-title">Personal Information</h5>
                                        <div class="nk-block-des">
                                            <p>Basic info, like your name , that you use on Eagle Winks.</p>
                                        </div>
                                    </div>
                                </div><!-- .nk-block-head -->
                                <div class="nk-data data-list">
                                    <div class="data-head">
                                        <h6 class="overline-title">Basic Info</h6>
                                    </div>
                                    <div class="data-item" data-toggle="modal" data-target="#profile-edit">
                                        <div class="data-col">
                                            <span class="data-label">Full Name</span>
                                            <span class="data-value"><?php echo ucfirst($fname);?></span>
                                        </div>
                                        <div class="data-col data-col-end"><span class="data-more"><em class="icon ni ni-forward-ios"></em></span></div>
                                    </div><!-- .data-item -->
                                    
                                    <div class="data-item">
                                        <div class="data-col">
                                            <span class="data-label">Email</span>
                                            <span class="data-value"><?php echo ucfirst($email);?></span>
                                        </div>
                                        <div class="data-col data-col-end"><span class="data-more disable"><em class="icon ni ni-lock-alt"></em></span></div>
                                    </div><!-- .data-item -->
                                    <div class="data-item" data-toggle="modal" data-target="#profile-edit">
                                        <div class="data-col">
                                            <span class="data-label">Phone Number</span>
                                            <span class="data-value text-soft"><?php echo ucfirst($phone);?></span>
                                        </div>
                                        <div class="data-col data-col-end"><span class="data-more"><em class="icon ni ni-forward-ios"></em></span></div>
                                    </div><!-- .data-item -->
                                    <div class="data-item" data-toggle="modal" data-target="#profile-edit">
                                        <div class="data-col">
                                            <span class="data-label">Date of Birth</span>
                                            <span class="data-value"><?php echo ucfirst($dateob);?></span>
                                        </div>
                                        <div class="data-col data-col-end"><span class="data-more"><em class="icon ni ni-forward-ios"></em></span></div>
                                    </div>
                                    <!-- 
                                    <div class="data-item" data-toggle="modal" data-target="#profile-edit" data-tab-target="#address">
                                        <div class="data-col">
                                            <span class="data-label">Address</span>
                                            <span class="data-value">2337 Kildeer Drive,<br>Kentucky, Canada</span>
                                        </div>
                                        <div class="data-col data-col-end"><span class="data-more"><em class="icon ni ni-forward-ios"></em></span></div>
                                    </div>
                                    data-item -->
                                </div><!-- .nk-data -->
                              
                               </div>
                            <!-- NK-Block @e -->
                            
                            <!-- .nk-data -->
                                <div class="nk-data data-list" id="bankdets">
                                    <div class="data-head">
                                        <h6 class="overline-title">Bank Details</h6>
                                    </div>
                                    <div class="data-item">
                                        <div class="data-col">
                                            <span class="data-label">Bank Name</span>
                                            <span class="data-value">
                                            <?php
                                                if($bank_names == ''){
                                                    echo 'N/A';
                                                }else{
                                                    echo $bank_names;
                                                }
                                            ?>
                                            </span>
                                        </div>
                                        <div class="data-col data-col-end"><a href="#" data-toggle="modal" data-target="#profile-edit" data-tab-target="#bank" class="link link-primary">Change </a></div>
                                    </div><!-- .data-item -->
                                    <div class="data-item">
                                        <div class="data-col">
                                            <span class="data-label">Account Name</span>
                                            <span class="data-value">
                                                <?php
                                                    if($act_names == ''){
                                                        echo 'N/A';
                                                    }else{
                                                        echo $act_names;
                                                    }
                                                ?>
                                            </span>
                                        </div>
                                        <div class="data-col data-col-end"><a href="#" data-toggle="modal" data-target="#profile-edit" data-tab-target="#bank" class="link link-primary">Change</a></div>
                                    </div><!-- .data-item -->
                                    <div class="data-item">
                                        <div class="data-col">
                                            <span class="data-label">Account Number</span>
                                            <span class="data-value">
                                                <?php
                                                    if($ac_numbers == ''){
                                                        echo 'N/A';
                                                    }else{
                                                        echo $ac_numbers;
                                                    }
                                                ?>
                                            </span>
                                        </div>
                                        <div class="data-col data-col-end"><a href="#" data-toggle="modal" data-target="#profile-edit" data-tab-target="#bank" class="link link-primary">Change</a></div>
                                    </div><!-- .data-item -->
                                </div><!-- .nk-data -->
                            <!-- //  Content End -->
                        </div>
                    </div>
                </div>
                <!-- content @e -->
                <!-- footer @s -->
                  <?php 
            include("footer.php");
            ?>
                <!-- footer @e -->
            </div>
            <!-- wrap @e -->
        </div>
        <!-- main @e -->
    </div>
    <!-- app-root @e -->
    <!-- @@ Profile Edit Modal @e -->
    <div class="modal fade" tabindex="-1" role="dialog" id="profile-edit">
        <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
            <div class="modal-content">
                <a href="#" class="close" data-dismiss="modal"><em class="icon ni ni-cross-sm"></em></a>
                <div class="modal-body modal-body-lg">
                    <h5 class="title">Update Profile</h5>
                    <div id="msg"></div>
                    <ul class="nk-nav nav nav-tabs">
                        <li class="nav-item">
                            <a class="nav-link active" data-toggle="tab" href="#personal">Personal</a>
                        </li>
                        <!--
                        <li class="nav-item">
                            <a class="nav-link" data-toggle="tab" href="#address">Address</a>
                        </li>-->
                         <li class="nav-item">
                            <a class="nav-link" data-toggle="tab" href="#bank">Bank Details</a>
                        </li>
                    </ul><!-- .nav-tabs -->
                    <div class="tab-content">
                        <div class="tab-pane active" id="personal">
                            <div class="row gy-4">
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <label class="form-label" for="full-name">Full Name</label>
                                        <input type="text" class="form-control form-control-lg" id="full-name" value="<?php echo ucfirst($fname);?>" placeholder="Enter Full name">
                                    </div>
                                </div>
                               
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="form-label" for="phone-no">Phone Number</label>
                                        <input type="text" class="form-control form-control-lg" id="phone_no" value="<?php echo ucfirst($phone);?>" placeholder="Phone Number">
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="form-label" for="birth-day">Date of Birth</label>
                                        <input type="date" class="form-control form-control-lg" id="dob" value="<?php echo ucfirst($dateob);?>" placeholder="Enter your BirthDay">
                                    </div>
                                </div>
                                <div class="col-12">
                                    <ul class="align-center flex-wrap flex-sm-nowrap gx-4 gy-2">
                                        <li>
                                            <button class="btn btn-lg btn-primary" id="prof1">Update Profile</button>
                                        </li>
                                        <li>
                                            <a href="#" data-dismiss="modal" class="link link-light">Cancel</a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <!--
                        <div class="tab-pane" id="address">
                            <div class="row gy-4">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="form-label" for="address-l1">Address Line 1</label>
                                        <input type="text" class="form-control form-control-lg" id="address-l1" value="">
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="form-label" for="address-l2">Address Line 2</label>
                                        <input type="text" class="form-control form-control-lg" id="address-l2" value="">
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="form-label" for="address-st">State</label>
                                        <input type="text" class="form-control form-control-lg" id="address-st" value="Kentucky">
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="form-label" for="address-county">Country</label>
                                        <select class="form-select" id="address-county" data-ui="lg">
                                            <option>Nigeria</option>
                                            <option>Ghana</option
                                            <option>Kenya</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-12">
                                    <ul class="align-center flex-wrap flex-sm-nowrap gx-4 gy-2">
                                        <li>
                                            <a href="#" class="btn btn-lg btn-primary">Update Address</a>
                                        </li>
                                        <li>
                                            <a href="#" data-dismiss="modal" class="link link-light">Cancel</a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                         -->
                        
                        <!-- .tab-pane -->
                        <div class="tab-pane" id="bank">
                            <?php
                                    if(isset($_POST['sub_acct'])){
                                        $ac_name = $_POST['account_name'];
                                        $bankcode = $_POST['bankcode'];
                                        $ac_number = $_POST['account_number'];
                                        
                                        $rt = $conn->query("SELECT * FROM `banks` WHERE `code`='$bankcode'");
                                        $rowsp = mysqli_fetch_array($rt);
                                        $bankname = $rowsp['name'];
                                        
                                        $sel = $conn->query("SELECT * FROM `bank_details` WHERE `code`='$code'");
                                        if(mysqli_num_rows($sel) >=1){
                                            $ins = $conn->query("UPDATE `bank_details` SET `bank_name`='$bankname',`acct_num`='$ac_number',`bank_code`='$bankcode', `ac_name`='$ac_name', `r_code`='' WHERE `code`='$code'");
                                        }else{
                                            $ins = $conn->query("INSERT INTO `bank_details`(`id`, `code`, `bank_name`, `acct_num`, `bank_code`, `ac_name`) VALUES (NULL,'$code','$bankname','$ac_number','$bankcode', '$ac_name')");
                                        
                                        }
                                        
                                        if($ins == true){
                                            echo '
                                                <script>
                                                alert("Account Details Updated")
                                                </script>
                                            ';
                                            echo '
                                                <script>
                                                window.location = ""
                                                </script>
                                            ';
                                        }else{
                                            echo '
                                                <script>
                                                alert("Try Again")
                                                </script>
                                            ';
                                            echo '
                                                <script>
                                                window.location = ""
                                                </script>
                                            ';
                                        }
                                        
                                    }
                                ?>
                            <div class="row gy-4">
                                
                                
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="form-label" for="bank-nam">Account Number</label>
                                            <input type="number" class="form-control form-control-lg" id="account_number" name="account_number" value="" required/>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="form-label" for="bank-nam">Bank Name</label>
                                            <select id="bnc" name="" class="form-control" required="required">
                                                        <option value="">--Select Bank Name--</option>
                                                        <?php
                                                            $cs = $conn->query("SELECT * FROM `banks`");
                                                            while($row = mysqli_fetch_array($cs)){
                                                                $bank = $row['name'];
                                                                $bank_code = $row['code'];
                                                                
                                                                echo '<option value="'.$bank_code.'">'.$bank.'</option>';
                                                            }
                                                        ?>
                                                    </select>
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div id="wait_bank"></div>
                                    </div>
                                   
                                   
                                    <div class="col-12">
                                        <ul class="align-center flex-wrap flex-sm-nowrap gx-4 gy-2">
                                            <li>
                                                
                                            </li>
                                            <li>
                                                <a href="#" data-dismiss="modal" class="link link-light">Close</a>
                                            </li>
                                        </ul>
                                    </div>
                                
                                
                            </div>
                        </div>
                        <!-- .tab-pane -->
                    </div><!-- .tab-content -->
                </div><!-- .modal-body -->
            </div><!-- .modal-content -->
        </div><!-- .modal-dialog -->
    </div><!-- .modal -->
    <!-- JavaScript -->
    <script src="js/bundle.js?ver=1.4.0"></script>
    <script src="js/scripts.js?ver=1.4.0"></script>
    <script src="js/charts/chart-crypto.js?ver=1.4.0"></script>
    <script>
        $("#prof1").on('click', function(){
        	var phone = $('#phone_no').val();
        	var dob = $('#dob').val();
        	var email = "<?php echo $email?>";
        	var dataString = "phone="+phone+'&dob='+dob+'&email='+email;
            $.ajax({
                url: 'update_phone',
                method: 'post',
                data: dataString,
                success: function (data) {
                  // the transaction status is in response.data.status
                  
                  if(data == 'success'){
                      $("#msg").html('<div class="alert alert-success"><i class="fa fa-user"></i><b>Data updated was successful</b></div>');
                      //alert("");
                      setTimeout(function(){
                          window.location = './';
                      }, 2000);
                      
                  }else{
                      $("#msg").html('<div class="alert alert-success"><i class="fa fa-user"></i><b>Try Again</b></div>');
                  }
                }
            });
        });
    </script>
    
                                <script>
                                   $('#bnc').on('change', function(){
                                       $("#wait_bank").html('<div style="width: 100%; text-align: center;"><img src="ajax-loader-big.gif"><br><span style="color: #00f;">Verifying Account..</span></div>');
                                       var banks = $("#bnc").val();
                                       var account_num = $("#account_number").val();
                                       var code = "<?php echo $code?>";
                                       
                                       if(account_num.length  < 10){
                                           $("#wait_bank").html('<div class="alert alert-danger"><i class="fa fa-user"></i><b>Account number should be 10 Digits</b></div>');
                                       }else if(account_num.length  > 10){
                                           $("#wait_bank").html('<div class="alert alert-danger"><i class="fa fa-user"></i><b>Account number should be 10 Digits</b></div>');
                                       }else{
                                               var dataString = "banks="+banks+'&account_num='+account_num;
                                                $.ajax({
                                                    url: 'verify_account',
                                                    method: 'post',
                                                    data: dataString,
                                                    success: function (data) {
                                                      $("#wait_bank").html(data);
                                                    }
                                                });
                                       }
                                       
                                       
                                       
                                       
                                       
                                   });
                               </script>
                               
                               <script>
                                   $('#account_number').on('keyup', function(){
                                       $("#wait_bank").html('<div style="width: 100%; text-align: center;"><img src="ajax-loader-big.gif"><br><span style="color: #00f;">Verifying Account..</span></div>');
                                       var banks = $("#bnc").val();
                                       var account_num = $("#account_number").val();
                                       var code = "<?php echo $code?>";
                                       
                                       if(account_num.length  < 10){
                                           $("#wait_bank").html('<div class="alert alert-danger"><em class="icon ni ni-shield-star-fill"></em><b>Account number should be 10 Digits</b></div>');
                                       }else if(account_num.length  > 10){
                                           $("#wait_bank").html('<div class="alert alert-danger"><em class="icon ni ni-shield-star-fill"></em><b>Account number should be 10 Digits</b></div>');
                                       }else if(banks  == ''){
                                           $("#wait_bank").html('<div class="alert alert-danger"><em class="icon ni ni-shield-star-fill"></em><b>Please Select Bank Name</b></div>');
                                       }else{
                                               var dataString = "banks="+banks+'&account_num='+account_num;
                                                $.ajax({
                                                    url: 'verify_account',
                                                    method: 'post',
                                                    data: dataString,
                                                    success: function (data) {
                                                      $("#wait_bank").html(data);
                                                    }
                                                });
                                       }
                                       
                                       
                                       
                                       
                                       
                                   });
                               </script>
</body>

</html>