<?php
	session_start();
	if($_SESSION['unohs'] == null){
		header("location:index.php?msg=unauthorized");
	}
?>
<?php
	include ("conn.php");
?>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>Dashboard</title>
  <link rel="stylesheet" href="vendors/mdi/css/materialdesignicons.min.css">
  <link rel="stylesheet" href="vendors/feather/feather.css">
  <link rel="stylesheet" href="vendors/base/vendor.bundle.base.css">
  <link rel="stylesheet" href="vendors/flag-icon-css/css/flag-icon.min.css"/>
  <link rel="stylesheet" href="vendors/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="vendors/jquery-bar-rating/fontawesome-stars-o.css">
  <link rel="stylesheet" href="vendors/jquery-bar-rating/fontawesome-stars.css">
  <link rel="stylesheet" href="css/style.css">
  <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">
  <link rel="stylesheet" href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.min.css">
  <link rel="stylesheet" href="https://cdn.datatables.net/fixedheader/3.2.3/css/fixedHeader.dataTables.min.css">
  <link rel="shortcut icon" href="images/favicon.png" />
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Sora:wght@600;700;800&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@500;600&display=swap">
  <style>
	.cool-input {
        border: 2px solid #007bff;
        border-radius: 0.25rem;
        padding: 0.5rem 1rem;
        font-size: 1rem;
        transition: all 0.3s ease;
    }
    .cool-input:focus {
        border-color: #0056b3;
        box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    }
    .cool-input::placeholder {
        color: #6c757d;
        opacity: 1;
    }
	.cool-button {
        padding: 0.5rem 1rem;
        font-size: 1rem;
        border-radius: 0.25rem;
        transition: all 0.3s ease;
    }
    .cool-button:hover {
        background-color: #0056b3;
        color: #fff;
    }
    .cool-button.btn-secondary:hover {
        background-color: #343a40;
        color: #fff;
    }
	#copied{
		visibility: hidden;
		z-index: 1;
		position: fixed;
		bottom: 50%;
		background-color: #333;
		color: #fff;
		border-radius: 6px;
		padding: 16px;
		max-width: 250px;
		font-size: 17px;
	}	   
	#copied.show {
		visibility: visible;
		-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
		animation: fadein 0.5s, fadeout 0.5s 2.5s;
	}

	/* ══════════════════════════════════════════════════════════
	   PREMIUM DEPOSIT TABLES — Dark Navy / Gold Fintech Theme
	   (একই Token System যা Withdraw Accept/Reject Page-এ আছে)
	   ══════════════════════════════════════════════════════════ */
	:root{
		--dp-bg-deep:#100B22;
		--dp-panel:#1B1633;
		--dp-panel-2:#221A44;
		--dp-border:rgba(245,197,66,0.22);
		--dp-gold:#F5C542;
		--dp-gold-soft:#E9C77A;
		--dp-text:#EFEBFB;
		--dp-text-muted:#9691B8;
		--dp-emerald:#22C58B;
		--dp-emerald-deep:#159A6B;
		--dp-coral:#F75676;
		--dp-coral-deep:#D63A58;
	}
	.content-wrapper{ background:var(--dp-bg-deep); }
	.dp-section{
		background:linear-gradient(165deg, var(--dp-panel) 0%, var(--dp-bg-deep) 100%);
		border:1px solid var(--dp-border);
		border-radius:18px;
		padding:24px 24px 8px;
		margin-top:10px;
		box-shadow:0 20px 50px -25px rgba(0,0,0,0.6);
	}
	.dp-section-head{
		display:flex;
		align-items:center;
		gap:10px;
		margin-bottom:18px;
	}
	.dp-section-icon{
		width:34px; height:34px;
		border-radius:10px;
		display:flex; align-items:center; justify-content:center;
		font-size:16px;
		background:rgba(245,197,66,0.14);
		border:1px solid rgba(245,197,66,0.3);
	}
	.dp-section-title{
		font-family:'Sora',sans-serif;
		font-weight:700;
		font-size:18px;
		color:var(--dp-text);
		margin:0;
		letter-spacing:-0.01em;
	}
	.dp-section-sub{
		font-family:'Inter',sans-serif;
		font-size:12px;
		color:var(--dp-text-muted);
		margin:2px 0 0;
	}

	.dp-section table.dataTable{
		font-family:'Inter',sans-serif;
		color:var(--dp-text);
		border-collapse:separate !important;
		border-spacing:0;
	}
	.dp-section table.dataTable thead th{
		font-family:'Inter',sans-serif;
		font-size:11px;
		letter-spacing:.08em;
		text-transform:uppercase;
		color:var(--dp-gold-soft);
		background:rgba(245,197,66,0.06);
		border-bottom:1px solid rgba(245,197,66,0.25) !important;
		border-top:none !important;
		padding:12px 14px !important;
		white-space:nowrap;
	}
	.dp-section table.dataTable tbody td{
		font-size:13.5px;
		padding:13px 14px !important;
		border-bottom:1px dashed rgba(150,145,184,0.16) !important;
		border-top:none !important;
		vertical-align:middle;
	}
	.dp-section table.dataTable tbody tr:hover{
		background:rgba(245,197,66,0.05) !important;
	}
	.dp-section table.dataTable.table-striped tbody tr:nth-of-type(odd){
		background:rgba(255,255,255,0.015);
	}
	.dp-mono{ font-family:'JetBrains Mono',monospace; font-size:12.5px; color:var(--dp-text); }
	.dp-amount{ font-family:'Sora',sans-serif; font-weight:700; color:var(--dp-gold); font-size:15px; }
	.dp-uid{ font-family:'JetBrains Mono',monospace; color:var(--dp-text-muted); }

	.dp-btn{
		font-family:'Inter',sans-serif;
		font-weight:600;
		font-size:12.5px;
		padding:8px 16px;
		border-radius:9px;
		border:none;
		cursor:pointer;
		display:inline-flex;
		align-items:center;
		gap:6px;
		transition:transform .12s ease;
		margin-bottom:6px;
	}
	.dp-btn:hover{ transform:translateY(-1px); }
	.dp-btn-approve{
		background:linear-gradient(180deg, var(--dp-emerald) 0%, var(--dp-emerald-deep) 100%);
		color:#06251A;
		box-shadow:0 8px 18px -8px rgba(34,197,139,0.55);
	}
	.dp-btn-reject{
		background:linear-gradient(180deg, var(--dp-coral) 0%, var(--dp-coral-deep) 100%);
		color:#2B0510;
		box-shadow:0 8px 18px -8px rgba(247,86,118,0.5);
	}

	/* DataTables-এর নিজস্ব Controls (Search/Length/Pagination) */
	.dp-section .dataTables_wrapper{ color:var(--dp-text-muted); font-family:'Inter',sans-serif; font-size:13px; }
	.dp-section .dataTables_filter input,
	.dp-section .dataTables_length select{
		background:var(--dp-panel-2);
		border:1px solid rgba(245,197,66,0.25);
		border-radius:8px;
		color:var(--dp-text);
		padding:5px 10px;
	}
	.dp-section .dataTables_filter input:focus,
	.dp-section .dataTables_length select:focus{ outline:none; border-color:var(--dp-gold); }
	.dp-section .dataTables_paginate .paginate_button{
		font-family:'Inter',sans-serif;
		color:var(--dp-text-muted) !important;
		border-radius:8px !important;
		border:1px solid transparent !important;
		margin:0 2px;
	}
	.dp-section .dataTables_paginate .paginate_button.current{
		background:rgba(245,197,66,0.16) !important;
		border:1px solid rgba(245,197,66,0.35) !important;
		color:var(--dp-gold) !important;
	}
	.dp-section .dataTables_paginate .paginate_button:hover{
		background:rgba(245,197,66,0.08) !important;
		color:var(--dp-gold) !important;
	}
	.dp-section .dataTables_info{ color:var(--dp-text-muted); }
  </style>
</head>
<body>
  <div class="container-scroller">
    <nav class="navbar col-lg-12 col-12 p-0 fixed-top d-flex flex-row">
      <div class="text-center navbar-brand-wrapper d-flex align-items-center justify-content-center">
        <a class="navbar-brand brand-logo" href="dashboard.php"><img src="images/logo.png" alt="logo"/></a>
        <a class="navbar-brand brand-logo-mini" href="dashboard.php"><img src="images/logo-mini.png" alt="logo"/></a>
      </div>
      <div class="navbar-menu-wrapper d-flex align-items-center justify-content-end">
        <button class="navbar-toggler navbar-toggler align-self-center" type="button" data-toggle="minimize">
          <span class="icon-menu"></span>
        </button>       
        <ul class="navbar-nav navbar-nav-right">           
          <li class="nav-item dropdown d-flex mr-4 ">
            <a class="nav-link count-indicator dropdown-toggle d-flex align-items-center justify-content-center" id="notificationDropdown" href="#" data-toggle="dropdown">
              <i class="icon-cog"></i>
            </a>
            <div class="dropdown-menu dropdown-menu-right navbar-dropdown preview-list" aria-labelledby="notificationDropdown">
              <p class="mb-0 font-weight-normal float-left dropdown-header">Settings</p>              
              <a class="dropdown-item preview-item" href="logout.php">
                  <i class="icon-inbox"></i> Logout
              </a>
            </div>
          </li>
        </ul>
        <button class="navbar-toggler navbar-toggler-right d-lg-none align-self-center" type="button" data-toggle="offcanvas">
          <span class="icon-menu"></span>
        </button>
      </div>
    </nav>
    <div class="container-fluid page-body-wrapper">
      <nav class="sidebar sidebar-offcanvas" id="sidebar">
        <div class="user-profile">
          <div class="user-image">
            <img src="images/faces/face28.png">
          </div>
          <div class="user-name">
              bigdelhi
          </div>
          <div class="user-designation">
              Admin
          </div>
        </div>
        <?php include 'compass.php';?>
      </nav>
      <div class="main-panel">
        <div class="content-wrapper">
          <div class="row">
            <div class="col-sm-12 mb-4 mb-xl-0">
              <h4 class="font-weight-bold text-dark">Deposit Update</h4>
            </div>
          </div> 		  		  		  			
		  <div class="row">
            <div class="col-sm-12"> 
				<div class="dp-section">
				  <div class="dp-section-head">
					<div class="dp-section-icon">⏳</div>
					<div>
						<h4 class="dp-section-title">Pending Deposits</h4>
						<p class="dp-section-sub">Approve করুন বা Reject করুন — Approve করলে User Wallet বাড়বে এবং System Coin কমবে</p>
					</div>
				  </div>
				  <div class="table-responsive">
					<table id="gameSpots" class="table table-striped table-bordered" style="width:100%">
						<thead>
							<tr>
								<th>#</th>
								<th>User ID</th>
								<th>Mobile</th>
								<th>Reference Number</th>
								<th>Amount</th>
	                          	<th>Order ID</th>
								<th>Date</th>
								<th>Action</th>											 
							</tr>
						</thead>
						<tbody>
							<?php
								$sqq = mysqli_query($conn, "SELECT * FROM `thevani` WHERE `sthiti` = '0' ORDER BY `shonu` DESC");
								$i = 0;
								while ($row = mysqli_fetch_array($sqq)) {
								$i = $i + 1;
							?>
							<tr class="<?php echo $row['shonu'];?>">
								<td><?php echo $i;?></td>
								<td class="dp-uid">#<?php echo $row['balakedara'];?></td>
								<td class="dp-mono"><?php echo $row['duravani'];?></td>
								<td class="dp-mono"><?php echo $row['ullekha'];?></td>
								<td class="dp-amount">৳<?php echo number_format($row['motta'],2);?></td>
	                          	<td class="dp-mono"><?php echo $row['dharavahi'];?></td>
								<td><?php echo date('d M Y, h:i A', strtotime($row['dinankavannuracisi']));?></td>
								<td>
									<form id="<?php echo 'app'.$row['shonu'];?>" class="approval-form">
										<input type="hidden" name="uid" value="<?php echo $row['balakedara'];?>">
										<input type="hidden" name="amount" value="<?php echo $row['motta'];?>">
										<input type="hidden" name="date" value="<?php echo $row['dinankavannuracisi'];?>"><!--Added-->
										<input type="hidden" name="sid" value="<?php echo $row['shonu'];?>"><!--Added-->
										<input type="hidden" name="ref_num" value="<?php echo $row['ullekha'];?>">
										<input type="hidden" name="app" value="Approve Payment">
										<button class="dp-btn dp-btn-approve" type="submit" name="approve">✓ Approve</button>
									</form>
									<form id="<?php echo 'rej'.$row['shonu'];?>" class="reject-form">
										<input type="hidden" name="uid" value="<?php echo $row['balakedara'];?>">
										<input type="hidden" name="amount" value="<?php echo $row['motta'];?>">
										<input type="hidden" name="date" value="<?php echo $row['dinankavannuracisi'];?>"><!--Added-->
										<input type="hidden" name="sid" value="<?php echo $row['shonu'];?>"><!--Added-->
										<input type="hidden" name="ref_num" value="<?php echo $row['ullekha'];?>">
										<input type="hidden" name="rej" value="Reject Payment">
										<button class="dp-btn dp-btn-reject" type="submit" name="reject">✕ Reject</button>
									</form>
								</td>
							   
							</tr>            
							<?php 
								}
							?>                   
						</tbody>
					</table>
				  </div>
				</div>
            </div>			
          </div>
		  <div class="row">
            <div class="col-sm-12">
				<div class="dp-section">
				  <div class="dp-section-head">
					<div class="dp-section-icon">✓</div>
					<div>
						<h4 class="dp-section-title">Completed Deposits</h4>
						<p class="dp-section-sub">আগে Approve হয়ে যাওয়া সব Deposit-এর History</p>
					</div>
				  </div>
				  <div class="table-responsive">
					<table id="dep_comp" class="table table-striped table-bordered" style="width:100%">
						<thead>
                            <tr>
                                <th>#</th>
                                <th>User ID</th>
                                <th>Mobile</th>
                                <th>Reference Number</th>
                                <th>Amount</th>
                              	<th>Order ID</th>
                                <th>Date</th>
                            </tr>
                        </thead>
                        <tbody>
                                              
                        </tbody>
					</table>
				  </div>
				</div>
			</div>
		  </div>
		</div>
		<footer class="footer">
			<div class="d-sm-flex justify-content-center justify-content-sm-between">
				<span class="text-muted d-block text-center text-sm-left d-sm-inline-block">Copyright © cv111.site 2024</span>
			</div>
		</footer>
      </div>     
    </div>
  </div>
  <script src="vendors/base/vendor.bundle.base.js"></script>
  <script src="js/off-canvas.js"></script>
  <script src="js/hoverable-collapse.js"></script>
  <script src="js/template.js"></script>
  <script src="vendors/chart.js/Chart.min.js"></script>
  <script src="vendors/jquery-bar-rating/jquery.barrating.min.js"></script>
  <script src="js/dashboard.js"></script>
  <script src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>
  <script>	
	document.querySelectorAll('.approval-form').forEach(function(form) {
		form.addEventListener('submit', function(e) {
			e.preventDefault();

			var formData = new FormData(this);
			var xhr = new XMLHttpRequest();
			xhr.open('POST', 'admin_deposit_req.php', true);

			xhr.onload = function() {
				if (xhr.status >= 200 && xhr.status < 400) {
					var arr = xhr.responseText.split('~');
					if (arr[0] == 1) {
						document.getElementsByClassName(arr[1])[0].style.display = 'none';
						$('#dep_comp').DataTable().ajax.reload();
					} else {
						/* ✅ FIX — আগে শুধু code '2'-এ Generic "Error" Alert
						   দেখাতো, বাকি সব Code (যেমন '3~Insufficient System
						   Balance...') সম্পূর্ণ Silent থাকতো, কিছুই দেখাতো না।
						   এখন Server যা Message পাঠায় সেটাই দেখাবে। */
						alert(arr[1] || "Error");
					}
				}
			};

			xhr.onerror = function() {
				alert("Error");
			};

			xhr.send(formData);
		});
	});
	
	document.querySelectorAll('.reject-form').forEach(function(form) {
		form.addEventListener('submit', function(e) {
			e.preventDefault();

			var formData = new FormData(this);
			var xhr = new XMLHttpRequest();
			xhr.open('POST', 'admin_deposit_req.php', true);

			xhr.onload = function() {
				if (xhr.status >= 200 && xhr.status < 400) {
					var arr = xhr.responseText.split('~');
					if (arr[0] == 1) {
						document.getElementsByClassName(arr[1])[0].style.display = 'none';
					} else if (arr[0] == 2) {
						alert("Error");
					}
				}
			};

			xhr.onerror = function() {
				alert("Error");
			};

			xhr.send(formData);
		});
	});
	
	$(document).ready(function() {
		$('#gameSpots').DataTable({
			"searching": true
			});
			
		$('#dep_comp').DataTable({
			"processing": true,
			"serverSide": true,
			"ajax": "deposit_update_approve.php",
			"paging": true,
			"lengthChange": true,
			"searching": true,
			"ordering": true,
			"info": true,
			"autoWidth": true,
			"pageLength": 10
			});
	} );
	
	if ( window.history.replaceState ) {
		window.history.replaceState( null, null, window.location.href );
	}
  </script>
</body>

</html>