<?php

session_start();
require_once('../database/config.php');
$usql = $conn->prepare("select * from loginusers WHERE username = ?");
$usql->execute([$_SESSION['username']]);
$userdata=$usql->fetch();

$disdata = null;
if ($userdata && isset($userdata['createby'])) {
    $dsql = $conn->prepare("select * from loginusers WHERE username = ?");
    $dsql->execute([$userdata['createby']]);
    $disdata=$dsql->fetch();
}

$supdata = null;
if ($disdata && isset($disdata['createby'])) {
    $ssql = $conn->prepare("select * from loginusers WHERE username = ?");
    $ssql->execute([$disdata['createby']]);
    $supdata=$ssql->fetch();
}

$wldata = null;
if ($supdata && isset($supdata['createby'])) {
    $wsql = $conn->prepare("select * from loginusers WHERE username = ?");
    $wsql->execute([$supdata['createby']]);
    $wldata = ($wsql->rowCount() > 0) ? $wsql->fetch() : null;
}


if(!isset($_SESSION['login_key']) || !isset($_SESSION['username']) ){
header("Location:auth-login.php"); 
echo '<script>
window.location = "auth-login.php"
</script>';  
}

if($userdata['usertype']=="wluser"){
if($userdata['id']==$webdata['users']){
}else{
echo '<script>
window.location = "logout.php"
</script>';    
}
}

// if($_SESSION['login_key'] != $userdata['login_key']){
//     session_destroy();
//     header('Location: index.php');
// }


$merchant_sql = $conn->prepare("SELECT * FROM add_merchant WHERE user = ?");
$merchant_sql->execute([$_SESSION['username']]);
$merchant_data = $merchant_sql->fetch(); // Fetch single row

$token = ($merchant_data && isset($merchant_data['access_token'])) ? $merchant_data['access_token'] : null;
$merchant_id = ($merchant_data && isset($merchant_data['merchant_id'])) ? $merchant_data['merchant_id'] : null;


// Generate CSRF token if it doesn't exist
if (empty($_SESSION['csrf_token'])) {
    $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}

?>


<!DOCTYPE html>
<html lang="en">

<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Home</title>
<!-- plugins:css -->
<link rel="stylesheet" href="../assets/vendors/mdi/css/materialdesignicons.min.css">
<link rel="stylesheet" href="../assets/vendors/base/vendor.bundle.base.css">
<!-- endinject -->
<!-- plugin css for this page -->
<link rel="stylesheet" href="../assets/vendors/datatables.net-bs4/dataTables.bootstrap4.css">
<!-- End plugin css for this page -->
<!-- inject:css -->
<link rel="stylesheet" href="../assets/css/style.css">
<!--<link rel="stylesheet" href="https://smartupi.in.net/panel/style.php?api_key=abc123">-->

<!--<link rel="stylesheet" href="https://smartupi.in.net/panel/materialdesignicons.min.css.php?api_key=abc123">-->
<!-- endinject -->
<link rel="shortcut icon" href="https://fastpay.us.cc/assets/logo/icon.png" />
  
  <!-- Include SweetAlert CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">

<!-- Include SweetAlert JS -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<script disable-devtool-auto="" src="https://cdn.jsdelivr.net/npm/disable-devtool@0.3.8/disable-devtool.min.js" data-url="https://www.google.com/"></script> 


</head>

<style>
/* Loader Styles */
.loader {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.9);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}

.loader img {
width: 100px;
height: 100px;
animation: spin 10s linear infinite;
}

@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}    
    
 @keyframes blink {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}

.blinking-badge {
font-size: 10px;
border-radius: 10px;
padding: 5px 10px;
background-color: #cf0e1e; /* Success color */
color: white;  /* Text color */
/* animation: blink 3s infinite; /* Apply blink animation */
}

</style>

<body>
    
<!-- Loader -->
<!--<div class="loader" id="loader">-->
<!--<img src="1480.gif" >-->
<!--</div>-->


<div class="container-scroller">
<!-- partial:partials/_navbar.html -->
<nav class="navbar col-lg-12 col-12 p-0 fixed-top d-flex flex-row">
<div class="navbar-brand-wrapper d-flex justify-content-center">
<div class="navbar-brand-inner-wrapper d-flex justify-content-between align-items-center w-100">  
<a class="navbar-brand brand-logo" href="index.php"><img src="../assets/logo/pay2inr.png" alt="logo"/></a>
<a class="navbar-brand brand-logo-mini" href="index.php"><img src="../assets/logo/pay2inr.png" alt="logo"/></a>

<button class="navbar-toggler navbar-toggler align-self-center" type="button" data-toggle="minimize">
<span class="mdi mdi-sort-variant"></span>
</button>
</div>  
</div>

<div class="navbar-menu-wrapper d-flex align-items-center justify-content-end ">
<ul class="navbar-nav mr-lg-4 w-100">
    
<li class="nav-item nav-search d-none d-lg-block w-100">
<marquee direction="left" scrollamount="5" onmouseover="this.stop();" onmouseout="this.start();" style="color:red;">
<?php echo $webdata['webnote']; ?>
</marquee>
</li>
</ul>

<ul class="navbar-nav navbar-nav-right">


    
   
          <li class="nav-item nav-profile dropdown">
            <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" id="profileDropdown">
              <img src="../assets/images/faces/face5.jpg" alt="profile"/>
              <span class="nav-profile-name"><?php echo strtoupper(!empty($userdata['owner_name']) ? $userdata['owner_name'] : $userdata['username']); ?></span>
            </a>
            <div class="dropdown-menu dropdown-menu-right navbar-dropdown" aria-labelledby="profileDropdown">
              <a class="dropdown-item" href="profile.php">
                <i class="mdi mdi-settings text-primary"></i>
               我的账户
              </a>
              <a class="dropdown-item" href="logout.php">
                <i class="mdi mdi-logout text-primary"></i>
                退出登录
              </a>
            </div>
          </li>
        </ul>
        <button class="navbar-toggler navbar-toggler-right d-lg-none align-self-center" type="button" data-toggle="offcanvas">
          <span class="mdi mdi-menu"></span>
        </button>
      </div>
    </nav>
    <!-- partial -->
    <div class="container-fluid page-body-wrapper">
      <!-- partial:partials/_sidebar.html -->
      <nav class="sidebar sidebar-offcanvas shadow" id="sidebar">
        <ul class="nav">
         <?php if ($userdata['usertype'] == "mainadmin") { ?>
          <li class="nav-item">
            <a class="nav-link" href="dashboard.php">
              <i class="mdi mdi-home menu-icon"></i>
              <span class="menu-title">首页 </span> <span class="badge badge-success" style="font-size: 10px; border-radius: 10px;">V 2.4</span>
            </a>
          </li>
		  <?php
         } else { ?>	  
          <li class="nav-item">
            <a class="nav-link" href="index.php">
              <i class="mdi mdi-home menu-icon"></i>
              <span class="menu-title">仪表板 </span>
            </a>
          </li>
          <?php } ?>
          
          <?php if ($userdata['usertype'] == "mainadmin" or $userdata['usertype'] == "wluser") { ?>
          <li class="nav-item">
            <a class="nav-link" data-toggle="collapse" href="#Users" aria-expanded="false" aria-controls="Users">
              <i class="mdi mdi-account-plus menu-icon"></i>
              <span class="menu-title">用户管理</span>
              <i class="menu-arrow"></i>
            </a>
            <div class="collapse" id="Users">
              <ul class="nav flex-column sub-menu">
                <?php if ($userdata['usertype'] == "mainadmin") { ?>
                <li class="nav-item"> <a class="nav-link" href="pending-users.php">待审核用户</a></li>
                 <?php } ?>
                <li class="nav-item"> <a class="nav-link" href="create-users.php">创建用户</a></li>
                <li class="nav-item"> <a class="nav-link" href="listof-users.php">用户列表</a></li>
                <?php if ($userdata['usertype'] == "mainadmin") { ?>
                <!--<li class="nav-item"> <a class="nav-link" href="white-label.php">Create White Label</a></li> -->
                <!--<li class="nav-item"> <a class="nav-link" href="list-white-label.php">List Of White Label</a></li>    -->
                 <?php } ?>

              </ul>
            </div>
          </li>
          <?php } ?>
          

           
          <?php if ($userdata['usertype'] == "mainadmin") { ?>
          <li class="nav-item">
            <a class="nav-link" href="manage-merchant.php">
              <i class="mdi mdi-bank menu-icon"></i>
              <span class="menu-title">商户管理</span>
            </a>
          </li>
          <?php } ?>
          
          <?php if ($userdata['usertype'] == "mainadmin") { ?>
          <li class="nav-item">
            <a class="nav-link" data-toggle="collapse" href="#Gateways" aria-expanded="false" aria-controls="Gateways">
              <i class="mdi mdi-swap-horizontal menu-icon"></i>
              <span class="menu-title">支付通道</span>
              <i class="menu-arrow"></i>
            </a>
            <div class="collapse" id="Gateways">
              <ul class="nav flex-column sub-menu">
                <li class="nav-item"> <a class="nav-link" href="upi-pool-management.php"> UPI池管理 </a></li>
                <!-- Future gateways can be added here -->
              </ul>
            </div>
          </li>
          <?php } ?>

          <li class="nav-item">
            <a class="nav-link" data-toggle="collapse" href="#Transactions" aria-expanded="false" aria-controls="Transactions">
              <i class="mdi mdi-view-headline menu-icon"></i>
              <span class="menu-title">交易管理</span>
              <i class="menu-arrow"></i>
            </a>
            <div class="collapse" id="Transactions">
              <ul class="nav flex-column sub-menu">
                <li class="nav-item"> <a class="nav-link" href="transactions.php"> 代收记录 </a></li>
                <li class="nav-item"> <a class="nav-link" href="payout-request.php"> 提现申请 </a></li>
                <li class="nav-item"> <a class="nav-link" href="payout-transactions.php"> 代付记录 </a></li>

                <li class="nav-item"> <a class="nav-link" href="callback-transactions.php"> 回调记录 </a></li>
                <?php if ($userdata['usertype'] == "mainadmin") { ?>
                <li class="nav-item"> <a class="nav-link" href="admin-payout-requests.php"> 代付审核 </a></li>
                <?php } ?>
              </ul>
            </div>
          </li>          


          

          

          
            
        <?php if ($userdata['usertype'] == "mainadmin") { ?>
          <li class="nav-item">
            <a class="nav-link" data-toggle="collapse" href="#Settings" aria-expanded="false" aria-controls="Settings">
              <i class="mdi mdi-settings menu-icon"></i>
              <span class="menu-title">网站设置</span>
              <i class="menu-arrow"></i>
            </a>
            <div class="collapse" id="Settings">
              <ul class="nav flex-column sub-menu">
                <li class="nav-item"> <a class="nav-link" href="notifications.php"> 通知管理 </a></li>
                <li class="nav-item"> <a class="nav-link" href="update-logo.php"> 上传Logo </a></li>
                <li class="nav-item"> <a class="nav-link" href="site-setting.php?type=update&siteid=<?php echo $webdata['id']; ?>"> 基础设置 </a></li>
                <li class="nav-item"> <a class="nav-link" href="upi-pool-management.php"> UPI设置 </a></li>
                <li class="nav-item"> <a class="nav-link" href="sms-api.php?type=update&siteid=<?php echo $webdata['id']; ?>"> 短信接口 </a></li>
                <li class="nav-item"> <a class="nav-link" href="cron-setting.php"> 计划任务 </a></li>

              </ul>
            </div>
          </li>
        <?php } ?>
        
          <li class="nav-item">
            <a class="nav-link" href="api-key.php">
              <i class="mdi mdi-file-document-box-outline menu-icon"></i>
              <span class="menu-title">API密钥</span>
            </a>
          </li>
          
            <li class="nav-item">
            <a class="nav-link" href="api-documentation.php">
              <i class="mdi mdi-file-document-box-outline menu-icon"></i>
              <span class="menu-title">API文档</span>
            </a>
          </li>
          
          <!--<li class="nav-item">-->
          <!--  <a class="nav-link" href="https://documenter.getpostman.com/view/28416396/2sAYkAPMrh">-->
          <!--    <i class="mdi mdi-code-braces  menu-icon"></i>-->
          <!--    <span class="menu-title">Postman Doc</span>-->
          <!--  </a>-->
          <!--</li>-->
          <!--<li class="nav-item">-->
          <!--  <a class="nav-link" href="https://wa.me/91<?php echo $webdata['webmob1'];?>">-->
          <!--    <i class="mdi mdi-whatsapp menu-icon"></i>-->
          <!--    <span class="menu-title">WhatsApp</span>-->
          <!--  </a>-->
          <!--</li>  -->
          <li class="nav-item">
            <a class="nav-link" href="logout.php">
              <i class="mdi mdi-power menu-icon"></i>
              <span class="menu-title">退出登录</span>
            </a>
          </li>                     
        </ul>
      </nav>
      <!-- partial -->
      
        <script>
  // Hide the loader when the page is fully loaded
window.onload = function() {
    const loader = document.getElementById('loader');
    loader.style.display = 'none';
};    
  </script>
  <!-- End custom js for this page-->