<?php
@session_start();
include "control/activity.php";

 $dd = new activity();
 $loginStatus = $_SESSION['loginDetails'];


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



  $table = "admin_calculation";
  $condition = null;
  $getAdminDetails = $dd->single($table,$condition);
  

  @$iid = $_REQUEST['game'];
  $table = "wingo_game_runing";
  $condition = " where game_number='$iid'";
  $getK3Result = $dd->single($table,$condition);
  @$mResult = $getK3Result['manual_result'];
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title><?= $getAdminDetails['title']; ?></title>
</head>
<body>

    <div class="main" id="main">
		  <?php include "menu.php"; ?>
    <div class="right"> 
  <div class="tab-content">


   <?php include "headermenu.php"; ?>


        <!-- Overview -->
         <div id="overview" class="tab-pane active"  >
                <div class="content" >
                  
               <div class="content-wrapper">
                 <div class="container-fluid">

                      <!--======================================================  Content  ====================================================-->                                            
                          <ol class="breadcrumb">
                            <li class="breadcrumb-item">
                              <a href="dashboard.php">CUSTOM RESULT</a>
                            </li>
                          </ol>

                          <div class="row">
                              <div class="col-xl-12 col-sm-12 mb-12">
                                  <input type="radio" id="gamesActivation1" onclick="getLottryActivity('1')" name="selectLottry"> Wingo Lottry
                                  <input type="radio" id="gamesActivation2" onclick="getLottryActivity('2')" name="selectLottry" style="margin-left:20px;"> K3 Lottry
                                  <input type="radio" id="gamesActivation3" onclick="getLottryActivity('3')" name="selectLottry" style="margin-left:20px;"> D5 Lottry
                                 
                                  <?php if(@$_REQUEST['iid'] == "1"){ ?>
                                  <table class="table table-bordered data-table" style="margin-top:30px;">
                                    <tr>
                                        <th colspan="5px"> <input onclick="selectGameType('1')" type="radio" name="k3games" id="gameType1" /> 1min WinGo  
                                                           <input onclick="selectGameType('2')" type="radio" name="k3games" id="gameType2" style="margin-left:30px;"/> 3min WinGo
                                                           <input onclick="selectGameType('3')" type="radio" name="k3games" id="gameType3" style="margin-left:30px;"/> 5min WinGo
                                                           <input onclick="selectGameType('4')" type="radio" name="k3games" id="gameType4" style="margin-left:30px;"/> 10min WinGo
                                                        

                                                           <font style="float:right; margin-right:30px;">Manul Result : <?= $mResult; ?></font>
                                                        </th>
                                    </tr>
                                    <tr>
                                        <td colspan="6px"><font color="red">Note* : Small Number 0-4 || Big number Start From 5-9</font></td>
                                    </tr>
                                    <tr>
                                        <th>Sr</th>
                                        <th>Periods</th>
                                        <th>Selected Number</th>
                                        <th>Bet Amount</th>
                                        <th>Win Amount</th>
                                        <th>Action</th>
                                    </tr>   

                                    <?php
                                     $gmnumber = $_REQUEST['game'];
                                    
                                    $table = "wingo_game_runing";
                                    $condition = " where game_number='$gmnumber'";
                                    $getRuningDetails = $dd->single($table,$condition);
                                    $prds = $getRuningDetails['periods'];


                                     $allNumber = "0,1,2,3,4,5,6,7,8,9,small,big,red,violet,green";
                                     $getToArray = explode(",",$allNumber);
                                     for($i=0; $i < count($getToArray); $i++)
                                     {

                                        $num = $getToArray[$i];
                                       



                                        if($getRuningDetails['manual_bet'] == $i){
                                            $clr = "#96E8E2";
                                        }else{
                                            $clr = null;
                                        }


                                        if($num == "small")
                                        {
                                             $table = "wingo_order_details";
                                            $condition = " where select_number='small' AND game_number='$gmnumber' AND status='pending'";
                                            $clm = "winAmount";
                                            $getWinSum = $dd->getSum($table,$clm,$condition);

                                            $clm = "amount";
                                            $getAmountSum = $dd->getSum($table,$clm,$condition);
                                        
                                           @ $smallWinAmount = $getWinSum['data'][0];
                                           @ $smallamount = $getAmountSum['data'][0];
                                        }


                                        if($num == "big")
                                        {
                                            $table = "wingo_order_details";
                                            $condition = " where select_number='big' AND game_number='$gmnumber' AND status='pending'";
                                            $clm = "winAmount";
                                            $getWinSum = $dd->getSum($table,$clm,$condition);

                                            $clm = "amount";
                                            $getAmountSum = $dd->getSum($table,$clm,$condition);
                                            
                                           @ $bigWinAmount = $getWinSum['data'][0];
                                           @ $biglamount = $getAmountSum['data'][0];
                                        }


                                        if($num == "red")
                                        {
                                            $table = "wingo_order_details";
                                            $condition = " where select_number='$num' AND game_number='$gmnumber' AND status='pending'";
                                            $clm = "winAmount";
                                            $getWinSum = $dd->getSum($table,$clm,$condition);

                                            $clm = "amount";
                                            $getAmountSum = $dd->getSum($table,$clm,$condition);
                                            
                                           @ $redWinAmount = $getWinSum['data'][0];
                                           @ $redamount = $getAmountSum['data'][0];
                                        }


                                        if($num == "green")
                                        {
                                            $table = "wingo_order_details";
                                            $condition = " where select_number='$num' AND game_number='$gmnumber' AND status='pending'";
                                            $clm = "winAmount";
                                            $getWinSum = $dd->getSum($table,$clm,$condition);

                                            $clm = "amount";
                                            $getAmountSum = $dd->getSum($table,$clm,$condition);
                                            
                                            
                                           @ $greenWinAmount = $getWinSum['data'][0];
                                           @ $greenamount = $getAmountSum['data'][0];
                                        }


                                        if($num == "violet")
                                        {
                                            $table = "wingo_order_details";
                                            $condition = " where select_number='$num' AND game_number='$gmnumber' AND status='pending'";
                                            $clm = "winAmount";
                                            $getWinSum = $dd->getSum($table,$clm,$condition);

                                            $clm = "amount";
                                            $getAmountSum = $dd->getSum($table,$clm,$condition);
                                            
                                            
                                           @ $violetWinAmount = $getWinSum['data'][0];
                                           @ $violetamount = $getAmountSum['data'][0];
                                        }



                                        if($num == 0){
                                            $table = "wingo_order_details";
                                            $condition = " where select_number='$num' AND game_number='$gmnumber' AND status='pending'";
                                            $clm = "winAmount";
                                            $getWinSum = $dd->getSum($table,$clm,$condition);

                                            $clm = "amount";
                                            $getAmountSum = $dd->getSum($table,$clm,$condition);
                                            
                                            
                                          @  $winAmount = $getWinSum['data'][0]+$violetWinAmount+$redWinAmount+$smallWinAmount;
                                          @  $amount = $getAmountSum['data'][0]+$violetamount+$redamount+$smallamount;
                                        }


                                        if($num == 1){
                                            
                                            $table = "wingo_order_details";
                                            $condition = " where select_number='$num' AND game_number='$gmnumber' AND status='pending'";
                                            $clm = "winAmount";
                                            $getWinSum = $dd->getSum($table,$clm,$condition);

                                            $clm = "amount";
                                            $getAmountSum = $dd->getSum($table,$clm,$condition);
                                            
                                            
                                           @ $winAmount = $getWinSum['data'][0]+$redWinAmount+$smallWinAmount;
                                           @ $amount = $getAmountSum['data'][0]+$redamount+$smallamount;
                                        }
                                        
                                        

                                        if($num == 2){
                                            $table = "wingo_order_details";
                                            $condition = " where select_number='$num' AND game_number='$gmnumber' AND status='pending'";
                                            $clm = "winAmount";
                                            $getWinSum = $dd->getSum($table,$clm,$condition);

                                            $clm = "amount";
                                            $getAmountSum = $dd->getSum($table,$clm,$condition);
                                            
                                            
                                           @ $winAmount = $getWinSum['data'][0]+$greenWinAmount+$smallWinAmount;
                                           @ $amount = $getAmountSum['data'][0]+$greenamount+$smallamount;
                                        }


                                        if($num == 3){
                                            $table = "wingo_order_details";
                                            $condition = " where select_number='$num' AND game_number='$gmnumber' AND status='pending'";
                                            $clm = "winAmount";
                                            $getWinSum = $dd->getSum($table,$clm,$condition);

                                            $clm = "amount";
                                            $getAmountSum = $dd->getSum($table,$clm,$condition);
                                            
                                            
                                           @ $winAmount = $getWinSum['data'][0]+$redWinAmount+$smallWinAmount;
                                           @ $amount = $getAmountSum['data'][0]+$redamount+$smallamount;
                                        }


                                        if($num == 4){
                                            $table = "wingo_order_details";
                                            $condition = " where select_number='$num' AND game_number='$gmnumber' AND status='pending'";
                                            $clm = "winAmount";
                                            $getWinSum = $dd->getSum($table,$clm,$condition);

                                            $clm = "amount";
                                            $getAmountSum = $dd->getSum($table,$clm,$condition);
                                            
                                            
                                           @ $winAmount = $getWinSum['data'][0]+$greenWinAmount+$smallWinAmount;
                                           @ $amount = $getAmountSum['data'][0]+$greenamount+$smallamount;
                                        }


                                        if($num == 5){
                                            $table = "wingo_order_details";
                                            $condition = " where select_number='$num' AND game_number='$gmnumber' AND status='pending'";
                                            $clm = "winAmount";
                                            $getWinSum = $dd->getSum($table,$clm,$condition);

                                            $clm = "amount";
                                            $getAmountSum = $dd->getSum($table,$clm,$condition);
                                            
                                           @ $winAmount = $getWinSum['data'][0]+$greenWinAmount+$violetWinAmount+$bigWinAmount;
                                           @ $amount = $getAmountSum['data'][0]+$greenamount+$violetamount+$biglamount;
                                        }


                                        if($num == 6){
                                            $table = "wingo_order_details";
                                            $condition = " where select_number='$num' AND game_number='$gmnumber' AND status='pending'";
                                            $clm = "winAmount";
                                            $getWinSum = $dd->getSum($table,$clm,$condition);

                                            $clm = "amount";
                                            $getAmountSum = $dd->getSum($table,$clm,$condition);
                                            
                                            
                                           @ $winAmount = $getWinSum['data'][0]+$redWinAmount+$bigWinAmount;
                                           @ $amount = $getAmountSum['data'][0]+$redamount+$biglamount;
                                        }


                                        if($num == 7){
                                            $table = "wingo_order_details";
                                            $condition = " where select_number='$num' AND game_number='$gmnumber' AND status='pending'";
                                            $clm = "winAmount";
                                            $getWinSum = $dd->getSum($table,$clm,$condition);

                                            $clm = "amount";
                                            $getAmountSum = $dd->getSum($table,$clm,$condition);
                                            
                                            
                                           @ $winAmount = $getWinSum['data'][0]+$greenWinAmount+$bigWinAmount;
                                           @ $amount = $getAmountSum['data'][0]+$greenamount+$biglamount;
                                        }


                                        if($num == 8){
                                            $table = "wingo_order_details";
                                            $condition = " where select_number='$num' AND game_number='$gmnumber' AND status='pending'";
                                            $clm = "winAmount";
                                            $getWinSum = $dd->getSum($table,$clm,$condition);

                                            $clm = "amount";
                                            $getAmountSum = $dd->getSum($table,$clm,$condition);
                                            
                                            
                                           @ $winAmount = $getWinSum['data'][0]+$redWinAmount+$bigWinAmount;
                                           @ $amount = $getAmountSum['data'][0]+$redamount+$biglamount;
                                        }

                                        if($num == 9){
                                            $table = "wingo_order_details";
                                            $condition = " where select_number='$num' AND game_number='$gmnumber' AND status='pending'";
                                            $clm = "winAmount";
                                            $getWinSum = $dd->getSum($table,$clm,$condition);

                                            $clm = "amount";
                                            $getAmountSum = $dd->getSum($table,$clm,$condition);
                                            
                                            
                                           @ $winAmount = $getWinSum['data'][0]+$greenWinAmount+$bigWinAmount;
                                            @$amount = $getAmountSum['data'][0]+$greenamount+$biglamount;
                                        }

                                        if($i>=0 AND $i<=9){
                                    ?>
                                     <tr>
                                        <td><?= $i; ?></td>
                                        <td><?= $getRuningDetails['periods']; ?></td>
                                        <td><?= $num; ?></td>
                                        <td><?= $amount; ?></td>
                                        <td><?= $winAmount; ?></td>
                                        <td><button style="background:<?= $clr; ?>" onclick="selectManualResult(<?= $i; ?>)">Select Result</buton></td>
                                    </tr> 

                                    <?php } }?>
                                    
                                    <?php
                                      $table = "wingo_order_details";
                                      $condition = " where status='pending' AND select_number='small' OR select_number='big' OR select_number='red' OR select_number='green' OR select_number='voilet'";
                                      $getExtra = $dd->fetch_multi($table,$condition);
                                      foreach($getExtra as $key){
                                          if($key->status == "pending" AND $key->periods==$prds){
                                    ?>
                                    
                                     <tr>
                                        <td><?= $i; ?></td>
                                        <td><?= $key->periods; ?></td>
                                        <td><?= $key->select_number; ?></td>
                                        <td><?= $key->amount; ?></td>
                                        <td><?= $key->winAmount; ?></td>
                                        <td><button disabled style="background:<?= $clr; ?>" onclick="selectManualResult(<?= $i; ?>)">Select Result</buton></td>
                                    </tr> 
                                    
                                    
                                    <?php }} ?>
                                 </table>
                                 <?php } ?>




                                 
                                  <?php if(@$_REQUEST['iid'] == "2"){ ?>
                                  <table class="table table-bordered data-table" style="margin-top:30px;">
                                    <tr>
                                        <th colspan="5px"> <input onclick="selectGameType('1')" type="radio" name="k3games" id="gameType1" /> 1min K3  
                                                           <input onclick="selectGameType('2')" type="radio" name="k3games" id="gameType2" style="margin-left:30px;"/> 3min K3
                                                           <input onclick="selectGameType('3')" type="radio" name="k3games" id="gameType3" style="margin-left:30px;"/> 5min K3
                                                           <input onclick="selectGameType('4')" type="radio" name="k3games" id="gameType4" style="margin-left:30px;"/> 10min K3
                                                            
                                                           <input id="setGotiya1" maxlength="1" onkeyup="getNumberCustem('1')" style="margin-left:30px; width:60px;" placeholder="1-6"/>
                                                           <input id="setGotiya2" maxlength="1" onkeyup="getNumberCustem('2')" style="margin-left:10px; width:60px;" placeholder="1-6"/>
                                                           <input id="setGotiya3" maxlength="1" onkeyup="getNumberCustem('3')" style="margin-left:10px; width:60px;" placeholder="1-6"/>
                                                           <button onclick="updateManualGames()">Update</button>


                                                           <font style="float:right; margin-right:30px;">Manul Result : <?= $mResult; ?></font>
                                                        </th>
                                    </tr>
                                    <tr>
                                        <th>Sr</th>
                                        <th>Periods</th>
                                        <th>Selected Number</th>
                                        <th>Bet Amount</th>
                                    </tr>   

                                    <?php
                                     $gmnumber = $_REQUEST['game'];
                                     
                                     $table = "k3_game_runing";
                                     $condition = " where game_number='$gmnumber'";
                                     $getK3Periods = $dd->single($table,$condition);
                                     
                                     $table = "k3_game_calculation";
                                     $condition = " where game_number='$gmnumber'";
                                     $getBetDetails = $dd->fetch_multi($table,$condition);
                                     foreach($getBetDetails as $key){
                                        @$i++; 
                                    ?>
                                     <tr>
                                        <td><?= $i; ?></td>
                                        <td><?= $getK3Periods['periods']; ?></td>
                                        <td><?= $key->selected_number; ?></td>
                                        <td><?= $key->bitAmount; ?></td>
                                    </tr> 


                                    <?php } ?>
                                 </table>
                                 <?php } ?>
                              </div>
                          </div>

<script>

   function selectManualResult(a)
   {
        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('?iid='+<?= $_REQUEST['iid']; ?>+'&game='+<?= $_REQUEST['game']; ?>,'_self');
            }
            else{
                alert(myArr.remark);
            }
        }
        xhttp.open("GET", "update_wingo_manual_result.php?iid="+<?= $_REQUEST['game']; ?>+"&snumber="+a);
        xhttp.send();  
   }




   function getNumberCustem(a)
   {
      if(a=='1')
      {
         var f1number = document.getElementById('setGotiya1').value;
         if(f1number.length >=1){
         if(f1number=="1" ||f1number=="2" ||f1number=="3" ||f1number=="4" ||f1number=="5" ||f1number=="6")
         {

         }
         else{
            alert('Number Noth Match..!!');
            document.getElementById('setGotiya1').value = "";
         }
        }
      }



      if(a=='2')
      {
         var f1number = document.getElementById('setGotiya2').value;
         if(f1number.length >=1){
         if(f1number=="1" ||f1number=="2" ||f1number=="3" ||f1number=="4" ||f1number=="5" ||f1number=="6")
         {

         }
         else{
            alert('Number Noth Match..!!');
            document.getElementById('setGotiya2').value = "";
         }
        }
      }



      if(a=='3')
      {
         var f1number = document.getElementById('setGotiya3').value;
         if(f1number.length >=1){
         if(f1number=="1" ||f1number=="2" ||f1number=="3" ||f1number=="4" ||f1number=="5" ||f1number=="6")
         {

         }
         else{
            alert('Number Noth Match..!!');
            document.getElementById('setGotiya3').value = "";
         }
        }
      }
   }







function updateManualGames()
{
    var iid2 = <?= $_REQUEST['iid']; ?>;
    var gameNumber = <?= $_REQUEST['game']; ?>;
    var num1 = document.getElementById('setGotiya1').value;
    var num2 = document.getElementById('setGotiya2').value;
    var num3 = document.getElementById('setGotiya3').value;
    var snumber = document.getElementById('setGotiya1').value+","+document.getElementById('setGotiya2').value+","+document.getElementById('setGotiya3').value;
    

    if(num1 == "" || num2 == "" || num3 == "")
    {
        alert('Required Field..!!');
    }
    else{

        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('?iid='+iid2+'&game='+gameNumber,'_self');
            }
            else{
                alert(myArr.remark);
            }
        }
        xhttp.open("GET", "update_custem_result.php?gamenumber="+gameNumber+"&number="+snumber);
        xhttp.send();  


    }
    
}







        if(<?= $_REQUEST['game']; ?> == "1")
        {
            document.getElementById('gameType1').checked = true;
        }


        if(<?= $_REQUEST['game']; ?> == "2")
        {
            document.getElementById('gameType2').checked = true;
        }


        if(<?= $_REQUEST['game']; ?> == "3")
        {
            document.getElementById('gameType3').checked = true;
        }


        if(<?= $_REQUEST['game']; ?> == "4")
        {
            document.getElementById('gameType4').checked = true;
        }



        if(<?= $_REQUEST['iid']; ?> == "1")
        {
            document.getElementById('gamesActivation1').checked = true;
        }


        if(<?= $_REQUEST['iid']; ?> == "2")
        {
            document.getElementById('gamesActivation2').checked = true;
        }


        
        if(<?= $_REQUEST['iid']; ?> == "3")
        {
            document.getElementById('gamesActivation3').checked = true;
        }


        function selectGameType(a)
        {
            window.open('?iid='+<?= $_REQUEST['iid']; ?>+'&game='+a,'_self');
        }
     </script>




      </div>
      <!-- /.container-fluid-->
       </div>  <!-- /content-wrapper-->


                </div>
                </div>
             </div><!--Right panel-->
</div><!--Main-->


</body>
</html>

<script>
    function getLottryActivity(a)
    {
        window.open('?iid='+a+'&game=1','_self');
    }
</script>

<?php include "style.php" ?>

<script>
    function getAction(a)
    {
       window.open('funds_deposit_by_request.php?iid='+a,'_self');
    }
</script>