<?php
session_start();
require_once('includes/init.php');

if(!empty($_GET['cp']) && !empty($_GET['cge'])) {
    $_SESSION['cp'] = $_GET['cp'];
    $_SESSION['cge'] = $_GET['cge'];
}

if($_GET['app'] == 'main') {
 $_SESSION['main_app'] = "1";
}

$_SESSION['token'] = $_COOKIE['token'] ?? null;

if ( !isset($_SESSION['token']) ) {
 header('location: login.php?' . http_build_query($_GET));
}

$token = $_SESSION['token'];

$user_data = get_user_by_token($conn, $token);

$time = time()+50;

$res=mysqli_query($conn,"update users set onlineStatus=$time where mobile=".$user_data['mobile']);


if ( empty( $user_data ) ) header('location: login.php?' . http_build_query($_GET));
?>
<!DOCTYPE html>
<html>
<head>
 <title>Dashboard</title>
 <meta charset="utf-8">
 <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" type="text/css">
 <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=false">
 <link rel="stylesheet" href="css/style.css" >
 
 <link href="https://fonts.googleapis.com/css2?family=Hind+Siliguri:wght@500&display=swap" rel="stylesheet">
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <!-- modal 
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>-->
  <!-- SweetAlert2 -->
  <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>

 <!-- auto modal -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<style>
	
		<?php include 'css/custom-style.php' ?>
		#htw button {
		    border: none;
	        font-weight: bold;
	        border-radius: 5px;
	        padding: 5px;
	        height: 60px;
        	width: 240px;
	        color: white;
	        outline: none;
	        margin: 10px auto;
	        display: inline-block;
	        background: #4CAF50;
	        box-shadow: 1px 1px 1px 1px rgba(0,0,0,0.2);
		}
		
		       .user-card {
    width: 92%;
    max-width: 380px;
    margin: 15px auto;
    padding: 18px;
    background: linear-gradient(135deg,#2a2a72,#009ffd);
    border-radius: 18px;
    display: flex;
    align-items: center;
    gap: 15px;
    color: #fff;
    box-shadow: 0 8px 22px rgba(0,0,0,0.25);
}

.uc-photo img {
    width: 75px;
    height: 75px;
    border-radius: 50%;
    border: 3px solid #fff;
    object-fit: cover;
}

.uc-info {
    flex: 1;
}

.uc-name {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.uc-mobile {
    margin: 3px 0 10px 0;
    font-size: 14px;
    color: #e8e8e8;
}

.uc-balance {
    background: rgba(255,255,255,0.15);
    padding: 10px 12px;
    border-radius: 10px;
}

.uc-b-title {
    display: block;
    font-size: 13px;
    opacity: 0.9;
}

.uc-b-amount {
    margin-top: 3px;
    font-size: 18px;
    font-weight: 700;
}

	</style>

    <script src="test.js"></script>
</head>
<body class="bg-primary">
   <div class="">
    
    
        <div class="user-card">
    <div class="uc-photo">
        <img src="img/profile.png" alt="Profile">
    </div>

    <div class="uc-info">
        <h3 class="uc-name"><?= $fname ?></h3>
        <p class="uc-mobile"><?= $mobile ?></p>

        <div class="uc-balance">
            <span class="uc-b-title">Your Balance</span>
            <span class="uc-b-amount">💰 <?= $user_data['balance'] ?? '1000' ;?> ৳</span>
        </div>
    </div>
</div>

    
    
    
       <section class="block-header">
           <div class="title">
               
           </div>
       </section>   
       <section class="block-main">
           <?php if( $multi_task == 1 ) : ?><center>
           <div class="line1">
               <div onclick="location.href='<?= $task1_url ?? '#'?>'" class="item">
                   <i class="material-icons icons">filter_1</i> <br>
                   App 1
               </div>
               <div onclick="location.href='<?= $task2_url ?? '#'?>'" class="item">
                   <i class="material-icons icons">filter_2</i> <br>
                   App 2
               </div>
               
                <div onclick="location.href='<?= $task3_url ?? '#'?>'" class="item">
             
                   <i class="material-icons icons">filter_3</i> <br>
                   App 3
               </div>
               
           </div></center>
           <?php endif ?>
           
           <center>
           <div class="line1">
               <?php if( $multi_task != 1 ) : ?>
               <?php if( $spin == 1 ) : ?>
               <?php if ( $spin_enabled == 0 ) : ?>
               <div class="item">
                   <i class="material-icons icons">assistant</i> <br>
                   <span id="">Spin Closed!</span></div>
                <?php else : ?>
               <div id="vpn" onclick="Android.spinActivity()" class="item">
                   <i class="material-icons icons">assistant</i> <br>
                   <span id="off">Play Spin</span>
               </div>
               <?php endif ?>
               <?php endif ?>
               <?php if( $task == 1 ) : ?>
               <?php if ( $task_enabled == 0 ) : ?>
               <div class="item">
                   <i class="material-icons icons">assistant</i> <br>
                   <span id="">Task Closed!</span></div>
                <?php else : ?>
               <div id="vpn" onclick="showIpPopup('User Id: <?= $user_data['id'] ?>  Mobile: <?= $user_data['mobile'] ?>')" class="item">
                   <i class="material-icons iconss ">assistant</i> <br>
                   <span id="off">Monetag Task</span>
               </div>
               <?php endif ?>
               <?php endif ?>
               
               <?php else : ?>
               <div onclick="location.href='<?= $task4_url ?? '#'?>'" class="item">
             
                   <i class="material-icons icons">filter_4</i> <br>
                   App 4
               </div>
               <?php endif ?>
            
              <div onclick="location.href='<?= $htw_link ?? '#'?>'" class="item">
                
                   <i class="material-icons icons">video_library</i> <br>
                   Work Video
               </div>
              
              <div onclick="Android.openWebActivity('Leaderboard', 'leaderboard')" class="item">
                   <i class="material-icons icons">leaderboard</i> <br>
                   Top Users
               </div>
              
               
               
           </div></center><center>
            <div class="line1">
              <div onclick="Android.openWebActivity('Refer List', 'refer')" class="item">
                   <i class="material-icons icons">escalator_warning</i> <br>
                   Refer
                   </div>
               <div onclick="Android.openWebActivity('Wallet', 'wallet')" class="item">
                  <i class="material-icons icons">payments</i> <br>
                   Withdraw
               </div>
               <div onclick="Android.openWebActivity('Payment History', 'payments')" class="item">
                   <i class="material-icons icons">history</i> <br>
                   History
               </div>
           </div></center>
           <center>
            <div class="line1">
               <div type="button" data-toggle="modal" data-target="#myModal" class="item">
                   <i class="material-icons icons">notifications</i> <br>
                   Notice
                   </div>
               <div onclick="location.href='<?= $tg_channel ?>'" class="item">
                   <i class="material-icons icons">campaign</i> <br>
                   Channel
               </div>
               <div onclick="location.href='<?= $support_group ?>'" class="item">
                   <i class="material-icons icons">support</i> <br>
                   Support
               </div>
           </div></center>
       </section>
       <?php include 'developer.php'; ?>
   </div>
<br>

<!--Home Notice Modal -->

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog modal-sm" role="document">
   <div class="modal-content">
    <div class="modal-body">
     <p class="lead">
  <?= nl2br( text2link($home_notice) ) ?></p>
    </div>
    <div class="modal-footer">
     <p class="btn btn-dialog" data-dismiss="modal" style="font-family: 'Hind Siliguri', sans-serif;text-align: left; color : black  ">Close</p>
     
    </div>
   </div>
  </div>
 </div>
 

<!--Button Notice Modal -->

<div class="modal fade" id="newModal" tabindex="-1" role="dialog">
  <div class="modal-dialog modal-sm" role="document">
   <div class="modal-content">
    <div class="modal-body">
     <p class="lead">
  <?= nl2br( text2link($important_notice) ) ?></p>
   </div>
    <div class="modal-footer">
     <p class="btn btn-dialog" data-dismiss="modal" style="font-family: 'Hind Siliguri', sans-serif;text-align: left; color : black  ">Close</p>
     
    </div>
   </div>
  </div>
 </div>




<?php if( $user_data['i_click'] > $invalid_limit ) : ?><script>Android.blockAlert(2)</script><?php endif ?>
<?php if($user_data['today_click'] == 0 || $user_data['today_spin'] == 0)  : ?>
<script>
$(document).ready(function(){
    $("#newModal").modal("show");  
});
</script>
<?php endif ?>

 
 <script type="text/javascript">
  $(document).ready(function() {
   setInterval(function () {
    $('#userData').load('user-data.php')
   }, 4000);
   
  });
  Android.setUserAccount("<?= base64_encode($token) ?>");
  
<!-- </script>-->
<!--     <?php if( $req_vpn == 1 ) : ?>-->
<!--      <script> -->
<!--     let allowedLocations = "<?= $cn_list ?>";-->

<!--$.get("https://ipinfo.io?token=<?= $ip_key ?>", function(response) {-->
<!--  if(!allowedLocations.includes(response.country)) {-->
<!--    $('#vpn').prop("onclick", null).off("click");-->
<!--    $('#off').html('Connect VPN');-->
   
<!--  };-->
<!--}, "jsonp")-->
<!--     </script>-->
     
     
     <?php endif ?>
     
     <?php if( $user_data['d_bonus'] == 1) :?>
     <script>
        $(document).on('click', '#d_succes', function(e) {
   swal.fire(
    'Sorry!',
    'Already Claimed!',
    'error'
   )
  });

     </script>
     
     <?php else :?>  
     <script type="text/javascript">
        $(document).ready(function(){
            $("#d_succes").click(function(){

                    swal.fire({title:'Bonus', 
                        text:'Do you want to collect daily bonus?', 
                        icon:'warning', 
                        buttons: true, 
                        dangerMode: true,
                        allowOutsideClick: false
                    })
                    .then((willOUT) => {
                            if (willOUT) {
                                  window.location.href = 'dbtf.php', {
                                  icon: 'success',
                                }
                              }
                    });

            });
        });
    </script>
    
    <?php endif ?> 
    <script>
        $(document).on('click', '#htw', function(e) {
   swal.fire(
    'Opps!',
    'How to Work linked not Available!',
    'error'
   )
  });

     </script>

  
<script>
  function updateUserStatus(){
   jQuery.ajax({
    url:'update_user_status.php',
    success:function(){
     
    }
   });
  }
  
  setInterval(function(){
   updateUserStatus();
  },3000);
        
   </script>


     
</body>
</html>