<?php 
session_start();
include 'conn_auth.php';
include 'customInfo.php';
include 'outputfunction.php';
if($rowUser['acct_nmb'] == ""){
header("location:login?fd=invalid");
}


 
function clean($str) {
global $conn;
    $str = @trim($str);
    if (get_magic_quotes_gpc()) {
        $str = stripslashes($str);
    }
    return $conn->real_escape_string($str);
}

// Assign profile photo 
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Dashboard - Connex Credit Union Secure Platform</title>
    <!-- Favicon icon -->
  <link rel="icon" type="image/png" sizes="16x16" href="webimg/fav-icon.png">
  <!-- Pignose Calender -->
    <link href="mz/plugins/pg-calendar/css/pignose.calendar.min.css" rel="stylesheet">
    <!-- Chartist -->
    <link rel="stylesheet" href="mz/plugins/chartist/css/chartist.min.css">
    <link rel="stylesheet" href="mz/plugins/chartist-plugin-tooltips/css/chartist-plugin-tooltip.css">
    <!-- Custom Stylesheet -->
    <link href="mz/plugins/toastr/css/toastr.min.css" rel="stylesheet">
    <link href="mz/css/style.css"  rel="stylesheet">
    <link href="mz/css/xtrastyle.css" rel="stylesheet">
</head>

<body>

    <!--*******************
        Preloader end
    ********************-->

    
    <!--**********************************
        Main wrapper start
    ***********************************-->
    <div id="main-wrapper">

         <?php include 'user_header.php'; ?>
        <!--**********************************
            Header end ti-comment-alt
        ***********************************-->

        <!--**********************************
            Sidebar start
        ***********************************-->
         <?php include 'user_sidebar.php'; ?>
        <!--**********************************
            Sidebar end
        ***********************************-->

        <!--**********************************
            Content body start
        ***********************************-->
        <div class="content-body">

            <div class="container-fluid mt-3">
                <div class="row">
                    <div class="col-lg-12 col-sm-12">
                        <div class="card dashbrdcolor">
                            <div class="card-body">
                                <h3 class="card-title text-white">
                                  <?php 
                //    $ipdata =  file_get_contents("https://api.myip.com");
                //  $dataArray = json_decode($ipdata, true); 
                // $userip = $dataArray["ip"];
                // $usercountry = $dataArray["country"];                                   
                   //echo '<span class="cnt-ip">IP: ' . $userip . '</span>';
                   //echo '<span class="cnt-ip">Country: ' . $usercountry . '</span>' ;  
                               ?>
                                </h3>
                                <div class="d-inline-block">
                                    <p class="text-white mb-0"><?php echo date("F - d Y"); ?></p>

                                    <h2 class="text-white"><?php echo $rowUser['cust_name']; ?></h2>
                                    <h5>Acc No: <?php echo $rowUser['acct_nmb'] == "" ? "Nill" : $rowUser['acct_nmb']; ?></h5> 
                                    <h6> <?php echo $rowUser['accnt_type'] == "" ? "Nill" : $rowUser['accnt_type']; ?></h6>

                                </div>
                                <span class="float-right display-5">
                                    
                                    <img src="<?php echo $profile_src; ?>" id="profilimg" />
                                    
                                </span>
                            </div>
                        </div>
                    </div>
                </div>

              

                   <div class="container-fluid">
                <div class="row">
                    <div class="col">
                        <div class="card">
                            <div class="card-body">
                              <div class="card-db-item">
                                <h4><?php echo $rowUser['accnt_type'] == "" ? "Nill" : $rowUser['accnt_type']; ?></h4>
                                <h3>Account No:</h3>
                                <span><?php echo $rowUser['acct_nmb'] == "" ? "Nill" : $rowUser['acct_nmb']; ?></span>
                              </div>
                            </div>
                        </div>
                    </div>
                     <div class="col">
                        <div class="card">
                            <div class="card-body">
                              <div class="card-tr-item">
                                <h4>Account Bal: </h4>
                                <h3><?php echo getCurrency(@$rowcurr['curr_type']).number_format(getBalance(@$rowUser['acct_nmb']), 2, '.', ','); ?></h3>
                                <div class="xtra-info-card">
                                   <span>Last Transaction Date</span>
                                   <h4><?php echo $trans_date =="Nill" ? "Nill": date(" l d, M Y ", strtotime($trans_date)); ?></h4> 
                                </div>
                                
                              </div>
                            </div>
                        </div>
                    </div>
                    <div class="col">
                        <div class="card">
                            <div class="card-body">
                              <div class="log-card-item">
                                <div class="cd-img-container">
                                  <span><img src="webimg/inter-transfer-icon.png"></span>
                                  <span><h4>Send Fund(s) to other account</h4> </span>
                                </div>
                                
                                 <a href="inter-bank-transfer">Start New transfer</a>
                              </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


<div class="container-fluid">
                <div class="row">
                    <div class="col">
                        <div class="card">
                            <div class="card-body">
                                <h4 class="card-title">Recent Transaction</h4>
                                <div class="table-responsive">
                                         <?php 
                            $selBank = $conn->query("select * from credit_info where accnt_nmb = '" . $rowUser['acct_nmb'] . "'  order by transact_id DESC") or die($conn->error);                     
                                          ?>
                                    <table class="table header-border">
                                        <thead>
                                            <tr>
                                                <th>Date</th>
                                                <th>Recipient Name</th>
                                                <th>Transaction Type</th>
                                                <th>Narration </th>
                                                <th>Amount</th>
                                                <th>Balance</th>
                                                
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php 
                                            if(!$selBank->num_rows){
                                            ?>
                                            <tr>
                                                <td colspan="6">No transaction has been done in this account</td>
                                            </tr>       
                                            <?php                                                                  
                                            }else{
                                            $rowDetails = $selBank->fetch_assoc(); 
                                            $amtTrans = $rowDetails['amt_cred'] == 0 ? $rowDetails['amt_dep'] : $rowDetails['amt_cred'];
                                             ?>
                                            <tr>
                                                <td><?php echo $rowDetails['dat_pay']; ?></td>
                                                <td><?php echo $rowDetails['payee_name']; ?></td>
                                                <td><?php echo  $rowDetails['amt_cred'] == 0 ? "Debit" : "Credit";  ?></td>
                                                <td><?php echo $rowDetails['narratn']; ?></td>
                                                <td><?php echo getCurrency(@$rowcurr['curr_type']). number_format($amtTrans, 2, '.', ','); ?></td>
                                                <td><?php echo getCurrency(@$rowcurr['curr_type']).number_format(getBalance($rowUser['acct_nmb']), 2, '.', ','); ?></td>
                                            </tr>
                                            <?php
                                            }
                                            ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
              </div>
            </div>
            <!-- #/ container -->
        </div>
        <!--**********************************
            Content body end
        ***********************************-->
        
        
        <!--**********************************
            Footer start
        ***********************************-->
       <?php include 'dashboard_footer.php'; ?>
        <!--**********************************
            Footer end
        ***********************************-->
    </div>
    <!--**********************************
        Main wrapper end
    ***********************************-->

    <!--**********************************
        Scripts
    ***********************************-->

  <script src="mz/plugins/common/common.min.js"></script>
    <script src="mz/js/custom.min.js"></script>
    <script src="mz/js/settings.js"></script>
    <script src="mz/js/gleek.js"></script>
    <script src="mz/js/styleSwitcher.js"></script>

    <!-- Chartjs -->
    <script src="mz/plugins/chart.js/Chart.bundle.min.js"></script>
    <!-- Circle progress -->
    <script src="mz/plugins/circle-progress/circle-progress.min.js"></script>
    <!-- Datamap -->
    <script src="mz/plugins/d3v3/index.js"></script>
    <script src="mz/plugins/topojson/topojson.min.js"></script>
    <script src="mz/plugins/datamaps/datamaps.world.min.js"></script>
    <!-- Morrisjs -->
    <script src="mz/plugins/raphael/raphael.min.js"></script>
    <script src="mz/plugins/morris/morris.min.js"></script>
    <!-- Pignose Calender -->
    <script src="mz/plugins/moment/moment.min.js"></script>
    <script src="mz/plugins/pg-calendar/js/pignose.calendar.min.js"></script>
    <!-- ChartistJS -->
    <script src="mz/plugins/chartist/js/chartist.min.js"></script>
    <script src="mz/plugins/chartist-plugin-tooltips/js/chartist-plugin-tooltip.min.js"></script>



    <script src="mz/js/dashboard/dashboard-1.js"></script>
     <script src="mz/plugins/toastr/js/toastr.min.js"></script>
    <script>
//       $.getJSON("https://api.nordvpn.com/server", function(data) {
//   var addresses = $.map(data, (d) => d.ip_address);
//   // Display all NordVPN addresses in the console
//   console.log(addresses);
// })

   $(document).ready(function(){
    let currnBal = "Your current balance is <?php echo getCurrency(@$rowcurr['curr_type']).number_format(getBalance(@$rowUser['acct_nmb']), 2, '.', ','); ?>"
    toastr.success(currnBal,{positionClass:"toast-top-full-width",timeOut:5e3,closeButton:!0,debug:!1,newestOnTop:!0,progressBar:!0,preventDuplicates:!0,onclick:null,showDuration:"300",hideDuration:"1000",extendedTimeOut:"1000",showEasing:"swing",hideEasing:"linear",showMethod:"fadeIn",hideMethod:"fadeOut",tapToDismiss:!1})
   })
    </script>
</body>

</html>