<?php
	session_start();
	if($_SESSION['unohs'] == null){
		header("location:index.php?msg=unauthorized");
	}
?>
<?php
	include ("conn.php");
	
	if(isset($_POST['newupi'])){
		$upiid = mysqli_real_escape_string($conn, $_POST['newupi']);
		$sql_q = "INSERT INTO deyyamrici (maulya, sthiti) VALUES ('".$upiid."', '0')";
		$chk = mysqli_query($conn, $sql_q);
		if($chk){
			echo '<script type="text/JavaScript"> alert("USDT ID Added"); </script>';
		}else {echo '<script type="text/JavaScript"> alert("USDT ID Failed"); </script>';}
	}
	
	if(isset($_POST['upiid'])){
		$a_id = $_POST['upiid'];
		$sql_s = "SELECT * FROM deyyamrici WHERE maulya = '".$a_id."'";
		$run = mysqli_query($conn, $sql_s);
		//Set status to 0
		$sql_d = "SELECT * FROM deyyamrici WHERE sthiti = '1'";		
		$run_d = mysqli_query($conn, $sql_d);
		$rund_f = mysqli_fetch_array($run_d);
		$ch_s0 = "UPDATE deyyamrici SET sthiti='0' WHERE shonu='".$rund_f['shonu']."'";
		$exe_ch_s0 = mysqli_query($conn, $ch_s0);
		//Set status to 1
		$run_f = mysqli_fetch_array($run);
		$ch_s1 = "UPDATE deyyamrici SET sthiti='1' WHERE shonu='".$run_f['shonu']."'";
		$exe_ch_s1 = mysqli_query($conn, $ch_s1);
	}
?>
<?php include 'header.php'; ?>

      <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">Add USDT</h4>
            </div>
          </div> 
		  <div class="row">
			<form action="#" id="upiform" method="post" autocomplete="off">
				<div class="d-flex align-items-center">	
					<input name="newupi" type="text" placeholder="Add an USDT ID" class="flex-grow-1 cool-input" style="height: 40px;" />
				</div>
				<div class="d-flex align-items-center mt-3">
					<button type="submit" class="btn btn-primary cool-button mr-2">Add</button>
				</div>
			</form>
          </div>
		  <div class="row">
            <?php
				$sel_upi = "SELECT * FROM deyyamrici WHERE sthiti='0' OR sthiti='1'";
				$upi_r = mysqli_query($conn, $sel_upi);
			?>
				<form action="#" id="upisave" method="post" autocomplete="off">
			<?php	while ($row = mysqli_fetch_array($upi_r)) {
			?>
				<input name="upiid" type="radio" style="margin-top: 10px; margin-left:12px;" value="<?php echo $row['maulya']; ?>" <?php if($row['sthiti']==1){echo "checked";} ?> />
				<label for="<?php echo $row['maulya']; ?>"><?php echo $row['maulya']; ?></label>
				</br>
			<?php	}
			?>
				<button type="submit" class="btn btn-primary cool-button mr-2">Save</button>
				</form>
          </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 © 51gameplay.online 2024</span>
          </div>
        </footer> -->
      </div>
    </div>
  </div>
 
  <script>	
	if ( window.history.replaceState ) {
        window.history.replaceState( null, null, window.location.href );
    }
  </script>
</body>

</html>