<?php
session_start();
@$userKey = $_SESSION['loginKey'];

if($userKey == "")
{
    echo "<script>window.open('login.php','_self')</script>";
}


include "control/activity.php";
$dd = new activity();


$table = "userdetails";
$condition = " where userKey='$userKey'";
$getuserdetails = $dd->single($table,$condition);
$daily_task = $getuserdetails['daily_task'];



$table = "admin_calculation";
$condition = null;
$getAdminDetails = $dd->single($table,$condition);
$task_1 = $getAdminDetails['task_1'];
$task_2 = $getAdminDetails['task_2'];
$task_3 = $getAdminDetails['task_3'];

$date = date("d/m/Y");


$table = "account_history";
$condition = " where userKey='$userKey' AND action_date like '%$date%'";
$getBetValue = $dd->fetch_multi($table,$condition);
foreach($getBetValue as $key){
    if($key->game_name == "k3"){
        $aammntA += $key->amount;
    }
    
    if($key->game_name == "Wingo"){
        $aammntB += $key->amount;
    }
}
$riningBetA = $getBetValue['data'][0];


$riningBet = $aammntA+$aammntB;
?>


<!DOCTYPE html>
<html lang="en" translate="no">
<head>
    <meta charset="UTF-8">
    <link rel="icon" type="image/svg+xml" href="./images/h5setting_20230808033047vpbk.ico">
    <meta name="google" content="notranslate">
    <meta name="robots" content="noindex,nofollow">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title><?= $getAdminDetails['title']; ?></title>
    <link rel="stylesheet" href="css/slick.css" />
    <link rel="stylesheet" href="css/modules.css" />
    <link rel="stylesheet" href="css/style.css" />
    <script src="js/jquery.min.js" type="text/javascript"></script>
    <script src="js/slick.min.js" type="text/javascript"></script>
    <script src="js/main.js" type="text/javascript"></script>
</head>
<body>
    <div id="app">
        <div class="dailySignIn__container">
            
            <div class="navbar">
                <div class="navbar-fixed" style="background: linear-gradient(90deg, rgb(206, 2, 4) 0%, rgb(242, 64, 58) 100%);">
                    <div class="navbar__content">
                        <div data-v-905dfe8c="" class="navbar__content-left"><!----></div>
                        <div class="navbar__content-center">
                            <div data-v-905dfe8c="" class="headLogo" style="background-image: url(./temp_img/<?= $dashboard_img; ?>);"></div>
                            <div data-v-905dfe8c="" class="navbar__content-title"></div>
                        </div>
                        <div data-v-905dfe8c="" class="navbar__content-right"></div>
                    </div>
                </div>
            </div>

            <!-- tast Banner -->
            <div class="task-banner">
                <div class="task_banner_iner">
                    <img data-v-ffac18b4="" data-src="images/present-360b680e.png" src="images/present-360b680e.png" lazy="loaded">
                    <div class="banner_content">
                        <div data-v-ffac18b4="" class="banner-title">Activity Award</div>
                        <div class="banner-content">
                            <div data-v-ffac18b4="">Complete weekly/daily tasks to receive rich rewards</div>
                            <div data-v-ffac18b4="">Weekly rewards cannot be accumulated to the next week, and daily rewards cannot be accumulated to the next day.</div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- task-panel -->
            <div class="task-panel">
                
                <?php
                   $cmnt = "Daily mission";
                   $table = "DailyMission";
                   $condition = null;
                   $getFullDetails = $dd->fetch_multi($table,$condition);
                   foreach($getFullDetails as $key){
                ?>
                
                
                <div class="task-item">
                    <div class="task-item-header">
                        <div data-v-ffac18b4="" class="hearder-status day"><?= $cmnt; ?></div>
                        <span data-v-ffac18b4="" class="headerR"><?php if($riningBet > $key->winAmount){echo "Finish";}else{ echo "Unfinished"; } ?></span>
                    </div>
                    <div class="task-item-type">
                        <div data-v-ffac18b4="" class="type-title weeklyType3"><div data-v-ffac18b4="">Daily betting bonus </div></div>
                        <div data-v-ffac18b4="" class="type-tip"><?= round($riningBet,2); ?>/<?= $key->winAmount; ?></div>
                    </div>
                    <div data-v-ffac18b4="" class="task-item-description">Daily betting bonus </div>
                    <div class="task-item-bottom">
                        <div data-v-ffac18b4="">Award amount</div>
                        <div class="bottom-title">
                            <img data-v-ffac18b4="" data-src="images/amountIcon-b2c8faab.png" src="images/amountIcon-b2c8faab.png" lazy="loaded">
                            <span data-v-ffac18b4="">₹<?= $key->awardAmount; ?></span>
                        </div>
                    </div> 
                    <div data-v-ffac18b4="" onclick='getToCheckCompleate("<?= $riningBet; ?>","<?= $key->winAmount; ?>","<?= $key->awardAmount; ?>")' class="btn btnOther status1">to complete</div>       
                </div>
                
                <?php } ?>
                
                
            </div>
            
        

        </div>
    </div>
    <?php include "footer.php"; ?>
</body>

</html>



<script>
    function getToCheckCompleate(a,b,c)
    {
       var runAmnt = parseInt(a);
       var winAmnt = parseInt(b);
       var famount = parseInt(c);
       
       if(runAmnt >= winAmnt)
       {
            if(<?= $daily_task; ?> < famount)
            {
                getRequestToRcvdThisAmount(a,b,c);
            }
            else{
                alert('Already Excute');
            }
           
       }else{
           alert('Not completed');
       }
    }
    
    
    
    
    function getRequestToRcvdThisAmount(a,b,c)
    {
            const xhttp = new XMLHttpRequest();
            xhttp.onload = function() {
            var demo_show = this.responseText;
            const myArr = JSON.parse(demo_show);
            if(myArr.status == "success")
            {
                alert(myArr.remark);
                window.open('?','_self');
            }
            else{
                alert(myArr.remark);
            }
            }
            xhttp.open("GET", "betIncentive.php?runing="+a+"&rcvdAmount="+b+"&rcvdBet="+c+"&userKey="+<?= $userKey; ?>);
            xhttp.send();
        
        
    }
</script>